diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97699ccc4..2faf62100 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ on: jobs: lint: - timeout-minutes: 10 + timeout-minutes: 15 name: lint runs-on: ${{ github.repository == 'stainless-sdks/orb-kotlin' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} if: github.event_name == 'push' || github.event.pull_request.head.repo.fork @@ -36,8 +36,33 @@ jobs: - name: Run lints run: ./scripts/lint + + build: + timeout-minutes: 15 + name: build + runs-on: ${{ github.repository == 'stainless-sdks/orb-kotlin' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} + if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + + steps: + - uses: actions/checkout@v4 + + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: | + 8 + 21 + cache: gradle + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build SDK + run: ./scripts/build + test: - timeout-minutes: 10 + timeout-minutes: 15 name: test runs-on: ${{ github.repository == 'stainless-sdks/orb-kotlin' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} if: github.event_name == 'push' || github.event.pull_request.head.repo.fork diff --git a/.github/workflows/publish-sonatype.yml b/.github/workflows/publish-sonatype.yml index 0265f1b1c..9b8da594d 100644 --- a/.github/workflows/publish-sonatype.yml +++ b/.github/workflows/publish-sonatype.yml @@ -22,7 +22,7 @@ jobs: distribution: temurin java-version: | 8 - 17 + 21 cache: gradle - name: Set up Gradle @@ -33,7 +33,7 @@ jobs: export -- GPG_SIGNING_KEY_ID printenv -- GPG_SIGNING_KEY | gpg --batch --passphrase-fd 3 --import 3<<< "$GPG_SIGNING_PASSWORD" GPG_SIGNING_KEY_ID="$(gpg --with-colons --list-keys | awk -F : -- '/^pub:/ { getline; print "0x" substr($10, length($10) - 7) }')" - ./gradlew publishAndReleaseToMavenCentral -Dorg.gradle.jvmargs="-Xmx8g" --stacktrace -PmavenCentralUsername="$SONATYPE_USERNAME" -PmavenCentralPassword="$SONATYPE_PASSWORD" --no-configuration-cache + ./gradlew publishAndReleaseToMavenCentral --stacktrace -PmavenCentralUsername="$SONATYPE_USERNAME" -PmavenCentralPassword="$SONATYPE_PASSWORD" --no-configuration-cache env: SONATYPE_USERNAME: ${{ secrets.ORB_SONATYPE_USERNAME || secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.ORB_SONATYPE_PASSWORD || secrets.SONATYPE_PASSWORD }} diff --git a/.gitignore b/.gitignore index 4e81838d6..b1346e6d1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,6 @@ .gradle .idea .kotlin -build +build/ codegen.log kls_database.db diff --git a/.release-please-manifest.json b/.release-please-manifest.json index caf148712..de0960aba 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.11.0" + ".": "1.12.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index c03739d1c..b3a9d31c0 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/orb%2Forb-4f31d46f5ba187fc4d702c9f9f1573dacb891edbd086f935707578d7c4f5fed8.yml -openapi_spec_hash: 25b1019f20a47b8af665aae5f8fd0025 -config_hash: 5135e9237207028f293049a77428c775 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-59c57f1cbc067a477f6bf673882c28065e01418b86fcff390bba0d4438c58105.yml +openapi_spec_hash: 4da2681664f766985d1c20df40240cd9 +config_hash: 05c94c0e6dbeab2c9b554c2e0d6371a0 diff --git a/CHANGELOG.md b/CHANGELOG.md index c16efd4eb..bd61b2eed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,85 @@ # Changelog +## 1.12.0 (2025-12-18) + +Full Changelog: [v1.11.0...v1.12.0](https://github.com/orbcorp/orb-kotlin/compare/v1.11.0...v1.12.0) + +### ⚠ BREAKING CHANGES + +* **api:** define shared model ConversionRateConfig + +### Features + +* add retryable exception ([6bf3387](https://github.com/orbcorp/orb-kotlin/commit/6bf3387e9efe151b2db48c51a454f4ac9abb03e1)) +* **api:** api update ([e4e8d24](https://github.com/orbcorp/orb-kotlin/commit/e4e8d24b25879216965e7c55c5e23ab3bbbc69f8)) +* **api:** api update ([68203a3](https://github.com/orbcorp/orb-kotlin/commit/68203a34d2c36b47aecb227b408452f65f4db572)) +* **api:** api update ([012b348](https://github.com/orbcorp/orb-kotlin/commit/012b348959220609a650011f38e967b55aa6c906)) +* **api:** api update ([bbe220c](https://github.com/orbcorp/orb-kotlin/commit/bbe220c8813cd6a5c491da043f0b39cffe06edca)) +* **api:** api update ([cfe2c88](https://github.com/orbcorp/orb-kotlin/commit/cfe2c8868aead2144f69f0b04e304de948adbf8d)) +* **api:** api update ([74b29ea](https://github.com/orbcorp/orb-kotlin/commit/74b29eac5934c4d52380859df2df42a5c6b8db46)) +* **api:** api update ([af8a41f](https://github.com/orbcorp/orb-kotlin/commit/af8a41f71ca341c4ca6362158c555810a217ec49)) +* **api:** api update ([0f366e8](https://github.com/orbcorp/orb-kotlin/commit/0f366e8c6196b679186999278cb93686eda3c6a9)) +* **api:** api update ([2eb59cf](https://github.com/orbcorp/orb-kotlin/commit/2eb59cfcbe3b452746ef31a5f7c89f43276cffe5)) +* **api:** api update ([99993b1](https://github.com/orbcorp/orb-kotlin/commit/99993b17f65917b21e1f87b14699f5ac5cb63e1e)) +* **api:** api update ([914623a](https://github.com/orbcorp/orb-kotlin/commit/914623ae6f05e8ea28761331aba3b36676f10a99)) +* **api:** api update ([fd82100](https://github.com/orbcorp/orb-kotlin/commit/fd821005e293869c0199d3d5261f3a806df74e41)) +* **api:** api update ([9c2441e](https://github.com/orbcorp/orb-kotlin/commit/9c2441e3488e02d6e3f130dbbc1e1a9c821ac15d)) +* **api:** api update ([680265b](https://github.com/orbcorp/orb-kotlin/commit/680265b0add2f0c05eee02f1410cda5d14bd758b)) +* **api:** api update ([a1a92f4](https://github.com/orbcorp/orb-kotlin/commit/a1a92f48d35131e22f8e4e9ce51f6a31c8445277)) +* **api:** api update ([83ad00c](https://github.com/orbcorp/orb-kotlin/commit/83ad00cb56d547e695b01e7e02e923247856f3c8)) +* **api:** api update ([42c2d10](https://github.com/orbcorp/orb-kotlin/commit/42c2d10e801b46d82791cb26511cc237c5a9614a)) +* **api:** api update ([f6987c9](https://github.com/orbcorp/orb-kotlin/commit/f6987c9fd19277bfdb124bf896a74584ae69090b)) +* **api:** api update ([a58f47b](https://github.com/orbcorp/orb-kotlin/commit/a58f47b9e018a45680b2819cbc6ff9945779573d)) +* **api:** api update ([0285f3a](https://github.com/orbcorp/orb-kotlin/commit/0285f3a1dd36ff49e345c862ac5dd8e714019df1)) +* **api:** api update ([6d42811](https://github.com/orbcorp/orb-kotlin/commit/6d42811246f63cd57f9c2b9917a291ba9ef5b6ae)) +* **api:** api update ([93761f0](https://github.com/orbcorp/orb-kotlin/commit/93761f0a10e3a553c7ca56701f746de784ee2516)) +* **api:** api update ([4c2a026](https://github.com/orbcorp/orb-kotlin/commit/4c2a026cdd5327b5d58a42f2ae81975b5a8b6821)) +* **api:** api update ([11cfcca](https://github.com/orbcorp/orb-kotlin/commit/11cfcca024a9abce1fbe8d3097c3d3aeb66eee34)) +* **api:** api update ([a9326c1](https://github.com/orbcorp/orb-kotlin/commit/a9326c1fc925f51377493ccb1d50cdbcd444df07)) +* **api:** api update ([c427776](https://github.com/orbcorp/orb-kotlin/commit/c427776d050d0cc71128bbd7c1f985bf70df342c)) +* **api:** api update ([c4c96c6](https://github.com/orbcorp/orb-kotlin/commit/c4c96c6e42c74985376828b8efe6d03e0dcb91b5)) +* **api:** api update ([a05fab4](https://github.com/orbcorp/orb-kotlin/commit/a05fab462983dba1d6c3755e1e1a65d24a527f60)) +* **api:** api update ([d631c4d](https://github.com/orbcorp/orb-kotlin/commit/d631c4dd6dbf3657a11731eebdb772ed770ad154)) +* **api:** api update ([f06d033](https://github.com/orbcorp/orb-kotlin/commit/f06d033e7331f839b77ae33d33b878be2c797e5f)) +* **api:** api update ([e2b7b1e](https://github.com/orbcorp/orb-kotlin/commit/e2b7b1ee8a2594a363552c3289326b63a87112ec)) +* **api:** api update ([a790d45](https://github.com/orbcorp/orb-kotlin/commit/a790d458789e5a7336dc8510510b593b0d36ce73)) +* **api:** api update ([ee76ab8](https://github.com/orbcorp/orb-kotlin/commit/ee76ab871131d964501afbc390d2ba11595003bd)) +* **api:** api update ([6180a95](https://github.com/orbcorp/orb-kotlin/commit/6180a95d21214a3bf90989d6a80e55cf2c066fc8)) +* **api:** api update ([d43255b](https://github.com/orbcorp/orb-kotlin/commit/d43255b2f3030d1575c1c88898e1e1be202a13b6)) +* **api:** define shared model ConversionRateConfig ([32b3512](https://github.com/orbcorp/orb-kotlin/commit/32b35124936f5fea58bf91d92313b242f0d56e97)) +* **client:** ensure compat with proguard ([a21fc50](https://github.com/orbcorp/orb-kotlin/commit/a21fc50739926011c56bb30b47999d83bf7462e1)) +* **client:** expose sleeper option ([1bc7983](https://github.com/orbcorp/orb-kotlin/commit/1bc798369b1883ba86b50ac4829ccb9f5331bca5)) +* extract minimum composite to type ([c89ade2](https://github.com/orbcorp/orb-kotlin/commit/c89ade2708c48dfd327c4260ab1afe01e051e8c9)) + + +### Bug Fixes + +* **ci:** use java-version 21 for publish step ([efc7891](https://github.com/orbcorp/orb-kotlin/commit/efc789114af507dd96e591c18696a07dffad9af6)) +* **client:** deserialization of empty objects ([d4ef4ac](https://github.com/orbcorp/orb-kotlin/commit/d4ef4acd10993041451835b56cf0d1ce4d145f71)) +* **client:** ensure single timer is created per client ([1bc7983](https://github.com/orbcorp/orb-kotlin/commit/1bc798369b1883ba86b50ac4829ccb9f5331bca5)) +* **client:** incorrect `getPackageVersion` impl ([1612dd1](https://github.com/orbcorp/orb-kotlin/commit/1612dd121630d64f7d0ba6cfad7807e38765eda3)) +* **client:** multi-value header serialization ([bdc7d3a](https://github.com/orbcorp/orb-kotlin/commit/bdc7d3aa262fe9d79e9ce81dbc79b4ad7ac748eb)) +* **client:** r8 support ([4d46e62](https://github.com/orbcorp/orb-kotlin/commit/4d46e6201e6bf0a1963f05e3982ecc97bcb9519c)) +* **schema:** Rename unit price type to avoid naming conflict ([25c6f8c](https://github.com/orbcorp/orb-kotlin/commit/25c6f8c58010e5c2dd909f8161c8fee5465f2847)) + + +### Chores + +* **internal:** bump ci test timeout ([c9b431a](https://github.com/orbcorp/orb-kotlin/commit/c9b431af1e09f27dd08de5d1b247b72f70d160ae)) +* **internal:** change some comment formatting ([537aba1](https://github.com/orbcorp/orb-kotlin/commit/537aba177c709243ce291115eb15e8c1fd0adfa4)) +* **internal:** codegen related update ([b0ad475](https://github.com/orbcorp/orb-kotlin/commit/b0ad475dd5023f009b7d8a9a111a1b09c2e9f433)) +* **internal:** codegen related update ([844eb52](https://github.com/orbcorp/orb-kotlin/commit/844eb52c3959f68a8c6230accf8e570edcd553e4)) +* **internal:** codegen related update ([3239df5](https://github.com/orbcorp/orb-kotlin/commit/3239df52ca72a667fccc76f7bdf4799644b8322b)) +* **internal:** codegen related update ([b604e38](https://github.com/orbcorp/orb-kotlin/commit/b604e38e11b64d22569de6c59c7e40c02e048b9e)) +* **internal:** codegen related update ([936fe66](https://github.com/orbcorp/orb-kotlin/commit/936fe660fab9ecefb656d1db54b3288ec14fb235)) +* **internal:** codegen related update ([d06f656](https://github.com/orbcorp/orb-kotlin/commit/d06f6564fcaeaf124295a7cc5db061e7092e4771)) +* **internal:** reduce proguard ci logging ([ba337ee](https://github.com/orbcorp/orb-kotlin/commit/ba337ee683dea8296441855e1c5583c86bfa7f04)) + + +### Documentation + +* remove `$` for better copy-pasteabality ([7e95cda](https://github.com/orbcorp/orb-kotlin/commit/7e95cda57ad7eef980190010d8c68db1fb7f9eb3)) + ## 1.11.0 (2025-07-26) Full Changelog: [v1.10.0...v1.11.0](https://github.com/orbcorp/orb-kotlin/compare/v1.10.0...v1.11.0) diff --git a/README.md b/README.md index a0e454c5b..5077e62fe 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.withorb.api/orb-kotlin)](https://central.sonatype.com/artifact/com.withorb.api/orb-kotlin/1.11.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.withorb.api/orb-kotlin)](https://central.sonatype.com/artifact/com.withorb.api/orb-kotlin/1.12.0) @@ -19,7 +19,7 @@ The REST API documentation can be found on [docs.withorb.com](https://docs.witho ### Gradle ```kotlin -implementation("com.withorb.api:orb-kotlin:1.11.0") +implementation("com.withorb.api:orb-kotlin:1.12.0") ``` ### Maven @@ -28,7 +28,7 @@ implementation("com.withorb.api:orb-kotlin:1.11.0") com.withorb.api orb-kotlin - 1.11.0 + 1.12.0 ``` @@ -229,6 +229,8 @@ The SDK throws custom unchecked exception types: - [`OrbIoException`](orb-kotlin-core/src/main/kotlin/com/withorb/api/errors/OrbIoException.kt): I/O networking errors. +- [`OrbRetryableException`](orb-kotlin-core/src/main/kotlin/com/withorb/api/errors/OrbRetryableException.kt): Generic error indicating a failure that could be retried by the client. + - [`OrbInvalidDataException`](orb-kotlin-core/src/main/kotlin/com/withorb/api/errors/OrbInvalidDataException.kt): Failure to interpret successfully parsed data. For example, when accessing a property that's supposed to be required, but the API unexpectedly omitted it from the response. - [`OrbException`](orb-kotlin-core/src/main/kotlin/com/withorb/api/errors/OrbException.kt): Base class for all exceptions. Most errors will result in one of the previously mentioned ones, but completely generic errors may be thrown using the base class. @@ -293,13 +295,13 @@ The SDK uses the standard [OkHttp logging interceptor](https://github.com/square Enable logging by setting the `ORB_LOG` environment variable to `info`: ```sh -$ export ORB_LOG=info +export ORB_LOG=info ``` Or to `debug` for more verbose logging: ```sh -$ export ORB_LOG=debug +export ORB_LOG=debug ``` ## Webhook Verification @@ -312,6 +314,12 @@ both of which will raise an error if the signature is invalid. Note that the `body` parameter must be the raw JSON string sent from the server (do not parse it first). The `.unwrap()` method can parse this JSON for you. +## ProGuard and R8 + +Although the SDK uses reflection, it is still usable with [ProGuard](https://github.com/Guardsquare/proguard) and [R8](https://developer.android.com/topic/performance/app-optimization/enable-app-optimization) because `orb-kotlin-core` is published with a [configuration file](orb-kotlin-core/src/main/resources/META-INF/proguard/orb-kotlin-core.pro) containing [keep rules](https://www.guardsquare.com/manual/configuration/usage). + +ProGuard and R8 should automatically detect and use the published rules, but you can also manually copy the keep rules if necessary. + ## Jackson The SDK depends on [Jackson](https://github.com/FasterXML/jackson) for JSON serialization/deserialization. It is compatible with version 2.13.4 or higher, but depends on version 2.18.2 by default. diff --git a/build.gradle.kts b/build.gradle.kts index 26526fba0..4fd74a10b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,16 @@ allprojects { group = "com.withorb.api" - version = "1.11.0" // x-release-please-version + version = "1.12.0" // x-release-please-version +} + +subprojects { + // These are populated with dependencies by `buildSrc` scripts. + tasks.register("format") { + group = "Verification" + description = "Formats all source files." + } + tasks.register("lint") { + group = "Verification" + description = "Verifies all source files are formatted." + } } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 778c89de5..c6dc92ec5 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -10,7 +10,6 @@ repositories { } dependencies { - implementation("com.diffplug.spotless:spotless-plugin-gradle:7.0.2") implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20") implementation("com.vanniktech:gradle-maven-publish-plugin:0.28.0") } diff --git a/buildSrc/src/main/kotlin/orb.java.gradle.kts b/buildSrc/src/main/kotlin/orb.java.gradle.kts index dfbacb86e..70fc33f41 100644 --- a/buildSrc/src/main/kotlin/orb.java.gradle.kts +++ b/buildSrc/src/main/kotlin/orb.java.gradle.kts @@ -1,24 +1,13 @@ -import com.diffplug.gradle.spotless.SpotlessExtension import org.gradle.api.tasks.testing.logging.TestExceptionFormat plugins { `java-library` - id("com.diffplug.spotless") } repositories { mavenCentral() } -configure { - java { - importOrder() - removeUnusedImports() - palantirJavaFormat() - toggleOffOn() - } -} - java { toolchain { languageVersion.set(JavaLanguageVersion.of(21)) @@ -53,3 +42,86 @@ tasks.withType().configureEach { exceptionFormat = TestExceptionFormat.FULL } } + +val palantir by configurations.creating +dependencies { + palantir("com.palantir.javaformat:palantir-java-format:2.73.0") +} + +fun registerPalantir( + name: String, + description: String, +) { + val javaName = "${name}Java" + tasks.register(javaName) { + group = "Verification" + this.description = description + + classpath = palantir + mainClass = "com.palantir.javaformat.java.Main" + + // Avoid an `IllegalAccessError` on Java 9+. + jvmArgs( + "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + "--add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", + "--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + ) + + // Use paths relative to the current module. + val argumentFile = + project.layout.buildDirectory.file("palantir-$name-args.txt").get().asFile + val lastRunTimeFile = + project.layout.buildDirectory.file("palantir-$name-last-run.txt").get().asFile + + // Read the time when this task was last executed for this module (if ever). + val lastRunTime = lastRunTimeFile.takeIf { it.exists() }?.readText()?.toLongOrNull() ?: 0L + + // Use a `fileTree` relative to the module's source directory. + val javaFiles = project.fileTree("src") { include("**/*.java") } + + // Determine if any files need to be formatted or linted and continue only if there is at least + // one file. + onlyIf { javaFiles.any { it.lastModified() > lastRunTime } } + + inputs.files(javaFiles) + + doFirst { + // Create the argument file and set the preferred formatting style. + argumentFile.parentFile.mkdirs() + argumentFile.writeText("--palantir\n") + + if (name == "lint") { + // For lint, do a dry run, so no files are modified. Set the exit code to 1 (instead of + // the default 0) if any files need to be formatted, indicating that linting has failed. + argumentFile.appendText("--dry-run\n") + argumentFile.appendText("--set-exit-if-changed\n") + } else { + // `--dry-run` and `--replace` (for in-place formatting) are mutually exclusive. + argumentFile.appendText("--replace\n") + } + + // Write the modified files to the argument file. + javaFiles.filter { it.lastModified() > lastRunTime } + .forEach { argumentFile.appendText("${it.absolutePath}\n") } + } + + doLast { + // Record the last execution time for later up-to-date checking. + lastRunTimeFile.writeText(System.currentTimeMillis().toString()) + } + + // Pass the argument file using the @ symbol + args = listOf("@${argumentFile.absolutePath}") + + outputs.upToDateWhen { javaFiles.none { it.lastModified() > lastRunTime } } + } + + tasks.named(name) { + dependsOn(tasks.named(javaName)) + } +} + +registerPalantir(name = "format", description = "Formats all Java source files.") +registerPalantir(name = "lint", description = "Verifies all Java source files are formatted.") diff --git a/buildSrc/src/main/kotlin/orb.kotlin.gradle.kts b/buildSrc/src/main/kotlin/orb.kotlin.gradle.kts index 2d4a5c55c..b908b3bed 100644 --- a/buildSrc/src/main/kotlin/orb.kotlin.gradle.kts +++ b/buildSrc/src/main/kotlin/orb.kotlin.gradle.kts @@ -1,4 +1,3 @@ -import com.diffplug.gradle.spotless.SpotlessExtension import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.KotlinVersion @@ -7,6 +6,10 @@ plugins { kotlin("jvm") } +repositories { + mavenCentral() +} + kotlin { jvmToolchain { languageVersion.set(JavaLanguageVersion.of(21)) @@ -27,14 +30,77 @@ kotlin { } } -configure { - kotlin { - ktfmt().kotlinlangStyle() - toggleOffOn() - } -} - tasks.withType().configureEach { systemProperty("junit.jupiter.execution.parallel.enabled", true) systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent") } + +val ktfmt by configurations.creating +dependencies { + ktfmt("com.facebook:ktfmt:0.56") +} + +fun registerKtfmt( + name: String, + description: String, +) { + val kotlinName = "${name}Kotlin" + tasks.register(kotlinName) { + group = "Verification" + this.description = description + + classpath = ktfmt + mainClass = "com.facebook.ktfmt.cli.Main" + + // Use paths relative to the current module. + val argumentFile = project.layout.buildDirectory.file("ktfmt-$name-args.txt").get().asFile + val lastRunTimeFile = + project.layout.buildDirectory.file("ktfmt-$name-last-run.txt").get().asFile + + // Read the time when this task was last executed for this module (if ever). + val lastRunTime = lastRunTimeFile.takeIf { it.exists() }?.readText()?.toLongOrNull() ?: 0L + + // Use a `fileTree` relative to the module's source directory. + val kotlinFiles = project.fileTree("src") { include("**/*.kt") } + + // Determine if any files need to be formatted or linted and continue only if there is at least + // one file (otherwise Ktfmt will fail). + onlyIf { kotlinFiles.any { it.lastModified() > lastRunTime } } + + inputs.files(kotlinFiles) + + doFirst { + // Create the argument file and set the preferred formatting style. + argumentFile.parentFile.mkdirs() + argumentFile.writeText("--kotlinlang-style\n") + + if (name == "lint") { + // For lint, do a dry run, so no files are modified. Set the exit code to 1 (instead of + // the default 0) if any files need to be formatted, indicating that linting has failed. + argumentFile.appendText("--dry-run\n") + argumentFile.appendText("--set-exit-if-changed\n") + } + + // Write the modified files to the argument file. + kotlinFiles.filter { it.lastModified() > lastRunTime } + .forEach { argumentFile.appendText("${it.absolutePath}\n") } + } + + doLast { + // Record the last execution time for later up-to-date checking. + lastRunTimeFile.writeText(System.currentTimeMillis().toString()) + } + + // Pass the argument file using the @ symbol + args = listOf("@${argumentFile.absolutePath}") + + outputs.upToDateWhen { kotlinFiles.none { it.lastModified() > lastRunTime } } + } + + tasks.named(name) { + dependsOn(tasks.named(kotlinName)) + } +} + +registerKtfmt(name = "format", description = "Formats all Kotlin source files.") +registerKtfmt(name = "lint", description = "Verifies all Kotlin source files are formatted.") diff --git a/examples/.keep b/examples/.keep deleted file mode 100644 index d8c73e937..000000000 --- a/examples/.keep +++ /dev/null @@ -1,4 +0,0 @@ -File generated from our OpenAPI spec by Stainless. - -This directory can be used to store example files demonstrating usage of this SDK. -It is ignored by Stainless code generation and its content (other than this keep file) won't be touched. \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index ff76593f6..6680f9ce9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,12 +4,13 @@ org.gradle.parallel=true org.gradle.daemon=false # These options improve our compilation and test performance. They are inherited by the Kotlin daemon. org.gradle.jvmargs=\ - -Xms1g \ - -Xmx4g \ + -Xms2g \ + -Xmx8g \ -XX:+UseParallelGC \ -XX:InitialCodeCacheSize=256m \ -XX:ReservedCodeCacheSize=1G \ - -XX:MetaspaceSize=256m \ + -XX:MetaspaceSize=512m \ + -XX:MaxMetaspaceSize=2G \ -XX:TieredStopAtLevel=1 \ -XX:GCTimeRatio=4 \ -XX:CICompilerCount=4 \ diff --git a/orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OkHttpClient.kt b/orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OkHttpClient.kt index e11a7c94e..093faa347 100644 --- a/orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OkHttpClient.kt +++ b/orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OkHttpClient.kt @@ -117,19 +117,19 @@ class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpC val builder = Request.Builder().url(toUrl()).method(method.name, body) headers.names().forEach { name -> - headers.values(name).forEach { builder.header(name, it) } + headers.values(name).forEach { builder.addHeader(name, it) } } if ( !headers.names().contains("X-Stainless-Read-Timeout") && client.readTimeoutMillis != 0 ) { - builder.header( + builder.addHeader( "X-Stainless-Read-Timeout", Duration.ofMillis(client.readTimeoutMillis.toLong()).seconds.toString(), ) } if (!headers.names().contains("X-Stainless-Timeout") && client.callTimeoutMillis != 0) { - builder.header( + builder.addHeader( "X-Stainless-Timeout", Duration.ofMillis(client.callTimeoutMillis.toLong()).seconds.toString(), ) diff --git a/orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt b/orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt index 13caa41b5..b9706f4b6 100644 --- a/orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt +++ b/orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.json.JsonMapper import com.withorb.api.client.OrbClient import com.withorb.api.client.OrbClientImpl import com.withorb.api.core.ClientOptions +import com.withorb.api.core.Sleeper import com.withorb.api.core.Timeout import com.withorb.api.core.http.Headers import com.withorb.api.core.http.HttpClient @@ -103,6 +104,17 @@ class OrbOkHttpClient private constructor() { */ fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) } + /** + * The interface to use for delaying execution, like during retries. + * + * This is primarily useful for using fake delays in tests. + * + * Defaults to real execution delays. + * + * This class takes ownership of the sleeper and closes it when closed. + */ + fun sleeper(sleeper: Sleeper) = apply { clientOptions.sleeper(sleeper) } + /** * The clock to use for operations that require timing, like retries. * diff --git a/orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt b/orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt index bb1291a78..c53344999 100644 --- a/orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt +++ b/orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.json.JsonMapper import com.withorb.api.client.OrbClientAsync import com.withorb.api.client.OrbClientAsyncImpl import com.withorb.api.core.ClientOptions +import com.withorb.api.core.Sleeper import com.withorb.api.core.Timeout import com.withorb.api.core.http.Headers import com.withorb.api.core.http.HttpClient @@ -103,6 +104,17 @@ class OrbOkHttpClientAsync private constructor() { */ fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) } + /** + * The interface to use for delaying execution, like during retries. + * + * This is primarily useful for using fake delays in tests. + * + * Defaults to real execution delays. + * + * This class takes ownership of the sleeper and closes it when closed. + */ + fun sleeper(sleeper: Sleeper) = apply { clientOptions.sleeper(sleeper) } + /** * The clock to use for operations that require timing, like retries. * diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/client/OrbClientAsyncImpl.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/client/OrbClientAsyncImpl.kt index f8e4e3018..33eade7ef 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/client/OrbClientAsyncImpl.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/client/OrbClientAsyncImpl.kt @@ -152,7 +152,7 @@ class OrbClientAsyncImpl(private val clientOptions: ClientOptions) : OrbClientAs override fun subscriptionChanges(): SubscriptionChangeServiceAsync = subscriptionChanges - override fun close() = clientOptions.httpClient.close() + override fun close() = clientOptions.close() class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : OrbClientAsync.WithRawResponse { diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/client/OrbClientImpl.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/client/OrbClientImpl.kt index c5937e469..3d8a11b6e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/client/OrbClientImpl.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/client/OrbClientImpl.kt @@ -145,7 +145,7 @@ class OrbClientImpl(private val clientOptions: ClientOptions) : OrbClient { override fun subscriptionChanges(): SubscriptionChangeService = subscriptionChanges - override fun close() = clientOptions.httpClient.close() + override fun close() = clientOptions.close() class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : OrbClient.WithRawResponse { diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt index b18610e24..64002c6f0 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt @@ -19,6 +19,8 @@ private constructor( * The HTTP client to use in the SDK. * * Use the one published in `orb-kotlin-client-okhttp` or implement your own. + * + * This class takes ownership of the client and closes it when closed. */ val httpClient: HttpClient, /** @@ -36,6 +38,16 @@ private constructor( * needs to be overridden. */ val jsonMapper: JsonMapper, + /** + * The interface to use for delaying execution, like during retries. + * + * This is primarily useful for using fake delays in tests. + * + * Defaults to real execution delays. + * + * This class takes ownership of the sleeper and closes it when closed. + */ + val sleeper: Sleeper, /** * The clock to use for operations that require timing, like retries. * @@ -127,6 +139,7 @@ private constructor( private var httpClient: HttpClient? = null private var checkJacksonVersionCompatibility: Boolean = true private var jsonMapper: JsonMapper = jsonMapper() + private var sleeper: Sleeper? = null private var clock: Clock = Clock.systemUTC() private var baseUrl: String? = null private var headers: Headers.Builder = Headers.builder() @@ -141,6 +154,7 @@ private constructor( httpClient = clientOptions.originalHttpClient checkJacksonVersionCompatibility = clientOptions.checkJacksonVersionCompatibility jsonMapper = clientOptions.jsonMapper + sleeper = clientOptions.sleeper clock = clientOptions.clock baseUrl = clientOptions.baseUrl headers = clientOptions.headers.toBuilder() @@ -156,6 +170,8 @@ private constructor( * The HTTP client to use in the SDK. * * Use the one published in `orb-kotlin-client-okhttp` or implement your own. + * + * This class takes ownership of the client and closes it when closed. */ fun httpClient(httpClient: HttpClient) = apply { this.httpClient = PhantomReachableClosingHttpClient(httpClient) @@ -180,6 +196,17 @@ private constructor( */ fun jsonMapper(jsonMapper: JsonMapper) = apply { this.jsonMapper = jsonMapper } + /** + * The interface to use for delaying execution, like during retries. + * + * This is primarily useful for using fake delays in tests. + * + * Defaults to real execution delays. + * + * This class takes ownership of the sleeper and closes it when closed. + */ + fun sleeper(sleeper: Sleeper) = apply { this.sleeper = PhantomReachableSleeper(sleeper) } + /** * The clock to use for operations that require timing, like retries. * @@ -364,6 +391,7 @@ private constructor( */ fun build(): ClientOptions { val httpClient = checkRequired("httpClient", httpClient) + val sleeper = sleeper ?: PhantomReachableSleeper(DefaultSleeper()) val apiKey = checkRequired("apiKey", apiKey) val headers = Headers.builder() @@ -387,12 +415,14 @@ private constructor( httpClient, RetryingHttpClient.builder() .httpClient(httpClient) + .sleeper(sleeper) .clock(clock) .maxRetries(maxRetries) .idempotencyHeader("Idempotency-Key") .build(), checkJacksonVersionCompatibility, jsonMapper, + sleeper, clock, baseUrl, headers.build(), @@ -405,4 +435,19 @@ private constructor( ) } } + + /** + * Closes these client options, relinquishing any underlying resources. + * + * This is purposefully not inherited from [AutoCloseable] because the client options are + * long-lived and usually should not be synchronously closed via try-with-resources. + * + * It's also usually not necessary to call this method at all. the default client automatically + * releases threads and connections if they remain idle, but if you are writing an application + * that needs to aggressively release unused resources, then you may call this method. + */ + fun close() { + httpClient.close() + sleeper.close() + } } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/DefaultSleeper.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/DefaultSleeper.kt new file mode 100644 index 000000000..8222607cb --- /dev/null +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/DefaultSleeper.kt @@ -0,0 +1,14 @@ +package com.withorb.api.core + +import java.time.Duration +import kotlin.time.toKotlinDuration +import kotlinx.coroutines.delay + +class DefaultSleeper : Sleeper { + + override fun sleep(duration: Duration) = Thread.sleep(duration.toMillis()) + + override suspend fun sleepAsync(duration: Duration) = delay(duration.toKotlinDuration()) + + override fun close() {} +} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/PhantomReachableExecutorService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/PhantomReachableExecutorService.kt new file mode 100644 index 000000000..b4617be28 --- /dev/null +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/PhantomReachableExecutorService.kt @@ -0,0 +1,58 @@ +package com.withorb.api.core + +import java.util.concurrent.Callable +import java.util.concurrent.ExecutorService +import java.util.concurrent.Future +import java.util.concurrent.TimeUnit + +/** + * A delegating wrapper around an [ExecutorService] that shuts it down once it's only phantom + * reachable. + * + * This class ensures the [ExecutorService] is shut down even if the user forgets to do it. + */ +internal class PhantomReachableExecutorService(private val executorService: ExecutorService) : + ExecutorService { + init { + closeWhenPhantomReachable(this) { executorService.shutdown() } + } + + override fun execute(command: Runnable) = executorService.execute(command) + + override fun shutdown() = executorService.shutdown() + + override fun shutdownNow(): MutableList = executorService.shutdownNow() + + override fun isShutdown(): Boolean = executorService.isShutdown + + override fun isTerminated(): Boolean = executorService.isTerminated + + override fun awaitTermination(timeout: Long, unit: TimeUnit): Boolean = + executorService.awaitTermination(timeout, unit) + + override fun submit(task: Callable): Future = executorService.submit(task) + + override fun submit(task: Runnable, result: T): Future = + executorService.submit(task, result) + + override fun submit(task: Runnable): Future<*> = executorService.submit(task) + + override fun invokeAll( + tasks: MutableCollection> + ): MutableList> = executorService.invokeAll(tasks) + + override fun invokeAll( + tasks: MutableCollection>, + timeout: Long, + unit: TimeUnit, + ): MutableList> = executorService.invokeAll(tasks, timeout, unit) + + override fun invokeAny(tasks: MutableCollection>): T = + executorService.invokeAny(tasks) + + override fun invokeAny( + tasks: MutableCollection>, + timeout: Long, + unit: TimeUnit, + ): T = executorService.invokeAny(tasks, timeout, unit) +} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/PhantomReachableSleeper.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/PhantomReachableSleeper.kt new file mode 100644 index 000000000..f3742aa51 --- /dev/null +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/PhantomReachableSleeper.kt @@ -0,0 +1,21 @@ +package com.withorb.api.core + +import java.time.Duration + +/** + * A delegating wrapper around a [Sleeper] that closes it once it's only phantom reachable. + * + * This class ensures the [Sleeper] is closed even if the user forgets to do it. + */ +internal class PhantomReachableSleeper(private val sleeper: Sleeper) : Sleeper { + + init { + closeWhenPhantomReachable(this, sleeper) + } + + override fun sleep(duration: Duration) = sleeper.sleep(duration) + + override suspend fun sleepAsync(duration: Duration) = sleeper.sleepAsync(duration) + + override fun close() = sleeper.close() +} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Properties.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Properties.kt index 9045e4dbf..f0f63ba44 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Properties.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Properties.kt @@ -2,7 +2,7 @@ package com.withorb.api.core -import java.util.Properties +import com.withorb.api.client.OrbClient fun getOsArch(): String { val osArch = System.getProperty("os.arch") @@ -16,7 +16,7 @@ fun getOsArch(): String { "x86_64" -> "x64" "arm" -> "arm" "aarch64" -> "arm64" - else -> "other:${osArch}" + else -> "other:$osArch" } } @@ -30,13 +30,12 @@ fun getOsName(): String { osName.startsWith("Linux") -> "Linux" osName.startsWith("Mac OS") -> "MacOS" osName.startsWith("Windows") -> "Windows" - else -> "Other:${osName}" + else -> "Other:$osName" } } fun getOsVersion(): String = System.getProperty("os.version", "unknown") -fun getPackageVersion(): String = - Properties::class.java.`package`.implementationVersion ?: "unknown" +fun getPackageVersion(): String = OrbClient::class.java.`package`.implementationVersion ?: "unknown" fun getJavaVersion(): String = System.getProperty("java.version", "unknown") diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Sleeper.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Sleeper.kt new file mode 100644 index 000000000..ae005b7b9 --- /dev/null +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Sleeper.kt @@ -0,0 +1,17 @@ +package com.withorb.api.core + +import java.time.Duration + +/** + * An interface for delaying execution for a specified amount of time. + * + * Useful for testing and cleaning up resources. + */ +interface Sleeper : AutoCloseable { + + /** Synchronously pauses execution for the given [duration]. */ + fun sleep(duration: Duration) + + /** Asynchronously pauses execution for the given [duration]. */ + suspend fun sleepAsync(duration: Duration) +} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Timeout.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Timeout.kt index e5ed8356e..aa60df127 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Timeout.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Timeout.kt @@ -141,10 +141,14 @@ private constructor( return true } - return /* spotless:off */ other is Timeout && connect == other.connect && read == other.read && write == other.write && request == other.request /* spotless:on */ + return other is Timeout && + connect == other.connect && + read == other.read && + write == other.write && + request == other.request } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(connect, read, write, request) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(connect, read, write, request) override fun toString() = "Timeout{connect=$connect, read=$read, write=$write, request=$request}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Utils.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Utils.kt index 41ae5d3c4..597e7de7f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Utils.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/Utils.kt @@ -6,6 +6,7 @@ import com.withorb.api.core.http.Headers import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.SortedMap +import java.util.concurrent.locks.Lock internal fun T?.getOrThrow(name: String): T = this ?: throw OrbInvalidDataException("`${name}` is not present") @@ -87,3 +88,19 @@ internal fun Headers.getRequiredHeader(name: String): String = values(name).firstOrNull() ?: throw OrbInvalidDataException("Could not find $name header") internal interface Enum + +/** + * Executes a suspending block of code while holding this lock. + * + * @param T the return type of the action + * @param action the suspending function to execute while holding the lock + * @return the result of executing the action + */ +internal suspend fun Lock.withLockAsync(action: suspend () -> T): T { + lock() + return try { + action() + } finally { + unlock() + } +} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/http/RetryingHttpClient.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/http/RetryingHttpClient.kt index 738ddfbae..37aadd1df 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/http/RetryingHttpClient.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/core/http/RetryingHttpClient.kt @@ -1,8 +1,11 @@ package com.withorb.api.core.http +import com.withorb.api.core.DefaultSleeper import com.withorb.api.core.RequestOptions +import com.withorb.api.core.Sleeper import com.withorb.api.core.checkRequired import com.withorb.api.errors.OrbIoException +import com.withorb.api.errors.OrbRetryableException import java.io.IOException import java.time.Clock import java.time.Duration @@ -15,8 +18,6 @@ import java.util.concurrent.ThreadLocalRandom import java.util.concurrent.TimeUnit import kotlin.math.min import kotlin.math.pow -import kotlin.time.toKotlinDuration -import kotlinx.coroutines.delay class RetryingHttpClient private constructor( @@ -112,7 +113,10 @@ private constructor( } } - override fun close() = httpClient.close() + override fun close() { + httpClient.close() + sleeper.close() + } private fun isRetryable(request: HttpRequest): Boolean = // Some requests, such as when a request body is being streamed, cannot be retried because @@ -159,9 +163,10 @@ private constructor( } private fun shouldRetry(throwable: Throwable): Boolean = - // Only retry IOException and OrbIoException, other exceptions are not intended to be - // retried. - throwable is IOException || throwable is OrbIoException + // Only retry known retryable exceptions, other exceptions are not intended to be retried. + throwable is IOException || + throwable is OrbIoException || + throwable is OrbRetryableException private fun getRetryBackoffDuration(retries: Int, response: HttpResponse?): Duration { // About the Retry-After header: @@ -216,21 +221,14 @@ private constructor( class Builder internal constructor() { private var httpClient: HttpClient? = null - private var sleeper: Sleeper = - object : Sleeper { - - override fun sleep(duration: Duration) = Thread.sleep(duration.toMillis()) - - override suspend fun sleepAsync(duration: Duration) = - delay(duration.toKotlinDuration()) - } + private var sleeper: Sleeper? = null private var clock: Clock = Clock.systemUTC() private var maxRetries: Int = 2 private var idempotencyHeader: String? = null fun httpClient(httpClient: HttpClient) = apply { this.httpClient = httpClient } - internal fun sleeper(sleeper: Sleeper) = apply { this.sleeper = sleeper } + fun sleeper(sleeper: Sleeper) = apply { this.sleeper = sleeper } fun clock(clock: Clock) = apply { this.clock = clock } @@ -241,17 +239,10 @@ private constructor( fun build(): HttpClient = RetryingHttpClient( checkRequired("httpClient", httpClient), - sleeper, + sleeper ?: DefaultSleeper(), clock, maxRetries, idempotencyHeader, ) } - - internal interface Sleeper { - - fun sleep(duration: Duration) - - suspend fun sleepAsync(duration: Duration) - } } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/errors/OrbRetryableException.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/errors/OrbRetryableException.kt new file mode 100644 index 000000000..b775d950b --- /dev/null +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/errors/OrbRetryableException.kt @@ -0,0 +1,13 @@ +package com.withorb.api.errors + +/** + * Exception that indicates a transient error that can be retried. + * + * When this exception is thrown during an HTTP request, the SDK will automatically retry the + * request up to the maximum number of retries. + * + * @param message A descriptive error message + * @param cause The underlying cause of this exception, if any + */ +class OrbRetryableException constructor(message: String? = null, cause: Throwable? = null) : + OrbException(message, cause) diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AccountingProviderConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AccountingProviderConfig.kt index c88d31918..1883cd288 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AccountingProviderConfig.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AccountingProviderConfig.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class AccountingProviderConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val externalProviderId: JsonField, private val providerType: JsonField, @@ -203,12 +204,15 @@ private constructor( return true } - return /* spotless:off */ other is AccountingProviderConfig && externalProviderId == other.externalProviderId && providerType == other.providerType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AccountingProviderConfig && + externalProviderId == other.externalProviderId && + providerType == other.providerType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(externalProviderId, providerType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(externalProviderId, providerType, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Address.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Address.kt index 61ba0c965..932fcb73f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Address.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Address.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class Address +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val city: JsonField, private val country: JsonField, @@ -318,12 +319,19 @@ private constructor( return true } - return /* spotless:off */ other is Address && city == other.city && country == other.country && line1 == other.line1 && line2 == other.line2 && postalCode == other.postalCode && state == other.state && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Address && + city == other.city && + country == other.country && + line1 == other.line1 && + line2 == other.line2 && + postalCode == other.postalCode && + state == other.state && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(city, country, line1, line2, postalCode, state, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(city, country, line1, line2, postalCode, state, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AddressInput.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AddressInput.kt index b833dff70..a57985530 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AddressInput.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AddressInput.kt @@ -15,6 +15,7 @@ import java.util.Collections import java.util.Objects class AddressInput +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val city: JsonField, private val country: JsonField, @@ -293,12 +294,19 @@ private constructor( return true } - return /* spotless:off */ other is AddressInput && city == other.city && country == other.country && line1 == other.line1 && line2 == other.line2 && postalCode == other.postalCode && state == other.state && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AddressInput && + city == other.city && + country == other.country && + line1 == other.line1 && + line2 == other.line2 && + postalCode == other.postalCode && + state == other.state && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(city, country, line1, line2, postalCode, state, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(city, country, line1, line2, postalCode, state, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AdjustmentInterval.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AdjustmentInterval.kt index fde27ce87..e9ffe44d3 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AdjustmentInterval.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AdjustmentInterval.kt @@ -29,6 +29,7 @@ import java.util.Collections import java.util.Objects class AdjustmentInterval +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustment: JsonField, @@ -501,10 +502,16 @@ private constructor( return true } - return /* spotless:off */ other is Adjustment && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && percentageDiscount == other.percentageDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ + return other is Adjustment && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + percentageDiscount == other.percentageDiscount && + minimum == other.minimum && + maximum == other.maximum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(usageDiscount, amountDiscount, percentageDiscount, minimum, maximum) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(usageDiscount, amountDiscount, percentageDiscount, minimum, maximum) override fun toString(): String = when { @@ -638,12 +645,25 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentInterval && id == other.id && adjustment == other.adjustment && appliesToPriceIntervalIds == other.appliesToPriceIntervalIds && endDate == other.endDate && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AdjustmentInterval && + id == other.id && + adjustment == other.adjustment && + appliesToPriceIntervalIds == other.appliesToPriceIntervalIds && + endDate == other.endDate && + startDate == other.startDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustment, appliesToPriceIntervalIds, endDate, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustment, + appliesToPriceIntervalIds, + endDate, + startDate, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AffectedBlock.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AffectedBlock.kt index 11b10c291..61d4b9b19 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AffectedBlock.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AffectedBlock.kt @@ -6,20 +6,25 @@ 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.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.time.OffsetDateTime import java.util.Collections import java.util.Objects class AffectedBlock +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val expiryDate: JsonField, + private val filters: JsonField>, private val perUnitCostBasis: JsonField, private val additionalProperties: MutableMap, ) { @@ -30,10 +35,13 @@ private constructor( @JsonProperty("expiry_date") @ExcludeMissing expiryDate: JsonField = JsonMissing.of(), + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), @JsonProperty("per_unit_cost_basis") @ExcludeMissing perUnitCostBasis: JsonField = JsonMissing.of(), - ) : this(id, expiryDate, perUnitCostBasis, mutableMapOf()) + ) : this(id, expiryDate, filters, perUnitCostBasis, mutableMapOf()) /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -47,6 +55,12 @@ private constructor( */ fun expiryDate(): OffsetDateTime? = expiryDate.getNullable("expiry_date") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -69,6 +83,13 @@ private constructor( @ExcludeMissing fun _expiryDate(): JsonField = expiryDate + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters + /** * Returns the raw JSON value of [perUnitCostBasis]. * @@ -100,6 +121,7 @@ private constructor( * ```kotlin * .id() * .expiryDate() + * .filters() * .perUnitCostBasis() * ``` */ @@ -111,12 +133,14 @@ private constructor( private var id: JsonField? = null private var expiryDate: JsonField? = null + private var filters: JsonField>? = null private var perUnitCostBasis: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(affectedBlock: AffectedBlock) = apply { id = affectedBlock.id expiryDate = affectedBlock.expiryDate + filters = affectedBlock.filters.map { it.toMutableList() } perUnitCostBasis = affectedBlock.perUnitCostBasis additionalProperties = affectedBlock.additionalProperties.toMutableMap() } @@ -144,6 +168,31 @@ private constructor( this.expiryDate = expiryDate } + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + fun perUnitCostBasis(perUnitCostBasis: String?) = perUnitCostBasis(JsonField.ofNullable(perUnitCostBasis)) @@ -186,6 +235,7 @@ private constructor( * ```kotlin * .id() * .expiryDate() + * .filters() * .perUnitCostBasis() * ``` * @@ -195,6 +245,7 @@ private constructor( AffectedBlock( checkRequired("id", id), checkRequired("expiryDate", expiryDate), + checkRequired("filters", filters).map { it.toImmutable() }, checkRequired("perUnitCostBasis", perUnitCostBasis), additionalProperties.toMutableMap(), ) @@ -209,6 +260,7 @@ private constructor( id() expiryDate() + filters().forEach { it.validate() } perUnitCostBasis() validated = true } @@ -229,22 +281,556 @@ private constructor( internal fun validity(): Int = (if (id.asKnown() == null) 0 else 1) + (if (expiryDate.asKnown() == null) 0 else 1) + + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (perUnitCostBasis.asKnown() == null) 0 else 1) + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is AffectedBlock && id == other.id && expiryDate == other.expiryDate && perUnitCostBasis == other.perUnitCostBasis && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AffectedBlock && + id == other.id && + expiryDate == other.expiryDate && + filters == other.filters && + perUnitCostBasis == other.perUnitCostBasis && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, expiryDate, perUnitCostBasis, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, expiryDate, filters, perUnitCostBasis, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "AffectedBlock{id=$id, expiryDate=$expiryDate, perUnitCostBasis=$perUnitCostBasis, additionalProperties=$additionalProperties}" + "AffectedBlock{id=$id, expiryDate=$expiryDate, filters=$filters, perUnitCostBasis=$perUnitCostBasis, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AggregatedCost.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AggregatedCost.kt index 1ed38a320..9a1d32c42 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AggregatedCost.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AggregatedCost.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class AggregatedCost +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val perPriceCosts: JsonField>, private val subtotal: JsonField, @@ -327,12 +328,25 @@ private constructor( return true } - return /* spotless:off */ other is AggregatedCost && perPriceCosts == other.perPriceCosts && subtotal == other.subtotal && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && total == other.total && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AggregatedCost && + perPriceCosts == other.perPriceCosts && + subtotal == other.subtotal && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + total == other.total && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(perPriceCosts, subtotal, timeframeEnd, timeframeStart, total, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + perPriceCosts, + subtotal, + timeframeEnd, + timeframeStart, + total, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Alert.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Alert.kt index 08a5ca1fc..5f3c0a922 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Alert.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Alert.kt @@ -26,6 +26,7 @@ import java.util.Objects * Alerts created through the API can be scoped to either customers or subscriptions. */ class Alert +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val createdAt: JsonField, @@ -587,6 +588,7 @@ private constructor( /** The metric the alert applies to. */ class Metric + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val additionalProperties: MutableMap, @@ -724,12 +726,12 @@ private constructor( return true } - return /* spotless:off */ other is Metric && id == other.id && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metric && + id == other.id && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -738,6 +740,7 @@ private constructor( /** The plan the alert applies to. */ class Plan + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val externalPlanId: JsonField, @@ -1001,12 +1004,17 @@ private constructor( return true } - return /* spotless:off */ other is Plan && id == other.id && externalPlanId == other.externalPlanId && name == other.name && planVersion == other.planVersion && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Plan && + id == other.id && + externalPlanId == other.externalPlanId && + name == other.name && + planVersion == other.planVersion && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, externalPlanId, name, planVersion, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, externalPlanId, name, planVersion, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1149,7 +1157,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -1159,6 +1167,7 @@ private constructor( /** Alert status is used to determine if an alert is currently in-alert or not. */ class BalanceAlertStatus + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val inAlert: JsonField, private val thresholdValue: JsonField, @@ -1349,12 +1358,15 @@ private constructor( return true } - return /* spotless:off */ other is BalanceAlertStatus && inAlert == other.inAlert && thresholdValue == other.thresholdValue && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BalanceAlertStatus && + inAlert == other.inAlert && + thresholdValue == other.thresholdValue && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(inAlert, thresholdValue, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(inAlert, thresholdValue, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1367,12 +1379,37 @@ private constructor( return true } - return /* spotless:off */ other is Alert && id == other.id && createdAt == other.createdAt && currency == other.currency && customer == other.customer && enabled == other.enabled && metric == other.metric && plan == other.plan && subscription == other.subscription && thresholds == other.thresholds && type == other.type && balanceAlertStatus == other.balanceAlertStatus && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Alert && + id == other.id && + createdAt == other.createdAt && + currency == other.currency && + customer == other.customer && + enabled == other.enabled && + metric == other.metric && + plan == other.plan && + subscription == other.subscription && + thresholds == other.thresholds && + type == other.type && + balanceAlertStatus == other.balanceAlertStatus && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, createdAt, currency, customer, enabled, metric, plan, subscription, thresholds, type, balanceAlertStatus, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + currency, + customer, + enabled, + metric, + plan, + subscription, + thresholds, + type, + balanceAlertStatus, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertCreateForCustomerParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertCreateForCustomerParams.kt index 5caf6d7e4..1a5474c90 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertCreateForCustomerParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertCreateForCustomerParams.kt @@ -331,6 +331,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val currency: JsonField, private val type: JsonField, @@ -566,12 +567,16 @@ private constructor( return true } - return /* spotless:off */ other is Body && currency == other.currency && type == other.type && thresholds == other.thresholds && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + currency == other.currency && + type == other.type && + thresholds == other.thresholds && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(currency, type, thresholds, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(currency, type, thresholds, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -702,7 +707,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -715,10 +720,15 @@ private constructor( return true } - return /* spotless:off */ other is AlertCreateForCustomerParams && customerId == other.customerId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AlertCreateForCustomerParams && + customerId == other.customerId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(customerId, body, additionalHeaders, additionalQueryParams) override fun toString() = "AlertCreateForCustomerParams{customerId=$customerId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertCreateForExternalCustomerParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertCreateForExternalCustomerParams.kt index 0a34fcc70..4c85b34c6 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertCreateForExternalCustomerParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertCreateForExternalCustomerParams.kt @@ -337,6 +337,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val currency: JsonField, private val type: JsonField, @@ -572,12 +573,16 @@ private constructor( return true } - return /* spotless:off */ other is Body && currency == other.currency && type == other.type && thresholds == other.thresholds && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + currency == other.currency && + type == other.type && + thresholds == other.thresholds && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(currency, type, thresholds, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(currency, type, thresholds, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -708,7 +713,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -721,10 +726,15 @@ private constructor( return true } - return /* spotless:off */ other is AlertCreateForExternalCustomerParams && externalCustomerId == other.externalCustomerId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AlertCreateForExternalCustomerParams && + externalCustomerId == other.externalCustomerId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalCustomerId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(externalCustomerId, body, additionalHeaders, additionalQueryParams) override fun toString() = "AlertCreateForExternalCustomerParams{externalCustomerId=$externalCustomerId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertCreateForSubscriptionParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertCreateForSubscriptionParams.kt index 04771b7cc..d0130f701 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertCreateForSubscriptionParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertCreateForSubscriptionParams.kt @@ -338,6 +338,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val thresholds: JsonField>, private val type: JsonField, @@ -572,12 +573,16 @@ private constructor( return true } - return /* spotless:off */ other is Body && thresholds == other.thresholds && type == other.type && metricId == other.metricId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + thresholds == other.thresholds && + type == other.type && + metricId == other.metricId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(thresholds, type, metricId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(thresholds, type, metricId, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -702,7 +707,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -715,10 +720,15 @@ private constructor( return true } - return /* spotless:off */ other is AlertCreateForSubscriptionParams && subscriptionId == other.subscriptionId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AlertCreateForSubscriptionParams && + subscriptionId == other.subscriptionId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) override fun toString() = "AlertCreateForSubscriptionParams{subscriptionId=$subscriptionId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertDisableParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertDisableParams.kt index 6dc4a86e2..11e03283a 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertDisableParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertDisableParams.kt @@ -229,10 +229,22 @@ private constructor( return true } - return /* spotless:off */ other is AlertDisableParams && alertConfigurationId == other.alertConfigurationId && subscriptionId == other.subscriptionId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is AlertDisableParams && + alertConfigurationId == other.alertConfigurationId && + subscriptionId == other.subscriptionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(alertConfigurationId, subscriptionId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + alertConfigurationId, + subscriptionId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) override fun toString() = "AlertDisableParams{alertConfigurationId=$alertConfigurationId, subscriptionId=$subscriptionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertEnableParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertEnableParams.kt index a57c1d49c..d92459458 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertEnableParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertEnableParams.kt @@ -229,10 +229,22 @@ private constructor( return true } - return /* spotless:off */ other is AlertEnableParams && alertConfigurationId == other.alertConfigurationId && subscriptionId == other.subscriptionId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is AlertEnableParams && + alertConfigurationId == other.alertConfigurationId && + subscriptionId == other.subscriptionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(alertConfigurationId, subscriptionId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + alertConfigurationId, + subscriptionId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) override fun toString() = "AlertEnableParams{alertConfigurationId=$alertConfigurationId, subscriptionId=$subscriptionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListPage.kt index 684d17838..66c75b6b5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListPage.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is AlertListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is AlertListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "AlertListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListPageAsync.kt index e4e0ec4ba..1376c6cdf 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListPageAsync.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is AlertListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is AlertListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "AlertListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListPageResponse.kt index 7921cc09f..249d4fd9e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class AlertListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -214,12 +215,15 @@ private constructor( return true } - return /* spotless:off */ other is AlertListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AlertListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListParams.kt index 5adbae16b..fb18cf24b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertListParams.kt @@ -14,7 +14,7 @@ import java.util.Objects * * The request must specify one of `customer_id`, `external_customer_id`, or `subscription_id`. * - * If querying by subscripion_id, the endpoint will return the subscription level alerts as well as + * If querying by subscription_id, the endpoint will return the subscription level alerts as well as * the plan level alerts associated with the subscription. * * The list of alerts is ordered starting from the most recently created alert. This endpoint @@ -291,10 +291,34 @@ private constructor( return true } - return /* spotless:off */ other is AlertListParams && createdAtGt == other.createdAtGt && createdAtGte == other.createdAtGte && createdAtLt == other.createdAtLt && createdAtLte == other.createdAtLte && cursor == other.cursor && customerId == other.customerId && externalCustomerId == other.externalCustomerId && limit == other.limit && subscriptionId == other.subscriptionId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AlertListParams && + createdAtGt == other.createdAtGt && + createdAtGte == other.createdAtGte && + createdAtLt == other.createdAtLt && + createdAtLte == other.createdAtLte && + cursor == other.cursor && + customerId == other.customerId && + externalCustomerId == other.externalCustomerId && + limit == other.limit && + subscriptionId == other.subscriptionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(createdAtGt, createdAtGte, createdAtLt, createdAtLte, cursor, customerId, externalCustomerId, limit, subscriptionId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + createdAtGt, + createdAtGte, + createdAtLt, + createdAtLte, + cursor, + customerId, + externalCustomerId, + limit, + subscriptionId, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "AlertListParams{createdAtGt=$createdAtGt, createdAtGte=$createdAtGte, createdAtLt=$createdAtLt, createdAtLte=$createdAtLte, cursor=$cursor, customerId=$customerId, externalCustomerId=$externalCustomerId, limit=$limit, subscriptionId=$subscriptionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertRetrieveParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertRetrieveParams.kt index aa8516268..2a465a67b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertRetrieveParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertRetrieveParams.kt @@ -170,10 +170,13 @@ private constructor( return true } - return /* spotless:off */ other is AlertRetrieveParams && alertId == other.alertId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AlertRetrieveParams && + alertId == other.alertId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(alertId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(alertId, additionalHeaders, additionalQueryParams) override fun toString() = "AlertRetrieveParams{alertId=$alertId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertUpdateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertUpdateParams.kt index 9c3d35214..015670473 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertUpdateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AlertUpdateParams.kt @@ -269,6 +269,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val thresholds: JsonField>, private val additionalProperties: MutableMap, @@ -430,12 +431,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && thresholds == other.thresholds && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + thresholds == other.thresholds && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(thresholds, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -448,10 +449,15 @@ private constructor( return true } - return /* spotless:off */ other is AlertUpdateParams && alertConfigurationId == other.alertConfigurationId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AlertUpdateParams && + alertConfigurationId == other.alertConfigurationId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(alertConfigurationId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(alertConfigurationId, body, additionalHeaders, additionalQueryParams) override fun toString() = "AlertUpdateParams{alertConfigurationId=$alertConfigurationId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Allocation.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Allocation.kt index 4cea3f8d3..ae54b8ec3 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Allocation.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Allocation.kt @@ -6,20 +6,25 @@ 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.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class Allocation +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val allowsRollover: JsonField, private val currency: JsonField, private val customExpiration: JsonField, + private val filters: JsonField>, private val additionalProperties: MutableMap, ) { @@ -32,7 +37,8 @@ private constructor( @JsonProperty("custom_expiration") @ExcludeMissing customExpiration: JsonField = JsonMissing.of(), - ) : this(allowsRollover, currency, customExpiration, mutableMapOf()) + @JsonProperty("filters") @ExcludeMissing filters: JsonField> = JsonMissing.of(), + ) : this(allowsRollover, currency, customExpiration, filters, mutableMapOf()) /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -52,6 +58,12 @@ private constructor( */ fun customExpiration(): CustomExpiration? = customExpiration.getNullable("custom_expiration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun filters(): List? = filters.getNullable("filters") + /** * Returns the raw JSON value of [allowsRollover]. * @@ -78,6 +90,13 @@ private constructor( @ExcludeMissing fun _customExpiration(): JsonField = customExpiration + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -111,12 +130,14 @@ private constructor( private var allowsRollover: JsonField? = null private var currency: JsonField? = null private var customExpiration: JsonField? = null + private var filters: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(allocation: Allocation) = apply { allowsRollover = allocation.allowsRollover currency = allocation.currency customExpiration = allocation.customExpiration + filters = allocation.filters.map { it.toMutableList() } additionalProperties = allocation.additionalProperties.toMutableMap() } @@ -157,6 +178,31 @@ private constructor( this.customExpiration = customExpiration } + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -195,6 +241,7 @@ private constructor( checkRequired("allowsRollover", allowsRollover), checkRequired("currency", currency), checkRequired("customExpiration", customExpiration), + (filters ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toMutableMap(), ) } @@ -209,6 +256,7 @@ private constructor( allowsRollover() currency() customExpiration()?.validate() + filters()?.forEach { it.validate() } validated = true } @@ -228,22 +276,556 @@ private constructor( internal fun validity(): Int = (if (allowsRollover.asKnown() == null) 0 else 1) + (if (currency.asKnown() == null) 0 else 1) + - (customExpiration.asKnown()?.validity() ?: 0) + (customExpiration.asKnown()?.validity() ?: 0) + + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is Allocation && allowsRollover == other.allowsRollover && currency == other.currency && customExpiration == other.customExpiration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Allocation && + allowsRollover == other.allowsRollover && + currency == other.currency && + customExpiration == other.customExpiration && + filters == other.filters && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(allowsRollover, currency, customExpiration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(allowsRollover, currency, customExpiration, filters, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "Allocation{allowsRollover=$allowsRollover, currency=$currency, customExpiration=$customExpiration, additionalProperties=$additionalProperties}" + "Allocation{allowsRollover=$allowsRollover, currency=$currency, customExpiration=$customExpiration, filters=$filters, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AmendmentLedgerEntry.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AmendmentLedgerEntry.kt index 518f4f6d7..bf3f011b5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AmendmentLedgerEntry.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AmendmentLedgerEntry.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class AmendmentLedgerEntry +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, @@ -735,7 +736,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryStatus && value == other.value /* spotless:on */ + return other is EntryStatus && value == other.value } override fun hashCode() = value.hashCode() @@ -855,7 +856,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryType && value == other.value /* spotless:on */ + return other is EntryType && value == other.value } override fun hashCode() = value.hashCode() @@ -955,12 +956,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -972,12 +971,41 @@ private constructor( return true } - return /* spotless:off */ other is AmendmentLedgerEntry && id == other.id && amount == other.amount && createdAt == other.createdAt && creditBlock == other.creditBlock && currency == other.currency && customer == other.customer && description == other.description && endingBalance == other.endingBalance && entryStatus == other.entryStatus && entryType == other.entryType && ledgerSequenceNumber == other.ledgerSequenceNumber && metadata == other.metadata && startingBalance == other.startingBalance && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AmendmentLedgerEntry && + id == other.id && + amount == other.amount && + createdAt == other.createdAt && + creditBlock == other.creditBlock && + currency == other.currency && + customer == other.customer && + description == other.description && + endingBalance == other.endingBalance && + entryStatus == other.entryStatus && + entryType == other.entryType && + ledgerSequenceNumber == other.ledgerSequenceNumber && + metadata == other.metadata && + startingBalance == other.startingBalance && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, createdAt, creditBlock, currency, customer, description, endingBalance, entryStatus, entryType, ledgerSequenceNumber, metadata, startingBalance, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + createdAt, + creditBlock, + currency, + customer, + description, + endingBalance, + entryStatus, + entryType, + ledgerSequenceNumber, + metadata, + startingBalance, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AmountDiscount.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AmountDiscount.kt index 6fbf2c402..5bec912af 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AmountDiscount.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AmountDiscount.kt @@ -19,11 +19,12 @@ import java.util.Collections import java.util.Objects class AmountDiscount +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amountDiscount: JsonField, private val discountType: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val reason: JsonField, private val additionalProperties: MutableMap, ) { @@ -41,7 +42,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("reason") @ExcludeMissing reason: JsonField = JsonMissing.of(), ) : this(amountDiscount, discountType, appliesToPriceIds, filters, reason, mutableMapOf()) @@ -74,7 +75,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). */ - fun filters(): List? = filters.getNullable("filters") + fun filters(): List? = filters.getNullable("filters") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server @@ -115,9 +116,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [reason]. @@ -158,7 +157,7 @@ private constructor( private var amountDiscount: JsonField? = null private var discountType: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var reason: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -229,25 +228,25 @@ private constructor( } /** The filters that determine which prices to apply this discount to. */ - fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -455,7 +454,7 @@ private constructor( return true } - return /* spotless:off */ other is DiscountType && value == other.value /* spotless:on */ + return other is DiscountType && value == other.value } override fun hashCode() = value.hashCode() @@ -463,17 +462,558 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is AmountDiscount && amountDiscount == other.amountDiscount && discountType == other.discountType && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && reason == other.reason && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AmountDiscount && + amountDiscount == other.amountDiscount && + discountType == other.discountType && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + reason == other.reason && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amountDiscount, discountType, appliesToPriceIds, filters, reason, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amountDiscount, + discountType, + appliesToPriceIds, + filters, + reason, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AmountDiscountInterval.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AmountDiscountInterval.kt index 87da187c2..40d6c920e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AmountDiscountInterval.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/AmountDiscountInterval.kt @@ -20,12 +20,13 @@ import java.util.Collections import java.util.Objects class AmountDiscountInterval +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amountDiscount: JsonField, private val appliesToPriceIntervalIds: JsonField>, private val discountType: JsonField, private val endDate: JsonField, - private val filters: JsonField>, + private val filters: JsonField>, private val startDate: JsonField, private val additionalProperties: MutableMap, ) { @@ -46,7 +47,7 @@ private constructor( endDate: JsonField = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("start_date") @ExcludeMissing startDate: JsonField = JsonMissing.of(), @@ -97,7 +98,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** * The start date of the discount interval. @@ -147,9 +148,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [startDate]. @@ -197,7 +196,7 @@ private constructor( private var appliesToPriceIntervalIds: JsonField>? = null private var discountType: JsonField? = null private var endDate: JsonField? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var startDate: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -279,25 +278,25 @@ private constructor( fun endDate(endDate: JsonField) = apply { this.endDate = endDate } /** The filters that determine which prices this discount interval applies to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -516,7 +515,7 @@ private constructor( return true } - return /* spotless:off */ other is DiscountType && value == other.value /* spotless:on */ + return other is DiscountType && value == other.value } override fun hashCode() = value.hashCode() @@ -524,17 +523,560 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is AmountDiscountInterval && amountDiscount == other.amountDiscount && appliesToPriceIntervalIds == other.appliesToPriceIntervalIds && discountType == other.discountType && endDate == other.endDate && filters == other.filters && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AmountDiscountInterval && + amountDiscount == other.amountDiscount && + appliesToPriceIntervalIds == other.appliesToPriceIntervalIds && + discountType == other.discountType && + endDate == other.endDate && + filters == other.filters && + startDate == other.startDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amountDiscount, appliesToPriceIntervalIds, discountType, endDate, filters, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amountDiscount, + appliesToPriceIntervalIds, + discountType, + endDate, + filters, + startDate, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaCreatePlanVersionParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaCreatePlanVersionParams.kt index 1b81c066b..faf727254 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaCreatePlanVersionParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaCreatePlanVersionParams.kt @@ -15,6 +15,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.withorb.api.core.BaseDeserializer import com.withorb.api.core.BaseSerializer +import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing @@ -30,12 +31,7 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects -/** - * This API endpoint is in beta and its interface may change. It is recommended for use only in test - * mode. - * - * This endpoint allows the creation of a new plan version for an existing plan. - */ +/** This endpoint allows the creation of a new plan version for an existing plan. */ class BetaCreatePlanVersionParams private constructor( private val planId: String?, @@ -547,6 +543,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val version: JsonField, private val addAdjustments: JsonField>, @@ -1074,12 +1071,31 @@ private constructor( return true } - return /* spotless:off */ other is Body && version == other.version && addAdjustments == other.addAdjustments && addPrices == other.addPrices && removeAdjustments == other.removeAdjustments && removePrices == other.removePrices && replaceAdjustments == other.replaceAdjustments && replacePrices == other.replacePrices && setAsDefault == other.setAsDefault && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + version == other.version && + addAdjustments == other.addAdjustments && + addPrices == other.addPrices && + removeAdjustments == other.removeAdjustments && + removePrices == other.removePrices && + replaceAdjustments == other.replaceAdjustments && + replacePrices == other.replacePrices && + setAsDefault == other.setAsDefault && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(version, addAdjustments, addPrices, removeAdjustments, removePrices, replaceAdjustments, replacePrices, setAsDefault, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + version, + addAdjustments, + addPrices, + removeAdjustments, + removePrices, + replaceAdjustments, + replacePrices, + setAsDefault, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1088,6 +1104,7 @@ private constructor( } class AddAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val adjustment: JsonField, private val planPhaseOrder: JsonField, @@ -1505,10 +1522,16 @@ private constructor( return true } - return /* spotless:off */ other is Adjustment && percentageDiscount == other.percentageDiscount && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ + return other is Adjustment && + percentageDiscount == other.percentageDiscount && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + minimum == other.minimum && + maximum == other.maximum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) override fun toString(): String = when { @@ -1633,12 +1656,15 @@ private constructor( return true } - return /* spotless:off */ other is AddAdjustment && adjustment == other.adjustment && planPhaseOrder == other.planPhaseOrder && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AddAdjustment && + adjustment == other.adjustment && + planPhaseOrder == other.planPhaseOrder && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustment, planPhaseOrder, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(adjustment, planPhaseOrder, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1647,6 +1673,7 @@ private constructor( } class AddPrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val allocationPrice: JsonField, private val planPhaseOrder: JsonField, @@ -1682,7 +1709,7 @@ private constructor( fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") /** - * The price to add to the plan + * New plan price request body params. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1786,7 +1813,7 @@ private constructor( this.planPhaseOrder = planPhaseOrder } - /** The price to add to the plan */ + /** New plan price request body params. */ fun price(price: Price?) = price(JsonField.ofNullable(price)) /** @@ -1801,26 +1828,21 @@ private constructor( /** Alias for calling [price] with `Price.ofUnit(unit)`. */ fun price(unit: NewPlanUnitPrice) = price(Price.ofUnit(unit)) - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: NewPlanPackagePrice) = price(Price.ofPackage(package_)) - - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: NewPlanMatrixPrice) = price(Price.ofMatrix(matrix)) - /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ fun price(tiered: NewPlanTieredPrice) = price(Price.ofTiered(tiered)) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: NewPlanTieredBpsPrice) = price(Price.ofTieredBps(tieredBps)) + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: NewPlanBulkPrice) = price(Price.ofBulk(bulk)) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: NewPlanBpsPrice) = price(Price.ofBps(bps)) + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: NewPlanBulkBpsPrice) = price(Price.ofBulkBps(bulkBps)) + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: NewPlanPackagePrice) = price(Price.ofPackage(package_)) - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: NewPlanBulkPrice) = price(Price.ofBulk(bulk)) + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: NewPlanMatrixPrice) = price(Price.ofMatrix(matrix)) /** * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. @@ -1836,9 +1858,16 @@ private constructor( fun price(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = price(Price.ofTieredWithMinimum(tieredWithMinimum)) - /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ - fun price(unitWithPercent: NewPlanUnitWithPercentPrice) = - price(Price.ofUnitWithPercent(unitWithPercent)) + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: NewPlanGroupedTieredPrice) = + price(Price.ofGroupedTiered(groupedTiered)) + + /** + * Alias for calling [price] with + * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + */ + fun price(tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice) = + price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) /** * Alias for calling [price] with @@ -1847,10 +1876,20 @@ private constructor( fun price(packageWithAllocation: NewPlanPackageWithAllocationPrice) = price(Price.ofPackageWithAllocation(packageWithAllocation)) + /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ + fun price(unitWithPercent: NewPlanUnitWithPercentPrice) = + price(Price.ofUnitWithPercent(unitWithPercent)) + + /** + * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun price(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = + price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + /** * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. */ - fun price(tieredWithProration: NewPlanTierWithProrationPrice) = + fun price(tieredWithProration: Price.TieredWithProration) = price(Price.ofTieredWithProration(tieredWithProration)) /** Alias for calling [price] with `Price.ofUnitWithProration(unitWithProration)`. */ @@ -1861,6 +1900,10 @@ private constructor( fun price(groupedAllocation: NewPlanGroupedAllocationPrice) = price(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: NewPlanBulkWithProrationPrice) = + price(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [price] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -1875,6 +1918,13 @@ private constructor( fun price(groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice) = price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** * Alias for calling [price] with * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. @@ -1882,10 +1932,6 @@ private constructor( fun price(matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice) = price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: NewPlanBulkWithProrationPrice) = - price(Price.ofBulkWithProration(bulkWithProration)) - /** * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. */ @@ -1923,20 +1969,19 @@ private constructor( /** * Alias for calling [price] with - * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. */ - fun price(tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice) = - price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) - /** - * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. - */ - fun price(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = - price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: NewPlanMinimumCompositePrice) = price(Price.ofMinimum(minimum)) - /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: NewPlanGroupedTieredPrice) = - price(Price.ofGroupedTiered(groupedTiered)) + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -2003,31 +2048,33 @@ private constructor( (if (planPhaseOrder.asKnown() == null) 0 else 1) + (price.asKnown()?.validity() ?: 0) - /** The price to add to the plan */ + /** New plan price request body params. */ @JsonDeserialize(using = Price.Deserializer::class) @JsonSerialize(using = Price.Serializer::class) class Price private constructor( private val unit: NewPlanUnitPrice? = null, - private val package_: NewPlanPackagePrice? = null, - private val matrix: NewPlanMatrixPrice? = null, private val tiered: NewPlanTieredPrice? = null, - private val tieredBps: NewPlanTieredBpsPrice? = null, - private val bps: NewPlanBpsPrice? = null, - private val bulkBps: NewPlanBulkBpsPrice? = null, private val bulk: NewPlanBulkPrice? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: NewPlanPackagePrice? = null, + private val matrix: NewPlanMatrixPrice? = null, private val thresholdTotalAmount: NewPlanThresholdTotalAmountPrice? = null, private val tieredPackage: NewPlanTieredPackagePrice? = null, private val tieredWithMinimum: NewPlanTieredWithMinimumPrice? = null, - private val unitWithPercent: NewPlanUnitWithPercentPrice? = null, + private val groupedTiered: NewPlanGroupedTieredPrice? = null, + private val tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice? = null, private val packageWithAllocation: NewPlanPackageWithAllocationPrice? = null, - private val tieredWithProration: NewPlanTierWithProrationPrice? = null, + private val unitWithPercent: NewPlanUnitWithPercentPrice? = null, + private val matrixWithAllocation: NewPlanMatrixWithAllocationPrice? = null, + private val tieredWithProration: TieredWithProration? = null, private val unitWithProration: NewPlanUnitWithProrationPrice? = null, private val groupedAllocation: NewPlanGroupedAllocationPrice? = null, + private val bulkWithProration: NewPlanBulkWithProrationPrice? = null, private val groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice? = null, private val groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice? = null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, private val matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice? = null, - private val bulkWithProration: NewPlanBulkWithProrationPrice? = null, private val groupedTieredPackage: NewPlanGroupedTieredPackagePrice? = null, private val maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice? = null, private val scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice? = @@ -2036,27 +2083,24 @@ private constructor( NewPlanScalableMatrixWithTieredPricingPrice? = null, private val cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice? = null, - private val tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice? = null, - private val matrixWithAllocation: NewPlanMatrixWithAllocationPrice? = null, - private val groupedTiered: NewPlanGroupedTieredPrice? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: NewPlanMinimumCompositePrice? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, private val _json: JsonValue? = null, ) { fun unit(): NewPlanUnitPrice? = unit - fun package_(): NewPlanPackagePrice? = package_ - - fun matrix(): NewPlanMatrixPrice? = matrix - fun tiered(): NewPlanTieredPrice? = tiered - fun tieredBps(): NewPlanTieredBpsPrice? = tieredBps + fun bulk(): NewPlanBulkPrice? = bulk - fun bps(): NewPlanBpsPrice? = bps + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters - fun bulkBps(): NewPlanBulkBpsPrice? = bulkBps + fun package_(): NewPlanPackagePrice? = package_ - fun bulk(): NewPlanBulkPrice? = bulk + fun matrix(): NewPlanMatrixPrice? = matrix fun thresholdTotalAmount(): NewPlanThresholdTotalAmountPrice? = thresholdTotalAmount @@ -2064,25 +2108,35 @@ private constructor( fun tieredWithMinimum(): NewPlanTieredWithMinimumPrice? = tieredWithMinimum - fun unitWithPercent(): NewPlanUnitWithPercentPrice? = unitWithPercent + fun groupedTiered(): NewPlanGroupedTieredPrice? = groupedTiered + + fun tieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice? = + tieredPackageWithMinimum fun packageWithAllocation(): NewPlanPackageWithAllocationPrice? = packageWithAllocation - fun tieredWithProration(): NewPlanTierWithProrationPrice? = tieredWithProration + fun unitWithPercent(): NewPlanUnitWithPercentPrice? = unitWithPercent + + fun matrixWithAllocation(): NewPlanMatrixWithAllocationPrice? = matrixWithAllocation + + fun tieredWithProration(): TieredWithProration? = tieredWithProration fun unitWithProration(): NewPlanUnitWithProrationPrice? = unitWithProration fun groupedAllocation(): NewPlanGroupedAllocationPrice? = groupedAllocation + fun bulkWithProration(): NewPlanBulkWithProrationPrice? = bulkWithProration + fun groupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice? = groupedWithProratedMinimum fun groupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice? = groupedWithMeteredMinimum - fun matrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice? = matrixWithDisplayName + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = + groupedWithMinMaxThresholds - fun bulkWithProration(): NewPlanBulkWithProrationPrice? = bulkWithProration + fun matrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice? = matrixWithDisplayName fun groupedTieredPackage(): NewPlanGroupedTieredPackagePrice? = groupedTieredPackage @@ -2096,28 +2150,26 @@ private constructor( fun cumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice? = cumulativeGroupedBulk - fun tieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice? = - tieredPackageWithMinimum - - fun matrixWithAllocation(): NewPlanMatrixWithAllocationPrice? = matrixWithAllocation + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = + cumulativeGroupedAllocation - fun groupedTiered(): NewPlanGroupedTieredPrice? = groupedTiered + fun minimum(): NewPlanMinimumCompositePrice? = minimum - fun isUnit(): Boolean = unit != null + fun percent(): Percent? = percent - fun isPackage(): Boolean = package_ != null + fun eventOutput(): EventOutput? = eventOutput - fun isMatrix(): Boolean = matrix != null + fun isUnit(): Boolean = unit != null fun isTiered(): Boolean = tiered != null - fun isTieredBps(): Boolean = tieredBps != null + fun isBulk(): Boolean = bulk != null - fun isBps(): Boolean = bps != null + fun isBulkWithFilters(): Boolean = bulkWithFilters != null - fun isBulkBps(): Boolean = bulkBps != null + fun isPackage(): Boolean = package_ != null - fun isBulk(): Boolean = bulk != null + fun isMatrix(): Boolean = matrix != null fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null @@ -2125,23 +2177,31 @@ private constructor( fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null - fun isUnitWithPercent(): Boolean = unitWithPercent != null + fun isGroupedTiered(): Boolean = groupedTiered != null + + fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + fun isUnitWithPercent(): Boolean = unitWithPercent != null + + fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isTieredWithProration(): Boolean = tieredWithProration != null fun isUnitWithProration(): Boolean = unitWithProration != null fun isGroupedAllocation(): Boolean = groupedAllocation != null + fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null - fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null @@ -2154,27 +2214,25 @@ private constructor( fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null - fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null - - fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null - fun isGroupedTiered(): Boolean = groupedTiered != null + fun isMinimum(): Boolean = minimum != null - fun asUnit(): NewPlanUnitPrice = unit.getOrThrow("unit") + fun isPercent(): Boolean = percent != null - fun asPackage(): NewPlanPackagePrice = package_.getOrThrow("package_") + fun isEventOutput(): Boolean = eventOutput != null - fun asMatrix(): NewPlanMatrixPrice = matrix.getOrThrow("matrix") + fun asUnit(): NewPlanUnitPrice = unit.getOrThrow("unit") fun asTiered(): NewPlanTieredPrice = tiered.getOrThrow("tiered") - fun asTieredBps(): NewPlanTieredBpsPrice = tieredBps.getOrThrow("tieredBps") + fun asBulk(): NewPlanBulkPrice = bulk.getOrThrow("bulk") - fun asBps(): NewPlanBpsPrice = bps.getOrThrow("bps") + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") - fun asBulkBps(): NewPlanBulkBpsPrice = bulkBps.getOrThrow("bulkBps") + fun asPackage(): NewPlanPackagePrice = package_.getOrThrow("package_") - fun asBulk(): NewPlanBulkPrice = bulk.getOrThrow("bulk") + fun asMatrix(): NewPlanMatrixPrice = matrix.getOrThrow("matrix") fun asThresholdTotalAmount(): NewPlanThresholdTotalAmountPrice = thresholdTotalAmount.getOrThrow("thresholdTotalAmount") @@ -2185,13 +2243,22 @@ private constructor( fun asTieredWithMinimum(): NewPlanTieredWithMinimumPrice = tieredWithMinimum.getOrThrow("tieredWithMinimum") - fun asUnitWithPercent(): NewPlanUnitWithPercentPrice = - unitWithPercent.getOrThrow("unitWithPercent") + fun asGroupedTiered(): NewPlanGroupedTieredPrice = + groupedTiered.getOrThrow("groupedTiered") + + fun asTieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice = + tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") fun asPackageWithAllocation(): NewPlanPackageWithAllocationPrice = packageWithAllocation.getOrThrow("packageWithAllocation") - fun asTieredWithProration(): NewPlanTierWithProrationPrice = + fun asUnitWithPercent(): NewPlanUnitWithPercentPrice = + unitWithPercent.getOrThrow("unitWithPercent") + + fun asMatrixWithAllocation(): NewPlanMatrixWithAllocationPrice = + matrixWithAllocation.getOrThrow("matrixWithAllocation") + + fun asTieredWithProration(): TieredWithProration = tieredWithProration.getOrThrow("tieredWithProration") fun asUnitWithProration(): NewPlanUnitWithProrationPrice = @@ -2200,18 +2267,21 @@ private constructor( fun asGroupedAllocation(): NewPlanGroupedAllocationPrice = groupedAllocation.getOrThrow("groupedAllocation") + fun asBulkWithProration(): NewPlanBulkWithProrationPrice = + bulkWithProration.getOrThrow("bulkWithProration") + fun asGroupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice = groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") fun asGroupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice = groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") + fun asMatrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice = matrixWithDisplayName.getOrThrow("matrixWithDisplayName") - fun asBulkWithProration(): NewPlanBulkWithProrationPrice = - bulkWithProration.getOrThrow("bulkWithProration") - fun asGroupedTieredPackage(): NewPlanGroupedTieredPackagePrice = groupedTieredPackage.getOrThrow("groupedTieredPackage") @@ -2227,45 +2297,50 @@ private constructor( fun asCumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice = cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") - fun asTieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice = - tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") - fun asMatrixWithAllocation(): NewPlanMatrixWithAllocationPrice = - matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun asMinimum(): NewPlanMinimumCompositePrice = minimum.getOrThrow("minimum") - fun asGroupedTiered(): NewPlanGroupedTieredPrice = - groupedTiered.getOrThrow("groupedTiered") + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") fun _json(): JsonValue? = _json fun accept(visitor: Visitor): T = when { unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) thresholdTotalAmount != null -> visitor.visitThresholdTotalAmount(thresholdTotalAmount) tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) - unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + tieredPackageWithMinimum != null -> + visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) packageWithAllocation != null -> visitor.visitPackageWithAllocation(packageWithAllocation) + unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + matrixWithAllocation != null -> + visitor.visitMatrixWithAllocation(matrixWithAllocation) tieredWithProration != null -> visitor.visitTieredWithProration(tieredWithProration) unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedWithProratedMinimum != null -> visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) groupedWithMeteredMinimum != null -> visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) matrixWithDisplayName != null -> visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedTieredPackage != null -> visitor.visitGroupedTieredPackage(groupedTieredPackage) maxGroupTieredPackage != null -> @@ -2278,11 +2353,11 @@ private constructor( ) cumulativeGroupedBulk != null -> visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) - tieredPackageWithMinimum != null -> - visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) - matrixWithAllocation != null -> - visitor.visitMatrixWithAllocation(matrixWithAllocation) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) else -> visitor.unknown(_json) } @@ -2299,32 +2374,24 @@ private constructor( unit.validate() } - override fun visitPackage(package_: NewPlanPackagePrice) { - package_.validate() - } - - override fun visitMatrix(matrix: NewPlanMatrixPrice) { - matrix.validate() - } - override fun visitTiered(tiered: NewPlanTieredPrice) { tiered.validate() } - override fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice) { - tieredBps.validate() + override fun visitBulk(bulk: NewPlanBulkPrice) { + bulk.validate() } - override fun visitBps(bps: NewPlanBpsPrice) { - bps.validate() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() } - override fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice) { - bulkBps.validate() + override fun visitPackage(package_: NewPlanPackagePrice) { + package_.validate() } - override fun visitBulk(bulk: NewPlanBulkPrice) { - bulk.validate() + override fun visitMatrix(matrix: NewPlanMatrixPrice) { + matrix.validate() } override fun visitThresholdTotalAmount( @@ -2343,10 +2410,14 @@ private constructor( tieredWithMinimum.validate() } - override fun visitUnitWithPercent( - unitWithPercent: NewPlanUnitWithPercentPrice + override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) { + groupedTiered.validate() + } + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice ) { - unitWithPercent.validate() + tieredPackageWithMinimum.validate() } override fun visitPackageWithAllocation( @@ -2355,8 +2426,20 @@ private constructor( packageWithAllocation.validate() } + override fun visitUnitWithPercent( + unitWithPercent: NewPlanUnitWithPercentPrice + ) { + unitWithPercent.validate() + } + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ) { + matrixWithAllocation.validate() + } + override fun visitTieredWithProration( - tieredWithProration: NewPlanTierWithProrationPrice + tieredWithProration: TieredWithProration ) { tieredWithProration.validate() } @@ -2373,6 +2456,12 @@ private constructor( groupedAllocation.validate() } + override fun visitBulkWithProration( + bulkWithProration: NewPlanBulkWithProrationPrice + ) { + bulkWithProration.validate() + } + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice ) { @@ -2385,16 +2474,16 @@ private constructor( groupedWithMeteredMinimum.validate() } - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds ) { - matrixWithDisplayName.validate() + groupedWithMinMaxThresholds.validate() } - override fun visitBulkWithProration( - bulkWithProration: NewPlanBulkWithProrationPrice + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice ) { - bulkWithProration.validate() + matrixWithDisplayName.validate() } override fun visitGroupedTieredPackage( @@ -2428,20 +2517,22 @@ private constructor( cumulativeGroupedBulk.validate() } - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation ) { - tieredPackageWithMinimum.validate() + cumulativeGroupedAllocation.validate() } - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ) { - matrixWithAllocation.validate() + override fun visitMinimum(minimum: NewPlanMinimumCompositePrice) { + minimum.validate() } - override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) { - groupedTiered.validate() + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() } } ) @@ -2467,22 +2558,18 @@ private constructor( object : Visitor { override fun visitUnit(unit: NewPlanUnitPrice) = unit.validity() + override fun visitTiered(tiered: NewPlanTieredPrice) = tiered.validity() + + override fun visitBulk(bulk: NewPlanBulkPrice) = bulk.validity() + + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() + override fun visitPackage(package_: NewPlanPackagePrice) = package_.validity() override fun visitMatrix(matrix: NewPlanMatrixPrice) = matrix.validity() - override fun visitTiered(tiered: NewPlanTieredPrice) = tiered.validity() - - override fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice) = - tieredBps.validity() - - override fun visitBps(bps: NewPlanBpsPrice) = bps.validity() - - override fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice) = bulkBps.validity() - - override fun visitBulk(bulk: NewPlanBulkPrice) = bulk.validity() - override fun visitThresholdTotalAmount( thresholdTotalAmount: NewPlanThresholdTotalAmountPrice ) = thresholdTotalAmount.validity() @@ -2494,16 +2581,27 @@ private constructor( tieredWithMinimum: NewPlanTieredWithMinimumPrice ) = tieredWithMinimum.validity() - override fun visitUnitWithPercent( - unitWithPercent: NewPlanUnitWithPercentPrice - ) = unitWithPercent.validity() + override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = + groupedTiered.validity() + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ) = tieredPackageWithMinimum.validity() override fun visitPackageWithAllocation( packageWithAllocation: NewPlanPackageWithAllocationPrice ) = packageWithAllocation.validity() + override fun visitUnitWithPercent( + unitWithPercent: NewPlanUnitWithPercentPrice + ) = unitWithPercent.validity() + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ) = matrixWithAllocation.validity() + override fun visitTieredWithProration( - tieredWithProration: NewPlanTierWithProrationPrice + tieredWithProration: TieredWithProration ) = tieredWithProration.validity() override fun visitUnitWithProration( @@ -2514,6 +2612,10 @@ private constructor( groupedAllocation: NewPlanGroupedAllocationPrice ) = groupedAllocation.validity() + override fun visitBulkWithProration( + bulkWithProration: NewPlanBulkWithProrationPrice + ) = bulkWithProration.validity() + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice ) = groupedWithProratedMinimum.validity() @@ -2522,14 +2624,14 @@ private constructor( groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice ) = groupedWithMeteredMinimum.validity() + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + override fun visitMatrixWithDisplayName( matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice ) = matrixWithDisplayName.validity() - override fun visitBulkWithProration( - bulkWithProration: NewPlanBulkWithProrationPrice - ) = bulkWithProration.validity() - override fun visitGroupedTieredPackage( groupedTieredPackage: NewPlanGroupedTieredPackagePrice ) = groupedTieredPackage.validity() @@ -2551,16 +2653,17 @@ private constructor( cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice ) = cumulativeGroupedBulk.validity() - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ) = tieredPackageWithMinimum.validity() + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ) = matrixWithAllocation.validity() + override fun visitMinimum(minimum: NewPlanMinimumCompositePrice) = + minimum.validity() - override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = - groupedTiered.validity() + override fun visitPercent(percent: Percent) = percent.validity() + + override fun visitEventOutput(eventOutput: EventOutput) = + eventOutput.validity() override fun unknown(json: JsonValue?) = 0 } @@ -2571,38 +2674,107 @@ private constructor( return true } - return /* spotless:off */ other is Price && unit == other.unit && package_ == other.package_ && matrix == other.matrix && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && tieredWithMinimum == other.tieredWithMinimum && unitWithPercent == other.unitWithPercent && packageWithAllocation == other.packageWithAllocation && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && bulkWithProration == other.bulkWithProration && groupedTieredPackage == other.groupedTieredPackage && maxGroupTieredPackage == other.maxGroupTieredPackage && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk && tieredPackageWithMinimum == other.tieredPackageWithMinimum && matrixWithAllocation == other.matrixWithAllocation && groupedTiered == other.groupedTiered /* spotless:on */ + return other is Price && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, tieredWithMinimum, unitWithPercent, packageWithAllocation, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, groupedWithMeteredMinimum, matrixWithDisplayName, bulkWithProration, groupedTieredPackage, maxGroupTieredPackage, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk, tieredPackageWithMinimum, matrixWithAllocation, groupedTiered) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) override fun toString(): String = when { unit != null -> "Price{unit=$unit}" - package_ != null -> "Price{package_=$package_}" - matrix != null -> "Price{matrix=$matrix}" tiered != null -> "Price{tiered=$tiered}" - tieredBps != null -> "Price{tieredBps=$tieredBps}" - bps != null -> "Price{bps=$bps}" - bulkBps != null -> "Price{bulkBps=$bulkBps}" bulk != null -> "Price{bulk=$bulk}" + bulkWithFilters != null -> "Price{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "Price{package_=$package_}" + matrix != null -> "Price{matrix=$matrix}" thresholdTotalAmount != null -> "Price{thresholdTotalAmount=$thresholdTotalAmount}" tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" - unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" + tieredPackageWithMinimum != null -> + "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" packageWithAllocation != null -> "Price{packageWithAllocation=$packageWithAllocation}" + unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + matrixWithAllocation != null -> + "Price{matrixWithAllocation=$matrixWithAllocation}" tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedWithProratedMinimum != null -> "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" groupedWithMeteredMinimum != null -> "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "Price{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" matrixWithDisplayName != null -> "Price{matrixWithDisplayName=$matrixWithDisplayName}" - bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedTieredPackage != null -> "Price{groupedTieredPackage=$groupedTieredPackage}" maxGroupTieredPackage != null -> @@ -2613,11 +2785,11 @@ private constructor( "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" cumulativeGroupedBulk != null -> "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" - tieredPackageWithMinimum != null -> - "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" - matrixWithAllocation != null -> - "Price{matrixWithAllocation=$matrixWithAllocation}" - groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" + cumulativeGroupedAllocation != null -> + "Price{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "Price{minimum=$minimum}" + percent != null -> "Price{percent=$percent}" + eventOutput != null -> "Price{eventOutput=$eventOutput}" _json != null -> "Price{_unknown=$_json}" else -> throw IllegalStateException("Invalid Price") } @@ -2626,19 +2798,16 @@ private constructor( fun ofUnit(unit: NewPlanUnitPrice) = Price(unit = unit) - fun ofPackage(package_: NewPlanPackagePrice) = Price(package_ = package_) - - fun ofMatrix(matrix: NewPlanMatrixPrice) = Price(matrix = matrix) - fun ofTiered(tiered: NewPlanTieredPrice) = Price(tiered = tiered) - fun ofTieredBps(tieredBps: NewPlanTieredBpsPrice) = Price(tieredBps = tieredBps) + fun ofBulk(bulk: NewPlanBulkPrice) = Price(bulk = bulk) - fun ofBps(bps: NewPlanBpsPrice) = Price(bps = bps) + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + Price(bulkWithFilters = bulkWithFilters) - fun ofBulkBps(bulkBps: NewPlanBulkBpsPrice) = Price(bulkBps = bulkBps) + fun ofPackage(package_: NewPlanPackagePrice) = Price(package_ = package_) - fun ofBulk(bulk: NewPlanBulkPrice) = Price(bulk = bulk) + fun ofMatrix(matrix: NewPlanMatrixPrice) = Price(matrix = matrix) fun ofThresholdTotalAmount(thresholdTotalAmount: NewPlanThresholdTotalAmountPrice) = Price(thresholdTotalAmount = thresholdTotalAmount) @@ -2649,14 +2818,24 @@ private constructor( fun ofTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = Price(tieredWithMinimum = tieredWithMinimum) - fun ofUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice) = - Price(unitWithPercent = unitWithPercent) + fun ofGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = + Price(groupedTiered = groupedTiered) + + fun ofTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) fun ofPackageWithAllocation( packageWithAllocation: NewPlanPackageWithAllocationPrice ) = Price(packageWithAllocation = packageWithAllocation) - fun ofTieredWithProration(tieredWithProration: NewPlanTierWithProrationPrice) = + fun ofUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice) = + Price(unitWithPercent = unitWithPercent) + + fun ofMatrixWithAllocation(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = + Price(matrixWithAllocation = matrixWithAllocation) + + fun ofTieredWithProration(tieredWithProration: TieredWithProration) = Price(tieredWithProration = tieredWithProration) fun ofUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice) = @@ -2665,6 +2844,9 @@ private constructor( fun ofGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice) = Price(groupedAllocation = groupedAllocation) + fun ofBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice) = + Price(bulkWithProration = bulkWithProration) + fun ofGroupedWithProratedMinimum( groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) @@ -2673,13 +2855,14 @@ private constructor( groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = Price(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + fun ofMatrixWithDisplayName( matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice ) = Price(matrixWithDisplayName = matrixWithDisplayName) - fun ofBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice) = - Price(bulkWithProration = bulkWithProration) - fun ofGroupedTieredPackage(groupedTieredPackage: NewPlanGroupedTieredPackagePrice) = Price(groupedTieredPackage = groupedTieredPackage) @@ -2699,15 +2882,15 @@ private constructor( cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) - fun ofTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = Price(cumulativeGroupedAllocation = cumulativeGroupedAllocation) - fun ofMatrixWithAllocation(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = - Price(matrixWithAllocation = matrixWithAllocation) + fun ofMinimum(minimum: NewPlanMinimumCompositePrice) = Price(minimum = minimum) - fun ofGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = - Price(groupedTiered = groupedTiered) + fun ofPercent(percent: Percent) = Price(percent = percent) + + fun ofEventOutput(eventOutput: EventOutput) = Price(eventOutput = eventOutput) } /** @@ -2717,19 +2900,15 @@ private constructor( fun visitUnit(unit: NewPlanUnitPrice): T - fun visitPackage(package_: NewPlanPackagePrice): T - - fun visitMatrix(matrix: NewPlanMatrixPrice): T - fun visitTiered(tiered: NewPlanTieredPrice): T - fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice): T + fun visitBulk(bulk: NewPlanBulkPrice): T - fun visitBps(bps: NewPlanBpsPrice): T + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T - fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice): T + fun visitPackage(package_: NewPlanPackagePrice): T - fun visitBulk(bulk: NewPlanBulkPrice): T + fun visitMatrix(matrix: NewPlanMatrixPrice): T fun visitThresholdTotalAmount( thresholdTotalAmount: NewPlanThresholdTotalAmountPrice @@ -2739,18 +2918,30 @@ private constructor( fun visitTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice): T - fun visitUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice): T + fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice): T + + fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ): T fun visitPackageWithAllocation( packageWithAllocation: NewPlanPackageWithAllocationPrice ): T - fun visitTieredWithProration(tieredWithProration: NewPlanTierWithProrationPrice): T + fun visitUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice): T + + fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ): T + + fun visitTieredWithProration(tieredWithProration: TieredWithProration): T fun visitUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice): T fun visitGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice): T + fun visitBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice): T + fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice ): T @@ -2759,12 +2950,14 @@ private constructor( groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice ): T + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ): T + fun visitMatrixWithDisplayName( matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice ): T - fun visitBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice): T - fun visitGroupedTieredPackage( groupedTieredPackage: NewPlanGroupedTieredPackagePrice ): T @@ -2785,15 +2978,15 @@ private constructor( cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice ): T - fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation ): T - fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ): T + fun visitMinimum(minimum: NewPlanMinimumCompositePrice): T - fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice): T + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T /** * Maps an unknown variant of [Price] to a value of type [T]. @@ -2822,36 +3015,28 @@ private constructor( Price(unit = it, _json = json) } ?: Price(_json = json) } - "package" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) - } - "matrix" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(matrix = it, _json = json) - } ?: Price(_json = json) - } "tiered" -> { return tryDeserialize(node, jacksonTypeRef())?.let { Price(tiered = it, _json = json) } ?: Price(_json = json) } - "tiered_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(tieredBps = it, _json = json) } ?: Price(_json = json) + "bulk" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulk = it, _json = json) + } ?: Price(_json = json) } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(bps = it, _json = json) + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulkWithFilters = it, _json = json) } ?: Price(_json = json) } - "bulk_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bulkBps = it, _json = json) } ?: Price(_json = json) + "package" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) } - "bulk" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(bulk = it, _json = json) + "matrix" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(matrix = it, _json = json) } ?: Price(_json = json) } "threshold_total_amount" -> { @@ -2875,12 +3060,17 @@ private constructor( ?.let { Price(tieredWithMinimum = it, _json = json) } ?: Price(_json = json) } - "unit_with_percent" -> { + "grouped_tiered" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(groupedTiered = it, _json = json) } + ?: Price(_json = json) + } + "tiered_package_with_minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(unitWithPercent = it, _json = json) } + ?.let { Price(tieredPackageWithMinimum = it, _json = json) } ?: Price(_json = json) } "package_with_allocation" -> { @@ -2891,11 +3081,24 @@ private constructor( ?.let { Price(packageWithAllocation = it, _json = json) } ?: Price(_json = json) } - "tiered_with_proration" -> { + "unit_with_percent" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(unitWithPercent = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_allocation" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) + ?.let { Price(matrixWithAllocation = it, _json = json) } + ?: Price(_json = json) + } + "tiered_with_proration" -> { + return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(tieredWithProration = it, _json = json) } ?: Price(_json = json) } @@ -2915,6 +3118,14 @@ private constructor( ?.let { Price(groupedAllocation = it, _json = json) } ?: Price(_json = json) } + "bulk_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(bulkWithProration = it, _json = json) } + ?: Price(_json = json) + } "grouped_with_prorated_minimum" -> { return tryDeserialize( node, @@ -2931,20 +3142,20 @@ private constructor( ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } ?: Price(_json = json) } - "matrix_with_display_name" -> { + "grouped_with_min_max_thresholds" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(matrixWithDisplayName = it, _json = json) } + ?.let { Price(groupedWithMinMaxThresholds = it, _json = json) } ?: Price(_json = json) } - "bulk_with_proration" -> { + "matrix_with_display_name" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(bulkWithProration = it, _json = json) } + ?.let { Price(matrixWithDisplayName = it, _json = json) } ?: Price(_json = json) } "grouped_tiered_package" -> { @@ -2987,26 +3198,30 @@ private constructor( ?.let { Price(cumulativeGroupedBulk = it, _json = json) } ?: Price(_json = json) } - "tiered_package_with_minimum" -> { + "cumulative_grouped_allocation" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(tieredPackageWithMinimum = it, _json = json) } + ?.let { Price(cumulativeGroupedAllocation = it, _json = json) } ?: Price(_json = json) } - "matrix_with_allocation" -> { + "minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(matrixWithAllocation = it, _json = json) } - ?: Price(_json = json) + ?.let { Price(minimum = it, _json = json) } ?: Price(_json = json) } - "grouped_tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(groupedTiered = it, _json = json) } - ?: Price(_json = json) + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(percent = it, _json = json) + } ?: Price(_json = json) + } + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(eventOutput = it, _json = json) + } ?: Price(_json = json) } } @@ -3023,36 +3238,42 @@ private constructor( ) { when { value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> + generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) value.thresholdTotalAmount != null -> generator.writeObject(value.thresholdTotalAmount) value.tieredPackage != null -> generator.writeObject(value.tieredPackage) value.tieredWithMinimum != null -> generator.writeObject(value.tieredWithMinimum) - value.unitWithPercent != null -> - generator.writeObject(value.unitWithPercent) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) + value.tieredPackageWithMinimum != null -> + generator.writeObject(value.tieredPackageWithMinimum) value.packageWithAllocation != null -> generator.writeObject(value.packageWithAllocation) + value.unitWithPercent != null -> + generator.writeObject(value.unitWithPercent) + value.matrixWithAllocation != null -> + generator.writeObject(value.matrixWithAllocation) value.tieredWithProration != null -> generator.writeObject(value.tieredWithProration) value.unitWithProration != null -> generator.writeObject(value.unitWithProration) value.groupedAllocation != null -> generator.writeObject(value.groupedAllocation) + value.bulkWithProration != null -> + generator.writeObject(value.bulkWithProration) value.groupedWithProratedMinimum != null -> generator.writeObject(value.groupedWithProratedMinimum) value.groupedWithMeteredMinimum != null -> generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) value.matrixWithDisplayName != null -> generator.writeObject(value.matrixWithDisplayName) - value.bulkWithProration != null -> - generator.writeObject(value.bulkWithProration) value.groupedTieredPackage != null -> generator.writeObject(value.groupedTieredPackage) value.maxGroupTieredPackage != null -> @@ -3063,2543 +3284,23451 @@ private constructor( generator.writeObject(value.scalableMatrixWithTieredPricing) value.cumulativeGroupedBulk != null -> generator.writeObject(value.cumulativeGroupedBulk) - value.tieredPackageWithMinimum != null -> - generator.writeObject(value.tieredPackageWithMinimum) - value.matrixWithAllocation != null -> - generator.writeObject(value.matrixWithAllocation) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Price") } } } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - return /* spotless:off */ other is AddPrice && allocationPrice == other.allocationPrice && planPhaseOrder == other.planPhaseOrder && price == other.price && additionalProperties == other.additionalProperties /* spotless:on */ - } + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bulkWithFiltersConfig: JsonField, + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(allocationPrice, planPhaseOrder, price, additionalProperties) } - /* spotless:on */ + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") - override fun hashCode(): Int = hashCode + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - override fun toString() = - "AddPrice{allocationPrice=$allocationPrice, planPhaseOrder=$planPhaseOrder, price=$price, additionalProperties=$additionalProperties}" - } + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - class RemoveAdjustment - private constructor( - private val adjustmentId: JsonField, - private val planPhaseOrder: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - @JsonCreator - private constructor( - @JsonProperty("adjustment_id") - @ExcludeMissing - adjustmentId: JsonField = JsonMissing.of(), - @JsonProperty("plan_phase_order") - @ExcludeMissing - planPhaseOrder: JsonField = JsonMissing.of(), - ) : this(adjustmentId, planPhaseOrder, mutableMapOf()) + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - /** - * The id of the adjustment to remove from on the plan. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun adjustmentId(): String = adjustmentId.getRequired("adjustment_id") + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - /** - * The phase to remove this adjustment from. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - /** - * Returns the raw JSON value of [adjustmentId]. - * - * Unlike [adjustmentId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("adjustment_id") - @ExcludeMissing - fun _adjustmentId(): JsonField = adjustmentId + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - /** - * Returns the raw JSON value of [planPhaseOrder]. - * - * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("plan_phase_order") - @ExcludeMissing - fun _planPhaseOrder(): JsonField = planPhaseOrder + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - fun toBuilder() = Builder().from(this) + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - companion object { + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - /** - * Returns a mutable builder for constructing an instance of [RemoveAdjustment]. - * - * The following fields are required: - * ```kotlin - * .adjustmentId() - * ``` - */ - fun builder() = Builder() - } + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - /** A builder for [RemoveAdjustment]. */ - class Builder internal constructor() { + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - private var adjustmentId: JsonField? = null - private var planPhaseOrder: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - internal fun from(removeAdjustment: RemoveAdjustment) = apply { - adjustmentId = removeAdjustment.adjustmentId - planPhaseOrder = removeAdjustment.planPhaseOrder - additionalProperties = removeAdjustment.additionalProperties.toMutableMap() - } + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - /** The id of the adjustment to remove from on the plan. */ - fun adjustmentId(adjustmentId: String) = adjustmentId(JsonField.of(adjustmentId)) + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - /** - * Sets [Builder.adjustmentId] to an arbitrary JSON value. - * - * You should usually call [Builder.adjustmentId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun adjustmentId(adjustmentId: JsonField) = apply { - this.adjustmentId = adjustmentId - } + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = + bulkWithFiltersConfig - /** The phase to remove this adjustment from. */ - fun planPhaseOrder(planPhaseOrder: Long?) = - planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - /** - * Alias for [Builder.planPhaseOrder]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - /** - * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. - * - * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun planPhaseOrder(planPhaseOrder: JsonField) = apply { - this.planPhaseOrder = planPhaseOrder - } + /** + * 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 - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - /** - * Returns an immutable instance of [RemoveAdjustment]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .adjustmentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): RemoveAdjustment = - RemoveAdjustment( - checkRequired("adjustmentId", adjustmentId), - planPhaseOrder, - additionalProperties.toMutableMap(), - ) - } + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - private var validated: Boolean = false + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - fun validate(): RemoveAdjustment = apply { - if (validated) { - return@apply - } + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - adjustmentId() - planPhaseOrder() - validated = true - } + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (adjustmentId.asKnown() == null) 0 else 1) + - (if (planPhaseOrder.asKnown() == null) 0 else 1) + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - return /* spotless:off */ other is RemoveAdjustment && adjustmentId == other.adjustmentId && planPhaseOrder == other.planPhaseOrder && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustmentId, planPhaseOrder, additionalProperties) } - /* spotless:on */ + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - override fun hashCode(): Int = hashCode + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [BulkWithFilters]. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } - override fun toString() = - "RemoveAdjustment{adjustmentId=$adjustmentId, planPhaseOrder=$planPhaseOrder, additionalProperties=$additionalProperties}" - } + /** A builder for [BulkWithFilters]. */ + class Builder internal constructor() { + + private var bulkWithFiltersConfig: JsonField? = null + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + itemId = bulkWithFilters.itemId + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + billableMetricId = bulkWithFilters.billableMetricId + billedInAdvance = bulkWithFilters.billedInAdvance + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + currency = bulkWithFilters.currency + dimensionalPriceConfiguration = + bulkWithFilters.dimensionalPriceConfiguration + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoiceGroupingKey = bulkWithFilters.invoiceGroupingKey + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + metadata = bulkWithFilters.metadata + referenceId = bulkWithFilters.referenceId + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() + } - class RemovePrice - private constructor( - private val priceId: JsonField, - private val planPhaseOrder: JsonField, - private val additionalProperties: MutableMap, - ) { + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig( + bulkWithFiltersConfig: JsonField + ) = apply { this.bulkWithFiltersConfig = bulkWithFiltersConfig } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - @JsonCreator - private constructor( - @JsonProperty("price_id") @ExcludeMissing priceId: JsonField = JsonMissing.of(), - @JsonProperty("plan_phase_order") - @ExcludeMissing - planPhaseOrder: JsonField = JsonMissing.of(), - ) : this(priceId, planPhaseOrder, mutableMapOf()) + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - /** - * The id of the price to remove from the plan. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun priceId(): String = priceId.getRequired("price_id") + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - /** - * The phase to remove this price from. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - /** - * Returns the raw JSON value of [priceId]. - * - * Unlike [priceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("price_id") @ExcludeMissing fun _priceId(): JsonField = priceId + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - /** - * Returns the raw JSON value of [planPhaseOrder]. - * - * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("plan_phase_order") - @ExcludeMissing - fun _planPhaseOrder(): JsonField = planPhaseOrder + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - fun toBuilder() = Builder().from(this) + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - companion object { + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - /** - * Returns a mutable builder for constructing an instance of [RemovePrice]. - * - * The following fields are required: - * ```kotlin - * .priceId() - * ``` - */ - fun builder() = Builder() - } + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - /** A builder for [RemovePrice]. */ - class Builder internal constructor() { + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - private var priceId: JsonField? = null - private var planPhaseOrder: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - internal fun from(removePrice: RemovePrice) = apply { - priceId = removePrice.priceId - planPhaseOrder = removePrice.planPhaseOrder - additionalProperties = removePrice.additionalProperties.toMutableMap() - } + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** The id of the price to remove from the plan. */ - fun priceId(priceId: String) = priceId(JsonField.of(priceId)) + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - /** - * Sets [Builder.priceId] to an arbitrary JSON value. - * - * You should usually call [Builder.priceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun priceId(priceId: JsonField) = apply { this.priceId = priceId } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** The phase to remove this price from. */ - fun planPhaseOrder(planPhaseOrder: Long?) = - planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + /** + * Returns an immutable instance of [BulkWithFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFilters = + BulkWithFilters( + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - /** - * Alias for [Builder.planPhaseOrder]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + private var validated: Boolean = false - /** - * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. - * - * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun planPhaseOrder(planPhaseOrder: JsonField) = apply { - this.planPhaseOrder = planPhaseOrder - } + fun validate(): BulkWithFilters = apply { + if (validated) { + return@apply + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + bulkWithFiltersConfig().validate() + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("bulk_with_filters")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + 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. + */ + internal fun validity(): Int = + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) + + /** + * Property filters to apply (all must match) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [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) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() + } - /** - * Returns an immutable instance of [RemovePrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .priceId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): RemovePrice = - RemovePrice( - checkRequired("priceId", priceId), - planPhaseOrder, - additionalProperties.toMutableMap(), - ) - } + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { - private var validated: Boolean = false + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() - fun validate(): RemovePrice = apply { - if (validated) { - return@apply - } + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithFiltersConfig.additionalProperties.toMutableMap() + } - priceId() - planPhaseOrder() - validated = true - } + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (priceId.asKnown() == null) 0 else 1) + - (if (planPhaseOrder.asKnown() == null) 0 else 1) + /** Bulk tiers for rating based on total usage volume */ + 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() } + } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * 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) + } + } - return /* spotless:off */ other is RemovePrice && priceId == other.priceId && planPhaseOrder == other.planPhaseOrder && additionalProperties == other.additionalProperties /* spotless:on */ - } + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(priceId, planPhaseOrder, additionalProperties) } - /* spotless:on */ + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - override fun hashCode(): Int = hashCode + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - override fun toString() = - "RemovePrice{priceId=$priceId, planPhaseOrder=$planPhaseOrder, additionalProperties=$additionalProperties}" - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - class ReplaceAdjustment - private constructor( - private val adjustment: JsonField, - private val replacesAdjustmentId: JsonField, - private val planPhaseOrder: JsonField, - private val additionalProperties: MutableMap, - ) { + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - @JsonCreator - private constructor( - @JsonProperty("adjustment") - @ExcludeMissing - adjustment: JsonField = JsonMissing.of(), - @JsonProperty("replaces_adjustment_id") - @ExcludeMissing - replacesAdjustmentId: JsonField = JsonMissing.of(), - @JsonProperty("plan_phase_order") - @ExcludeMissing - planPhaseOrder: JsonField = JsonMissing.of(), - ) : this(adjustment, replacesAdjustmentId, planPhaseOrder, mutableMapOf()) + /** + * Returns an immutable instance of [BulkWithFiltersConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } - /** - * The definition of a new adjustment to create and add to the plan. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun adjustment(): Adjustment = adjustment.getRequired("adjustment") + private var validated: Boolean = false - /** - * The id of the adjustment on the plan to replace in the plan. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } + + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = + propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + propertyKey() + propertyValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = + tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filters, tiers, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFilters && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFilters{bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class TieredWithProration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val tieredWithProrationConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + tieredWithProrationConfig: JsonField = + JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for tiered_with_proration pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tieredWithProrationConfig(): TieredWithProrationConfig = + tieredWithProrationConfig.getRequired("tiered_with_proration_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [tieredWithProrationConfig]. + * + * Unlike [tieredWithProrationConfig], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + fun _tieredWithProrationConfig(): JsonField = + tieredWithProrationConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [TieredWithProration]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProration]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("tiered_with_proration") + private var name: JsonField? = null + private var tieredWithProrationConfig: JsonField? = + null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tieredWithProration: TieredWithProration) = apply { + cadence = tieredWithProration.cadence + itemId = tieredWithProration.itemId + modelType = tieredWithProration.modelType + name = tieredWithProration.name + tieredWithProrationConfig = tieredWithProration.tieredWithProrationConfig + billableMetricId = tieredWithProration.billableMetricId + billedInAdvance = tieredWithProration.billedInAdvance + billingCycleConfiguration = tieredWithProration.billingCycleConfiguration + conversionRate = tieredWithProration.conversionRate + conversionRateConfig = tieredWithProration.conversionRateConfig + currency = tieredWithProration.currency + dimensionalPriceConfiguration = + tieredWithProration.dimensionalPriceConfiguration + externalPriceId = tieredWithProration.externalPriceId + fixedPriceQuantity = tieredWithProration.fixedPriceQuantity + invoiceGroupingKey = tieredWithProration.invoiceGroupingKey + invoicingCycleConfiguration = + tieredWithProration.invoicingCycleConfiguration + metadata = tieredWithProration.metadata + referenceId = tieredWithProration.referenceId + additionalProperties = + tieredWithProration.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for tiered_with_proration pricing */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: TieredWithProrationConfig + ) = tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) + + /** + * Sets [Builder.tieredWithProrationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.tieredWithProrationConfig] with a well-typed + * [TieredWithProrationConfig] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: JsonField + ) = apply { this.tieredWithProrationConfig = tieredWithProrationConfig } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TieredWithProration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProration = + TieredWithProration( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("tieredWithProrationConfig", tieredWithProrationConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProration = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("tiered_with_proration")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + tieredWithProrationConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("tiered_with_proration")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (tieredWithProrationConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for tiered_with_proration pricing */ + class TieredWithProrationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Tiers for rating based on total usage quantities into the specified tier with + * proration + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 + * [TieredWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProrationConfig]. */ + class Builder internal constructor() { + + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = + apply { + tiers = tieredWithProrationConfig.tiers.map { it.toMutableList() } + additionalProperties = + tieredWithProrationConfig.additionalProperties.toMutableMap() + } + + /** + * Tiers for rating based on total usage quantities into the specified tier + * with proration + */ + 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 [TieredWithProrationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProrationConfig = + TieredWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProrationConfig = apply { + if (validated) { + return@apply + } + + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tiered with proration tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Inclusive tier starting value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun tierLowerBound(): String = + tierLowerBound.getRequired("tier_lower_bound") + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Inclusive tier starting value */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProration && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredWithProrationConfig == other.tieredWithProrationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProration{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, tieredWithProrationConfig=$tieredWithProrationConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val groupedWithMinMaxThresholdsConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + groupedWithMinMaxThresholdsConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for grouped_with_min_max_thresholds pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired( + "grouped_with_min_max_thresholds_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. + * + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + fun _groupedWithMinMaxThresholdsConfig(): + JsonField = groupedWithMinMaxThresholdsConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [GroupedWithMinMaxThresholds]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholds]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("grouped_with_min_max_thresholds") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = + apply { + cadence = groupedWithMinMaxThresholds.cadence + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + itemId = groupedWithMinMaxThresholds.itemId + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + billableMetricId = groupedWithMinMaxThresholds.billableMetricId + billedInAdvance = groupedWithMinMaxThresholds.billedInAdvance + billingCycleConfiguration = + groupedWithMinMaxThresholds.billingCycleConfiguration + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + currency = groupedWithMinMaxThresholds.currency + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + invoiceGroupingKey = groupedWithMinMaxThresholds.invoiceGroupingKey + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + metadata = groupedWithMinMaxThresholds.metadata + referenceId = groupedWithMinMaxThresholds.referenceId + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = + groupedWithMinMaxThresholdsConfig( + JsonField.of(groupedWithMinMaxThresholdsConfig) + ) + + /** + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a + * well-typed [GroupedWithMinMaxThresholdsConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: + JsonField + ) = apply { + this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( + checkRequired("cadence", cadence), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholds = apply { + if (validated) { + return@apply + } + + cadence().validate() + groupedWithMinMaxThresholdsConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @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 + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate + additionalProperties = + groupedWithMinMaxThresholdsConfig.additionalProperties + .toMutableMap() + } + + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } + + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } + + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = + perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + if (validated) { + return@apply + } + + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholds && + cadence == other.cadence && + groupedWithMinMaxThresholdsConfig == + other.groupedWithMinMaxThresholdsConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholds{cadence=$cadence, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val cumulativeGroupedAllocationConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for cumulative_grouped_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired( + "cumulative_grouped_allocation_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): + JsonField = cumulativeGroupedAllocationConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [CumulativeGroupedAllocation]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocation]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("cumulative_grouped_allocation") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = + apply { + cadence = cumulativeGroupedAllocation.cadence + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + itemId = cumulativeGroupedAllocation.itemId + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + billableMetricId = cumulativeGroupedAllocation.billableMetricId + billedInAdvance = cumulativeGroupedAllocation.billedInAdvance + billingCycleConfiguration = + cumulativeGroupedAllocation.billingCycleConfiguration + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + currency = cumulativeGroupedAllocation.currency + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoiceGroupingKey = cumulativeGroupedAllocation.invoiceGroupingKey + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + metadata = cumulativeGroupedAllocation.metadata + referenceId = cumulativeGroupedAllocation.referenceId + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = + cumulativeGroupedAllocationConfig( + JsonField.of(cumulativeGroupedAllocationConfig) + ) + + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a + * well-typed [CumulativeGroupedAllocationConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: + JsonField + ) = apply { + this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( + checkRequired("cadence", cadence), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocation = apply { + if (validated) { + return@apply + } + + cadence().validate() + cumulativeGroupedAllocationConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("cumulative_grouped_allocation")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + mutableMapOf(), + ) + + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 + * [CumulativeGroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = + cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties + .toMutableMap() + } + + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } + + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation + } + + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply + } + + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocation && + cadence == other.cadence && + cumulativeGroupedAllocationConfig == + other.cumulativeGroupedAllocationConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocation{cadence=$cadence, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val percentConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [Percent]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Percent]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("percent") + private var name: JsonField? = null + private var percentConfig: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percent: Percent) = apply { + cadence = percent.cadence + itemId = percent.itemId + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + billableMetricId = percent.billableMetricId + billedInAdvance = percent.billedInAdvance + billingCycleConfiguration = percent.billingCycleConfiguration + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + currency = percent.currency + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoiceGroupingKey = percent.invoiceGroupingKey + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + metadata = percent.metadata + referenceId = percent.referenceId + additionalProperties = percent.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed + * [PercentConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Percent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Percent = + Percent( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("percentConfig", percentConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Percent = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("percent")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + percentConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent") + @ExcludeMissing + fun _percent(): JsonField = percent + + @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 + * [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PercentConfig]. */ + class Builder internal constructor() { + + private var percent: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() + } + + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PercentConfig = apply { + if (validated) { + return@apply + } + + percent() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(percent, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Percent && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Percent{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, percentConfig=$percentConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val eventOutputConfig: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [EventOutput]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutput]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var eventOutputConfig: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("event_output") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutput: EventOutput) = apply { + cadence = eventOutput.cadence + eventOutputConfig = eventOutput.eventOutputConfig + itemId = eventOutput.itemId + modelType = eventOutput.modelType + name = eventOutput.name + billableMetricId = eventOutput.billableMetricId + billedInAdvance = eventOutput.billedInAdvance + billingCycleConfiguration = eventOutput.billingCycleConfiguration + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + currency = eventOutput.currency + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoiceGroupingKey = eventOutput.invoiceGroupingKey + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + metadata = eventOutput.metadata + referenceId = eventOutput.referenceId + additionalProperties = eventOutput.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutput = + EventOutput( + checkRequired("cadence", cadence), + checkRequired("eventOutputConfig", eventOutputConfig), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutput = apply { + if (validated) { + return@apply + } + + cadence().validate() + eventOutputConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("event_output")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a + * unit rate will be ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = + defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events + * will also be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @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 + * [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutputConfig]. */ + class Builder internal constructor() { + + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = + eventOutputConfig.additionalProperties.toMutableMap() + } + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey + } + + /** + * If provided, this amount will be used as the unit rate when an event does + * not have a value for the `unit_rating_key`. If not provided, events + * missing a unit rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate + } + + /** + * An optional key in the event data to group by (e.g., event ID). All + * events will also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutputConfig = apply { + if (validated) { + return@apply + } + + unitRatingKey() + defaultUnitRate() + groupingKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + unitRatingKey, + defaultUnitRate, + groupingKey, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutput && + cadence == other.cadence && + eventOutputConfig == other.eventOutputConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutput{cadence=$cadence, eventOutputConfig=$eventOutputConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddPrice && + allocationPrice == other.allocationPrice && + planPhaseOrder == other.planPhaseOrder && + price == other.price && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(allocationPrice, planPhaseOrder, price, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddPrice{allocationPrice=$allocationPrice, planPhaseOrder=$planPhaseOrder, price=$price, additionalProperties=$additionalProperties}" + } + + class RemoveAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val adjustmentId: JsonField, + private val planPhaseOrder: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("adjustment_id") + @ExcludeMissing + adjustmentId: JsonField = JsonMissing.of(), + @JsonProperty("plan_phase_order") + @ExcludeMissing + planPhaseOrder: JsonField = JsonMissing.of(), + ) : this(adjustmentId, planPhaseOrder, mutableMapOf()) + + /** + * The id of the adjustment to remove from on the plan. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun adjustmentId(): String = adjustmentId.getRequired("adjustment_id") + + /** + * The phase to remove this adjustment from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + + /** + * Returns the raw JSON value of [adjustmentId]. + * + * Unlike [adjustmentId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("adjustment_id") + @ExcludeMissing + fun _adjustmentId(): JsonField = adjustmentId + + /** + * Returns the raw JSON value of [planPhaseOrder]. + * + * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("plan_phase_order") + @ExcludeMissing + fun _planPhaseOrder(): JsonField = planPhaseOrder + + @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 [RemoveAdjustment]. + * + * The following fields are required: + * ```kotlin + * .adjustmentId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [RemoveAdjustment]. */ + class Builder internal constructor() { + + private var adjustmentId: JsonField? = null + private var planPhaseOrder: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(removeAdjustment: RemoveAdjustment) = apply { + adjustmentId = removeAdjustment.adjustmentId + planPhaseOrder = removeAdjustment.planPhaseOrder + additionalProperties = removeAdjustment.additionalProperties.toMutableMap() + } + + /** The id of the adjustment to remove from on the plan. */ + fun adjustmentId(adjustmentId: String) = adjustmentId(JsonField.of(adjustmentId)) + + /** + * Sets [Builder.adjustmentId] to an arbitrary JSON value. + * + * You should usually call [Builder.adjustmentId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun adjustmentId(adjustmentId: JsonField) = apply { + this.adjustmentId = adjustmentId + } + + /** The phase to remove this adjustment from. */ + fun planPhaseOrder(planPhaseOrder: Long?) = + planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + + /** + * Alias for [Builder.planPhaseOrder]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + + /** + * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. + * + * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun planPhaseOrder(planPhaseOrder: JsonField) = apply { + this.planPhaseOrder = planPhaseOrder + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [RemoveAdjustment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .adjustmentId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RemoveAdjustment = + RemoveAdjustment( + checkRequired("adjustmentId", adjustmentId), + planPhaseOrder, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RemoveAdjustment = apply { + if (validated) { + return@apply + } + + adjustmentId() + planPhaseOrder() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (adjustmentId.asKnown() == null) 0 else 1) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RemoveAdjustment && + adjustmentId == other.adjustmentId && + planPhaseOrder == other.planPhaseOrder && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(adjustmentId, planPhaseOrder, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemoveAdjustment{adjustmentId=$adjustmentId, planPhaseOrder=$planPhaseOrder, additionalProperties=$additionalProperties}" + } + + class RemovePrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val priceId: JsonField, + private val planPhaseOrder: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("price_id") @ExcludeMissing priceId: JsonField = JsonMissing.of(), + @JsonProperty("plan_phase_order") + @ExcludeMissing + planPhaseOrder: JsonField = JsonMissing.of(), + ) : this(priceId, planPhaseOrder, mutableMapOf()) + + /** + * The id of the price to remove from the plan. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun priceId(): String = priceId.getRequired("price_id") + + /** + * The phase to remove this price from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + + /** + * Returns the raw JSON value of [priceId]. + * + * Unlike [priceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("price_id") @ExcludeMissing fun _priceId(): JsonField = priceId + + /** + * Returns the raw JSON value of [planPhaseOrder]. + * + * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("plan_phase_order") + @ExcludeMissing + fun _planPhaseOrder(): JsonField = planPhaseOrder + + @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 [RemovePrice]. + * + * The following fields are required: + * ```kotlin + * .priceId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [RemovePrice]. */ + class Builder internal constructor() { + + private var priceId: JsonField? = null + private var planPhaseOrder: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(removePrice: RemovePrice) = apply { + priceId = removePrice.priceId + planPhaseOrder = removePrice.planPhaseOrder + additionalProperties = removePrice.additionalProperties.toMutableMap() + } + + /** The id of the price to remove from the plan. */ + fun priceId(priceId: String) = priceId(JsonField.of(priceId)) + + /** + * Sets [Builder.priceId] to an arbitrary JSON value. + * + * You should usually call [Builder.priceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun priceId(priceId: JsonField) = apply { this.priceId = priceId } + + /** The phase to remove this price from. */ + fun planPhaseOrder(planPhaseOrder: Long?) = + planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + + /** + * Alias for [Builder.planPhaseOrder]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + + /** + * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. + * + * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun planPhaseOrder(planPhaseOrder: JsonField) = apply { + this.planPhaseOrder = planPhaseOrder + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [RemovePrice]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .priceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RemovePrice = + RemovePrice( + checkRequired("priceId", priceId), + planPhaseOrder, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RemovePrice = apply { + if (validated) { + return@apply + } + + priceId() + planPhaseOrder() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (priceId.asKnown() == null) 0 else 1) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RemovePrice && + priceId == other.priceId && + planPhaseOrder == other.planPhaseOrder && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(priceId, planPhaseOrder, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemovePrice{priceId=$priceId, planPhaseOrder=$planPhaseOrder, additionalProperties=$additionalProperties}" + } + + class ReplaceAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val adjustment: JsonField, + private val replacesAdjustmentId: JsonField, + private val planPhaseOrder: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("adjustment") + @ExcludeMissing + adjustment: JsonField = JsonMissing.of(), + @JsonProperty("replaces_adjustment_id") + @ExcludeMissing + replacesAdjustmentId: JsonField = JsonMissing.of(), + @JsonProperty("plan_phase_order") + @ExcludeMissing + planPhaseOrder: JsonField = JsonMissing.of(), + ) : this(adjustment, replacesAdjustmentId, planPhaseOrder, mutableMapOf()) + + /** + * The definition of a new adjustment to create and add to the plan. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun adjustment(): Adjustment = adjustment.getRequired("adjustment") + + /** + * The id of the adjustment on the plan to replace in the plan. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun replacesAdjustmentId(): String = + replacesAdjustmentId.getRequired("replaces_adjustment_id") + + /** + * The phase to replace this adjustment from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + + /** + * Returns the raw JSON value of [adjustment]. + * + * Unlike [adjustment], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("adjustment") + @ExcludeMissing + fun _adjustment(): JsonField = adjustment + + /** + * Returns the raw JSON value of [replacesAdjustmentId]. + * + * Unlike [replacesAdjustmentId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("replaces_adjustment_id") + @ExcludeMissing + fun _replacesAdjustmentId(): JsonField = replacesAdjustmentId + + /** + * Returns the raw JSON value of [planPhaseOrder]. + * + * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("plan_phase_order") + @ExcludeMissing + fun _planPhaseOrder(): JsonField = planPhaseOrder + + @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 [ReplaceAdjustment]. + * + * The following fields are required: + * ```kotlin + * .adjustment() + * .replacesAdjustmentId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ReplaceAdjustment]. */ + class Builder internal constructor() { + + private var adjustment: JsonField? = null + private var replacesAdjustmentId: JsonField? = null + private var planPhaseOrder: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(replaceAdjustment: ReplaceAdjustment) = apply { + adjustment = replaceAdjustment.adjustment + replacesAdjustmentId = replaceAdjustment.replacesAdjustmentId + planPhaseOrder = replaceAdjustment.planPhaseOrder + additionalProperties = replaceAdjustment.additionalProperties.toMutableMap() + } + + /** The definition of a new adjustment to create and add to the plan. */ + fun adjustment(adjustment: Adjustment) = adjustment(JsonField.of(adjustment)) + + /** + * Sets [Builder.adjustment] to an arbitrary JSON value. + * + * You should usually call [Builder.adjustment] with a well-typed [Adjustment] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun adjustment(adjustment: JsonField) = apply { + this.adjustment = adjustment + } + + /** + * Alias for calling [adjustment] with + * `Adjustment.ofPercentageDiscount(percentageDiscount)`. + */ + fun adjustment(percentageDiscount: NewPercentageDiscount) = + adjustment(Adjustment.ofPercentageDiscount(percentageDiscount)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewPercentageDiscount.builder() + * .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) + * .percentageDiscount(percentageDiscount) + * .build() + * ``` + */ + fun percentageDiscountAdjustment(percentageDiscount: Double) = + adjustment( + NewPercentageDiscount.builder() + .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) + .percentageDiscount(percentageDiscount) + .build() + ) + + /** Alias for calling [adjustment] with `Adjustment.ofUsageDiscount(usageDiscount)`. */ + fun adjustment(usageDiscount: NewUsageDiscount) = + adjustment(Adjustment.ofUsageDiscount(usageDiscount)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewUsageDiscount.builder() + * .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) + * .usageDiscount(usageDiscount) + * .build() + * ``` + */ + fun usageDiscountAdjustment(usageDiscount: Double) = + adjustment( + NewUsageDiscount.builder() + .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) + .usageDiscount(usageDiscount) + .build() + ) + + /** + * Alias for calling [adjustment] with `Adjustment.ofAmountDiscount(amountDiscount)`. + */ + fun adjustment(amountDiscount: NewAmountDiscount) = + adjustment(Adjustment.ofAmountDiscount(amountDiscount)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewAmountDiscount.builder() + * .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) + * .amountDiscount(amountDiscount) + * .build() + * ``` + */ + fun amountDiscountAdjustment(amountDiscount: String) = + adjustment( + NewAmountDiscount.builder() + .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) + .amountDiscount(amountDiscount) + .build() + ) + + /** Alias for calling [adjustment] with `Adjustment.ofMinimum(minimum)`. */ + fun adjustment(minimum: NewMinimum) = adjustment(Adjustment.ofMinimum(minimum)) + + /** Alias for calling [adjustment] with `Adjustment.ofMaximum(maximum)`. */ + fun adjustment(maximum: NewMaximum) = adjustment(Adjustment.ofMaximum(maximum)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewMaximum.builder() + * .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) + * .maximumAmount(maximumAmount) + * .build() + * ``` + */ + fun maximumAdjustment(maximumAmount: String) = + adjustment( + NewMaximum.builder() + .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) + .maximumAmount(maximumAmount) + .build() + ) + + /** The id of the adjustment on the plan to replace in the plan. */ + fun replacesAdjustmentId(replacesAdjustmentId: String) = + replacesAdjustmentId(JsonField.of(replacesAdjustmentId)) + + /** + * Sets [Builder.replacesAdjustmentId] to an arbitrary JSON value. + * + * You should usually call [Builder.replacesAdjustmentId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun replacesAdjustmentId(replacesAdjustmentId: JsonField) = apply { + this.replacesAdjustmentId = replacesAdjustmentId + } + + /** The phase to replace this adjustment from. */ + fun planPhaseOrder(planPhaseOrder: Long?) = + planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + + /** + * Alias for [Builder.planPhaseOrder]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + + /** + * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. + * + * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun planPhaseOrder(planPhaseOrder: JsonField) = apply { + this.planPhaseOrder = planPhaseOrder + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ReplaceAdjustment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .adjustment() + * .replacesAdjustmentId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ReplaceAdjustment = + ReplaceAdjustment( + checkRequired("adjustment", adjustment), + checkRequired("replacesAdjustmentId", replacesAdjustmentId), + planPhaseOrder, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ReplaceAdjustment = apply { + if (validated) { + return@apply + } + + adjustment().validate() + replacesAdjustmentId() + planPhaseOrder() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (adjustment.asKnown()?.validity() ?: 0) + + (if (replacesAdjustmentId.asKnown() == null) 0 else 1) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + /** The definition of a new adjustment to create and add to the plan. */ + @JsonDeserialize(using = Adjustment.Deserializer::class) + @JsonSerialize(using = Adjustment.Serializer::class) + class Adjustment + private constructor( + private val percentageDiscount: NewPercentageDiscount? = null, + private val usageDiscount: NewUsageDiscount? = null, + private val amountDiscount: NewAmountDiscount? = null, + private val minimum: NewMinimum? = null, + private val maximum: NewMaximum? = null, + private val _json: JsonValue? = null, + ) { + + fun percentageDiscount(): NewPercentageDiscount? = percentageDiscount + + fun usageDiscount(): NewUsageDiscount? = usageDiscount + + fun amountDiscount(): NewAmountDiscount? = amountDiscount + + fun minimum(): NewMinimum? = minimum + + fun maximum(): NewMaximum? = maximum + + fun isPercentageDiscount(): Boolean = percentageDiscount != null + + fun isUsageDiscount(): Boolean = usageDiscount != null + + fun isAmountDiscount(): Boolean = amountDiscount != null + + fun isMinimum(): Boolean = minimum != null + + fun isMaximum(): Boolean = maximum != null + + fun asPercentageDiscount(): NewPercentageDiscount = + percentageDiscount.getOrThrow("percentageDiscount") + + fun asUsageDiscount(): NewUsageDiscount = usageDiscount.getOrThrow("usageDiscount") + + fun asAmountDiscount(): NewAmountDiscount = amountDiscount.getOrThrow("amountDiscount") + + fun asMinimum(): NewMinimum = minimum.getOrThrow("minimum") + + fun asMaximum(): NewMaximum = maximum.getOrThrow("maximum") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + percentageDiscount != null -> + visitor.visitPercentageDiscount(percentageDiscount) + usageDiscount != null -> visitor.visitUsageDiscount(usageDiscount) + amountDiscount != null -> visitor.visitAmountDiscount(amountDiscount) + minimum != null -> visitor.visitMinimum(minimum) + maximum != null -> visitor.visitMaximum(maximum) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Adjustment = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitPercentageDiscount( + percentageDiscount: NewPercentageDiscount + ) { + percentageDiscount.validate() + } + + override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) { + usageDiscount.validate() + } + + override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) { + amountDiscount.validate() + } + + override fun visitMinimum(minimum: NewMinimum) { + minimum.validate() + } + + override fun visitMaximum(maximum: NewMaximum) { + maximum.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitPercentageDiscount( + percentageDiscount: NewPercentageDiscount + ) = percentageDiscount.validity() + + override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) = + usageDiscount.validity() + + override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) = + amountDiscount.validity() + + override fun visitMinimum(minimum: NewMinimum) = minimum.validity() + + override fun visitMaximum(maximum: NewMaximum) = maximum.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Adjustment && + percentageDiscount == other.percentageDiscount && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + minimum == other.minimum && + maximum == other.maximum + } + + override fun hashCode(): Int = + Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) + + override fun toString(): String = + when { + percentageDiscount != null -> + "Adjustment{percentageDiscount=$percentageDiscount}" + usageDiscount != null -> "Adjustment{usageDiscount=$usageDiscount}" + amountDiscount != null -> "Adjustment{amountDiscount=$amountDiscount}" + minimum != null -> "Adjustment{minimum=$minimum}" + maximum != null -> "Adjustment{maximum=$maximum}" + _json != null -> "Adjustment{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Adjustment") + } + + companion object { + + fun ofPercentageDiscount(percentageDiscount: NewPercentageDiscount) = + Adjustment(percentageDiscount = percentageDiscount) + + fun ofUsageDiscount(usageDiscount: NewUsageDiscount) = + Adjustment(usageDiscount = usageDiscount) + + fun ofAmountDiscount(amountDiscount: NewAmountDiscount) = + Adjustment(amountDiscount = amountDiscount) + + fun ofMinimum(minimum: NewMinimum) = Adjustment(minimum = minimum) + + fun ofMaximum(maximum: NewMaximum) = Adjustment(maximum = maximum) + } + + /** + * An interface that defines how to map each variant of [Adjustment] to a value of type + * [T]. + */ + interface Visitor { + + fun visitPercentageDiscount(percentageDiscount: NewPercentageDiscount): T + + fun visitUsageDiscount(usageDiscount: NewUsageDiscount): T + + fun visitAmountDiscount(amountDiscount: NewAmountDiscount): T + + fun visitMinimum(minimum: NewMinimum): T + + fun visitMaximum(maximum: NewMaximum): T + + /** + * Maps an unknown variant of [Adjustment] to a value of type [T]. + * + * An instance of [Adjustment] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on an + * older version than the API, then the API may respond with new variants that the + * SDK is unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown Adjustment: $json") + } + } + + internal class Deserializer : BaseDeserializer(Adjustment::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Adjustment { + val json = JsonValue.fromJsonNode(node) + val adjustmentType = json.asObject()?.get("adjustment_type")?.asString() + + when (adjustmentType) { + "percentage_discount" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Adjustment(percentageDiscount = it, _json = json) } + ?: Adjustment(_json = json) + } + "usage_discount" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(usageDiscount = it, _json = json) + } ?: Adjustment(_json = json) + } + "amount_discount" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(amountDiscount = it, _json = json) + } ?: Adjustment(_json = json) + } + "minimum" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(minimum = it, _json = json) + } ?: Adjustment(_json = json) + } + "maximum" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(maximum = it, _json = json) + } ?: Adjustment(_json = json) + } + } + + return Adjustment(_json = json) + } + } + + internal class Serializer : BaseSerializer(Adjustment::class) { + + override fun serialize( + value: Adjustment, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.percentageDiscount != null -> + generator.writeObject(value.percentageDiscount) + value.usageDiscount != null -> generator.writeObject(value.usageDiscount) + value.amountDiscount != null -> generator.writeObject(value.amountDiscount) + value.minimum != null -> generator.writeObject(value.minimum) + value.maximum != null -> generator.writeObject(value.maximum) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Adjustment") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ReplaceAdjustment && + adjustment == other.adjustment && + replacesAdjustmentId == other.replacesAdjustmentId && + planPhaseOrder == other.planPhaseOrder && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(adjustment, replacesAdjustmentId, planPhaseOrder, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ReplaceAdjustment{adjustment=$adjustment, replacesAdjustmentId=$replacesAdjustmentId, planPhaseOrder=$planPhaseOrder, additionalProperties=$additionalProperties}" + } + + class ReplacePrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val replacesPriceId: JsonField, + private val allocationPrice: JsonField, + private val planPhaseOrder: JsonField, + private val price: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("replaces_price_id") + @ExcludeMissing + replacesPriceId: JsonField = JsonMissing.of(), + @JsonProperty("allocation_price") + @ExcludeMissing + allocationPrice: JsonField = JsonMissing.of(), + @JsonProperty("plan_phase_order") + @ExcludeMissing + planPhaseOrder: JsonField = JsonMissing.of(), + @JsonProperty("price") @ExcludeMissing price: JsonField = JsonMissing.of(), + ) : this(replacesPriceId, allocationPrice, planPhaseOrder, price, mutableMapOf()) + + /** + * The id of the price on the plan to replace in the plan. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun replacesPriceId(): String = replacesPriceId.getRequired("replaces_price_id") + + /** + * The allocation price to add to the plan. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allocationPrice(): NewAllocationPrice? = allocationPrice.getNullable("allocation_price") + + /** + * The phase to replace this price from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + + /** + * New plan price request body params. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun price(): Price? = price.getNullable("price") + + /** + * Returns the raw JSON value of [replacesPriceId]. + * + * Unlike [replacesPriceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("replaces_price_id") + @ExcludeMissing + fun _replacesPriceId(): JsonField = replacesPriceId + + /** + * Returns the raw JSON value of [allocationPrice]. + * + * Unlike [allocationPrice], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("allocation_price") + @ExcludeMissing + fun _allocationPrice(): JsonField = allocationPrice + + /** + * Returns the raw JSON value of [planPhaseOrder]. + * + * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("plan_phase_order") + @ExcludeMissing + fun _planPhaseOrder(): JsonField = planPhaseOrder + + /** + * 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 + + @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 [ReplacePrice]. + * + * The following fields are required: + * ```kotlin + * .replacesPriceId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ReplacePrice]. */ + class Builder internal constructor() { + + private var replacesPriceId: JsonField? = null + private var allocationPrice: JsonField = JsonMissing.of() + private var planPhaseOrder: JsonField = JsonMissing.of() + private var price: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(replacePrice: ReplacePrice) = apply { + replacesPriceId = replacePrice.replacesPriceId + allocationPrice = replacePrice.allocationPrice + planPhaseOrder = replacePrice.planPhaseOrder + price = replacePrice.price + additionalProperties = replacePrice.additionalProperties.toMutableMap() + } + + /** The id of the price on the plan to replace in the plan. */ + fun replacesPriceId(replacesPriceId: String) = + replacesPriceId(JsonField.of(replacesPriceId)) + + /** + * Sets [Builder.replacesPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.replacesPriceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun replacesPriceId(replacesPriceId: JsonField) = apply { + this.replacesPriceId = replacesPriceId + } + + /** The allocation price to add to the plan. */ + fun allocationPrice(allocationPrice: NewAllocationPrice?) = + allocationPrice(JsonField.ofNullable(allocationPrice)) + + /** + * Sets [Builder.allocationPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.allocationPrice] with a well-typed + * [NewAllocationPrice] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun allocationPrice(allocationPrice: JsonField) = apply { + this.allocationPrice = allocationPrice + } + + /** The phase to replace this price from. */ + fun planPhaseOrder(planPhaseOrder: Long?) = + planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + + /** + * Alias for [Builder.planPhaseOrder]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + + /** + * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. + * + * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun planPhaseOrder(planPhaseOrder: JsonField) = apply { + this.planPhaseOrder = planPhaseOrder + } + + /** New plan price request body params. */ + fun price(price: Price?) = price(JsonField.ofNullable(price)) + + /** + * Sets [Builder.price] to an arbitrary JSON value. + * + * You should usually call [Builder.price] with a well-typed [Price] 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 } + + /** Alias for calling [price] with `Price.ofUnit(unit)`. */ + fun price(unit: NewPlanUnitPrice) = price(Price.ofUnit(unit)) + + /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ + fun price(tiered: NewPlanTieredPrice) = price(Price.ofTiered(tiered)) + + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: NewPlanBulkPrice) = price(Price.ofBulk(bulk)) + + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) + + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: NewPlanPackagePrice) = price(Price.ofPackage(package_)) + + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: NewPlanMatrixPrice) = price(Price.ofMatrix(matrix)) + + /** + * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. + */ + fun price(thresholdTotalAmount: NewPlanThresholdTotalAmountPrice) = + price(Price.ofThresholdTotalAmount(thresholdTotalAmount)) + + /** Alias for calling [price] with `Price.ofTieredPackage(tieredPackage)`. */ + fun price(tieredPackage: NewPlanTieredPackagePrice) = + price(Price.ofTieredPackage(tieredPackage)) + + /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ + fun price(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = + price(Price.ofTieredWithMinimum(tieredWithMinimum)) + + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: NewPlanGroupedTieredPrice) = + price(Price.ofGroupedTiered(groupedTiered)) + + /** + * Alias for calling [price] with + * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + */ + fun price(tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice) = + price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofPackageWithAllocation(packageWithAllocation)`. + */ + fun price(packageWithAllocation: NewPlanPackageWithAllocationPrice) = + price(Price.ofPackageWithAllocation(packageWithAllocation)) + + /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ + fun price(unitWithPercent: NewPlanUnitWithPercentPrice) = + price(Price.ofUnitWithPercent(unitWithPercent)) + + /** + * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun price(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = + price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + + /** + * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. + */ + fun price(tieredWithProration: Price.TieredWithProration) = + price(Price.ofTieredWithProration(tieredWithProration)) + + /** Alias for calling [price] with `Price.ofUnitWithProration(unitWithProration)`. */ + fun price(unitWithProration: NewPlanUnitWithProrationPrice) = + price(Price.ofUnitWithProration(unitWithProration)) + + /** Alias for calling [price] with `Price.ofGroupedAllocation(groupedAllocation)`. */ + fun price(groupedAllocation: NewPlanGroupedAllocationPrice) = + price(Price.ofGroupedAllocation(groupedAllocation)) + + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: NewPlanBulkWithProrationPrice) = + price(Price.ofBulkWithProration(bulkWithProration)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. + */ + fun price(groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice) = + price(Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. + */ + fun price(groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice) = + price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + + /** + * Alias for calling [price] with + * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. + */ + fun price(matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice) = + price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) + + /** + * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. + */ + fun price(groupedTieredPackage: NewPlanGroupedTieredPackagePrice) = + price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + + /** + * Alias for calling [price] with + * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. + */ + fun price(maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice) = + price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + + /** + * Alias for calling [price] with + * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. + */ + fun price(scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice) = + price(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) + + /** + * Alias for calling [price] with + * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. + */ + fun price( + scalableMatrixWithTieredPricing: NewPlanScalableMatrixWithTieredPricingPrice + ) = price(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) + + /** + * Alias for calling [price] with + * `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. + */ + fun price(cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice) = + price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + + /** + * Alias for calling [price] with + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. + */ + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: NewPlanMinimumCompositePrice) = price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ReplacePrice]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .replacesPriceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ReplacePrice = + ReplacePrice( + checkRequired("replacesPriceId", replacesPriceId), + allocationPrice, + planPhaseOrder, + price, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ReplacePrice = apply { + if (validated) { + return@apply + } + + replacesPriceId() + allocationPrice()?.validate() + planPhaseOrder() + price()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. */ - fun replacesAdjustmentId(): String = - replacesAdjustmentId.getRequired("replaces_adjustment_id") + internal fun validity(): Int = + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (allocationPrice.asKnown()?.validity() ?: 0) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + (price.asKnown()?.validity() ?: 0) + + /** New plan price request body params. */ + @JsonDeserialize(using = Price.Deserializer::class) + @JsonSerialize(using = Price.Serializer::class) + class Price + private constructor( + private val unit: NewPlanUnitPrice? = null, + private val tiered: NewPlanTieredPrice? = null, + private val bulk: NewPlanBulkPrice? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: NewPlanPackagePrice? = null, + private val matrix: NewPlanMatrixPrice? = null, + private val thresholdTotalAmount: NewPlanThresholdTotalAmountPrice? = null, + private val tieredPackage: NewPlanTieredPackagePrice? = null, + private val tieredWithMinimum: NewPlanTieredWithMinimumPrice? = null, + private val groupedTiered: NewPlanGroupedTieredPrice? = null, + private val tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice? = null, + private val packageWithAllocation: NewPlanPackageWithAllocationPrice? = null, + private val unitWithPercent: NewPlanUnitWithPercentPrice? = null, + private val matrixWithAllocation: NewPlanMatrixWithAllocationPrice? = null, + private val tieredWithProration: TieredWithProration? = null, + private val unitWithProration: NewPlanUnitWithProrationPrice? = null, + private val groupedAllocation: NewPlanGroupedAllocationPrice? = null, + private val bulkWithProration: NewPlanBulkWithProrationPrice? = null, + private val groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice? = null, + private val groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice? = null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, + private val matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice? = null, + private val groupedTieredPackage: NewPlanGroupedTieredPackagePrice? = null, + private val maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice? = null, + private val scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice? = + null, + private val scalableMatrixWithTieredPricing: + NewPlanScalableMatrixWithTieredPricingPrice? = + null, + private val cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: NewPlanMinimumCompositePrice? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, + private val _json: JsonValue? = null, + ) { + + fun unit(): NewPlanUnitPrice? = unit + + fun tiered(): NewPlanTieredPrice? = tiered + + fun bulk(): NewPlanBulkPrice? = bulk + + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters + + fun package_(): NewPlanPackagePrice? = package_ + + fun matrix(): NewPlanMatrixPrice? = matrix + + fun thresholdTotalAmount(): NewPlanThresholdTotalAmountPrice? = thresholdTotalAmount + + fun tieredPackage(): NewPlanTieredPackagePrice? = tieredPackage + + fun tieredWithMinimum(): NewPlanTieredWithMinimumPrice? = tieredWithMinimum + + fun groupedTiered(): NewPlanGroupedTieredPrice? = groupedTiered + + fun tieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice? = + tieredPackageWithMinimum + + fun packageWithAllocation(): NewPlanPackageWithAllocationPrice? = packageWithAllocation + + fun unitWithPercent(): NewPlanUnitWithPercentPrice? = unitWithPercent + + fun matrixWithAllocation(): NewPlanMatrixWithAllocationPrice? = matrixWithAllocation + + fun tieredWithProration(): TieredWithProration? = tieredWithProration + + fun unitWithProration(): NewPlanUnitWithProrationPrice? = unitWithProration + + fun groupedAllocation(): NewPlanGroupedAllocationPrice? = groupedAllocation + + fun bulkWithProration(): NewPlanBulkWithProrationPrice? = bulkWithProration + + fun groupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice? = + groupedWithProratedMinimum + + fun groupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice? = + groupedWithMeteredMinimum + + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = + groupedWithMinMaxThresholds + + fun matrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice? = matrixWithDisplayName + + fun groupedTieredPackage(): NewPlanGroupedTieredPackagePrice? = groupedTieredPackage + + fun maxGroupTieredPackage(): NewPlanMaxGroupTieredPackagePrice? = maxGroupTieredPackage + + fun scalableMatrixWithUnitPricing(): NewPlanScalableMatrixWithUnitPricingPrice? = + scalableMatrixWithUnitPricing + + fun scalableMatrixWithTieredPricing(): NewPlanScalableMatrixWithTieredPricingPrice? = + scalableMatrixWithTieredPricing + + fun cumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice? = cumulativeGroupedBulk + + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = + cumulativeGroupedAllocation + + fun minimum(): NewPlanMinimumCompositePrice? = minimum + + fun percent(): Percent? = percent + + fun eventOutput(): EventOutput? = eventOutput + + fun isUnit(): Boolean = unit != null + + fun isTiered(): Boolean = tiered != null + + fun isBulk(): Boolean = bulk != null + + fun isBulkWithFilters(): Boolean = bulkWithFilters != null + + fun isPackage(): Boolean = package_ != null + + fun isMatrix(): Boolean = matrix != null + + fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null + + fun isTieredPackage(): Boolean = tieredPackage != null + + fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null + + fun isGroupedTiered(): Boolean = groupedTiered != null + + fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + + fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + + fun isUnitWithPercent(): Boolean = unitWithPercent != null + + fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + + fun isTieredWithProration(): Boolean = tieredWithProration != null + + fun isUnitWithProration(): Boolean = unitWithProration != null + + fun isGroupedAllocation(): Boolean = groupedAllocation != null + + fun isBulkWithProration(): Boolean = bulkWithProration != null + + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null + + fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null + + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null + + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + + fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + + fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null + + fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null + + fun isScalableMatrixWithTieredPricing(): Boolean = + scalableMatrixWithTieredPricing != null + + fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null + + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null + + fun isMinimum(): Boolean = minimum != null + + fun isPercent(): Boolean = percent != null + + fun isEventOutput(): Boolean = eventOutput != null + + fun asUnit(): NewPlanUnitPrice = unit.getOrThrow("unit") + + fun asTiered(): NewPlanTieredPrice = tiered.getOrThrow("tiered") + + fun asBulk(): NewPlanBulkPrice = bulk.getOrThrow("bulk") + + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") + + fun asPackage(): NewPlanPackagePrice = package_.getOrThrow("package_") + + fun asMatrix(): NewPlanMatrixPrice = matrix.getOrThrow("matrix") + + fun asThresholdTotalAmount(): NewPlanThresholdTotalAmountPrice = + thresholdTotalAmount.getOrThrow("thresholdTotalAmount") + + fun asTieredPackage(): NewPlanTieredPackagePrice = + tieredPackage.getOrThrow("tieredPackage") + + fun asTieredWithMinimum(): NewPlanTieredWithMinimumPrice = + tieredWithMinimum.getOrThrow("tieredWithMinimum") + + fun asGroupedTiered(): NewPlanGroupedTieredPrice = + groupedTiered.getOrThrow("groupedTiered") + + fun asTieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice = + tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + + fun asPackageWithAllocation(): NewPlanPackageWithAllocationPrice = + packageWithAllocation.getOrThrow("packageWithAllocation") + + fun asUnitWithPercent(): NewPlanUnitWithPercentPrice = + unitWithPercent.getOrThrow("unitWithPercent") + + fun asMatrixWithAllocation(): NewPlanMatrixWithAllocationPrice = + matrixWithAllocation.getOrThrow("matrixWithAllocation") + + fun asTieredWithProration(): TieredWithProration = + tieredWithProration.getOrThrow("tieredWithProration") + + fun asUnitWithProration(): NewPlanUnitWithProrationPrice = + unitWithProration.getOrThrow("unitWithProration") + + fun asGroupedAllocation(): NewPlanGroupedAllocationPrice = + groupedAllocation.getOrThrow("groupedAllocation") + + fun asBulkWithProration(): NewPlanBulkWithProrationPrice = + bulkWithProration.getOrThrow("bulkWithProration") + + fun asGroupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice = + groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") + + fun asGroupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice = + groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") + + fun asMatrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice = + matrixWithDisplayName.getOrThrow("matrixWithDisplayName") + + fun asGroupedTieredPackage(): NewPlanGroupedTieredPackagePrice = + groupedTieredPackage.getOrThrow("groupedTieredPackage") + + fun asMaxGroupTieredPackage(): NewPlanMaxGroupTieredPackagePrice = + maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") + + fun asScalableMatrixWithUnitPricing(): NewPlanScalableMatrixWithUnitPricingPrice = + scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") + + fun asScalableMatrixWithTieredPricing(): NewPlanScalableMatrixWithTieredPricingPrice = + scalableMatrixWithTieredPricing.getOrThrow("scalableMatrixWithTieredPricing") + + fun asCumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice = + cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") + + fun asMinimum(): NewPlanMinimumCompositePrice = minimum.getOrThrow("minimum") + + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + unit != null -> visitor.visitUnit(unit) + tiered != null -> visitor.visitTiered(tiered) + bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) + thresholdTotalAmount != null -> + visitor.visitThresholdTotalAmount(thresholdTotalAmount) + tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) + tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + tieredPackageWithMinimum != null -> + visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) + packageWithAllocation != null -> + visitor.visitPackageWithAllocation(packageWithAllocation) + unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + matrixWithAllocation != null -> + visitor.visitMatrixWithAllocation(matrixWithAllocation) + tieredWithProration != null -> + visitor.visitTieredWithProration(tieredWithProration) + unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) + groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) + groupedWithProratedMinimum != null -> + visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) + groupedWithMeteredMinimum != null -> + visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) + matrixWithDisplayName != null -> + visitor.visitMatrixWithDisplayName(matrixWithDisplayName) + groupedTieredPackage != null -> + visitor.visitGroupedTieredPackage(groupedTieredPackage) + maxGroupTieredPackage != null -> + visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) + scalableMatrixWithUnitPricing != null -> + visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) + scalableMatrixWithTieredPricing != null -> + visitor.visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing + ) + cumulativeGroupedBulk != null -> + visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Price = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitUnit(unit: NewPlanUnitPrice) { + unit.validate() + } + + override fun visitTiered(tiered: NewPlanTieredPrice) { + tiered.validate() + } + + override fun visitBulk(bulk: NewPlanBulkPrice) { + bulk.validate() + } + + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() + } + + override fun visitPackage(package_: NewPlanPackagePrice) { + package_.validate() + } + + override fun visitMatrix(matrix: NewPlanMatrixPrice) { + matrix.validate() + } + + override fun visitThresholdTotalAmount( + thresholdTotalAmount: NewPlanThresholdTotalAmountPrice + ) { + thresholdTotalAmount.validate() + } + + override fun visitTieredPackage(tieredPackage: NewPlanTieredPackagePrice) { + tieredPackage.validate() + } + + override fun visitTieredWithMinimum( + tieredWithMinimum: NewPlanTieredWithMinimumPrice + ) { + tieredWithMinimum.validate() + } + + override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) { + groupedTiered.validate() + } + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ) { + tieredPackageWithMinimum.validate() + } + + override fun visitPackageWithAllocation( + packageWithAllocation: NewPlanPackageWithAllocationPrice + ) { + packageWithAllocation.validate() + } + + override fun visitUnitWithPercent( + unitWithPercent: NewPlanUnitWithPercentPrice + ) { + unitWithPercent.validate() + } + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ) { + matrixWithAllocation.validate() + } + + override fun visitTieredWithProration( + tieredWithProration: TieredWithProration + ) { + tieredWithProration.validate() + } + + override fun visitUnitWithProration( + unitWithProration: NewPlanUnitWithProrationPrice + ) { + unitWithProration.validate() + } + + override fun visitGroupedAllocation( + groupedAllocation: NewPlanGroupedAllocationPrice + ) { + groupedAllocation.validate() + } + + override fun visitBulkWithProration( + bulkWithProration: NewPlanBulkWithProrationPrice + ) { + bulkWithProration.validate() + } + + override fun visitGroupedWithProratedMinimum( + groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice + ) { + groupedWithProratedMinimum.validate() + } + + override fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice + ) { + groupedWithMeteredMinimum.validate() + } + + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) { + groupedWithMinMaxThresholds.validate() + } + + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice + ) { + matrixWithDisplayName.validate() + } + + override fun visitGroupedTieredPackage( + groupedTieredPackage: NewPlanGroupedTieredPackagePrice + ) { + groupedTieredPackage.validate() + } + + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice + ) { + maxGroupTieredPackage.validate() + } + + override fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice + ) { + scalableMatrixWithUnitPricing.validate() + } + + override fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewPlanScalableMatrixWithTieredPricingPrice + ) { + scalableMatrixWithTieredPricing.validate() + } + + override fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice + ) { + cumulativeGroupedBulk.validate() + } + + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) { + cumulativeGroupedAllocation.validate() + } + + override fun visitMinimum(minimum: NewPlanMinimumCompositePrice) { + minimum.validate() + } + + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitUnit(unit: NewPlanUnitPrice) = unit.validity() + + override fun visitTiered(tiered: NewPlanTieredPrice) = tiered.validity() + + override fun visitBulk(bulk: NewPlanBulkPrice) = bulk.validity() + + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() + + override fun visitPackage(package_: NewPlanPackagePrice) = + package_.validity() + + override fun visitMatrix(matrix: NewPlanMatrixPrice) = matrix.validity() + + override fun visitThresholdTotalAmount( + thresholdTotalAmount: NewPlanThresholdTotalAmountPrice + ) = thresholdTotalAmount.validity() + + override fun visitTieredPackage(tieredPackage: NewPlanTieredPackagePrice) = + tieredPackage.validity() + + override fun visitTieredWithMinimum( + tieredWithMinimum: NewPlanTieredWithMinimumPrice + ) = tieredWithMinimum.validity() + + override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = + groupedTiered.validity() + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ) = tieredPackageWithMinimum.validity() + + override fun visitPackageWithAllocation( + packageWithAllocation: NewPlanPackageWithAllocationPrice + ) = packageWithAllocation.validity() + + override fun visitUnitWithPercent( + unitWithPercent: NewPlanUnitWithPercentPrice + ) = unitWithPercent.validity() + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ) = matrixWithAllocation.validity() + + override fun visitTieredWithProration( + tieredWithProration: TieredWithProration + ) = tieredWithProration.validity() + + override fun visitUnitWithProration( + unitWithProration: NewPlanUnitWithProrationPrice + ) = unitWithProration.validity() + + override fun visitGroupedAllocation( + groupedAllocation: NewPlanGroupedAllocationPrice + ) = groupedAllocation.validity() + + override fun visitBulkWithProration( + bulkWithProration: NewPlanBulkWithProrationPrice + ) = bulkWithProration.validity() + + override fun visitGroupedWithProratedMinimum( + groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice + ) = groupedWithProratedMinimum.validity() + + override fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice + ) = groupedWithMeteredMinimum.validity() + + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice + ) = matrixWithDisplayName.validity() + + override fun visitGroupedTieredPackage( + groupedTieredPackage: NewPlanGroupedTieredPackagePrice + ) = groupedTieredPackage.validity() + + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice + ) = maxGroupTieredPackage.validity() + + override fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice + ) = scalableMatrixWithUnitPricing.validity() + + override fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewPlanScalableMatrixWithTieredPricingPrice + ) = scalableMatrixWithTieredPricing.validity() + + override fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice + ) = cumulativeGroupedBulk.validity() + + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() + + override fun visitMinimum(minimum: NewPlanMinimumCompositePrice) = + minimum.validity() + + override fun visitPercent(percent: Percent) = percent.validity() + + override fun visitEventOutput(eventOutput: EventOutput) = + eventOutput.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Price && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput + } + + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) + + override fun toString(): String = + when { + unit != null -> "Price{unit=$unit}" + tiered != null -> "Price{tiered=$tiered}" + bulk != null -> "Price{bulk=$bulk}" + bulkWithFilters != null -> "Price{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "Price{package_=$package_}" + matrix != null -> "Price{matrix=$matrix}" + thresholdTotalAmount != null -> + "Price{thresholdTotalAmount=$thresholdTotalAmount}" + tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" + tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" + groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" + tieredPackageWithMinimum != null -> + "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" + packageWithAllocation != null -> + "Price{packageWithAllocation=$packageWithAllocation}" + unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + matrixWithAllocation != null -> + "Price{matrixWithAllocation=$matrixWithAllocation}" + tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" + unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" + groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" + groupedWithProratedMinimum != null -> + "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" + groupedWithMeteredMinimum != null -> + "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "Price{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" + matrixWithDisplayName != null -> + "Price{matrixWithDisplayName=$matrixWithDisplayName}" + groupedTieredPackage != null -> + "Price{groupedTieredPackage=$groupedTieredPackage}" + maxGroupTieredPackage != null -> + "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" + scalableMatrixWithUnitPricing != null -> + "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" + scalableMatrixWithTieredPricing != null -> + "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" + cumulativeGroupedBulk != null -> + "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" + cumulativeGroupedAllocation != null -> + "Price{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "Price{minimum=$minimum}" + percent != null -> "Price{percent=$percent}" + eventOutput != null -> "Price{eventOutput=$eventOutput}" + _json != null -> "Price{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Price") + } + + companion object { + + fun ofUnit(unit: NewPlanUnitPrice) = Price(unit = unit) + + fun ofTiered(tiered: NewPlanTieredPrice) = Price(tiered = tiered) + + fun ofBulk(bulk: NewPlanBulkPrice) = Price(bulk = bulk) + + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + Price(bulkWithFilters = bulkWithFilters) + + fun ofPackage(package_: NewPlanPackagePrice) = Price(package_ = package_) + + fun ofMatrix(matrix: NewPlanMatrixPrice) = Price(matrix = matrix) + + fun ofThresholdTotalAmount(thresholdTotalAmount: NewPlanThresholdTotalAmountPrice) = + Price(thresholdTotalAmount = thresholdTotalAmount) + + fun ofTieredPackage(tieredPackage: NewPlanTieredPackagePrice) = + Price(tieredPackage = tieredPackage) + + fun ofTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = + Price(tieredWithMinimum = tieredWithMinimum) + + fun ofGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = + Price(groupedTiered = groupedTiered) + + fun ofTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + + fun ofPackageWithAllocation( + packageWithAllocation: NewPlanPackageWithAllocationPrice + ) = Price(packageWithAllocation = packageWithAllocation) + + fun ofUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice) = + Price(unitWithPercent = unitWithPercent) + + fun ofMatrixWithAllocation(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = + Price(matrixWithAllocation = matrixWithAllocation) + + fun ofTieredWithProration(tieredWithProration: TieredWithProration) = + Price(tieredWithProration = tieredWithProration) + + fun ofUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice) = + Price(unitWithProration = unitWithProration) + + fun ofGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice) = + Price(groupedAllocation = groupedAllocation) + + fun ofBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice) = + Price(bulkWithProration = bulkWithProration) + + fun ofGroupedWithProratedMinimum( + groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice + ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) + + fun ofGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice + ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = Price(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + + fun ofMatrixWithDisplayName( + matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice + ) = Price(matrixWithDisplayName = matrixWithDisplayName) + + fun ofGroupedTieredPackage(groupedTieredPackage: NewPlanGroupedTieredPackagePrice) = + Price(groupedTieredPackage = groupedTieredPackage) + + fun ofMaxGroupTieredPackage( + maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice + ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) + + fun ofScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice + ) = Price(scalableMatrixWithUnitPricing = scalableMatrixWithUnitPricing) + + fun ofScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: NewPlanScalableMatrixWithTieredPricingPrice + ) = Price(scalableMatrixWithTieredPricing = scalableMatrixWithTieredPricing) + + fun ofCumulativeGroupedBulk( + cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice + ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) + + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = Price(cumulativeGroupedAllocation = cumulativeGroupedAllocation) + + fun ofMinimum(minimum: NewPlanMinimumCompositePrice) = Price(minimum = minimum) + + fun ofPercent(percent: Percent) = Price(percent = percent) + + fun ofEventOutput(eventOutput: EventOutput) = Price(eventOutput = eventOutput) + } + + /** + * An interface that defines how to map each variant of [Price] to a value of type [T]. + */ + interface Visitor { + + fun visitUnit(unit: NewPlanUnitPrice): T + + fun visitTiered(tiered: NewPlanTieredPrice): T + + fun visitBulk(bulk: NewPlanBulkPrice): T + + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T + + fun visitPackage(package_: NewPlanPackagePrice): T + + fun visitMatrix(matrix: NewPlanMatrixPrice): T + + fun visitThresholdTotalAmount( + thresholdTotalAmount: NewPlanThresholdTotalAmountPrice + ): T + + fun visitTieredPackage(tieredPackage: NewPlanTieredPackagePrice): T + + fun visitTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice): T + + fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice): T + + fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ): T + + fun visitPackageWithAllocation( + packageWithAllocation: NewPlanPackageWithAllocationPrice + ): T + + fun visitUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice): T + + fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ): T + + fun visitTieredWithProration(tieredWithProration: TieredWithProration): T + + fun visitUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice): T + + fun visitGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice): T + + fun visitBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice): T + + fun visitGroupedWithProratedMinimum( + groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice + ): T + + fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice + ): T + + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ): T + + fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice + ): T + + fun visitGroupedTieredPackage( + groupedTieredPackage: NewPlanGroupedTieredPackagePrice + ): T + + fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice + ): T + + fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice + ): T + + fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: NewPlanScalableMatrixWithTieredPricingPrice + ): T + + fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice + ): T + + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ): T + + fun visitMinimum(minimum: NewPlanMinimumCompositePrice): T + + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T + + /** + * Maps an unknown variant of [Price] to a value of type [T]. + * + * An instance of [Price] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown Price: $json") + } + } + + internal class Deserializer : BaseDeserializer(Price::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Price { + val json = JsonValue.fromJsonNode(node) + val modelType = json.asObject()?.get("model_type")?.asString() + + when (modelType) { + "unit" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(unit = it, _json = json) + } ?: Price(_json = json) + } + "tiered" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(tiered = it, _json = json) + } ?: Price(_json = json) + } + "bulk" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulk = it, _json = json) + } ?: Price(_json = json) + } + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulkWithFilters = it, _json = json) + } ?: Price(_json = json) + } + "package" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) + } + "matrix" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(matrix = it, _json = json) + } ?: Price(_json = json) + } + "threshold_total_amount" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(thresholdTotalAmount = it, _json = json) } + ?: Price(_json = json) + } + "tiered_package" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(tieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "tiered_with_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tieredWithMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_tiered" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(groupedTiered = it, _json = json) } + ?: Price(_json = json) + } + "tiered_package_with_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tieredPackageWithMinimum = it, _json = json) } + ?: Price(_json = json) + } + "package_with_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(packageWithAllocation = it, _json = json) } + ?: Price(_json = json) + } + "unit_with_percent" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(unitWithPercent = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(matrixWithAllocation = it, _json = json) } + ?: Price(_json = json) + } + "tiered_with_proration" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(tieredWithProration = it, _json = json) } + ?: Price(_json = json) + } + "unit_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(unitWithProration = it, _json = json) } + ?: Price(_json = json) + } + "grouped_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedAllocation = it, _json = json) } + ?: Price(_json = json) + } + "bulk_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(bulkWithProration = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_prorated_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithProratedMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_metered_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_min_max_thresholds" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithMinMaxThresholds = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_display_name" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(matrixWithDisplayName = it, _json = json) } + ?: Price(_json = json) + } + "grouped_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedTieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "max_group_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(maxGroupTieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "scalable_matrix_with_unit_pricing" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(scalableMatrixWithUnitPricing = it, _json = json) } + ?: Price(_json = json) + } + "scalable_matrix_with_tiered_pricing" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(scalableMatrixWithTieredPricing = it, _json = json) } + ?: Price(_json = json) + } + "cumulative_grouped_bulk" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(cumulativeGroupedBulk = it, _json = json) } + ?: Price(_json = json) + } + "cumulative_grouped_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(cumulativeGroupedAllocation = it, _json = json) } + ?: Price(_json = json) + } + "minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(minimum = it, _json = json) } ?: Price(_json = json) + } + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(percent = it, _json = json) + } ?: Price(_json = json) + } + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(eventOutput = it, _json = json) + } ?: Price(_json = json) + } + } + + return Price(_json = json) + } + } + + internal class Serializer : BaseSerializer(Price::class) { + + override fun serialize( + value: Price, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.unit != null -> generator.writeObject(value.unit) + value.tiered != null -> generator.writeObject(value.tiered) + value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> + generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) + value.thresholdTotalAmount != null -> + generator.writeObject(value.thresholdTotalAmount) + value.tieredPackage != null -> generator.writeObject(value.tieredPackage) + value.tieredWithMinimum != null -> + generator.writeObject(value.tieredWithMinimum) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) + value.tieredPackageWithMinimum != null -> + generator.writeObject(value.tieredPackageWithMinimum) + value.packageWithAllocation != null -> + generator.writeObject(value.packageWithAllocation) + value.unitWithPercent != null -> + generator.writeObject(value.unitWithPercent) + value.matrixWithAllocation != null -> + generator.writeObject(value.matrixWithAllocation) + value.tieredWithProration != null -> + generator.writeObject(value.tieredWithProration) + value.unitWithProration != null -> + generator.writeObject(value.unitWithProration) + value.groupedAllocation != null -> + generator.writeObject(value.groupedAllocation) + value.bulkWithProration != null -> + generator.writeObject(value.bulkWithProration) + value.groupedWithProratedMinimum != null -> + generator.writeObject(value.groupedWithProratedMinimum) + value.groupedWithMeteredMinimum != null -> + generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) + value.matrixWithDisplayName != null -> + generator.writeObject(value.matrixWithDisplayName) + value.groupedTieredPackage != null -> + generator.writeObject(value.groupedTieredPackage) + value.maxGroupTieredPackage != null -> + generator.writeObject(value.maxGroupTieredPackage) + value.scalableMatrixWithUnitPricing != null -> + generator.writeObject(value.scalableMatrixWithUnitPricing) + value.scalableMatrixWithTieredPricing != null -> + generator.writeObject(value.scalableMatrixWithTieredPricing) + value.cumulativeGroupedBulk != null -> + generator.writeObject(value.cumulativeGroupedBulk) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Price") + } + } + } + + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bulkWithFiltersConfig: JsonField, + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = + bulkWithFiltersConfig + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [BulkWithFilters]. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFilters]. */ + class Builder internal constructor() { + + private var bulkWithFiltersConfig: JsonField? = null + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + itemId = bulkWithFilters.itemId + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + billableMetricId = bulkWithFilters.billableMetricId + billedInAdvance = bulkWithFilters.billedInAdvance + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + currency = bulkWithFilters.currency + dimensionalPriceConfiguration = + bulkWithFilters.dimensionalPriceConfiguration + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoiceGroupingKey = bulkWithFilters.invoiceGroupingKey + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + metadata = bulkWithFilters.metadata + referenceId = bulkWithFilters.referenceId + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() + } + + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig( + bulkWithFiltersConfig: JsonField + ) = apply { this.bulkWithFiltersConfig = bulkWithFiltersConfig } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BulkWithFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFilters = + BulkWithFilters( + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFilters = apply { + if (validated) { + return@apply + } + + bulkWithFiltersConfig().validate() + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("bulk_with_filters")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) + + /** + * Property filters to apply (all must match) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [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 + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { + + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithFiltersConfig.additionalProperties.toMutableMap() + } + + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + + /** Bulk tiers for rating based on total usage volume */ + 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 [BulkWithFiltersConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } + + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = + propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + propertyKey() + propertyValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = + tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filters, tiers, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFilters && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFilters{bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class TieredWithProration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val tieredWithProrationConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + tieredWithProrationConfig: JsonField = + JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for tiered_with_proration pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tieredWithProrationConfig(): TieredWithProrationConfig = + tieredWithProrationConfig.getRequired("tiered_with_proration_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [tieredWithProrationConfig]. + * + * Unlike [tieredWithProrationConfig], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + fun _tieredWithProrationConfig(): JsonField = + tieredWithProrationConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [TieredWithProration]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProration]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("tiered_with_proration") + private var name: JsonField? = null + private var tieredWithProrationConfig: JsonField? = + null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tieredWithProration: TieredWithProration) = apply { + cadence = tieredWithProration.cadence + itemId = tieredWithProration.itemId + modelType = tieredWithProration.modelType + name = tieredWithProration.name + tieredWithProrationConfig = tieredWithProration.tieredWithProrationConfig + billableMetricId = tieredWithProration.billableMetricId + billedInAdvance = tieredWithProration.billedInAdvance + billingCycleConfiguration = tieredWithProration.billingCycleConfiguration + conversionRate = tieredWithProration.conversionRate + conversionRateConfig = tieredWithProration.conversionRateConfig + currency = tieredWithProration.currency + dimensionalPriceConfiguration = + tieredWithProration.dimensionalPriceConfiguration + externalPriceId = tieredWithProration.externalPriceId + fixedPriceQuantity = tieredWithProration.fixedPriceQuantity + invoiceGroupingKey = tieredWithProration.invoiceGroupingKey + invoicingCycleConfiguration = + tieredWithProration.invoicingCycleConfiguration + metadata = tieredWithProration.metadata + referenceId = tieredWithProration.referenceId + additionalProperties = + tieredWithProration.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for tiered_with_proration pricing */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: TieredWithProrationConfig + ) = tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) + + /** + * Sets [Builder.tieredWithProrationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.tieredWithProrationConfig] with a well-typed + * [TieredWithProrationConfig] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: JsonField + ) = apply { this.tieredWithProrationConfig = tieredWithProrationConfig } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TieredWithProration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProration = + TieredWithProration( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("tieredWithProrationConfig", tieredWithProrationConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProration = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("tiered_with_proration")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + tieredWithProrationConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("tiered_with_proration")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (tieredWithProrationConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for tiered_with_proration pricing */ + class TieredWithProrationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Tiers for rating based on total usage quantities into the specified tier with + * proration + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 + * [TieredWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProrationConfig]. */ + class Builder internal constructor() { + + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = + apply { + tiers = tieredWithProrationConfig.tiers.map { it.toMutableList() } + additionalProperties = + tieredWithProrationConfig.additionalProperties.toMutableMap() + } + + /** + * Tiers for rating based on total usage quantities into the specified tier + * with proration + */ + 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 [TieredWithProrationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProrationConfig = + TieredWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProrationConfig = apply { + if (validated) { + return@apply + } + + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tiered with proration tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Inclusive tier starting value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun tierLowerBound(): String = + tierLowerBound.getRequired("tier_lower_bound") + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Inclusive tier starting value */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProration && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredWithProrationConfig == other.tieredWithProrationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProration{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, tieredWithProrationConfig=$tieredWithProrationConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val groupedWithMinMaxThresholdsConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + groupedWithMinMaxThresholdsConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for grouped_with_min_max_thresholds pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired( + "grouped_with_min_max_thresholds_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - /** - * The phase to replace this adjustment from. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - /** - * Returns the raw JSON value of [adjustment]. - * - * Unlike [adjustment], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("adjustment") - @ExcludeMissing - fun _adjustment(): JsonField = adjustment + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - /** - * Returns the raw JSON value of [replacesAdjustmentId]. - * - * Unlike [replacesAdjustmentId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("replaces_adjustment_id") - @ExcludeMissing - fun _replacesAdjustmentId(): JsonField = replacesAdjustmentId + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - /** - * Returns the raw JSON value of [planPhaseOrder]. - * - * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("plan_phase_order") - @ExcludeMissing - fun _planPhaseOrder(): JsonField = planPhaseOrder + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - fun toBuilder() = Builder().from(this) + /** + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. + * + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + fun _groupedWithMinMaxThresholdsConfig(): + JsonField = groupedWithMinMaxThresholdsConfig - companion object { + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - /** - * Returns a mutable builder for constructing an instance of [ReplaceAdjustment]. - * - * The following fields are required: - * ```kotlin - * .adjustment() - * .replacesAdjustmentId() - * ``` - */ - fun builder() = Builder() - } + /** + * 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 - /** A builder for [ReplaceAdjustment]. */ - class Builder internal constructor() { + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - private var adjustment: JsonField? = null - private var replacesAdjustmentId: JsonField? = null - private var planPhaseOrder: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - internal fun from(replaceAdjustment: ReplaceAdjustment) = apply { - adjustment = replaceAdjustment.adjustment - replacesAdjustmentId = replaceAdjustment.replacesAdjustmentId - planPhaseOrder = replaceAdjustment.planPhaseOrder - additionalProperties = replaceAdjustment.additionalProperties.toMutableMap() - } + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - /** The definition of a new adjustment to create and add to the plan. */ - fun adjustment(adjustment: Adjustment) = adjustment(JsonField.of(adjustment)) + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - /** - * Sets [Builder.adjustment] to an arbitrary JSON value. - * - * You should usually call [Builder.adjustment] with a well-typed [Adjustment] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun adjustment(adjustment: JsonField) = apply { - this.adjustment = adjustment - } + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - /** - * Alias for calling [adjustment] with - * `Adjustment.ofPercentageDiscount(percentageDiscount)`. - */ - fun adjustment(percentageDiscount: NewPercentageDiscount) = - adjustment(Adjustment.ofPercentageDiscount(percentageDiscount)) + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewPercentageDiscount.builder() - * .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) - * .percentageDiscount(percentageDiscount) - * .build() - * ``` - */ - fun percentageDiscountAdjustment(percentageDiscount: Double) = - adjustment( - NewPercentageDiscount.builder() - .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) - .percentageDiscount(percentageDiscount) - .build() - ) + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - /** Alias for calling [adjustment] with `Adjustment.ofUsageDiscount(usageDiscount)`. */ - fun adjustment(usageDiscount: NewUsageDiscount) = - adjustment(Adjustment.ofUsageDiscount(usageDiscount)) + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewUsageDiscount.builder() - * .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) - * .usageDiscount(usageDiscount) - * .build() - * ``` - */ - fun usageDiscountAdjustment(usageDiscount: Double) = - adjustment( - NewUsageDiscount.builder() - .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) - .usageDiscount(usageDiscount) - .build() - ) + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - /** - * Alias for calling [adjustment] with `Adjustment.ofAmountDiscount(amountDiscount)`. - */ - fun adjustment(amountDiscount: NewAmountDiscount) = - adjustment(Adjustment.ofAmountDiscount(amountDiscount)) + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewAmountDiscount.builder() - * .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) - * .amountDiscount(amountDiscount) - * .build() - * ``` - */ - fun amountDiscountAdjustment(amountDiscount: String) = - adjustment( - NewAmountDiscount.builder() - .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) - .amountDiscount(amountDiscount) - .build() - ) + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - /** Alias for calling [adjustment] with `Adjustment.ofMinimum(minimum)`. */ - fun adjustment(minimum: NewMinimum) = adjustment(Adjustment.ofMinimum(minimum)) + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - /** Alias for calling [adjustment] with `Adjustment.ofMaximum(maximum)`. */ - fun adjustment(maximum: NewMaximum) = adjustment(Adjustment.ofMaximum(maximum)) + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewMaximum.builder() - * .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) - * .maximumAmount(maximumAmount) - * .build() - * ``` - */ - fun maximumAdjustment(maximumAmount: String) = - adjustment( - NewMaximum.builder() - .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) - .maximumAmount(maximumAmount) - .build() - ) + @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 + * [GroupedWithMinMaxThresholds]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholds]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("grouped_with_min_max_thresholds") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = + apply { + cadence = groupedWithMinMaxThresholds.cadence + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + itemId = groupedWithMinMaxThresholds.itemId + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + billableMetricId = groupedWithMinMaxThresholds.billableMetricId + billedInAdvance = groupedWithMinMaxThresholds.billedInAdvance + billingCycleConfiguration = + groupedWithMinMaxThresholds.billingCycleConfiguration + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + currency = groupedWithMinMaxThresholds.currency + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + invoiceGroupingKey = groupedWithMinMaxThresholds.invoiceGroupingKey + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + metadata = groupedWithMinMaxThresholds.metadata + referenceId = groupedWithMinMaxThresholds.referenceId + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = + groupedWithMinMaxThresholdsConfig( + JsonField.of(groupedWithMinMaxThresholdsConfig) + ) + + /** + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a + * well-typed [GroupedWithMinMaxThresholdsConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: + JsonField + ) = apply { + this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - /** The id of the adjustment on the plan to replace in the plan. */ - fun replacesAdjustmentId(replacesAdjustmentId: String) = - replacesAdjustmentId(JsonField.of(replacesAdjustmentId)) + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - /** - * Sets [Builder.replacesAdjustmentId] to an arbitrary JSON value. - * - * You should usually call [Builder.replacesAdjustmentId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun replacesAdjustmentId(replacesAdjustmentId: JsonField) = apply { - this.replacesAdjustmentId = replacesAdjustmentId - } + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - /** The phase to replace this adjustment from. */ - fun planPhaseOrder(planPhaseOrder: Long?) = - planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - /** - * Alias for [Builder.planPhaseOrder]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** - * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. - * - * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun planPhaseOrder(planPhaseOrder: JsonField) = apply { - this.planPhaseOrder = planPhaseOrder - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( + checkRequired("cadence", cadence), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + private var validated: Boolean = false - /** - * Returns an immutable instance of [ReplaceAdjustment]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .adjustment() - * .replacesAdjustmentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ReplaceAdjustment = - ReplaceAdjustment( - checkRequired("adjustment", adjustment), - checkRequired("replacesAdjustmentId", replacesAdjustmentId), - planPhaseOrder, - additionalProperties.toMutableMap(), - ) - } + fun validate(): GroupedWithMinMaxThresholds = apply { + if (validated) { + return@apply + } - private var validated: Boolean = false + cadence().validate() + groupedWithMinMaxThresholdsConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - fun validate(): ReplaceAdjustment = apply { - if (validated) { - return@apply - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - adjustment().validate() - replacesAdjustmentId() - planPhaseOrder() - validated = true - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (adjustment.asKnown()?.validity() ?: 0) + - (if (replacesAdjustmentId.asKnown() == null) 0 else 1) + - (if (planPhaseOrder.asKnown() == null) 0 else 1) + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - /** The definition of a new adjustment to create and add to the plan. */ - @JsonDeserialize(using = Adjustment.Deserializer::class) - @JsonSerialize(using = Adjustment.Serializer::class) - class Adjustment - private constructor( - private val percentageDiscount: NewPercentageDiscount? = null, - private val usageDiscount: NewUsageDiscount? = null, - private val amountDiscount: NewAmountDiscount? = null, - private val minimum: NewMinimum? = null, - private val maximum: NewMaximum? = null, - private val _json: JsonValue? = null, - ) { + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN + } - fun percentageDiscount(): NewPercentageDiscount? = percentageDiscount + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") + } - fun usageDiscount(): NewUsageDiscount? = usageDiscount + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } - fun amountDiscount(): NewAmountDiscount? = amountDiscount + known() + validated = true + } - fun minimum(): NewMinimum? = minimum + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun maximum(): NewMaximum? = maximum + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun isPercentageDiscount(): Boolean = percentageDiscount != null + return other is Cadence && value == other.value + } - fun isUsageDiscount(): Boolean = usageDiscount != null + override fun hashCode() = value.hashCode() - fun isAmountDiscount(): Boolean = amountDiscount != null + override fun toString() = value.toString() + } - fun isMinimum(): Boolean = minimum != null + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { - fun isMaximum(): Boolean = maximum != null + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun asPercentageDiscount(): NewPercentageDiscount = - percentageDiscount.getOrThrow("percentageDiscount") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + */ + fun builder() = Builder() + } - fun asUsageDiscount(): NewUsageDiscount = usageDiscount.getOrThrow("usageDiscount") + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate + additionalProperties = + groupedWithMinMaxThresholdsConfig.additionalProperties + .toMutableMap() + } - fun asAmountDiscount(): NewAmountDiscount = amountDiscount.getOrThrow("amountDiscount") + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } - fun asMinimum(): NewMinimum = minimum.getOrThrow("minimum") + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } - fun asMaximum(): NewMaximum = maximum.getOrThrow("maximum") + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } - fun _json(): JsonValue? = _json + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = + perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate + } - fun accept(visitor: Visitor): T = - when { - percentageDiscount != null -> - visitor.visitPercentageDiscount(percentageDiscount) - usageDiscount != null -> visitor.visitUsageDiscount(usageDiscount) - amountDiscount != null -> visitor.visitAmountDiscount(amountDiscount) - minimum != null -> visitor.visitMinimum(minimum) - maximum != null -> visitor.visitMaximum(maximum) - else -> visitor.unknown(_json) - } + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - private var validated: Boolean = false + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun validate(): Adjustment = apply { - if (validated) { - return@apply - } + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - accept( - object : Visitor { - override fun visitPercentageDiscount( - percentageDiscount: NewPercentageDiscount - ) { - percentageDiscount.validate() + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) { - usageDiscount.validate() + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) { - amountDiscount.validate() + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + if (validated) { + return@apply } - override fun visitMinimum(minimum: NewMinimum) { - minimum.validate() + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - override fun visitMaximum(maximum: NewMaximum) { - maximum.validate() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitPercentageDiscount( - percentageDiscount: NewPercentageDiscount - ) = percentageDiscount.validity() + override fun hashCode(): Int = hashCode - override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) = - usageDiscount.validity() + override fun toString() = + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" + } - override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) = - amountDiscount.validity() + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - override fun visitMinimum(minimum: NewMinimum) = minimum.validity() + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - override fun visitMaximum(maximum: NewMaximum) = maximum.validity() + fun toBuilder() = Builder().from(this) - override fun unknown(json: JsonValue?) = 0 + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + fun builder() = Builder() } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** A builder for [Metadata]. */ + class Builder internal constructor() { - return /* spotless:off */ other is Adjustment && percentageDiscount == other.percentageDiscount && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ - } + private var additionalProperties: MutableMap = + mutableMapOf() - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) /* spotless:on */ + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } - override fun toString(): String = - when { - percentageDiscount != null -> - "Adjustment{percentageDiscount=$percentageDiscount}" - usageDiscount != null -> "Adjustment{usageDiscount=$usageDiscount}" - amountDiscount != null -> "Adjustment{amountDiscount=$amountDiscount}" - minimum != null -> "Adjustment{minimum=$minimum}" - maximum != null -> "Adjustment{maximum=$maximum}" - _json != null -> "Adjustment{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Adjustment") - } + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - companion object { + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } - fun ofPercentageDiscount(percentageDiscount: NewPercentageDiscount) = - Adjustment(percentageDiscount = percentageDiscount) + private var validated: Boolean = false - fun ofUsageDiscount(usageDiscount: NewUsageDiscount) = - Adjustment(usageDiscount = usageDiscount) + fun validate(): Metadata = apply { + if (validated) { + return@apply + } - fun ofAmountDiscount(amountDiscount: NewAmountDiscount) = - Adjustment(amountDiscount = amountDiscount) + validated = true + } - fun ofMinimum(minimum: NewMinimum) = Adjustment(minimum = minimum) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofMaximum(maximum: NewMaximum) = Adjustment(maximum = maximum) - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } - /** - * An interface that defines how to map each variant of [Adjustment] to a value of type - * [T]. - */ - interface Visitor { + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun visitPercentageDiscount(percentageDiscount: NewPercentageDiscount): T + return other is Metadata && + additionalProperties == other.additionalProperties + } - fun visitUsageDiscount(usageDiscount: NewUsageDiscount): T + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - fun visitAmountDiscount(amountDiscount: NewAmountDiscount): T + override fun hashCode(): Int = hashCode - fun visitMinimum(minimum: NewMinimum): T + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } - fun visitMaximum(maximum: NewMaximum): T + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholds && + cadence == other.cadence && + groupedWithMinMaxThresholdsConfig == + other.groupedWithMinMaxThresholdsConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholds{cadence=$cadence, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val cumulativeGroupedAllocationConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) /** - * Maps an unknown variant of [Adjustment] to a value of type [T]. + * The cadence to bill for this price on. * - * An instance of [Adjustment] can contain an unknown variant if it was deserialized - * from data that doesn't match any known variant. For example, if the SDK is on an - * older version than the API, then the API may respond with new variants that the - * SDK is unaware of. + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for cumulative_grouped_allocation pricing * - * @throws OrbInvalidDataException in the default implementation. + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown Adjustment: $json") - } - } + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired( + "cumulative_grouped_allocation_config" + ) - internal class Deserializer : BaseDeserializer(Adjustment::class) { + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - override fun ObjectCodec.deserialize(node: JsonNode): Adjustment { - val json = JsonValue.fromJsonNode(node) - val adjustmentType = json.asObject()?.get("adjustment_type")?.asString() + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - when (adjustmentType) { - "percentage_discount" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Adjustment(percentageDiscount = it, _json = json) } - ?: Adjustment(_json = json) - } - "usage_discount" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(usageDiscount = it, _json = json) - } ?: Adjustment(_json = json) - } - "amount_discount" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(amountDiscount = it, _json = json) - } ?: Adjustment(_json = json) - } - "minimum" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(minimum = it, _json = json) - } ?: Adjustment(_json = json) - } - "maximum" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(maximum = it, _json = json) - } ?: Adjustment(_json = json) - } - } + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - return Adjustment(_json = json) - } - } + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - internal class Serializer : BaseSerializer(Adjustment::class) { + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - override fun serialize( - value: Adjustment, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.percentageDiscount != null -> - generator.writeObject(value.percentageDiscount) - value.usageDiscount != null -> generator.writeObject(value.usageDiscount) - value.amountDiscount != null -> generator.writeObject(value.amountDiscount) - value.minimum != null -> generator.writeObject(value.minimum) - value.maximum != null -> generator.writeObject(value.maximum) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Adjustment") - } - } - } - } + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - return /* spotless:off */ other is ReplaceAdjustment && adjustment == other.adjustment && replacesAdjustmentId == other.replacesAdjustmentId && planPhaseOrder == other.planPhaseOrder && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustment, replacesAdjustmentId, planPhaseOrder, additionalProperties) } - /* spotless:on */ + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - override fun hashCode(): Int = hashCode + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - override fun toString() = - "ReplaceAdjustment{adjustment=$adjustment, replacesAdjustmentId=$replacesAdjustmentId, planPhaseOrder=$planPhaseOrder, additionalProperties=$additionalProperties}" - } + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - class ReplacePrice - private constructor( - private val replacesPriceId: JsonField, - private val allocationPrice: JsonField, - private val planPhaseOrder: JsonField, - private val price: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - @JsonCreator - private constructor( - @JsonProperty("replaces_price_id") - @ExcludeMissing - replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("allocation_price") - @ExcludeMissing - allocationPrice: JsonField = JsonMissing.of(), - @JsonProperty("plan_phase_order") - @ExcludeMissing - planPhaseOrder: JsonField = JsonMissing.of(), - @JsonProperty("price") @ExcludeMissing price: JsonField = JsonMissing.of(), - ) : this(replacesPriceId, allocationPrice, planPhaseOrder, price, mutableMapOf()) + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - /** - * The id of the price on the plan to replace in the plan. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun replacesPriceId(): String = replacesPriceId.getRequired("replaces_price_id") + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - /** - * The allocation price to add to the plan. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun allocationPrice(): NewAllocationPrice? = allocationPrice.getNullable("allocation_price") + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - /** - * The phase to replace this price from. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - /** - * The price to add to the plan - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun price(): Price? = price.getNullable("price") + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - /** - * Returns the raw JSON value of [replacesPriceId]. - * - * Unlike [replacesPriceId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("replaces_price_id") - @ExcludeMissing - fun _replacesPriceId(): JsonField = replacesPriceId + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): + JsonField = cumulativeGroupedAllocationConfig - /** - * Returns the raw JSON value of [allocationPrice]. - * - * Unlike [allocationPrice], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("allocation_price") - @ExcludeMissing - fun _allocationPrice(): JsonField = allocationPrice + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - /** - * Returns the raw JSON value of [planPhaseOrder]. - * - * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("plan_phase_order") - @ExcludeMissing - fun _planPhaseOrder(): JsonField = planPhaseOrder + /** + * 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 [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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - fun toBuilder() = Builder().from(this) + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - companion object { + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - /** - * Returns a mutable builder for constructing an instance of [ReplacePrice]. - * - * The following fields are required: - * ```kotlin - * .replacesPriceId() - * ``` - */ - fun builder() = Builder() - } + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - /** A builder for [ReplacePrice]. */ - class Builder internal constructor() { + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - private var replacesPriceId: JsonField? = null - private var allocationPrice: JsonField = JsonMissing.of() - private var planPhaseOrder: JsonField = JsonMissing.of() - private var price: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - internal fun from(replacePrice: ReplacePrice) = apply { - replacesPriceId = replacePrice.replacesPriceId - allocationPrice = replacePrice.allocationPrice - planPhaseOrder = replacePrice.planPhaseOrder - price = replacePrice.price - additionalProperties = replacePrice.additionalProperties.toMutableMap() - } + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - /** The id of the price on the plan to replace in the plan. */ - fun replacesPriceId(replacesPriceId: String) = - replacesPriceId(JsonField.of(replacesPriceId)) + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - /** - * Sets [Builder.replacesPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.replacesPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun replacesPriceId(replacesPriceId: JsonField) = apply { - this.replacesPriceId = replacesPriceId - } + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - /** The allocation price to add to the plan. */ - fun allocationPrice(allocationPrice: NewAllocationPrice?) = - allocationPrice(JsonField.ofNullable(allocationPrice)) + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - /** - * Sets [Builder.allocationPrice] to an arbitrary JSON value. - * - * You should usually call [Builder.allocationPrice] with a well-typed - * [NewAllocationPrice] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun allocationPrice(allocationPrice: JsonField) = apply { - this.allocationPrice = allocationPrice - } + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - /** The phase to replace this price from. */ - fun planPhaseOrder(planPhaseOrder: Long?) = - planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** - * Alias for [Builder.planPhaseOrder]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CumulativeGroupedAllocation]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } - /** - * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. - * - * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun planPhaseOrder(planPhaseOrder: JsonField) = apply { - this.planPhaseOrder = planPhaseOrder - } + /** A builder for [CumulativeGroupedAllocation]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("cumulative_grouped_allocation") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = + apply { + cadence = cumulativeGroupedAllocation.cadence + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + itemId = cumulativeGroupedAllocation.itemId + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + billableMetricId = cumulativeGroupedAllocation.billableMetricId + billedInAdvance = cumulativeGroupedAllocation.billedInAdvance + billingCycleConfiguration = + cumulativeGroupedAllocation.billingCycleConfiguration + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + currency = cumulativeGroupedAllocation.currency + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoiceGroupingKey = cumulativeGroupedAllocation.invoiceGroupingKey + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + metadata = cumulativeGroupedAllocation.metadata + referenceId = cumulativeGroupedAllocation.referenceId + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } - /** The price to add to the plan */ - fun price(price: Price?) = price(JsonField.ofNullable(price)) + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = + cumulativeGroupedAllocationConfig( + JsonField.of(cumulativeGroupedAllocationConfig) + ) - /** - * Sets [Builder.price] to an arbitrary JSON value. - * - * You should usually call [Builder.price] with a well-typed [Price] 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 } + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a + * well-typed [CumulativeGroupedAllocationConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: + JsonField + ) = apply { + this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig + } - /** Alias for calling [price] with `Price.ofUnit(unit)`. */ - fun price(unit: NewPlanUnitPrice) = price(Price.ofUnit(unit)) + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: NewPlanPackagePrice) = price(Price.ofPackage(package_)) + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: NewPlanMatrixPrice) = price(Price.ofMatrix(matrix)) + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ - fun price(tiered: NewPlanTieredPrice) = price(Price.ofTiered(tiered)) + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: NewPlanTieredBpsPrice) = price(Price.ofTieredBps(tieredBps)) + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: NewPlanBpsPrice) = price(Price.ofBps(bps)) + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: NewPlanBulkBpsPrice) = price(Price.ofBulkBps(bulkBps)) + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: NewPlanBulkPrice) = price(Price.ofBulk(bulk)) + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - /** - * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. - */ - fun price(thresholdTotalAmount: NewPlanThresholdTotalAmountPrice) = - price(Price.ofThresholdTotalAmount(thresholdTotalAmount)) + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - /** Alias for calling [price] with `Price.ofTieredPackage(tieredPackage)`. */ - fun price(tieredPackage: NewPlanTieredPackagePrice) = - price(Price.ofTieredPackage(tieredPackage)) + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ - fun price(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = - price(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ - fun price(unitWithPercent: NewPlanUnitWithPercentPrice) = - price(Price.ofUnitWithPercent(unitWithPercent)) + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** - * Alias for calling [price] with - * `Price.ofPackageWithAllocation(packageWithAllocation)`. - */ - fun price(packageWithAllocation: NewPlanPackageWithAllocationPrice) = - price(Price.ofPackageWithAllocation(packageWithAllocation)) + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** - * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. - */ - fun price(tieredWithProration: NewPlanTierWithProrationPrice) = - price(Price.ofTieredWithProration(tieredWithProration)) + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** Alias for calling [price] with `Price.ofUnitWithProration(unitWithProration)`. */ - fun price(unitWithProration: NewPlanUnitWithProrationPrice) = - price(Price.ofUnitWithProration(unitWithProration)) + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - /** Alias for calling [price] with `Price.ofGroupedAllocation(groupedAllocation)`. */ - fun price(groupedAllocation: NewPlanGroupedAllocationPrice) = - price(Price.ofGroupedAllocation(groupedAllocation)) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** - * Alias for calling [price] with - * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. - */ - fun price(groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice) = - price(Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)) + /** + * Returns an immutable instance of [CumulativeGroupedAllocation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( + checkRequired("cadence", cadence), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - /** - * Alias for calling [price] with - * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. - */ - fun price(groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice) = - price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + private var validated: Boolean = false - /** - * Alias for calling [price] with - * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. - */ - fun price(matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice) = - price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) + fun validate(): CumulativeGroupedAllocation = apply { + if (validated) { + return@apply + } - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: NewPlanBulkWithProrationPrice) = - price(Price.ofBulkWithProration(bulkWithProration)) + cadence().validate() + cumulativeGroupedAllocationConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("cumulative_grouped_allocation")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - /** - * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. - */ - fun price(groupedTieredPackage: NewPlanGroupedTieredPackagePrice) = - price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** - * Alias for calling [price] with - * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. - */ - fun price(maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice) = - price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - /** - * Alias for calling [price] with - * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. - */ - fun price(scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice) = - price(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - /** - * Alias for calling [price] with - * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. - */ - fun price( - scalableMatrixWithTieredPricing: NewPlanScalableMatrixWithTieredPricingPrice - ) = price(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - /** - * Alias for calling [price] with - * `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. - */ - fun price(cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice) = - price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") + } - /** - * Alias for calling [price] with - * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. - */ - fun price(tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice) = - price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } - /** - * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. - */ - fun price(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = - price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + known() + validated = true + } - /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: NewPlanGroupedTieredPrice) = - price(Price.ofGroupedTiered(groupedTiered)) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + 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 Cadence && 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) - } + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * Returns an immutable instance of [ReplacePrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .replacesPriceId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ReplacePrice = - ReplacePrice( - checkRequired("replacesPriceId", replacesPriceId), - allocationPrice, - planPhaseOrder, - price, - additionalProperties.toMutableMap(), - ) - } + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + mutableMapOf(), + ) + + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CumulativeGroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - fun validate(): ReplacePrice = apply { - if (validated) { - return@apply - } + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = + cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties + .toMutableMap() + } - replacesPriceId() - allocationPrice()?.validate() - planPhaseOrder() - price()?.validate() - validated = true - } + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (replacesPriceId.asKnown() == null) 0 else 1) + - (allocationPrice.asKnown()?.validity() ?: 0) + - (if (planPhaseOrder.asKnown() == null) 0 else 1) + - (price.asKnown()?.validity() ?: 0) + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } - /** The price to add to the plan */ - @JsonDeserialize(using = Price.Deserializer::class) - @JsonSerialize(using = Price.Serializer::class) - class Price - private constructor( - private val unit: NewPlanUnitPrice? = null, - private val package_: NewPlanPackagePrice? = null, - private val matrix: NewPlanMatrixPrice? = null, - private val tiered: NewPlanTieredPrice? = null, - private val tieredBps: NewPlanTieredBpsPrice? = null, - private val bps: NewPlanBpsPrice? = null, - private val bulkBps: NewPlanBulkBpsPrice? = null, - private val bulk: NewPlanBulkPrice? = null, - private val thresholdTotalAmount: NewPlanThresholdTotalAmountPrice? = null, - private val tieredPackage: NewPlanTieredPackagePrice? = null, - private val tieredWithMinimum: NewPlanTieredWithMinimumPrice? = null, - private val unitWithPercent: NewPlanUnitWithPercentPrice? = null, - private val packageWithAllocation: NewPlanPackageWithAllocationPrice? = null, - private val tieredWithProration: NewPlanTierWithProrationPrice? = null, - private val unitWithProration: NewPlanUnitWithProrationPrice? = null, - private val groupedAllocation: NewPlanGroupedAllocationPrice? = null, - private val groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice? = null, - private val groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice? = null, - private val matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice? = null, - private val bulkWithProration: NewPlanBulkWithProrationPrice? = null, - private val groupedTieredPackage: NewPlanGroupedTieredPackagePrice? = null, - private val maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice? = null, - private val scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice? = - null, - private val scalableMatrixWithTieredPricing: - NewPlanScalableMatrixWithTieredPricingPrice? = - null, - private val cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice? = null, - private val tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice? = null, - private val matrixWithAllocation: NewPlanMatrixWithAllocationPrice? = null, - private val groupedTiered: NewPlanGroupedTieredPrice? = null, - private val _json: JsonValue? = null, - ) { + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } - fun unit(): NewPlanUnitPrice? = unit + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun package_(): NewPlanPackagePrice? = package_ + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun matrix(): NewPlanMatrixPrice? = matrix + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - fun tiered(): NewPlanTieredPrice? = tiered + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun tieredBps(): NewPlanTieredBpsPrice? = tieredBps + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun bps(): NewPlanBpsPrice? = bps + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } - fun bulkBps(): NewPlanBulkBpsPrice? = bulkBps + private var validated: Boolean = false - fun bulk(): NewPlanBulkPrice? = bulk + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply + } - fun thresholdTotalAmount(): NewPlanThresholdTotalAmountPrice? = thresholdTotalAmount + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true + } - fun tieredPackage(): NewPlanTieredPackagePrice? = tieredPackage + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun tieredWithMinimum(): NewPlanTieredWithMinimumPrice? = tieredWithMinimum + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun unitWithPercent(): NewPlanUnitWithPercentPrice? = unitWithPercent + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } - fun packageWithAllocation(): NewPlanPackageWithAllocationPrice? = packageWithAllocation + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) + } - fun tieredWithProration(): NewPlanTierWithProrationPrice? = tieredWithProration + override fun hashCode(): Int = hashCode - fun unitWithProration(): NewPlanUnitWithProrationPrice? = unitWithProration + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } - fun groupedAllocation(): NewPlanGroupedAllocationPrice? = groupedAllocation + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - fun groupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice? = - groupedWithProratedMinimum + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - fun groupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice? = - groupedWithMeteredMinimum + fun toBuilder() = Builder().from(this) - fun matrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice? = matrixWithDisplayName + companion object { - fun bulkWithProration(): NewPlanBulkWithProrationPrice? = bulkWithProration + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + fun builder() = Builder() + } - fun groupedTieredPackage(): NewPlanGroupedTieredPackagePrice? = groupedTieredPackage + /** A builder for [Metadata]. */ + class Builder internal constructor() { - fun maxGroupTieredPackage(): NewPlanMaxGroupTieredPackagePrice? = maxGroupTieredPackage + private var additionalProperties: MutableMap = + mutableMapOf() - fun scalableMatrixWithUnitPricing(): NewPlanScalableMatrixWithUnitPricingPrice? = - scalableMatrixWithUnitPricing + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } - fun scalableMatrixWithTieredPricing(): NewPlanScalableMatrixWithTieredPricingPrice? = - scalableMatrixWithTieredPricing + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun cumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice? = cumulativeGroupedBulk + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun tieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice? = - tieredPackageWithMinimum + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - fun matrixWithAllocation(): NewPlanMatrixWithAllocationPrice? = matrixWithAllocation + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun groupedTiered(): NewPlanGroupedTieredPrice? = groupedTiered + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun isUnit(): Boolean = unit != null + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } - fun isPackage(): Boolean = package_ != null + private var validated: Boolean = false - fun isMatrix(): Boolean = matrix != null + fun validate(): Metadata = apply { + if (validated) { + return@apply + } - fun isTiered(): Boolean = tiered != null + validated = true + } - fun isTieredBps(): Boolean = tieredBps != null + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun isBps(): Boolean = bps != null + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } - fun isBulkBps(): Boolean = bulkBps != null + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun isBulk(): Boolean = bulk != null + return other is Metadata && + additionalProperties == other.additionalProperties + } - fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - fun isTieredPackage(): Boolean = tieredPackage != null + override fun hashCode(): Int = hashCode - fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } - fun isUnitWithPercent(): Boolean = unitWithPercent != null + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + return other is CumulativeGroupedAllocation && + cadence == other.cadence && + cumulativeGroupedAllocationConfig == + other.cumulativeGroupedAllocationConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } - fun isTieredWithProration(): Boolean = tieredWithProration != null + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } - fun isUnitWithProration(): Boolean = unitWithProration != null + override fun hashCode(): Int = hashCode - fun isGroupedAllocation(): Boolean = groupedAllocation != null + override fun toString() = + "CumulativeGroupedAllocation{cadence=$cadence, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } - fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val percentConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) - fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - fun isBulkWithProration(): Boolean = bulkWithProration != null + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") - fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - fun isScalableMatrixWithTieredPricing(): Boolean = - scalableMatrixWithTieredPricing != null + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - fun isGroupedTiered(): Boolean = groupedTiered != null + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - fun asUnit(): NewPlanUnitPrice = unit.getOrThrow("unit") + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - fun asPackage(): NewPlanPackagePrice = package_.getOrThrow("package_") + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - fun asMatrix(): NewPlanMatrixPrice = matrix.getOrThrow("matrix") + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - fun asTiered(): NewPlanTieredPrice = tiered.getOrThrow("tiered") + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - fun asTieredBps(): NewPlanTieredBpsPrice = tieredBps.getOrThrow("tieredBps") + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - fun asBps(): NewPlanBpsPrice = bps.getOrThrow("bps") + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - fun asBulkBps(): NewPlanBulkBpsPrice = bulkBps.getOrThrow("bulkBps") + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - fun asBulk(): NewPlanBulkPrice = bulk.getOrThrow("bulk") + /** + * 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 - fun asThresholdTotalAmount(): NewPlanThresholdTotalAmountPrice = - thresholdTotalAmount.getOrThrow("thresholdTotalAmount") + /** + * Returns the raw JSON value of [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig - fun asTieredPackage(): NewPlanTieredPackagePrice = - tieredPackage.getOrThrow("tieredPackage") + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - fun asTieredWithMinimum(): NewPlanTieredWithMinimumPrice = - tieredWithMinimum.getOrThrow("tieredWithMinimum") + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - fun asUnitWithPercent(): NewPlanUnitWithPercentPrice = - unitWithPercent.getOrThrow("unitWithPercent") + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - fun asPackageWithAllocation(): NewPlanPackageWithAllocationPrice = - packageWithAllocation.getOrThrow("packageWithAllocation") + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - fun asTieredWithProration(): NewPlanTierWithProrationPrice = - tieredWithProration.getOrThrow("tieredWithProration") + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - fun asUnitWithProration(): NewPlanUnitWithProrationPrice = - unitWithProration.getOrThrow("unitWithProration") + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - fun asGroupedAllocation(): NewPlanGroupedAllocationPrice = - groupedAllocation.getOrThrow("groupedAllocation") + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - fun asGroupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice = - groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - fun asGroupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice = - groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - fun asMatrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice = - matrixWithDisplayName.getOrThrow("matrixWithDisplayName") + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - fun asBulkWithProration(): NewPlanBulkWithProrationPrice = - bulkWithProration.getOrThrow("bulkWithProration") + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - fun asGroupedTieredPackage(): NewPlanGroupedTieredPackagePrice = - groupedTieredPackage.getOrThrow("groupedTieredPackage") + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - fun asMaxGroupTieredPackage(): NewPlanMaxGroupTieredPackagePrice = - maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - fun asScalableMatrixWithUnitPricing(): NewPlanScalableMatrixWithUnitPricingPrice = - scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun asScalableMatrixWithTieredPricing(): NewPlanScalableMatrixWithTieredPricingPrice = - scalableMatrixWithTieredPricing.getOrThrow("scalableMatrixWithTieredPricing") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Percent]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + */ + fun builder() = Builder() + } - fun asCumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice = - cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + /** A builder for [Percent]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("percent") + private var name: JsonField? = null + private var percentConfig: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percent: Percent) = apply { + cadence = percent.cadence + itemId = percent.itemId + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + billableMetricId = percent.billableMetricId + billedInAdvance = percent.billedInAdvance + billingCycleConfiguration = percent.billingCycleConfiguration + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + currency = percent.currency + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoiceGroupingKey = percent.invoiceGroupingKey + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + metadata = percent.metadata + referenceId = percent.referenceId + additionalProperties = percent.additionalProperties.toMutableMap() + } - fun asTieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice = - tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed + * [PercentConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } - fun asMatrixWithAllocation(): NewPlanMatrixWithAllocationPrice = - matrixWithAllocation.getOrThrow("matrixWithAllocation") + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - fun asGroupedTiered(): NewPlanGroupedTieredPrice = - groupedTiered.getOrThrow("groupedTiered") + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - fun _json(): JsonValue? = _json + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) - tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) - bulk != null -> visitor.visitBulk(bulk) - thresholdTotalAmount != null -> - visitor.visitThresholdTotalAmount(thresholdTotalAmount) - tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) - tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) - unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) - packageWithAllocation != null -> - visitor.visitPackageWithAllocation(packageWithAllocation) - tieredWithProration != null -> - visitor.visitTieredWithProration(tieredWithProration) - unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) - groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) - groupedWithProratedMinimum != null -> - visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) - groupedWithMeteredMinimum != null -> - visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) - matrixWithDisplayName != null -> - visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) - groupedTieredPackage != null -> - visitor.visitGroupedTieredPackage(groupedTieredPackage) - maxGroupTieredPackage != null -> - visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) - scalableMatrixWithUnitPricing != null -> - visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) - scalableMatrixWithTieredPricing != null -> - visitor.visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() ) - cumulativeGroupedBulk != null -> - visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) - tieredPackageWithMinimum != null -> - visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) - matrixWithAllocation != null -> - visitor.visitMatrixWithAllocation(matrixWithAllocation) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) - else -> visitor.unknown(_json) - } - private var validated: Boolean = false + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - fun validate(): Price = apply { - if (validated) { - return@apply - } + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - accept( - object : Visitor { - override fun visitUnit(unit: NewPlanUnitPrice) { - unit.validate() - } + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - override fun visitPackage(package_: NewPlanPackagePrice) { - package_.validate() - } + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - override fun visitMatrix(matrix: NewPlanMatrixPrice) { - matrix.validate() - } + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - override fun visitTiered(tiered: NewPlanTieredPrice) { - tiered.validate() - } + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - override fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice) { - tieredBps.validate() - } + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - override fun visitBps(bps: NewPlanBpsPrice) { - bps.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - override fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice) { - bulkBps.validate() - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - override fun visitBulk(bulk: NewPlanBulkPrice) { - bulk.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitThresholdTotalAmount( - thresholdTotalAmount: NewPlanThresholdTotalAmountPrice - ) { - thresholdTotalAmount.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - override fun visitTieredPackage(tieredPackage: NewPlanTieredPackagePrice) { - tieredPackage.validate() - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - override fun visitTieredWithMinimum( - tieredWithMinimum: NewPlanTieredWithMinimumPrice - ) { - tieredWithMinimum.validate() - } + /** + * Returns an immutable instance of [Percent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Percent = + Percent( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("percentConfig", percentConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - override fun visitUnitWithPercent( - unitWithPercent: NewPlanUnitWithPercentPrice - ) { - unitWithPercent.validate() - } + private var validated: Boolean = false - override fun visitPackageWithAllocation( - packageWithAllocation: NewPlanPackageWithAllocationPrice - ) { - packageWithAllocation.validate() - } + fun validate(): Percent = apply { + if (validated) { + return@apply + } - override fun visitTieredWithProration( - tieredWithProration: NewPlanTierWithProrationPrice - ) { - tieredWithProration.validate() + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("percent")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") } + } + name() + percentConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - override fun visitUnitWithProration( - unitWithProration: NewPlanUnitWithProrationPrice - ) { - unitWithProration.validate() - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitGroupedAllocation( - groupedAllocation: NewPlanGroupedAllocationPrice - ) { - groupedAllocation.validate() - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - override fun visitGroupedWithProratedMinimum( - groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice - ) { - groupedWithProratedMinimum.validate() - } + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - override fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice - ) { - groupedWithMeteredMinimum.validate() - } + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice - ) { - matrixWithDisplayName.validate() + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN } - override fun visitBulkWithProration( - bulkWithProration: NewPlanBulkWithProrationPrice - ) { - bulkWithProration.validate() + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") } - override fun visitGroupedTieredPackage( - groupedTieredPackage: NewPlanGroupedTieredPackagePrice - ) { - groupedTieredPackage.validate() + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply } - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice - ) { - maxGroupTieredPackage.validate() + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - override fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice - ) { - scalableMatrixWithUnitPricing.validate() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - override fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewPlanScalableMatrixWithTieredPricingPrice - ) { - scalableMatrixWithTieredPricing.validate() + return other is Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent") + @ExcludeMissing + fun _percent(): JsonField = percent + + @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 + * [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PercentConfig]. */ + class Builder internal constructor() { + + private var percent: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() } - override fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice - ) { - cumulativeGroupedBulk.validate() + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ) { - tieredPackageWithMinimum.validate() + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ) { - matrixWithAllocation.validate() + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) { - groupedTiered.validate() + /** + * Returns an immutable instance of [PercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PercentConfig = apply { + if (validated) { + return@apply } + + percent() + validated = true } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: NewPlanUnitPrice) = unit.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun visitPackage(package_: NewPlanPackagePrice) = - package_.validity() + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties + } - override fun visitMatrix(matrix: NewPlanMatrixPrice) = matrix.validity() + private val hashCode: Int by lazy { + Objects.hash(percent, additionalProperties) + } - override fun visitTiered(tiered: NewPlanTieredPrice) = tiered.validity() + override fun hashCode(): Int = hashCode - override fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice) = - tieredBps.validity() + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" + } - override fun visitBps(bps: NewPlanBpsPrice) = bps.validity() + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - override fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice) = bulkBps.validity() + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - override fun visitBulk(bulk: NewPlanBulkPrice) = bulk.validity() + fun toBuilder() = Builder().from(this) - override fun visitThresholdTotalAmount( - thresholdTotalAmount: NewPlanThresholdTotalAmountPrice - ) = thresholdTotalAmount.validity() + companion object { - override fun visitTieredPackage(tieredPackage: NewPlanTieredPackagePrice) = - tieredPackage.validity() + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + fun builder() = Builder() + } - override fun visitTieredWithMinimum( - tieredWithMinimum: NewPlanTieredWithMinimumPrice - ) = tieredWithMinimum.validity() + /** A builder for [Metadata]. */ + class Builder internal constructor() { - override fun visitUnitWithPercent( - unitWithPercent: NewPlanUnitWithPercentPrice - ) = unitWithPercent.validity() + private var additionalProperties: MutableMap = + mutableMapOf() - override fun visitPackageWithAllocation( - packageWithAllocation: NewPlanPackageWithAllocationPrice - ) = packageWithAllocation.validity() + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } - override fun visitTieredWithProration( - tieredWithProration: NewPlanTierWithProrationPrice - ) = tieredWithProration.validity() + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - override fun visitUnitWithProration( - unitWithProration: NewPlanUnitWithProrationPrice - ) = unitWithProration.validity() + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - override fun visitGroupedAllocation( - groupedAllocation: NewPlanGroupedAllocationPrice - ) = groupedAllocation.validity() + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - override fun visitGroupedWithProratedMinimum( - groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice - ) = groupedWithProratedMinimum.validity() + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - override fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice - ) = groupedWithMeteredMinimum.validity() + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice - ) = matrixWithDisplayName.validity() + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } - override fun visitBulkWithProration( - bulkWithProration: NewPlanBulkWithProrationPrice - ) = bulkWithProration.validity() + private var validated: Boolean = false - override fun visitGroupedTieredPackage( - groupedTieredPackage: NewPlanGroupedTieredPackagePrice - ) = groupedTieredPackage.validity() + fun validate(): Metadata = apply { + if (validated) { + return@apply + } - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice - ) = maxGroupTieredPackage.validity() + validated = true + } - override fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice - ) = scalableMatrixWithUnitPricing.validity() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewPlanScalableMatrixWithTieredPricingPrice - ) = scalableMatrixWithTieredPricing.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } - override fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice - ) = cumulativeGroupedBulk.validity() + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ) = tieredPackageWithMinimum.validity() + return other is Metadata && + additionalProperties == other.additionalProperties + } - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ) = matrixWithAllocation.validity() + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = - groupedTiered.validity() + override fun hashCode(): Int = hashCode - override fun unknown(json: JsonValue?) = 0 + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + return other is Percent && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) } - return /* spotless:off */ other is Price && unit == other.unit && package_ == other.package_ && matrix == other.matrix && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && tieredWithMinimum == other.tieredWithMinimum && unitWithPercent == other.unitWithPercent && packageWithAllocation == other.packageWithAllocation && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && bulkWithProration == other.bulkWithProration && groupedTieredPackage == other.groupedTieredPackage && maxGroupTieredPackage == other.maxGroupTieredPackage && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk && tieredPackageWithMinimum == other.tieredPackageWithMinimum && matrixWithAllocation == other.matrixWithAllocation && groupedTiered == other.groupedTiered /* spotless:on */ + override fun hashCode(): Int = hashCode + + override fun toString() = + "Percent{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, percentConfig=$percentConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, tieredWithMinimum, unitWithPercent, packageWithAllocation, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, groupedWithMeteredMinimum, matrixWithDisplayName, bulkWithProration, groupedTieredPackage, maxGroupTieredPackage, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk, tieredPackageWithMinimum, matrixWithAllocation, groupedTiered) /* spotless:on */ + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val eventOutputConfig: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) - override fun toString(): String = - when { - unit != null -> "Price{unit=$unit}" - package_ != null -> "Price{package_=$package_}" - matrix != null -> "Price{matrix=$matrix}" - tiered != null -> "Price{tiered=$tiered}" - tieredBps != null -> "Price{tieredBps=$tieredBps}" - bps != null -> "Price{bps=$bps}" - bulkBps != null -> "Price{bulkBps=$bulkBps}" - bulk != null -> "Price{bulk=$bulk}" - thresholdTotalAmount != null -> - "Price{thresholdTotalAmount=$thresholdTotalAmount}" - tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" - tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" - unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" - packageWithAllocation != null -> - "Price{packageWithAllocation=$packageWithAllocation}" - tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" - unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" - groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" - groupedWithProratedMinimum != null -> - "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" - groupedWithMeteredMinimum != null -> - "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" - matrixWithDisplayName != null -> - "Price{matrixWithDisplayName=$matrixWithDisplayName}" - bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" - groupedTieredPackage != null -> - "Price{groupedTieredPackage=$groupedTieredPackage}" - maxGroupTieredPackage != null -> - "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" - scalableMatrixWithUnitPricing != null -> - "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" - scalableMatrixWithTieredPricing != null -> - "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" - cumulativeGroupedBulk != null -> - "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" - tieredPackageWithMinimum != null -> - "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" - matrixWithAllocation != null -> - "Price{matrixWithAllocation=$matrixWithAllocation}" - groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" - _json != null -> "Price{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Price") - } + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - companion object { + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") - fun ofUnit(unit: NewPlanUnitPrice) = Price(unit = unit) + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - fun ofPackage(package_: NewPlanPackagePrice) = Price(package_ = package_) + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - fun ofMatrix(matrix: NewPlanMatrixPrice) = Price(matrix = matrix) + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - fun ofTiered(tiered: NewPlanTieredPrice) = Price(tiered = tiered) + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - fun ofTieredBps(tieredBps: NewPlanTieredBpsPrice) = Price(tieredBps = tieredBps) + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - fun ofBps(bps: NewPlanBpsPrice) = Price(bps = bps) + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - fun ofBulkBps(bulkBps: NewPlanBulkBpsPrice) = Price(bulkBps = bulkBps) + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - fun ofBulk(bulk: NewPlanBulkPrice) = Price(bulk = bulk) + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - fun ofThresholdTotalAmount(thresholdTotalAmount: NewPlanThresholdTotalAmountPrice) = - Price(thresholdTotalAmount = thresholdTotalAmount) + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - fun ofTieredPackage(tieredPackage: NewPlanTieredPackagePrice) = - Price(tieredPackage = tieredPackage) + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - fun ofTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = - Price(tieredWithMinimum = tieredWithMinimum) + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - fun ofUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice) = - Price(unitWithPercent = unitWithPercent) + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - fun ofPackageWithAllocation( - packageWithAllocation: NewPlanPackageWithAllocationPrice - ) = Price(packageWithAllocation = packageWithAllocation) + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - fun ofTieredWithProration(tieredWithProration: NewPlanTierWithProrationPrice) = - Price(tieredWithProration = tieredWithProration) + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - fun ofUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice) = - Price(unitWithProration = unitWithProration) + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - fun ofGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice) = - Price(groupedAllocation = groupedAllocation) + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - fun ofGroupedWithProratedMinimum( - groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice - ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig - fun ofGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice - ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - fun ofMatrixWithDisplayName( - matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice - ) = Price(matrixWithDisplayName = matrixWithDisplayName) + /** + * 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 - fun ofBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice) = - Price(bulkWithProration = bulkWithProration) + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - fun ofGroupedTieredPackage(groupedTieredPackage: NewPlanGroupedTieredPackagePrice) = - Price(groupedTieredPackage = groupedTieredPackage) + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - fun ofMaxGroupTieredPackage( - maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice - ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - fun ofScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice - ) = Price(scalableMatrixWithUnitPricing = scalableMatrixWithUnitPricing) + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - fun ofScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: NewPlanScalableMatrixWithTieredPricingPrice - ) = Price(scalableMatrixWithTieredPricing = scalableMatrixWithTieredPricing) + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - fun ofCumulativeGroupedBulk( - cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice - ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - fun ofTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - fun ofMatrixWithAllocation(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = - Price(matrixWithAllocation = matrixWithAllocation) + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - fun ofGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = - Price(groupedTiered = groupedTiered) - } + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - /** - * An interface that defines how to map each variant of [Price] to a value of type [T]. - */ - interface Visitor { + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - fun visitUnit(unit: NewPlanUnitPrice): T + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - fun visitPackage(package_: NewPlanPackagePrice): T + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - fun visitMatrix(matrix: NewPlanMatrixPrice): T + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - fun visitTiered(tiered: NewPlanTieredPrice): T + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice): T + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EventOutput]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } - fun visitBps(bps: NewPlanBpsPrice): T + /** A builder for [EventOutput]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var eventOutputConfig: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("event_output") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutput: EventOutput) = apply { + cadence = eventOutput.cadence + eventOutputConfig = eventOutput.eventOutputConfig + itemId = eventOutput.itemId + modelType = eventOutput.modelType + name = eventOutput.name + billableMetricId = eventOutput.billableMetricId + billedInAdvance = eventOutput.billedInAdvance + billingCycleConfiguration = eventOutput.billingCycleConfiguration + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + currency = eventOutput.currency + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoiceGroupingKey = eventOutput.invoiceGroupingKey + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + metadata = eventOutput.metadata + referenceId = eventOutput.referenceId + additionalProperties = eventOutput.additionalProperties.toMutableMap() + } - fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice): T + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } - fun visitBulk(bulk: NewPlanBulkPrice): T + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - fun visitThresholdTotalAmount( - thresholdTotalAmount: NewPlanThresholdTotalAmountPrice - ): T + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - fun visitTieredPackage(tieredPackage: NewPlanTieredPackagePrice): T + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - fun visitTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice): T + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - fun visitUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice): T + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - fun visitPackageWithAllocation( - packageWithAllocation: NewPlanPackageWithAllocationPrice - ): T + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - fun visitTieredWithProration(tieredWithProration: NewPlanTierWithProrationPrice): T + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - fun visitUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice): T + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - fun visitGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice): T + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - fun visitGroupedWithProratedMinimum( - groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice - ): T + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice - ): T + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice - ): T + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun visitBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice): T + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun visitGroupedTieredPackage( - groupedTieredPackage: NewPlanGroupedTieredPackagePrice - ): T + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice - ): T + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice - ): T + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: NewPlanScalableMatrixWithTieredPricingPrice - ): T + /** + * Returns an immutable instance of [EventOutput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutput = + EventOutput( + checkRequired("cadence", cadence), + checkRequired("eventOutputConfig", eventOutputConfig), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice - ): T + private var validated: Boolean = false - fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ): T + fun validate(): EventOutput = apply { + if (validated) { + return@apply + } - fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ): T + cadence().validate() + eventOutputConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("event_output")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [Price] to a value of type [T]. - * - * An instance of [Price] can contain an unknown variant if it was deserialized from - * data that doesn't match any known variant. For example, if the SDK is on an older - * version than the API, then the API may respond with new variants that the SDK is - * unaware of. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown Price: $json") - } - } + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - internal class Deserializer : BaseDeserializer(Price::class) { + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - override fun ObjectCodec.deserialize(node: JsonNode): Price { - val json = JsonValue.fromJsonNode(node) - val modelType = json.asObject()?.get("model_type")?.asString() + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - when (modelType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(unit = it, _json = json) - } ?: Price(_json = json) - } - "package" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) - } - "matrix" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(matrix = it, _json = json) - } ?: Price(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(tiered = it, _json = json) - } ?: Price(_json = json) - } - "tiered_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(tieredBps = it, _json = json) } ?: Price(_json = json) + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(bps = it, _json = json) - } ?: Price(_json = json) - } - "bulk_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bulkBps = it, _json = json) } ?: Price(_json = json) + + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") } - "bulk" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(bulk = it, _json = json) - } ?: Price(_json = json) + + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply } - "threshold_total_amount" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(thresholdTotalAmount = it, _json = json) } - ?: Price(_json = json) + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "tiered_package" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(tieredPackage = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - "tiered_with_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredWithMinimum = it, _json = json) } - ?: Price(_json = json) + + return other is Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a + * unit rate will be ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = + defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events + * will also be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @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 + * [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutputConfig]. */ + class Builder internal constructor() { + + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = + eventOutputConfig.additionalProperties.toMutableMap() } - "unit_with_percent" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(unitWithPercent = it, _json = json) } - ?: Price(_json = json) + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey } - "package_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(packageWithAllocation = it, _json = json) } - ?: Price(_json = json) + + /** + * If provided, this amount will be used as the unit rate when an event does + * not have a value for the `unit_rating_key`. If not provided, events + * missing a unit rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate } - "tiered_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredWithProration = it, _json = json) } - ?: Price(_json = json) + + /** + * An optional key in the event data to group by (e.g., event ID). All + * events will also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey } - "unit_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(unitWithProration = it, _json = json) } - ?: Price(_json = json) + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - "grouped_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedAllocation = it, _json = json) } - ?: Price(_json = json) + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - "grouped_with_prorated_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedWithProratedMinimum = it, _json = json) } - ?: Price(_json = json) + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - "grouped_with_metered_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns an immutable instance of [EventOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutputConfig = apply { + if (validated) { + return@apply } - "matrix_with_display_name" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithDisplayName = it, _json = json) } - ?: Price(_json = json) + + unitRatingKey() + defaultUnitRate() + groupingKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "bulk_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(bulkWithProration = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - "grouped_tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedTieredPackage = it, _json = json) } - ?: Price(_json = json) + + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + unitRatingKey, + defaultUnitRate, + groupingKey, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() } - "max_group_tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(maxGroupTieredPackage = it, _json = json) } - ?: Price(_json = json) + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - "scalable_matrix_with_unit_pricing" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(scalableMatrixWithUnitPricing = it, _json = json) } - ?: Price(_json = json) + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - "scalable_matrix_with_tiered_pricing" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(scalableMatrixWithTieredPricing = it, _json = json) } - ?: Price(_json = json) + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - "cumulative_grouped_bulk" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(cumulativeGroupedBulk = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply } - "tiered_package_with_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredPackageWithMinimum = it, _json = json) } - ?: Price(_json = json) + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "matrix_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithAllocation = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() } - "grouped_tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(groupedTiered = it, _json = json) } - ?: Price(_json = json) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Metadata && + additionalProperties == other.additionalProperties } - return Price(_json = json) - } - } + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - internal class Serializer : BaseSerializer(Price::class) { + override fun hashCode(): Int = hashCode - override fun serialize( - value: Price, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) - value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) - value.bulk != null -> generator.writeObject(value.bulk) - value.thresholdTotalAmount != null -> - generator.writeObject(value.thresholdTotalAmount) - value.tieredPackage != null -> generator.writeObject(value.tieredPackage) - value.tieredWithMinimum != null -> - generator.writeObject(value.tieredWithMinimum) - value.unitWithPercent != null -> - generator.writeObject(value.unitWithPercent) - value.packageWithAllocation != null -> - generator.writeObject(value.packageWithAllocation) - value.tieredWithProration != null -> - generator.writeObject(value.tieredWithProration) - value.unitWithProration != null -> - generator.writeObject(value.unitWithProration) - value.groupedAllocation != null -> - generator.writeObject(value.groupedAllocation) - value.groupedWithProratedMinimum != null -> - generator.writeObject(value.groupedWithProratedMinimum) - value.groupedWithMeteredMinimum != null -> - generator.writeObject(value.groupedWithMeteredMinimum) - value.matrixWithDisplayName != null -> - generator.writeObject(value.matrixWithDisplayName) - value.bulkWithProration != null -> - generator.writeObject(value.bulkWithProration) - value.groupedTieredPackage != null -> - generator.writeObject(value.groupedTieredPackage) - value.maxGroupTieredPackage != null -> - generator.writeObject(value.maxGroupTieredPackage) - value.scalableMatrixWithUnitPricing != null -> - generator.writeObject(value.scalableMatrixWithUnitPricing) - value.scalableMatrixWithTieredPricing != null -> - generator.writeObject(value.scalableMatrixWithTieredPricing) - value.cumulativeGroupedBulk != null -> - generator.writeObject(value.cumulativeGroupedBulk) - value.tieredPackageWithMinimum != null -> - generator.writeObject(value.tieredPackageWithMinimum) - value.matrixWithAllocation != null -> - generator.writeObject(value.matrixWithAllocation) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Price") + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is EventOutput && + cadence == other.cadence && + eventOutputConfig == other.eventOutputConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutput{cadence=$cadence, eventOutputConfig=$eventOutputConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" } } @@ -5608,12 +26737,23 @@ private constructor( return true } - return /* spotless:off */ other is ReplacePrice && replacesPriceId == other.replacesPriceId && allocationPrice == other.allocationPrice && planPhaseOrder == other.planPhaseOrder && price == other.price && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ReplacePrice && + replacesPriceId == other.replacesPriceId && + allocationPrice == other.allocationPrice && + planPhaseOrder == other.planPhaseOrder && + price == other.price && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(replacesPriceId, allocationPrice, planPhaseOrder, price, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + replacesPriceId, + allocationPrice, + planPhaseOrder, + price, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -5626,10 +26766,15 @@ private constructor( return true } - return /* spotless:off */ other is BetaCreatePlanVersionParams && planId == other.planId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is BetaCreatePlanVersionParams && + planId == other.planId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(planId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(planId, body, additionalHeaders, additionalQueryParams) override fun toString() = "BetaCreatePlanVersionParams{planId=$planId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaExternalPlanIdCreatePlanVersionParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaExternalPlanIdCreatePlanVersionParams.kt index 22b25ab0c..460e9ff52 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaExternalPlanIdCreatePlanVersionParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaExternalPlanIdCreatePlanVersionParams.kt @@ -15,6 +15,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.withorb.api.core.BaseDeserializer import com.withorb.api.core.BaseSerializer +import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing @@ -30,12 +31,7 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects -/** - * This API endpoint is in beta and its interface may change. It is recommended for use only in test - * mode. - * - * This endpoint allows the creation of a new plan version for an existing plan. - */ +/** This endpoint allows the creation of a new plan version for an existing plan. */ class BetaExternalPlanIdCreatePlanVersionParams private constructor( private val externalPlanId: String?, @@ -552,6 +548,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val version: JsonField, private val addAdjustments: JsonField>, @@ -1079,12 +1076,31 @@ private constructor( return true } - return /* spotless:off */ other is Body && version == other.version && addAdjustments == other.addAdjustments && addPrices == other.addPrices && removeAdjustments == other.removeAdjustments && removePrices == other.removePrices && replaceAdjustments == other.replaceAdjustments && replacePrices == other.replacePrices && setAsDefault == other.setAsDefault && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + version == other.version && + addAdjustments == other.addAdjustments && + addPrices == other.addPrices && + removeAdjustments == other.removeAdjustments && + removePrices == other.removePrices && + replaceAdjustments == other.replaceAdjustments && + replacePrices == other.replacePrices && + setAsDefault == other.setAsDefault && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(version, addAdjustments, addPrices, removeAdjustments, removePrices, replaceAdjustments, replacePrices, setAsDefault, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + version, + addAdjustments, + addPrices, + removeAdjustments, + removePrices, + replaceAdjustments, + replacePrices, + setAsDefault, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1093,6 +1109,7 @@ private constructor( } class AddAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val adjustment: JsonField, private val planPhaseOrder: JsonField, @@ -1510,10 +1527,16 @@ private constructor( return true } - return /* spotless:off */ other is Adjustment && percentageDiscount == other.percentageDiscount && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ + return other is Adjustment && + percentageDiscount == other.percentageDiscount && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + minimum == other.minimum && + maximum == other.maximum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) override fun toString(): String = when { @@ -1638,12 +1661,15 @@ private constructor( return true } - return /* spotless:off */ other is AddAdjustment && adjustment == other.adjustment && planPhaseOrder == other.planPhaseOrder && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AddAdjustment && + adjustment == other.adjustment && + planPhaseOrder == other.planPhaseOrder && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustment, planPhaseOrder, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(adjustment, planPhaseOrder, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1652,6 +1678,7 @@ private constructor( } class AddPrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val allocationPrice: JsonField, private val planPhaseOrder: JsonField, @@ -1687,7 +1714,7 @@ private constructor( fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") /** - * The price to add to the plan + * New plan price request body params. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1791,7 +1818,7 @@ private constructor( this.planPhaseOrder = planPhaseOrder } - /** The price to add to the plan */ + /** New plan price request body params. */ fun price(price: Price?) = price(JsonField.ofNullable(price)) /** @@ -1806,26 +1833,21 @@ private constructor( /** Alias for calling [price] with `Price.ofUnit(unit)`. */ fun price(unit: NewPlanUnitPrice) = price(Price.ofUnit(unit)) - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: NewPlanPackagePrice) = price(Price.ofPackage(package_)) - - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: NewPlanMatrixPrice) = price(Price.ofMatrix(matrix)) - /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ fun price(tiered: NewPlanTieredPrice) = price(Price.ofTiered(tiered)) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: NewPlanTieredBpsPrice) = price(Price.ofTieredBps(tieredBps)) + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: NewPlanBulkPrice) = price(Price.ofBulk(bulk)) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: NewPlanBpsPrice) = price(Price.ofBps(bps)) + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: NewPlanBulkBpsPrice) = price(Price.ofBulkBps(bulkBps)) + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: NewPlanPackagePrice) = price(Price.ofPackage(package_)) - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: NewPlanBulkPrice) = price(Price.ofBulk(bulk)) + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: NewPlanMatrixPrice) = price(Price.ofMatrix(matrix)) /** * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. @@ -1841,9 +1863,16 @@ private constructor( fun price(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = price(Price.ofTieredWithMinimum(tieredWithMinimum)) - /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ - fun price(unitWithPercent: NewPlanUnitWithPercentPrice) = - price(Price.ofUnitWithPercent(unitWithPercent)) + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: NewPlanGroupedTieredPrice) = + price(Price.ofGroupedTiered(groupedTiered)) + + /** + * Alias for calling [price] with + * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + */ + fun price(tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice) = + price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) /** * Alias for calling [price] with @@ -1852,10 +1881,20 @@ private constructor( fun price(packageWithAllocation: NewPlanPackageWithAllocationPrice) = price(Price.ofPackageWithAllocation(packageWithAllocation)) + /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ + fun price(unitWithPercent: NewPlanUnitWithPercentPrice) = + price(Price.ofUnitWithPercent(unitWithPercent)) + + /** + * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun price(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = + price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + /** * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. */ - fun price(tieredWithProration: NewPlanTierWithProrationPrice) = + fun price(tieredWithProration: Price.TieredWithProration) = price(Price.ofTieredWithProration(tieredWithProration)) /** Alias for calling [price] with `Price.ofUnitWithProration(unitWithProration)`. */ @@ -1866,6 +1905,10 @@ private constructor( fun price(groupedAllocation: NewPlanGroupedAllocationPrice) = price(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: NewPlanBulkWithProrationPrice) = + price(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [price] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -1880,6 +1923,13 @@ private constructor( fun price(groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice) = price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** * Alias for calling [price] with * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. @@ -1887,10 +1937,6 @@ private constructor( fun price(matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice) = price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: NewPlanBulkWithProrationPrice) = - price(Price.ofBulkWithProration(bulkWithProration)) - /** * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. */ @@ -1928,20 +1974,19 @@ private constructor( /** * Alias for calling [price] with - * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. */ - fun price(tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice) = - price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) - /** - * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. - */ - fun price(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = - price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: NewPlanMinimumCompositePrice) = price(Price.ofMinimum(minimum)) - /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: NewPlanGroupedTieredPrice) = - price(Price.ofGroupedTiered(groupedTiered)) + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -2008,31 +2053,33 @@ private constructor( (if (planPhaseOrder.asKnown() == null) 0 else 1) + (price.asKnown()?.validity() ?: 0) - /** The price to add to the plan */ + /** New plan price request body params. */ @JsonDeserialize(using = Price.Deserializer::class) @JsonSerialize(using = Price.Serializer::class) class Price private constructor( private val unit: NewPlanUnitPrice? = null, - private val package_: NewPlanPackagePrice? = null, - private val matrix: NewPlanMatrixPrice? = null, private val tiered: NewPlanTieredPrice? = null, - private val tieredBps: NewPlanTieredBpsPrice? = null, - private val bps: NewPlanBpsPrice? = null, - private val bulkBps: NewPlanBulkBpsPrice? = null, private val bulk: NewPlanBulkPrice? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: NewPlanPackagePrice? = null, + private val matrix: NewPlanMatrixPrice? = null, private val thresholdTotalAmount: NewPlanThresholdTotalAmountPrice? = null, private val tieredPackage: NewPlanTieredPackagePrice? = null, private val tieredWithMinimum: NewPlanTieredWithMinimumPrice? = null, - private val unitWithPercent: NewPlanUnitWithPercentPrice? = null, + private val groupedTiered: NewPlanGroupedTieredPrice? = null, + private val tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice? = null, private val packageWithAllocation: NewPlanPackageWithAllocationPrice? = null, - private val tieredWithProration: NewPlanTierWithProrationPrice? = null, + private val unitWithPercent: NewPlanUnitWithPercentPrice? = null, + private val matrixWithAllocation: NewPlanMatrixWithAllocationPrice? = null, + private val tieredWithProration: TieredWithProration? = null, private val unitWithProration: NewPlanUnitWithProrationPrice? = null, private val groupedAllocation: NewPlanGroupedAllocationPrice? = null, + private val bulkWithProration: NewPlanBulkWithProrationPrice? = null, private val groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice? = null, private val groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice? = null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, private val matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice? = null, - private val bulkWithProration: NewPlanBulkWithProrationPrice? = null, private val groupedTieredPackage: NewPlanGroupedTieredPackagePrice? = null, private val maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice? = null, private val scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice? = @@ -2041,27 +2088,24 @@ private constructor( NewPlanScalableMatrixWithTieredPricingPrice? = null, private val cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice? = null, - private val tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice? = null, - private val matrixWithAllocation: NewPlanMatrixWithAllocationPrice? = null, - private val groupedTiered: NewPlanGroupedTieredPrice? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: NewPlanMinimumCompositePrice? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, private val _json: JsonValue? = null, ) { fun unit(): NewPlanUnitPrice? = unit - fun package_(): NewPlanPackagePrice? = package_ - - fun matrix(): NewPlanMatrixPrice? = matrix - fun tiered(): NewPlanTieredPrice? = tiered - fun tieredBps(): NewPlanTieredBpsPrice? = tieredBps + fun bulk(): NewPlanBulkPrice? = bulk - fun bps(): NewPlanBpsPrice? = bps + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters - fun bulkBps(): NewPlanBulkBpsPrice? = bulkBps + fun package_(): NewPlanPackagePrice? = package_ - fun bulk(): NewPlanBulkPrice? = bulk + fun matrix(): NewPlanMatrixPrice? = matrix fun thresholdTotalAmount(): NewPlanThresholdTotalAmountPrice? = thresholdTotalAmount @@ -2069,25 +2113,35 @@ private constructor( fun tieredWithMinimum(): NewPlanTieredWithMinimumPrice? = tieredWithMinimum - fun unitWithPercent(): NewPlanUnitWithPercentPrice? = unitWithPercent + fun groupedTiered(): NewPlanGroupedTieredPrice? = groupedTiered + + fun tieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice? = + tieredPackageWithMinimum fun packageWithAllocation(): NewPlanPackageWithAllocationPrice? = packageWithAllocation - fun tieredWithProration(): NewPlanTierWithProrationPrice? = tieredWithProration + fun unitWithPercent(): NewPlanUnitWithPercentPrice? = unitWithPercent + + fun matrixWithAllocation(): NewPlanMatrixWithAllocationPrice? = matrixWithAllocation + + fun tieredWithProration(): TieredWithProration? = tieredWithProration fun unitWithProration(): NewPlanUnitWithProrationPrice? = unitWithProration fun groupedAllocation(): NewPlanGroupedAllocationPrice? = groupedAllocation + fun bulkWithProration(): NewPlanBulkWithProrationPrice? = bulkWithProration + fun groupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice? = groupedWithProratedMinimum fun groupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice? = groupedWithMeteredMinimum - fun matrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice? = matrixWithDisplayName + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = + groupedWithMinMaxThresholds - fun bulkWithProration(): NewPlanBulkWithProrationPrice? = bulkWithProration + fun matrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice? = matrixWithDisplayName fun groupedTieredPackage(): NewPlanGroupedTieredPackagePrice? = groupedTieredPackage @@ -2101,28 +2155,26 @@ private constructor( fun cumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice? = cumulativeGroupedBulk - fun tieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice? = - tieredPackageWithMinimum - - fun matrixWithAllocation(): NewPlanMatrixWithAllocationPrice? = matrixWithAllocation + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = + cumulativeGroupedAllocation - fun groupedTiered(): NewPlanGroupedTieredPrice? = groupedTiered + fun minimum(): NewPlanMinimumCompositePrice? = minimum - fun isUnit(): Boolean = unit != null + fun percent(): Percent? = percent - fun isPackage(): Boolean = package_ != null + fun eventOutput(): EventOutput? = eventOutput - fun isMatrix(): Boolean = matrix != null + fun isUnit(): Boolean = unit != null fun isTiered(): Boolean = tiered != null - fun isTieredBps(): Boolean = tieredBps != null + fun isBulk(): Boolean = bulk != null - fun isBps(): Boolean = bps != null + fun isBulkWithFilters(): Boolean = bulkWithFilters != null - fun isBulkBps(): Boolean = bulkBps != null + fun isPackage(): Boolean = package_ != null - fun isBulk(): Boolean = bulk != null + fun isMatrix(): Boolean = matrix != null fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null @@ -2130,23 +2182,31 @@ private constructor( fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null - fun isUnitWithPercent(): Boolean = unitWithPercent != null + fun isGroupedTiered(): Boolean = groupedTiered != null + + fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + fun isUnitWithPercent(): Boolean = unitWithPercent != null + + fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isTieredWithProration(): Boolean = tieredWithProration != null fun isUnitWithProration(): Boolean = unitWithProration != null fun isGroupedAllocation(): Boolean = groupedAllocation != null + fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null - fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null @@ -2159,27 +2219,25 @@ private constructor( fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null - fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null - - fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null - fun isGroupedTiered(): Boolean = groupedTiered != null + fun isMinimum(): Boolean = minimum != null - fun asUnit(): NewPlanUnitPrice = unit.getOrThrow("unit") + fun isPercent(): Boolean = percent != null - fun asPackage(): NewPlanPackagePrice = package_.getOrThrow("package_") + fun isEventOutput(): Boolean = eventOutput != null - fun asMatrix(): NewPlanMatrixPrice = matrix.getOrThrow("matrix") + fun asUnit(): NewPlanUnitPrice = unit.getOrThrow("unit") fun asTiered(): NewPlanTieredPrice = tiered.getOrThrow("tiered") - fun asTieredBps(): NewPlanTieredBpsPrice = tieredBps.getOrThrow("tieredBps") + fun asBulk(): NewPlanBulkPrice = bulk.getOrThrow("bulk") - fun asBps(): NewPlanBpsPrice = bps.getOrThrow("bps") + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") - fun asBulkBps(): NewPlanBulkBpsPrice = bulkBps.getOrThrow("bulkBps") + fun asPackage(): NewPlanPackagePrice = package_.getOrThrow("package_") - fun asBulk(): NewPlanBulkPrice = bulk.getOrThrow("bulk") + fun asMatrix(): NewPlanMatrixPrice = matrix.getOrThrow("matrix") fun asThresholdTotalAmount(): NewPlanThresholdTotalAmountPrice = thresholdTotalAmount.getOrThrow("thresholdTotalAmount") @@ -2190,13 +2248,22 @@ private constructor( fun asTieredWithMinimum(): NewPlanTieredWithMinimumPrice = tieredWithMinimum.getOrThrow("tieredWithMinimum") - fun asUnitWithPercent(): NewPlanUnitWithPercentPrice = - unitWithPercent.getOrThrow("unitWithPercent") + fun asGroupedTiered(): NewPlanGroupedTieredPrice = + groupedTiered.getOrThrow("groupedTiered") + + fun asTieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice = + tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") fun asPackageWithAllocation(): NewPlanPackageWithAllocationPrice = packageWithAllocation.getOrThrow("packageWithAllocation") - fun asTieredWithProration(): NewPlanTierWithProrationPrice = + fun asUnitWithPercent(): NewPlanUnitWithPercentPrice = + unitWithPercent.getOrThrow("unitWithPercent") + + fun asMatrixWithAllocation(): NewPlanMatrixWithAllocationPrice = + matrixWithAllocation.getOrThrow("matrixWithAllocation") + + fun asTieredWithProration(): TieredWithProration = tieredWithProration.getOrThrow("tieredWithProration") fun asUnitWithProration(): NewPlanUnitWithProrationPrice = @@ -2205,18 +2272,21 @@ private constructor( fun asGroupedAllocation(): NewPlanGroupedAllocationPrice = groupedAllocation.getOrThrow("groupedAllocation") + fun asBulkWithProration(): NewPlanBulkWithProrationPrice = + bulkWithProration.getOrThrow("bulkWithProration") + fun asGroupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice = groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") fun asGroupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice = groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") + fun asMatrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice = matrixWithDisplayName.getOrThrow("matrixWithDisplayName") - fun asBulkWithProration(): NewPlanBulkWithProrationPrice = - bulkWithProration.getOrThrow("bulkWithProration") - fun asGroupedTieredPackage(): NewPlanGroupedTieredPackagePrice = groupedTieredPackage.getOrThrow("groupedTieredPackage") @@ -2232,45 +2302,50 @@ private constructor( fun asCumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice = cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") - fun asTieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice = - tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") - fun asMatrixWithAllocation(): NewPlanMatrixWithAllocationPrice = - matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun asMinimum(): NewPlanMinimumCompositePrice = minimum.getOrThrow("minimum") - fun asGroupedTiered(): NewPlanGroupedTieredPrice = - groupedTiered.getOrThrow("groupedTiered") + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") fun _json(): JsonValue? = _json fun accept(visitor: Visitor): T = when { unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) thresholdTotalAmount != null -> visitor.visitThresholdTotalAmount(thresholdTotalAmount) tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) - unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + tieredPackageWithMinimum != null -> + visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) packageWithAllocation != null -> visitor.visitPackageWithAllocation(packageWithAllocation) + unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + matrixWithAllocation != null -> + visitor.visitMatrixWithAllocation(matrixWithAllocation) tieredWithProration != null -> visitor.visitTieredWithProration(tieredWithProration) unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedWithProratedMinimum != null -> visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) groupedWithMeteredMinimum != null -> visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) matrixWithDisplayName != null -> visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedTieredPackage != null -> visitor.visitGroupedTieredPackage(groupedTieredPackage) maxGroupTieredPackage != null -> @@ -2283,11 +2358,11 @@ private constructor( ) cumulativeGroupedBulk != null -> visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) - tieredPackageWithMinimum != null -> - visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) - matrixWithAllocation != null -> - visitor.visitMatrixWithAllocation(matrixWithAllocation) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) else -> visitor.unknown(_json) } @@ -2304,32 +2379,24 @@ private constructor( unit.validate() } - override fun visitPackage(package_: NewPlanPackagePrice) { - package_.validate() - } - - override fun visitMatrix(matrix: NewPlanMatrixPrice) { - matrix.validate() - } - override fun visitTiered(tiered: NewPlanTieredPrice) { tiered.validate() } - override fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice) { - tieredBps.validate() + override fun visitBulk(bulk: NewPlanBulkPrice) { + bulk.validate() } - override fun visitBps(bps: NewPlanBpsPrice) { - bps.validate() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() } - override fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice) { - bulkBps.validate() + override fun visitPackage(package_: NewPlanPackagePrice) { + package_.validate() } - override fun visitBulk(bulk: NewPlanBulkPrice) { - bulk.validate() + override fun visitMatrix(matrix: NewPlanMatrixPrice) { + matrix.validate() } override fun visitThresholdTotalAmount( @@ -2348,10 +2415,14 @@ private constructor( tieredWithMinimum.validate() } - override fun visitUnitWithPercent( - unitWithPercent: NewPlanUnitWithPercentPrice + override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) { + groupedTiered.validate() + } + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice ) { - unitWithPercent.validate() + tieredPackageWithMinimum.validate() } override fun visitPackageWithAllocation( @@ -2360,8 +2431,20 @@ private constructor( packageWithAllocation.validate() } + override fun visitUnitWithPercent( + unitWithPercent: NewPlanUnitWithPercentPrice + ) { + unitWithPercent.validate() + } + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ) { + matrixWithAllocation.validate() + } + override fun visitTieredWithProration( - tieredWithProration: NewPlanTierWithProrationPrice + tieredWithProration: TieredWithProration ) { tieredWithProration.validate() } @@ -2378,6 +2461,12 @@ private constructor( groupedAllocation.validate() } + override fun visitBulkWithProration( + bulkWithProration: NewPlanBulkWithProrationPrice + ) { + bulkWithProration.validate() + } + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice ) { @@ -2390,16 +2479,16 @@ private constructor( groupedWithMeteredMinimum.validate() } - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds ) { - matrixWithDisplayName.validate() + groupedWithMinMaxThresholds.validate() } - override fun visitBulkWithProration( - bulkWithProration: NewPlanBulkWithProrationPrice + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice ) { - bulkWithProration.validate() + matrixWithDisplayName.validate() } override fun visitGroupedTieredPackage( @@ -2433,20 +2522,22 @@ private constructor( cumulativeGroupedBulk.validate() } - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation ) { - tieredPackageWithMinimum.validate() + cumulativeGroupedAllocation.validate() } - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ) { - matrixWithAllocation.validate() + override fun visitMinimum(minimum: NewPlanMinimumCompositePrice) { + minimum.validate() } - override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) { - groupedTiered.validate() + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() } } ) @@ -2472,22 +2563,18 @@ private constructor( object : Visitor { override fun visitUnit(unit: NewPlanUnitPrice) = unit.validity() + override fun visitTiered(tiered: NewPlanTieredPrice) = tiered.validity() + + override fun visitBulk(bulk: NewPlanBulkPrice) = bulk.validity() + + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() + override fun visitPackage(package_: NewPlanPackagePrice) = package_.validity() override fun visitMatrix(matrix: NewPlanMatrixPrice) = matrix.validity() - override fun visitTiered(tiered: NewPlanTieredPrice) = tiered.validity() - - override fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice) = - tieredBps.validity() - - override fun visitBps(bps: NewPlanBpsPrice) = bps.validity() - - override fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice) = bulkBps.validity() - - override fun visitBulk(bulk: NewPlanBulkPrice) = bulk.validity() - override fun visitThresholdTotalAmount( thresholdTotalAmount: NewPlanThresholdTotalAmountPrice ) = thresholdTotalAmount.validity() @@ -2499,16 +2586,27 @@ private constructor( tieredWithMinimum: NewPlanTieredWithMinimumPrice ) = tieredWithMinimum.validity() - override fun visitUnitWithPercent( - unitWithPercent: NewPlanUnitWithPercentPrice - ) = unitWithPercent.validity() + override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = + groupedTiered.validity() + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ) = tieredPackageWithMinimum.validity() override fun visitPackageWithAllocation( packageWithAllocation: NewPlanPackageWithAllocationPrice ) = packageWithAllocation.validity() + override fun visitUnitWithPercent( + unitWithPercent: NewPlanUnitWithPercentPrice + ) = unitWithPercent.validity() + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ) = matrixWithAllocation.validity() + override fun visitTieredWithProration( - tieredWithProration: NewPlanTierWithProrationPrice + tieredWithProration: TieredWithProration ) = tieredWithProration.validity() override fun visitUnitWithProration( @@ -2519,6 +2617,10 @@ private constructor( groupedAllocation: NewPlanGroupedAllocationPrice ) = groupedAllocation.validity() + override fun visitBulkWithProration( + bulkWithProration: NewPlanBulkWithProrationPrice + ) = bulkWithProration.validity() + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice ) = groupedWithProratedMinimum.validity() @@ -2527,14 +2629,14 @@ private constructor( groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice ) = groupedWithMeteredMinimum.validity() + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + override fun visitMatrixWithDisplayName( matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice ) = matrixWithDisplayName.validity() - override fun visitBulkWithProration( - bulkWithProration: NewPlanBulkWithProrationPrice - ) = bulkWithProration.validity() - override fun visitGroupedTieredPackage( groupedTieredPackage: NewPlanGroupedTieredPackagePrice ) = groupedTieredPackage.validity() @@ -2556,16 +2658,17 @@ private constructor( cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice ) = cumulativeGroupedBulk.validity() - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ) = tieredPackageWithMinimum.validity() + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ) = matrixWithAllocation.validity() + override fun visitMinimum(minimum: NewPlanMinimumCompositePrice) = + minimum.validity() - override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = - groupedTiered.validity() + override fun visitPercent(percent: Percent) = percent.validity() + + override fun visitEventOutput(eventOutput: EventOutput) = + eventOutput.validity() override fun unknown(json: JsonValue?) = 0 } @@ -2576,38 +2679,107 @@ private constructor( return true } - return /* spotless:off */ other is Price && unit == other.unit && package_ == other.package_ && matrix == other.matrix && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && tieredWithMinimum == other.tieredWithMinimum && unitWithPercent == other.unitWithPercent && packageWithAllocation == other.packageWithAllocation && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && bulkWithProration == other.bulkWithProration && groupedTieredPackage == other.groupedTieredPackage && maxGroupTieredPackage == other.maxGroupTieredPackage && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk && tieredPackageWithMinimum == other.tieredPackageWithMinimum && matrixWithAllocation == other.matrixWithAllocation && groupedTiered == other.groupedTiered /* spotless:on */ + return other is Price && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, tieredWithMinimum, unitWithPercent, packageWithAllocation, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, groupedWithMeteredMinimum, matrixWithDisplayName, bulkWithProration, groupedTieredPackage, maxGroupTieredPackage, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk, tieredPackageWithMinimum, matrixWithAllocation, groupedTiered) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) override fun toString(): String = when { unit != null -> "Price{unit=$unit}" - package_ != null -> "Price{package_=$package_}" - matrix != null -> "Price{matrix=$matrix}" tiered != null -> "Price{tiered=$tiered}" - tieredBps != null -> "Price{tieredBps=$tieredBps}" - bps != null -> "Price{bps=$bps}" - bulkBps != null -> "Price{bulkBps=$bulkBps}" bulk != null -> "Price{bulk=$bulk}" + bulkWithFilters != null -> "Price{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "Price{package_=$package_}" + matrix != null -> "Price{matrix=$matrix}" thresholdTotalAmount != null -> "Price{thresholdTotalAmount=$thresholdTotalAmount}" tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" - unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" + tieredPackageWithMinimum != null -> + "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" packageWithAllocation != null -> "Price{packageWithAllocation=$packageWithAllocation}" + unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + matrixWithAllocation != null -> + "Price{matrixWithAllocation=$matrixWithAllocation}" tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedWithProratedMinimum != null -> "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" groupedWithMeteredMinimum != null -> "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "Price{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" matrixWithDisplayName != null -> "Price{matrixWithDisplayName=$matrixWithDisplayName}" - bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedTieredPackage != null -> "Price{groupedTieredPackage=$groupedTieredPackage}" maxGroupTieredPackage != null -> @@ -2618,11 +2790,11 @@ private constructor( "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" cumulativeGroupedBulk != null -> "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" - tieredPackageWithMinimum != null -> - "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" - matrixWithAllocation != null -> - "Price{matrixWithAllocation=$matrixWithAllocation}" - groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" + cumulativeGroupedAllocation != null -> + "Price{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "Price{minimum=$minimum}" + percent != null -> "Price{percent=$percent}" + eventOutput != null -> "Price{eventOutput=$eventOutput}" _json != null -> "Price{_unknown=$_json}" else -> throw IllegalStateException("Invalid Price") } @@ -2631,19 +2803,16 @@ private constructor( fun ofUnit(unit: NewPlanUnitPrice) = Price(unit = unit) - fun ofPackage(package_: NewPlanPackagePrice) = Price(package_ = package_) - - fun ofMatrix(matrix: NewPlanMatrixPrice) = Price(matrix = matrix) - fun ofTiered(tiered: NewPlanTieredPrice) = Price(tiered = tiered) - fun ofTieredBps(tieredBps: NewPlanTieredBpsPrice) = Price(tieredBps = tieredBps) + fun ofBulk(bulk: NewPlanBulkPrice) = Price(bulk = bulk) - fun ofBps(bps: NewPlanBpsPrice) = Price(bps = bps) + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + Price(bulkWithFilters = bulkWithFilters) - fun ofBulkBps(bulkBps: NewPlanBulkBpsPrice) = Price(bulkBps = bulkBps) + fun ofPackage(package_: NewPlanPackagePrice) = Price(package_ = package_) - fun ofBulk(bulk: NewPlanBulkPrice) = Price(bulk = bulk) + fun ofMatrix(matrix: NewPlanMatrixPrice) = Price(matrix = matrix) fun ofThresholdTotalAmount(thresholdTotalAmount: NewPlanThresholdTotalAmountPrice) = Price(thresholdTotalAmount = thresholdTotalAmount) @@ -2654,14 +2823,24 @@ private constructor( fun ofTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = Price(tieredWithMinimum = tieredWithMinimum) - fun ofUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice) = - Price(unitWithPercent = unitWithPercent) + fun ofGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = + Price(groupedTiered = groupedTiered) + + fun ofTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) fun ofPackageWithAllocation( packageWithAllocation: NewPlanPackageWithAllocationPrice ) = Price(packageWithAllocation = packageWithAllocation) - fun ofTieredWithProration(tieredWithProration: NewPlanTierWithProrationPrice) = + fun ofUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice) = + Price(unitWithPercent = unitWithPercent) + + fun ofMatrixWithAllocation(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = + Price(matrixWithAllocation = matrixWithAllocation) + + fun ofTieredWithProration(tieredWithProration: TieredWithProration) = Price(tieredWithProration = tieredWithProration) fun ofUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice) = @@ -2670,6 +2849,9 @@ private constructor( fun ofGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice) = Price(groupedAllocation = groupedAllocation) + fun ofBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice) = + Price(bulkWithProration = bulkWithProration) + fun ofGroupedWithProratedMinimum( groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) @@ -2678,13 +2860,14 @@ private constructor( groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = Price(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + fun ofMatrixWithDisplayName( matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice ) = Price(matrixWithDisplayName = matrixWithDisplayName) - fun ofBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice) = - Price(bulkWithProration = bulkWithProration) - fun ofGroupedTieredPackage(groupedTieredPackage: NewPlanGroupedTieredPackagePrice) = Price(groupedTieredPackage = groupedTieredPackage) @@ -2704,15 +2887,15 @@ private constructor( cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) - fun ofTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = Price(cumulativeGroupedAllocation = cumulativeGroupedAllocation) - fun ofMatrixWithAllocation(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = - Price(matrixWithAllocation = matrixWithAllocation) + fun ofMinimum(minimum: NewPlanMinimumCompositePrice) = Price(minimum = minimum) - fun ofGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = - Price(groupedTiered = groupedTiered) + fun ofPercent(percent: Percent) = Price(percent = percent) + + fun ofEventOutput(eventOutput: EventOutput) = Price(eventOutput = eventOutput) } /** @@ -2722,19 +2905,15 @@ private constructor( fun visitUnit(unit: NewPlanUnitPrice): T - fun visitPackage(package_: NewPlanPackagePrice): T - - fun visitMatrix(matrix: NewPlanMatrixPrice): T - fun visitTiered(tiered: NewPlanTieredPrice): T - fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice): T + fun visitBulk(bulk: NewPlanBulkPrice): T - fun visitBps(bps: NewPlanBpsPrice): T + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T - fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice): T + fun visitPackage(package_: NewPlanPackagePrice): T - fun visitBulk(bulk: NewPlanBulkPrice): T + fun visitMatrix(matrix: NewPlanMatrixPrice): T fun visitThresholdTotalAmount( thresholdTotalAmount: NewPlanThresholdTotalAmountPrice @@ -2744,18 +2923,30 @@ private constructor( fun visitTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice): T - fun visitUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice): T + fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice): T + + fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ): T fun visitPackageWithAllocation( packageWithAllocation: NewPlanPackageWithAllocationPrice ): T - fun visitTieredWithProration(tieredWithProration: NewPlanTierWithProrationPrice): T + fun visitUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice): T + + fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ): T + + fun visitTieredWithProration(tieredWithProration: TieredWithProration): T fun visitUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice): T fun visitGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice): T + fun visitBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice): T + fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice ): T @@ -2764,12 +2955,14 @@ private constructor( groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice ): T + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ): T + fun visitMatrixWithDisplayName( matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice ): T - fun visitBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice): T - fun visitGroupedTieredPackage( groupedTieredPackage: NewPlanGroupedTieredPackagePrice ): T @@ -2790,15 +2983,15 @@ private constructor( cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice ): T - fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation ): T - fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ): T + fun visitMinimum(minimum: NewPlanMinimumCompositePrice): T - fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice): T + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T /** * Maps an unknown variant of [Price] to a value of type [T]. @@ -2827,36 +3020,28 @@ private constructor( Price(unit = it, _json = json) } ?: Price(_json = json) } - "package" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) - } - "matrix" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(matrix = it, _json = json) - } ?: Price(_json = json) - } "tiered" -> { return tryDeserialize(node, jacksonTypeRef())?.let { Price(tiered = it, _json = json) } ?: Price(_json = json) } - "tiered_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(tieredBps = it, _json = json) } ?: Price(_json = json) + "bulk" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulk = it, _json = json) + } ?: Price(_json = json) } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(bps = it, _json = json) + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulkWithFilters = it, _json = json) } ?: Price(_json = json) } - "bulk_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bulkBps = it, _json = json) } ?: Price(_json = json) + "package" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) } - "bulk" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(bulk = it, _json = json) + "matrix" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(matrix = it, _json = json) } ?: Price(_json = json) } "threshold_total_amount" -> { @@ -2880,12 +3065,17 @@ private constructor( ?.let { Price(tieredWithMinimum = it, _json = json) } ?: Price(_json = json) } - "unit_with_percent" -> { + "grouped_tiered" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(groupedTiered = it, _json = json) } + ?: Price(_json = json) + } + "tiered_package_with_minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(unitWithPercent = it, _json = json) } + ?.let { Price(tieredPackageWithMinimum = it, _json = json) } ?: Price(_json = json) } "package_with_allocation" -> { @@ -2896,11 +3086,24 @@ private constructor( ?.let { Price(packageWithAllocation = it, _json = json) } ?: Price(_json = json) } - "tiered_with_proration" -> { + "unit_with_percent" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(unitWithPercent = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_allocation" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) + ?.let { Price(matrixWithAllocation = it, _json = json) } + ?: Price(_json = json) + } + "tiered_with_proration" -> { + return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(tieredWithProration = it, _json = json) } ?: Price(_json = json) } @@ -2920,6 +3123,14 @@ private constructor( ?.let { Price(groupedAllocation = it, _json = json) } ?: Price(_json = json) } + "bulk_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(bulkWithProration = it, _json = json) } + ?: Price(_json = json) + } "grouped_with_prorated_minimum" -> { return tryDeserialize( node, @@ -2936,20 +3147,20 @@ private constructor( ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } ?: Price(_json = json) } - "matrix_with_display_name" -> { + "grouped_with_min_max_thresholds" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(matrixWithDisplayName = it, _json = json) } + ?.let { Price(groupedWithMinMaxThresholds = it, _json = json) } ?: Price(_json = json) } - "bulk_with_proration" -> { + "matrix_with_display_name" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(bulkWithProration = it, _json = json) } + ?.let { Price(matrixWithDisplayName = it, _json = json) } ?: Price(_json = json) } "grouped_tiered_package" -> { @@ -2992,26 +3203,30 @@ private constructor( ?.let { Price(cumulativeGroupedBulk = it, _json = json) } ?: Price(_json = json) } - "tiered_package_with_minimum" -> { + "cumulative_grouped_allocation" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(tieredPackageWithMinimum = it, _json = json) } + ?.let { Price(cumulativeGroupedAllocation = it, _json = json) } ?: Price(_json = json) } - "matrix_with_allocation" -> { + "minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(matrixWithAllocation = it, _json = json) } - ?: Price(_json = json) + ?.let { Price(minimum = it, _json = json) } ?: Price(_json = json) } - "grouped_tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(groupedTiered = it, _json = json) } - ?: Price(_json = json) + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(percent = it, _json = json) + } ?: Price(_json = json) + } + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(eventOutput = it, _json = json) + } ?: Price(_json = json) } } @@ -3028,36 +3243,42 @@ private constructor( ) { when { value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> + generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) value.thresholdTotalAmount != null -> generator.writeObject(value.thresholdTotalAmount) value.tieredPackage != null -> generator.writeObject(value.tieredPackage) value.tieredWithMinimum != null -> generator.writeObject(value.tieredWithMinimum) - value.unitWithPercent != null -> - generator.writeObject(value.unitWithPercent) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) + value.tieredPackageWithMinimum != null -> + generator.writeObject(value.tieredPackageWithMinimum) value.packageWithAllocation != null -> generator.writeObject(value.packageWithAllocation) + value.unitWithPercent != null -> + generator.writeObject(value.unitWithPercent) + value.matrixWithAllocation != null -> + generator.writeObject(value.matrixWithAllocation) value.tieredWithProration != null -> generator.writeObject(value.tieredWithProration) value.unitWithProration != null -> generator.writeObject(value.unitWithProration) value.groupedAllocation != null -> generator.writeObject(value.groupedAllocation) + value.bulkWithProration != null -> + generator.writeObject(value.bulkWithProration) value.groupedWithProratedMinimum != null -> generator.writeObject(value.groupedWithProratedMinimum) value.groupedWithMeteredMinimum != null -> generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) value.matrixWithDisplayName != null -> generator.writeObject(value.matrixWithDisplayName) - value.bulkWithProration != null -> - generator.writeObject(value.bulkWithProration) value.groupedTieredPackage != null -> generator.writeObject(value.groupedTieredPackage) value.maxGroupTieredPackage != null -> @@ -3068,2543 +3289,23451 @@ private constructor( generator.writeObject(value.scalableMatrixWithTieredPricing) value.cumulativeGroupedBulk != null -> generator.writeObject(value.cumulativeGroupedBulk) - value.tieredPackageWithMinimum != null -> - generator.writeObject(value.tieredPackageWithMinimum) - value.matrixWithAllocation != null -> - generator.writeObject(value.matrixWithAllocation) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Price") } } } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - return /* spotless:off */ other is AddPrice && allocationPrice == other.allocationPrice && planPhaseOrder == other.planPhaseOrder && price == other.price && additionalProperties == other.additionalProperties /* spotless:on */ - } + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bulkWithFiltersConfig: JsonField, + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(allocationPrice, planPhaseOrder, price, additionalProperties) } - /* spotless:on */ + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") - override fun hashCode(): Int = hashCode + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - override fun toString() = - "AddPrice{allocationPrice=$allocationPrice, planPhaseOrder=$planPhaseOrder, price=$price, additionalProperties=$additionalProperties}" - } + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - class RemoveAdjustment - private constructor( - private val adjustmentId: JsonField, - private val planPhaseOrder: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - @JsonCreator - private constructor( - @JsonProperty("adjustment_id") - @ExcludeMissing - adjustmentId: JsonField = JsonMissing.of(), - @JsonProperty("plan_phase_order") - @ExcludeMissing - planPhaseOrder: JsonField = JsonMissing.of(), - ) : this(adjustmentId, planPhaseOrder, mutableMapOf()) + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - /** - * The id of the adjustment to remove from on the plan. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun adjustmentId(): String = adjustmentId.getRequired("adjustment_id") + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - /** - * The phase to remove this adjustment from. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - /** - * Returns the raw JSON value of [adjustmentId]. - * - * Unlike [adjustmentId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("adjustment_id") - @ExcludeMissing - fun _adjustmentId(): JsonField = adjustmentId + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - /** - * Returns the raw JSON value of [planPhaseOrder]. - * - * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("plan_phase_order") - @ExcludeMissing - fun _planPhaseOrder(): JsonField = planPhaseOrder + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - fun toBuilder() = Builder().from(this) + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - companion object { + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - /** - * Returns a mutable builder for constructing an instance of [RemoveAdjustment]. - * - * The following fields are required: - * ```kotlin - * .adjustmentId() - * ``` - */ - fun builder() = Builder() - } + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - /** A builder for [RemoveAdjustment]. */ - class Builder internal constructor() { + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - private var adjustmentId: JsonField? = null - private var planPhaseOrder: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - internal fun from(removeAdjustment: RemoveAdjustment) = apply { - adjustmentId = removeAdjustment.adjustmentId - planPhaseOrder = removeAdjustment.planPhaseOrder - additionalProperties = removeAdjustment.additionalProperties.toMutableMap() - } + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - /** The id of the adjustment to remove from on the plan. */ - fun adjustmentId(adjustmentId: String) = adjustmentId(JsonField.of(adjustmentId)) + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - /** - * Sets [Builder.adjustmentId] to an arbitrary JSON value. - * - * You should usually call [Builder.adjustmentId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun adjustmentId(adjustmentId: JsonField) = apply { - this.adjustmentId = adjustmentId - } + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = + bulkWithFiltersConfig - /** The phase to remove this adjustment from. */ - fun planPhaseOrder(planPhaseOrder: Long?) = - planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - /** - * Alias for [Builder.planPhaseOrder]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - /** - * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. - * - * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun planPhaseOrder(planPhaseOrder: JsonField) = apply { - this.planPhaseOrder = planPhaseOrder - } + /** + * 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 - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - /** - * Returns an immutable instance of [RemoveAdjustment]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .adjustmentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): RemoveAdjustment = - RemoveAdjustment( - checkRequired("adjustmentId", adjustmentId), - planPhaseOrder, - additionalProperties.toMutableMap(), - ) - } + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - private var validated: Boolean = false + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - fun validate(): RemoveAdjustment = apply { - if (validated) { - return@apply - } + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - adjustmentId() - planPhaseOrder() - validated = true - } + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (adjustmentId.asKnown() == null) 0 else 1) + - (if (planPhaseOrder.asKnown() == null) 0 else 1) + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - return /* spotless:off */ other is RemoveAdjustment && adjustmentId == other.adjustmentId && planPhaseOrder == other.planPhaseOrder && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustmentId, planPhaseOrder, additionalProperties) } - /* spotless:on */ + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - override fun hashCode(): Int = hashCode + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [BulkWithFilters]. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } - override fun toString() = - "RemoveAdjustment{adjustmentId=$adjustmentId, planPhaseOrder=$planPhaseOrder, additionalProperties=$additionalProperties}" - } + /** A builder for [BulkWithFilters]. */ + class Builder internal constructor() { + + private var bulkWithFiltersConfig: JsonField? = null + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + itemId = bulkWithFilters.itemId + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + billableMetricId = bulkWithFilters.billableMetricId + billedInAdvance = bulkWithFilters.billedInAdvance + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + currency = bulkWithFilters.currency + dimensionalPriceConfiguration = + bulkWithFilters.dimensionalPriceConfiguration + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoiceGroupingKey = bulkWithFilters.invoiceGroupingKey + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + metadata = bulkWithFilters.metadata + referenceId = bulkWithFilters.referenceId + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() + } - class RemovePrice - private constructor( - private val priceId: JsonField, - private val planPhaseOrder: JsonField, - private val additionalProperties: MutableMap, - ) { + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig( + bulkWithFiltersConfig: JsonField + ) = apply { this.bulkWithFiltersConfig = bulkWithFiltersConfig } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - @JsonCreator - private constructor( - @JsonProperty("price_id") @ExcludeMissing priceId: JsonField = JsonMissing.of(), - @JsonProperty("plan_phase_order") - @ExcludeMissing - planPhaseOrder: JsonField = JsonMissing.of(), - ) : this(priceId, planPhaseOrder, mutableMapOf()) + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - /** - * The id of the price to remove from the plan. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun priceId(): String = priceId.getRequired("price_id") + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - /** - * The phase to remove this price from. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - /** - * Returns the raw JSON value of [priceId]. - * - * Unlike [priceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("price_id") @ExcludeMissing fun _priceId(): JsonField = priceId + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - /** - * Returns the raw JSON value of [planPhaseOrder]. - * - * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("plan_phase_order") - @ExcludeMissing - fun _planPhaseOrder(): JsonField = planPhaseOrder + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - fun toBuilder() = Builder().from(this) + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - companion object { + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - /** - * Returns a mutable builder for constructing an instance of [RemovePrice]. - * - * The following fields are required: - * ```kotlin - * .priceId() - * ``` - */ - fun builder() = Builder() - } + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - /** A builder for [RemovePrice]. */ - class Builder internal constructor() { + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - private var priceId: JsonField? = null - private var planPhaseOrder: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - internal fun from(removePrice: RemovePrice) = apply { - priceId = removePrice.priceId - planPhaseOrder = removePrice.planPhaseOrder - additionalProperties = removePrice.additionalProperties.toMutableMap() - } + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** The id of the price to remove from the plan. */ - fun priceId(priceId: String) = priceId(JsonField.of(priceId)) + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - /** - * Sets [Builder.priceId] to an arbitrary JSON value. - * - * You should usually call [Builder.priceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun priceId(priceId: JsonField) = apply { this.priceId = priceId } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** The phase to remove this price from. */ - fun planPhaseOrder(planPhaseOrder: Long?) = - planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + /** + * Returns an immutable instance of [BulkWithFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFilters = + BulkWithFilters( + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - /** - * Alias for [Builder.planPhaseOrder]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + private var validated: Boolean = false - /** - * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. - * - * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun planPhaseOrder(planPhaseOrder: JsonField) = apply { - this.planPhaseOrder = planPhaseOrder - } + fun validate(): BulkWithFilters = apply { + if (validated) { + return@apply + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + bulkWithFiltersConfig().validate() + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("bulk_with_filters")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + 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. + */ + internal fun validity(): Int = + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) + + /** + * Property filters to apply (all must match) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [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) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() + } - /** - * Returns an immutable instance of [RemovePrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .priceId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): RemovePrice = - RemovePrice( - checkRequired("priceId", priceId), - planPhaseOrder, - additionalProperties.toMutableMap(), - ) - } + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { - private var validated: Boolean = false + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() - fun validate(): RemovePrice = apply { - if (validated) { - return@apply - } + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithFiltersConfig.additionalProperties.toMutableMap() + } - priceId() - planPhaseOrder() - validated = true - } + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (priceId.asKnown() == null) 0 else 1) + - (if (planPhaseOrder.asKnown() == null) 0 else 1) + /** Bulk tiers for rating based on total usage volume */ + 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() } + } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * 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) + } + } - return /* spotless:off */ other is RemovePrice && priceId == other.priceId && planPhaseOrder == other.planPhaseOrder && additionalProperties == other.additionalProperties /* spotless:on */ - } + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(priceId, planPhaseOrder, additionalProperties) } - /* spotless:on */ + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - override fun hashCode(): Int = hashCode + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - override fun toString() = - "RemovePrice{priceId=$priceId, planPhaseOrder=$planPhaseOrder, additionalProperties=$additionalProperties}" - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - class ReplaceAdjustment - private constructor( - private val adjustment: JsonField, - private val replacesAdjustmentId: JsonField, - private val planPhaseOrder: JsonField, - private val additionalProperties: MutableMap, - ) { + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - @JsonCreator - private constructor( - @JsonProperty("adjustment") - @ExcludeMissing - adjustment: JsonField = JsonMissing.of(), - @JsonProperty("replaces_adjustment_id") - @ExcludeMissing - replacesAdjustmentId: JsonField = JsonMissing.of(), - @JsonProperty("plan_phase_order") - @ExcludeMissing - planPhaseOrder: JsonField = JsonMissing.of(), - ) : this(adjustment, replacesAdjustmentId, planPhaseOrder, mutableMapOf()) + /** + * Returns an immutable instance of [BulkWithFiltersConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } - /** - * The definition of a new adjustment to create and add to the plan. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun adjustment(): Adjustment = adjustment.getRequired("adjustment") + private var validated: Boolean = false - /** - * The id of the adjustment on the plan to replace in the plan. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } + + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = + propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + propertyKey() + propertyValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = + tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filters, tiers, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFilters && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFilters{bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class TieredWithProration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val tieredWithProrationConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + tieredWithProrationConfig: JsonField = + JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for tiered_with_proration pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tieredWithProrationConfig(): TieredWithProrationConfig = + tieredWithProrationConfig.getRequired("tiered_with_proration_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [tieredWithProrationConfig]. + * + * Unlike [tieredWithProrationConfig], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + fun _tieredWithProrationConfig(): JsonField = + tieredWithProrationConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [TieredWithProration]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProration]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("tiered_with_proration") + private var name: JsonField? = null + private var tieredWithProrationConfig: JsonField? = + null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tieredWithProration: TieredWithProration) = apply { + cadence = tieredWithProration.cadence + itemId = tieredWithProration.itemId + modelType = tieredWithProration.modelType + name = tieredWithProration.name + tieredWithProrationConfig = tieredWithProration.tieredWithProrationConfig + billableMetricId = tieredWithProration.billableMetricId + billedInAdvance = tieredWithProration.billedInAdvance + billingCycleConfiguration = tieredWithProration.billingCycleConfiguration + conversionRate = tieredWithProration.conversionRate + conversionRateConfig = tieredWithProration.conversionRateConfig + currency = tieredWithProration.currency + dimensionalPriceConfiguration = + tieredWithProration.dimensionalPriceConfiguration + externalPriceId = tieredWithProration.externalPriceId + fixedPriceQuantity = tieredWithProration.fixedPriceQuantity + invoiceGroupingKey = tieredWithProration.invoiceGroupingKey + invoicingCycleConfiguration = + tieredWithProration.invoicingCycleConfiguration + metadata = tieredWithProration.metadata + referenceId = tieredWithProration.referenceId + additionalProperties = + tieredWithProration.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for tiered_with_proration pricing */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: TieredWithProrationConfig + ) = tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) + + /** + * Sets [Builder.tieredWithProrationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.tieredWithProrationConfig] with a well-typed + * [TieredWithProrationConfig] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: JsonField + ) = apply { this.tieredWithProrationConfig = tieredWithProrationConfig } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TieredWithProration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProration = + TieredWithProration( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("tieredWithProrationConfig", tieredWithProrationConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProration = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("tiered_with_proration")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + tieredWithProrationConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("tiered_with_proration")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (tieredWithProrationConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for tiered_with_proration pricing */ + class TieredWithProrationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Tiers for rating based on total usage quantities into the specified tier with + * proration + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 + * [TieredWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProrationConfig]. */ + class Builder internal constructor() { + + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = + apply { + tiers = tieredWithProrationConfig.tiers.map { it.toMutableList() } + additionalProperties = + tieredWithProrationConfig.additionalProperties.toMutableMap() + } + + /** + * Tiers for rating based on total usage quantities into the specified tier + * with proration + */ + 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 [TieredWithProrationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProrationConfig = + TieredWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProrationConfig = apply { + if (validated) { + return@apply + } + + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tiered with proration tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Inclusive tier starting value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun tierLowerBound(): String = + tierLowerBound.getRequired("tier_lower_bound") + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Inclusive tier starting value */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProration && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredWithProrationConfig == other.tieredWithProrationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProration{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, tieredWithProrationConfig=$tieredWithProrationConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val groupedWithMinMaxThresholdsConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + groupedWithMinMaxThresholdsConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for grouped_with_min_max_thresholds pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired( + "grouped_with_min_max_thresholds_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. + * + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + fun _groupedWithMinMaxThresholdsConfig(): + JsonField = groupedWithMinMaxThresholdsConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [GroupedWithMinMaxThresholds]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholds]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("grouped_with_min_max_thresholds") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = + apply { + cadence = groupedWithMinMaxThresholds.cadence + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + itemId = groupedWithMinMaxThresholds.itemId + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + billableMetricId = groupedWithMinMaxThresholds.billableMetricId + billedInAdvance = groupedWithMinMaxThresholds.billedInAdvance + billingCycleConfiguration = + groupedWithMinMaxThresholds.billingCycleConfiguration + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + currency = groupedWithMinMaxThresholds.currency + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + invoiceGroupingKey = groupedWithMinMaxThresholds.invoiceGroupingKey + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + metadata = groupedWithMinMaxThresholds.metadata + referenceId = groupedWithMinMaxThresholds.referenceId + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = + groupedWithMinMaxThresholdsConfig( + JsonField.of(groupedWithMinMaxThresholdsConfig) + ) + + /** + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a + * well-typed [GroupedWithMinMaxThresholdsConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: + JsonField + ) = apply { + this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( + checkRequired("cadence", cadence), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholds = apply { + if (validated) { + return@apply + } + + cadence().validate() + groupedWithMinMaxThresholdsConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @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 + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate + additionalProperties = + groupedWithMinMaxThresholdsConfig.additionalProperties + .toMutableMap() + } + + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } + + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } + + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = + perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + if (validated) { + return@apply + } + + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholds && + cadence == other.cadence && + groupedWithMinMaxThresholdsConfig == + other.groupedWithMinMaxThresholdsConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholds{cadence=$cadence, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val cumulativeGroupedAllocationConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for cumulative_grouped_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired( + "cumulative_grouped_allocation_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): + JsonField = cumulativeGroupedAllocationConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [CumulativeGroupedAllocation]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocation]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("cumulative_grouped_allocation") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = + apply { + cadence = cumulativeGroupedAllocation.cadence + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + itemId = cumulativeGroupedAllocation.itemId + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + billableMetricId = cumulativeGroupedAllocation.billableMetricId + billedInAdvance = cumulativeGroupedAllocation.billedInAdvance + billingCycleConfiguration = + cumulativeGroupedAllocation.billingCycleConfiguration + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + currency = cumulativeGroupedAllocation.currency + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoiceGroupingKey = cumulativeGroupedAllocation.invoiceGroupingKey + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + metadata = cumulativeGroupedAllocation.metadata + referenceId = cumulativeGroupedAllocation.referenceId + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = + cumulativeGroupedAllocationConfig( + JsonField.of(cumulativeGroupedAllocationConfig) + ) + + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a + * well-typed [CumulativeGroupedAllocationConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: + JsonField + ) = apply { + this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( + checkRequired("cadence", cadence), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocation = apply { + if (validated) { + return@apply + } + + cadence().validate() + cumulativeGroupedAllocationConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("cumulative_grouped_allocation")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + mutableMapOf(), + ) + + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 + * [CumulativeGroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = + cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties + .toMutableMap() + } + + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } + + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation + } + + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply + } + + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocation && + cadence == other.cadence && + cumulativeGroupedAllocationConfig == + other.cumulativeGroupedAllocationConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocation{cadence=$cadence, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val percentConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [Percent]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Percent]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("percent") + private var name: JsonField? = null + private var percentConfig: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percent: Percent) = apply { + cadence = percent.cadence + itemId = percent.itemId + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + billableMetricId = percent.billableMetricId + billedInAdvance = percent.billedInAdvance + billingCycleConfiguration = percent.billingCycleConfiguration + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + currency = percent.currency + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoiceGroupingKey = percent.invoiceGroupingKey + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + metadata = percent.metadata + referenceId = percent.referenceId + additionalProperties = percent.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed + * [PercentConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Percent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Percent = + Percent( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("percentConfig", percentConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Percent = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("percent")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + percentConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent") + @ExcludeMissing + fun _percent(): JsonField = percent + + @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 + * [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PercentConfig]. */ + class Builder internal constructor() { + + private var percent: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() + } + + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PercentConfig = apply { + if (validated) { + return@apply + } + + percent() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(percent, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Percent && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Percent{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, percentConfig=$percentConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val eventOutputConfig: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [EventOutput]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutput]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var eventOutputConfig: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("event_output") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutput: EventOutput) = apply { + cadence = eventOutput.cadence + eventOutputConfig = eventOutput.eventOutputConfig + itemId = eventOutput.itemId + modelType = eventOutput.modelType + name = eventOutput.name + billableMetricId = eventOutput.billableMetricId + billedInAdvance = eventOutput.billedInAdvance + billingCycleConfiguration = eventOutput.billingCycleConfiguration + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + currency = eventOutput.currency + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoiceGroupingKey = eventOutput.invoiceGroupingKey + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + metadata = eventOutput.metadata + referenceId = eventOutput.referenceId + additionalProperties = eventOutput.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutput = + EventOutput( + checkRequired("cadence", cadence), + checkRequired("eventOutputConfig", eventOutputConfig), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutput = apply { + if (validated) { + return@apply + } + + cadence().validate() + eventOutputConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("event_output")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a + * unit rate will be ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = + defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events + * will also be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @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 + * [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutputConfig]. */ + class Builder internal constructor() { + + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = + eventOutputConfig.additionalProperties.toMutableMap() + } + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey + } + + /** + * If provided, this amount will be used as the unit rate when an event does + * not have a value for the `unit_rating_key`. If not provided, events + * missing a unit rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate + } + + /** + * An optional key in the event data to group by (e.g., event ID). All + * events will also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutputConfig = apply { + if (validated) { + return@apply + } + + unitRatingKey() + defaultUnitRate() + groupingKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + unitRatingKey, + defaultUnitRate, + groupingKey, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutput && + cadence == other.cadence && + eventOutputConfig == other.eventOutputConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutput{cadence=$cadence, eventOutputConfig=$eventOutputConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddPrice && + allocationPrice == other.allocationPrice && + planPhaseOrder == other.planPhaseOrder && + price == other.price && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(allocationPrice, planPhaseOrder, price, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddPrice{allocationPrice=$allocationPrice, planPhaseOrder=$planPhaseOrder, price=$price, additionalProperties=$additionalProperties}" + } + + class RemoveAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val adjustmentId: JsonField, + private val planPhaseOrder: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("adjustment_id") + @ExcludeMissing + adjustmentId: JsonField = JsonMissing.of(), + @JsonProperty("plan_phase_order") + @ExcludeMissing + planPhaseOrder: JsonField = JsonMissing.of(), + ) : this(adjustmentId, planPhaseOrder, mutableMapOf()) + + /** + * The id of the adjustment to remove from on the plan. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun adjustmentId(): String = adjustmentId.getRequired("adjustment_id") + + /** + * The phase to remove this adjustment from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + + /** + * Returns the raw JSON value of [adjustmentId]. + * + * Unlike [adjustmentId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("adjustment_id") + @ExcludeMissing + fun _adjustmentId(): JsonField = adjustmentId + + /** + * Returns the raw JSON value of [planPhaseOrder]. + * + * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("plan_phase_order") + @ExcludeMissing + fun _planPhaseOrder(): JsonField = planPhaseOrder + + @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 [RemoveAdjustment]. + * + * The following fields are required: + * ```kotlin + * .adjustmentId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [RemoveAdjustment]. */ + class Builder internal constructor() { + + private var adjustmentId: JsonField? = null + private var planPhaseOrder: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(removeAdjustment: RemoveAdjustment) = apply { + adjustmentId = removeAdjustment.adjustmentId + planPhaseOrder = removeAdjustment.planPhaseOrder + additionalProperties = removeAdjustment.additionalProperties.toMutableMap() + } + + /** The id of the adjustment to remove from on the plan. */ + fun adjustmentId(adjustmentId: String) = adjustmentId(JsonField.of(adjustmentId)) + + /** + * Sets [Builder.adjustmentId] to an arbitrary JSON value. + * + * You should usually call [Builder.adjustmentId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun adjustmentId(adjustmentId: JsonField) = apply { + this.adjustmentId = adjustmentId + } + + /** The phase to remove this adjustment from. */ + fun planPhaseOrder(planPhaseOrder: Long?) = + planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + + /** + * Alias for [Builder.planPhaseOrder]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + + /** + * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. + * + * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun planPhaseOrder(planPhaseOrder: JsonField) = apply { + this.planPhaseOrder = planPhaseOrder + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [RemoveAdjustment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .adjustmentId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RemoveAdjustment = + RemoveAdjustment( + checkRequired("adjustmentId", adjustmentId), + planPhaseOrder, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RemoveAdjustment = apply { + if (validated) { + return@apply + } + + adjustmentId() + planPhaseOrder() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (adjustmentId.asKnown() == null) 0 else 1) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RemoveAdjustment && + adjustmentId == other.adjustmentId && + planPhaseOrder == other.planPhaseOrder && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(adjustmentId, planPhaseOrder, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemoveAdjustment{adjustmentId=$adjustmentId, planPhaseOrder=$planPhaseOrder, additionalProperties=$additionalProperties}" + } + + class RemovePrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val priceId: JsonField, + private val planPhaseOrder: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("price_id") @ExcludeMissing priceId: JsonField = JsonMissing.of(), + @JsonProperty("plan_phase_order") + @ExcludeMissing + planPhaseOrder: JsonField = JsonMissing.of(), + ) : this(priceId, planPhaseOrder, mutableMapOf()) + + /** + * The id of the price to remove from the plan. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun priceId(): String = priceId.getRequired("price_id") + + /** + * The phase to remove this price from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + + /** + * Returns the raw JSON value of [priceId]. + * + * Unlike [priceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("price_id") @ExcludeMissing fun _priceId(): JsonField = priceId + + /** + * Returns the raw JSON value of [planPhaseOrder]. + * + * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("plan_phase_order") + @ExcludeMissing + fun _planPhaseOrder(): JsonField = planPhaseOrder + + @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 [RemovePrice]. + * + * The following fields are required: + * ```kotlin + * .priceId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [RemovePrice]. */ + class Builder internal constructor() { + + private var priceId: JsonField? = null + private var planPhaseOrder: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(removePrice: RemovePrice) = apply { + priceId = removePrice.priceId + planPhaseOrder = removePrice.planPhaseOrder + additionalProperties = removePrice.additionalProperties.toMutableMap() + } + + /** The id of the price to remove from the plan. */ + fun priceId(priceId: String) = priceId(JsonField.of(priceId)) + + /** + * Sets [Builder.priceId] to an arbitrary JSON value. + * + * You should usually call [Builder.priceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun priceId(priceId: JsonField) = apply { this.priceId = priceId } + + /** The phase to remove this price from. */ + fun planPhaseOrder(planPhaseOrder: Long?) = + planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + + /** + * Alias for [Builder.planPhaseOrder]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + + /** + * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. + * + * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun planPhaseOrder(planPhaseOrder: JsonField) = apply { + this.planPhaseOrder = planPhaseOrder + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [RemovePrice]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .priceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RemovePrice = + RemovePrice( + checkRequired("priceId", priceId), + planPhaseOrder, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RemovePrice = apply { + if (validated) { + return@apply + } + + priceId() + planPhaseOrder() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (priceId.asKnown() == null) 0 else 1) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RemovePrice && + priceId == other.priceId && + planPhaseOrder == other.planPhaseOrder && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(priceId, planPhaseOrder, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemovePrice{priceId=$priceId, planPhaseOrder=$planPhaseOrder, additionalProperties=$additionalProperties}" + } + + class ReplaceAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val adjustment: JsonField, + private val replacesAdjustmentId: JsonField, + private val planPhaseOrder: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("adjustment") + @ExcludeMissing + adjustment: JsonField = JsonMissing.of(), + @JsonProperty("replaces_adjustment_id") + @ExcludeMissing + replacesAdjustmentId: JsonField = JsonMissing.of(), + @JsonProperty("plan_phase_order") + @ExcludeMissing + planPhaseOrder: JsonField = JsonMissing.of(), + ) : this(adjustment, replacesAdjustmentId, planPhaseOrder, mutableMapOf()) + + /** + * The definition of a new adjustment to create and add to the plan. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun adjustment(): Adjustment = adjustment.getRequired("adjustment") + + /** + * The id of the adjustment on the plan to replace in the plan. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun replacesAdjustmentId(): String = + replacesAdjustmentId.getRequired("replaces_adjustment_id") + + /** + * The phase to replace this adjustment from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + + /** + * Returns the raw JSON value of [adjustment]. + * + * Unlike [adjustment], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("adjustment") + @ExcludeMissing + fun _adjustment(): JsonField = adjustment + + /** + * Returns the raw JSON value of [replacesAdjustmentId]. + * + * Unlike [replacesAdjustmentId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("replaces_adjustment_id") + @ExcludeMissing + fun _replacesAdjustmentId(): JsonField = replacesAdjustmentId + + /** + * Returns the raw JSON value of [planPhaseOrder]. + * + * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("plan_phase_order") + @ExcludeMissing + fun _planPhaseOrder(): JsonField = planPhaseOrder + + @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 [ReplaceAdjustment]. + * + * The following fields are required: + * ```kotlin + * .adjustment() + * .replacesAdjustmentId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ReplaceAdjustment]. */ + class Builder internal constructor() { + + private var adjustment: JsonField? = null + private var replacesAdjustmentId: JsonField? = null + private var planPhaseOrder: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(replaceAdjustment: ReplaceAdjustment) = apply { + adjustment = replaceAdjustment.adjustment + replacesAdjustmentId = replaceAdjustment.replacesAdjustmentId + planPhaseOrder = replaceAdjustment.planPhaseOrder + additionalProperties = replaceAdjustment.additionalProperties.toMutableMap() + } + + /** The definition of a new adjustment to create and add to the plan. */ + fun adjustment(adjustment: Adjustment) = adjustment(JsonField.of(adjustment)) + + /** + * Sets [Builder.adjustment] to an arbitrary JSON value. + * + * You should usually call [Builder.adjustment] with a well-typed [Adjustment] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun adjustment(adjustment: JsonField) = apply { + this.adjustment = adjustment + } + + /** + * Alias for calling [adjustment] with + * `Adjustment.ofPercentageDiscount(percentageDiscount)`. + */ + fun adjustment(percentageDiscount: NewPercentageDiscount) = + adjustment(Adjustment.ofPercentageDiscount(percentageDiscount)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewPercentageDiscount.builder() + * .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) + * .percentageDiscount(percentageDiscount) + * .build() + * ``` + */ + fun percentageDiscountAdjustment(percentageDiscount: Double) = + adjustment( + NewPercentageDiscount.builder() + .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) + .percentageDiscount(percentageDiscount) + .build() + ) + + /** Alias for calling [adjustment] with `Adjustment.ofUsageDiscount(usageDiscount)`. */ + fun adjustment(usageDiscount: NewUsageDiscount) = + adjustment(Adjustment.ofUsageDiscount(usageDiscount)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewUsageDiscount.builder() + * .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) + * .usageDiscount(usageDiscount) + * .build() + * ``` + */ + fun usageDiscountAdjustment(usageDiscount: Double) = + adjustment( + NewUsageDiscount.builder() + .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) + .usageDiscount(usageDiscount) + .build() + ) + + /** + * Alias for calling [adjustment] with `Adjustment.ofAmountDiscount(amountDiscount)`. + */ + fun adjustment(amountDiscount: NewAmountDiscount) = + adjustment(Adjustment.ofAmountDiscount(amountDiscount)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewAmountDiscount.builder() + * .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) + * .amountDiscount(amountDiscount) + * .build() + * ``` + */ + fun amountDiscountAdjustment(amountDiscount: String) = + adjustment( + NewAmountDiscount.builder() + .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) + .amountDiscount(amountDiscount) + .build() + ) + + /** Alias for calling [adjustment] with `Adjustment.ofMinimum(minimum)`. */ + fun adjustment(minimum: NewMinimum) = adjustment(Adjustment.ofMinimum(minimum)) + + /** Alias for calling [adjustment] with `Adjustment.ofMaximum(maximum)`. */ + fun adjustment(maximum: NewMaximum) = adjustment(Adjustment.ofMaximum(maximum)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewMaximum.builder() + * .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) + * .maximumAmount(maximumAmount) + * .build() + * ``` + */ + fun maximumAdjustment(maximumAmount: String) = + adjustment( + NewMaximum.builder() + .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) + .maximumAmount(maximumAmount) + .build() + ) + + /** The id of the adjustment on the plan to replace in the plan. */ + fun replacesAdjustmentId(replacesAdjustmentId: String) = + replacesAdjustmentId(JsonField.of(replacesAdjustmentId)) + + /** + * Sets [Builder.replacesAdjustmentId] to an arbitrary JSON value. + * + * You should usually call [Builder.replacesAdjustmentId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun replacesAdjustmentId(replacesAdjustmentId: JsonField) = apply { + this.replacesAdjustmentId = replacesAdjustmentId + } + + /** The phase to replace this adjustment from. */ + fun planPhaseOrder(planPhaseOrder: Long?) = + planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + + /** + * Alias for [Builder.planPhaseOrder]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + + /** + * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. + * + * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun planPhaseOrder(planPhaseOrder: JsonField) = apply { + this.planPhaseOrder = planPhaseOrder + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ReplaceAdjustment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .adjustment() + * .replacesAdjustmentId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ReplaceAdjustment = + ReplaceAdjustment( + checkRequired("adjustment", adjustment), + checkRequired("replacesAdjustmentId", replacesAdjustmentId), + planPhaseOrder, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ReplaceAdjustment = apply { + if (validated) { + return@apply + } + + adjustment().validate() + replacesAdjustmentId() + planPhaseOrder() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (adjustment.asKnown()?.validity() ?: 0) + + (if (replacesAdjustmentId.asKnown() == null) 0 else 1) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + /** The definition of a new adjustment to create and add to the plan. */ + @JsonDeserialize(using = Adjustment.Deserializer::class) + @JsonSerialize(using = Adjustment.Serializer::class) + class Adjustment + private constructor( + private val percentageDiscount: NewPercentageDiscount? = null, + private val usageDiscount: NewUsageDiscount? = null, + private val amountDiscount: NewAmountDiscount? = null, + private val minimum: NewMinimum? = null, + private val maximum: NewMaximum? = null, + private val _json: JsonValue? = null, + ) { + + fun percentageDiscount(): NewPercentageDiscount? = percentageDiscount + + fun usageDiscount(): NewUsageDiscount? = usageDiscount + + fun amountDiscount(): NewAmountDiscount? = amountDiscount + + fun minimum(): NewMinimum? = minimum + + fun maximum(): NewMaximum? = maximum + + fun isPercentageDiscount(): Boolean = percentageDiscount != null + + fun isUsageDiscount(): Boolean = usageDiscount != null + + fun isAmountDiscount(): Boolean = amountDiscount != null + + fun isMinimum(): Boolean = minimum != null + + fun isMaximum(): Boolean = maximum != null + + fun asPercentageDiscount(): NewPercentageDiscount = + percentageDiscount.getOrThrow("percentageDiscount") + + fun asUsageDiscount(): NewUsageDiscount = usageDiscount.getOrThrow("usageDiscount") + + fun asAmountDiscount(): NewAmountDiscount = amountDiscount.getOrThrow("amountDiscount") + + fun asMinimum(): NewMinimum = minimum.getOrThrow("minimum") + + fun asMaximum(): NewMaximum = maximum.getOrThrow("maximum") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + percentageDiscount != null -> + visitor.visitPercentageDiscount(percentageDiscount) + usageDiscount != null -> visitor.visitUsageDiscount(usageDiscount) + amountDiscount != null -> visitor.visitAmountDiscount(amountDiscount) + minimum != null -> visitor.visitMinimum(minimum) + maximum != null -> visitor.visitMaximum(maximum) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Adjustment = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitPercentageDiscount( + percentageDiscount: NewPercentageDiscount + ) { + percentageDiscount.validate() + } + + override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) { + usageDiscount.validate() + } + + override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) { + amountDiscount.validate() + } + + override fun visitMinimum(minimum: NewMinimum) { + minimum.validate() + } + + override fun visitMaximum(maximum: NewMaximum) { + maximum.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitPercentageDiscount( + percentageDiscount: NewPercentageDiscount + ) = percentageDiscount.validity() + + override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) = + usageDiscount.validity() + + override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) = + amountDiscount.validity() + + override fun visitMinimum(minimum: NewMinimum) = minimum.validity() + + override fun visitMaximum(maximum: NewMaximum) = maximum.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Adjustment && + percentageDiscount == other.percentageDiscount && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + minimum == other.minimum && + maximum == other.maximum + } + + override fun hashCode(): Int = + Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) + + override fun toString(): String = + when { + percentageDiscount != null -> + "Adjustment{percentageDiscount=$percentageDiscount}" + usageDiscount != null -> "Adjustment{usageDiscount=$usageDiscount}" + amountDiscount != null -> "Adjustment{amountDiscount=$amountDiscount}" + minimum != null -> "Adjustment{minimum=$minimum}" + maximum != null -> "Adjustment{maximum=$maximum}" + _json != null -> "Adjustment{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Adjustment") + } + + companion object { + + fun ofPercentageDiscount(percentageDiscount: NewPercentageDiscount) = + Adjustment(percentageDiscount = percentageDiscount) + + fun ofUsageDiscount(usageDiscount: NewUsageDiscount) = + Adjustment(usageDiscount = usageDiscount) + + fun ofAmountDiscount(amountDiscount: NewAmountDiscount) = + Adjustment(amountDiscount = amountDiscount) + + fun ofMinimum(minimum: NewMinimum) = Adjustment(minimum = minimum) + + fun ofMaximum(maximum: NewMaximum) = Adjustment(maximum = maximum) + } + + /** + * An interface that defines how to map each variant of [Adjustment] to a value of type + * [T]. + */ + interface Visitor { + + fun visitPercentageDiscount(percentageDiscount: NewPercentageDiscount): T + + fun visitUsageDiscount(usageDiscount: NewUsageDiscount): T + + fun visitAmountDiscount(amountDiscount: NewAmountDiscount): T + + fun visitMinimum(minimum: NewMinimum): T + + fun visitMaximum(maximum: NewMaximum): T + + /** + * Maps an unknown variant of [Adjustment] to a value of type [T]. + * + * An instance of [Adjustment] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on an + * older version than the API, then the API may respond with new variants that the + * SDK is unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown Adjustment: $json") + } + } + + internal class Deserializer : BaseDeserializer(Adjustment::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Adjustment { + val json = JsonValue.fromJsonNode(node) + val adjustmentType = json.asObject()?.get("adjustment_type")?.asString() + + when (adjustmentType) { + "percentage_discount" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Adjustment(percentageDiscount = it, _json = json) } + ?: Adjustment(_json = json) + } + "usage_discount" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(usageDiscount = it, _json = json) + } ?: Adjustment(_json = json) + } + "amount_discount" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(amountDiscount = it, _json = json) + } ?: Adjustment(_json = json) + } + "minimum" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(minimum = it, _json = json) + } ?: Adjustment(_json = json) + } + "maximum" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(maximum = it, _json = json) + } ?: Adjustment(_json = json) + } + } + + return Adjustment(_json = json) + } + } + + internal class Serializer : BaseSerializer(Adjustment::class) { + + override fun serialize( + value: Adjustment, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.percentageDiscount != null -> + generator.writeObject(value.percentageDiscount) + value.usageDiscount != null -> generator.writeObject(value.usageDiscount) + value.amountDiscount != null -> generator.writeObject(value.amountDiscount) + value.minimum != null -> generator.writeObject(value.minimum) + value.maximum != null -> generator.writeObject(value.maximum) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Adjustment") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ReplaceAdjustment && + adjustment == other.adjustment && + replacesAdjustmentId == other.replacesAdjustmentId && + planPhaseOrder == other.planPhaseOrder && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(adjustment, replacesAdjustmentId, planPhaseOrder, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ReplaceAdjustment{adjustment=$adjustment, replacesAdjustmentId=$replacesAdjustmentId, planPhaseOrder=$planPhaseOrder, additionalProperties=$additionalProperties}" + } + + class ReplacePrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val replacesPriceId: JsonField, + private val allocationPrice: JsonField, + private val planPhaseOrder: JsonField, + private val price: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("replaces_price_id") + @ExcludeMissing + replacesPriceId: JsonField = JsonMissing.of(), + @JsonProperty("allocation_price") + @ExcludeMissing + allocationPrice: JsonField = JsonMissing.of(), + @JsonProperty("plan_phase_order") + @ExcludeMissing + planPhaseOrder: JsonField = JsonMissing.of(), + @JsonProperty("price") @ExcludeMissing price: JsonField = JsonMissing.of(), + ) : this(replacesPriceId, allocationPrice, planPhaseOrder, price, mutableMapOf()) + + /** + * The id of the price on the plan to replace in the plan. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun replacesPriceId(): String = replacesPriceId.getRequired("replaces_price_id") + + /** + * The allocation price to add to the plan. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allocationPrice(): NewAllocationPrice? = allocationPrice.getNullable("allocation_price") + + /** + * The phase to replace this price from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + + /** + * New plan price request body params. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun price(): Price? = price.getNullable("price") + + /** + * Returns the raw JSON value of [replacesPriceId]. + * + * Unlike [replacesPriceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("replaces_price_id") + @ExcludeMissing + fun _replacesPriceId(): JsonField = replacesPriceId + + /** + * Returns the raw JSON value of [allocationPrice]. + * + * Unlike [allocationPrice], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("allocation_price") + @ExcludeMissing + fun _allocationPrice(): JsonField = allocationPrice + + /** + * Returns the raw JSON value of [planPhaseOrder]. + * + * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("plan_phase_order") + @ExcludeMissing + fun _planPhaseOrder(): JsonField = planPhaseOrder + + /** + * 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 + + @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 [ReplacePrice]. + * + * The following fields are required: + * ```kotlin + * .replacesPriceId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ReplacePrice]. */ + class Builder internal constructor() { + + private var replacesPriceId: JsonField? = null + private var allocationPrice: JsonField = JsonMissing.of() + private var planPhaseOrder: JsonField = JsonMissing.of() + private var price: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(replacePrice: ReplacePrice) = apply { + replacesPriceId = replacePrice.replacesPriceId + allocationPrice = replacePrice.allocationPrice + planPhaseOrder = replacePrice.planPhaseOrder + price = replacePrice.price + additionalProperties = replacePrice.additionalProperties.toMutableMap() + } + + /** The id of the price on the plan to replace in the plan. */ + fun replacesPriceId(replacesPriceId: String) = + replacesPriceId(JsonField.of(replacesPriceId)) + + /** + * Sets [Builder.replacesPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.replacesPriceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun replacesPriceId(replacesPriceId: JsonField) = apply { + this.replacesPriceId = replacesPriceId + } + + /** The allocation price to add to the plan. */ + fun allocationPrice(allocationPrice: NewAllocationPrice?) = + allocationPrice(JsonField.ofNullable(allocationPrice)) + + /** + * Sets [Builder.allocationPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.allocationPrice] with a well-typed + * [NewAllocationPrice] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun allocationPrice(allocationPrice: JsonField) = apply { + this.allocationPrice = allocationPrice + } + + /** The phase to replace this price from. */ + fun planPhaseOrder(planPhaseOrder: Long?) = + planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + + /** + * Alias for [Builder.planPhaseOrder]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + + /** + * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. + * + * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun planPhaseOrder(planPhaseOrder: JsonField) = apply { + this.planPhaseOrder = planPhaseOrder + } + + /** New plan price request body params. */ + fun price(price: Price?) = price(JsonField.ofNullable(price)) + + /** + * Sets [Builder.price] to an arbitrary JSON value. + * + * You should usually call [Builder.price] with a well-typed [Price] 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 } + + /** Alias for calling [price] with `Price.ofUnit(unit)`. */ + fun price(unit: NewPlanUnitPrice) = price(Price.ofUnit(unit)) + + /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ + fun price(tiered: NewPlanTieredPrice) = price(Price.ofTiered(tiered)) + + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: NewPlanBulkPrice) = price(Price.ofBulk(bulk)) + + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) + + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: NewPlanPackagePrice) = price(Price.ofPackage(package_)) + + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: NewPlanMatrixPrice) = price(Price.ofMatrix(matrix)) + + /** + * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. + */ + fun price(thresholdTotalAmount: NewPlanThresholdTotalAmountPrice) = + price(Price.ofThresholdTotalAmount(thresholdTotalAmount)) + + /** Alias for calling [price] with `Price.ofTieredPackage(tieredPackage)`. */ + fun price(tieredPackage: NewPlanTieredPackagePrice) = + price(Price.ofTieredPackage(tieredPackage)) + + /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ + fun price(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = + price(Price.ofTieredWithMinimum(tieredWithMinimum)) + + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: NewPlanGroupedTieredPrice) = + price(Price.ofGroupedTiered(groupedTiered)) + + /** + * Alias for calling [price] with + * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + */ + fun price(tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice) = + price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofPackageWithAllocation(packageWithAllocation)`. + */ + fun price(packageWithAllocation: NewPlanPackageWithAllocationPrice) = + price(Price.ofPackageWithAllocation(packageWithAllocation)) + + /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ + fun price(unitWithPercent: NewPlanUnitWithPercentPrice) = + price(Price.ofUnitWithPercent(unitWithPercent)) + + /** + * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun price(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = + price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + + /** + * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. + */ + fun price(tieredWithProration: Price.TieredWithProration) = + price(Price.ofTieredWithProration(tieredWithProration)) + + /** Alias for calling [price] with `Price.ofUnitWithProration(unitWithProration)`. */ + fun price(unitWithProration: NewPlanUnitWithProrationPrice) = + price(Price.ofUnitWithProration(unitWithProration)) + + /** Alias for calling [price] with `Price.ofGroupedAllocation(groupedAllocation)`. */ + fun price(groupedAllocation: NewPlanGroupedAllocationPrice) = + price(Price.ofGroupedAllocation(groupedAllocation)) + + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: NewPlanBulkWithProrationPrice) = + price(Price.ofBulkWithProration(bulkWithProration)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. + */ + fun price(groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice) = + price(Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. + */ + fun price(groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice) = + price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + + /** + * Alias for calling [price] with + * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. + */ + fun price(matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice) = + price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) + + /** + * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. + */ + fun price(groupedTieredPackage: NewPlanGroupedTieredPackagePrice) = + price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + + /** + * Alias for calling [price] with + * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. + */ + fun price(maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice) = + price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + + /** + * Alias for calling [price] with + * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. + */ + fun price(scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice) = + price(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) + + /** + * Alias for calling [price] with + * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. + */ + fun price( + scalableMatrixWithTieredPricing: NewPlanScalableMatrixWithTieredPricingPrice + ) = price(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) + + /** + * Alias for calling [price] with + * `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. + */ + fun price(cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice) = + price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + + /** + * Alias for calling [price] with + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. + */ + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: NewPlanMinimumCompositePrice) = price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ReplacePrice]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .replacesPriceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ReplacePrice = + ReplacePrice( + checkRequired("replacesPriceId", replacesPriceId), + allocationPrice, + planPhaseOrder, + price, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ReplacePrice = apply { + if (validated) { + return@apply + } + + replacesPriceId() + allocationPrice()?.validate() + planPhaseOrder() + price()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. */ - fun replacesAdjustmentId(): String = - replacesAdjustmentId.getRequired("replaces_adjustment_id") + internal fun validity(): Int = + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (allocationPrice.asKnown()?.validity() ?: 0) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + (price.asKnown()?.validity() ?: 0) + + /** New plan price request body params. */ + @JsonDeserialize(using = Price.Deserializer::class) + @JsonSerialize(using = Price.Serializer::class) + class Price + private constructor( + private val unit: NewPlanUnitPrice? = null, + private val tiered: NewPlanTieredPrice? = null, + private val bulk: NewPlanBulkPrice? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: NewPlanPackagePrice? = null, + private val matrix: NewPlanMatrixPrice? = null, + private val thresholdTotalAmount: NewPlanThresholdTotalAmountPrice? = null, + private val tieredPackage: NewPlanTieredPackagePrice? = null, + private val tieredWithMinimum: NewPlanTieredWithMinimumPrice? = null, + private val groupedTiered: NewPlanGroupedTieredPrice? = null, + private val tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice? = null, + private val packageWithAllocation: NewPlanPackageWithAllocationPrice? = null, + private val unitWithPercent: NewPlanUnitWithPercentPrice? = null, + private val matrixWithAllocation: NewPlanMatrixWithAllocationPrice? = null, + private val tieredWithProration: TieredWithProration? = null, + private val unitWithProration: NewPlanUnitWithProrationPrice? = null, + private val groupedAllocation: NewPlanGroupedAllocationPrice? = null, + private val bulkWithProration: NewPlanBulkWithProrationPrice? = null, + private val groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice? = null, + private val groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice? = null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, + private val matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice? = null, + private val groupedTieredPackage: NewPlanGroupedTieredPackagePrice? = null, + private val maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice? = null, + private val scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice? = + null, + private val scalableMatrixWithTieredPricing: + NewPlanScalableMatrixWithTieredPricingPrice? = + null, + private val cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: NewPlanMinimumCompositePrice? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, + private val _json: JsonValue? = null, + ) { + + fun unit(): NewPlanUnitPrice? = unit + + fun tiered(): NewPlanTieredPrice? = tiered + + fun bulk(): NewPlanBulkPrice? = bulk + + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters + + fun package_(): NewPlanPackagePrice? = package_ + + fun matrix(): NewPlanMatrixPrice? = matrix + + fun thresholdTotalAmount(): NewPlanThresholdTotalAmountPrice? = thresholdTotalAmount + + fun tieredPackage(): NewPlanTieredPackagePrice? = tieredPackage + + fun tieredWithMinimum(): NewPlanTieredWithMinimumPrice? = tieredWithMinimum + + fun groupedTiered(): NewPlanGroupedTieredPrice? = groupedTiered + + fun tieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice? = + tieredPackageWithMinimum + + fun packageWithAllocation(): NewPlanPackageWithAllocationPrice? = packageWithAllocation + + fun unitWithPercent(): NewPlanUnitWithPercentPrice? = unitWithPercent + + fun matrixWithAllocation(): NewPlanMatrixWithAllocationPrice? = matrixWithAllocation + + fun tieredWithProration(): TieredWithProration? = tieredWithProration + + fun unitWithProration(): NewPlanUnitWithProrationPrice? = unitWithProration + + fun groupedAllocation(): NewPlanGroupedAllocationPrice? = groupedAllocation + + fun bulkWithProration(): NewPlanBulkWithProrationPrice? = bulkWithProration + + fun groupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice? = + groupedWithProratedMinimum + + fun groupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice? = + groupedWithMeteredMinimum + + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = + groupedWithMinMaxThresholds + + fun matrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice? = matrixWithDisplayName + + fun groupedTieredPackage(): NewPlanGroupedTieredPackagePrice? = groupedTieredPackage + + fun maxGroupTieredPackage(): NewPlanMaxGroupTieredPackagePrice? = maxGroupTieredPackage + + fun scalableMatrixWithUnitPricing(): NewPlanScalableMatrixWithUnitPricingPrice? = + scalableMatrixWithUnitPricing + + fun scalableMatrixWithTieredPricing(): NewPlanScalableMatrixWithTieredPricingPrice? = + scalableMatrixWithTieredPricing + + fun cumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice? = cumulativeGroupedBulk + + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = + cumulativeGroupedAllocation + + fun minimum(): NewPlanMinimumCompositePrice? = minimum + + fun percent(): Percent? = percent + + fun eventOutput(): EventOutput? = eventOutput + + fun isUnit(): Boolean = unit != null + + fun isTiered(): Boolean = tiered != null + + fun isBulk(): Boolean = bulk != null + + fun isBulkWithFilters(): Boolean = bulkWithFilters != null + + fun isPackage(): Boolean = package_ != null + + fun isMatrix(): Boolean = matrix != null + + fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null + + fun isTieredPackage(): Boolean = tieredPackage != null + + fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null + + fun isGroupedTiered(): Boolean = groupedTiered != null + + fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + + fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + + fun isUnitWithPercent(): Boolean = unitWithPercent != null + + fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + + fun isTieredWithProration(): Boolean = tieredWithProration != null + + fun isUnitWithProration(): Boolean = unitWithProration != null + + fun isGroupedAllocation(): Boolean = groupedAllocation != null + + fun isBulkWithProration(): Boolean = bulkWithProration != null + + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null + + fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null + + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null + + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + + fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + + fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null + + fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null + + fun isScalableMatrixWithTieredPricing(): Boolean = + scalableMatrixWithTieredPricing != null + + fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null + + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null + + fun isMinimum(): Boolean = minimum != null + + fun isPercent(): Boolean = percent != null + + fun isEventOutput(): Boolean = eventOutput != null + + fun asUnit(): NewPlanUnitPrice = unit.getOrThrow("unit") + + fun asTiered(): NewPlanTieredPrice = tiered.getOrThrow("tiered") + + fun asBulk(): NewPlanBulkPrice = bulk.getOrThrow("bulk") + + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") + + fun asPackage(): NewPlanPackagePrice = package_.getOrThrow("package_") + + fun asMatrix(): NewPlanMatrixPrice = matrix.getOrThrow("matrix") + + fun asThresholdTotalAmount(): NewPlanThresholdTotalAmountPrice = + thresholdTotalAmount.getOrThrow("thresholdTotalAmount") + + fun asTieredPackage(): NewPlanTieredPackagePrice = + tieredPackage.getOrThrow("tieredPackage") + + fun asTieredWithMinimum(): NewPlanTieredWithMinimumPrice = + tieredWithMinimum.getOrThrow("tieredWithMinimum") + + fun asGroupedTiered(): NewPlanGroupedTieredPrice = + groupedTiered.getOrThrow("groupedTiered") + + fun asTieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice = + tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + + fun asPackageWithAllocation(): NewPlanPackageWithAllocationPrice = + packageWithAllocation.getOrThrow("packageWithAllocation") + + fun asUnitWithPercent(): NewPlanUnitWithPercentPrice = + unitWithPercent.getOrThrow("unitWithPercent") + + fun asMatrixWithAllocation(): NewPlanMatrixWithAllocationPrice = + matrixWithAllocation.getOrThrow("matrixWithAllocation") + + fun asTieredWithProration(): TieredWithProration = + tieredWithProration.getOrThrow("tieredWithProration") + + fun asUnitWithProration(): NewPlanUnitWithProrationPrice = + unitWithProration.getOrThrow("unitWithProration") + + fun asGroupedAllocation(): NewPlanGroupedAllocationPrice = + groupedAllocation.getOrThrow("groupedAllocation") + + fun asBulkWithProration(): NewPlanBulkWithProrationPrice = + bulkWithProration.getOrThrow("bulkWithProration") + + fun asGroupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice = + groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") + + fun asGroupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice = + groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") + + fun asMatrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice = + matrixWithDisplayName.getOrThrow("matrixWithDisplayName") + + fun asGroupedTieredPackage(): NewPlanGroupedTieredPackagePrice = + groupedTieredPackage.getOrThrow("groupedTieredPackage") + + fun asMaxGroupTieredPackage(): NewPlanMaxGroupTieredPackagePrice = + maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") + + fun asScalableMatrixWithUnitPricing(): NewPlanScalableMatrixWithUnitPricingPrice = + scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") + + fun asScalableMatrixWithTieredPricing(): NewPlanScalableMatrixWithTieredPricingPrice = + scalableMatrixWithTieredPricing.getOrThrow("scalableMatrixWithTieredPricing") + + fun asCumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice = + cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") + + fun asMinimum(): NewPlanMinimumCompositePrice = minimum.getOrThrow("minimum") + + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + unit != null -> visitor.visitUnit(unit) + tiered != null -> visitor.visitTiered(tiered) + bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) + thresholdTotalAmount != null -> + visitor.visitThresholdTotalAmount(thresholdTotalAmount) + tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) + tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + tieredPackageWithMinimum != null -> + visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) + packageWithAllocation != null -> + visitor.visitPackageWithAllocation(packageWithAllocation) + unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + matrixWithAllocation != null -> + visitor.visitMatrixWithAllocation(matrixWithAllocation) + tieredWithProration != null -> + visitor.visitTieredWithProration(tieredWithProration) + unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) + groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) + groupedWithProratedMinimum != null -> + visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) + groupedWithMeteredMinimum != null -> + visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) + matrixWithDisplayName != null -> + visitor.visitMatrixWithDisplayName(matrixWithDisplayName) + groupedTieredPackage != null -> + visitor.visitGroupedTieredPackage(groupedTieredPackage) + maxGroupTieredPackage != null -> + visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) + scalableMatrixWithUnitPricing != null -> + visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) + scalableMatrixWithTieredPricing != null -> + visitor.visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing + ) + cumulativeGroupedBulk != null -> + visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Price = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitUnit(unit: NewPlanUnitPrice) { + unit.validate() + } + + override fun visitTiered(tiered: NewPlanTieredPrice) { + tiered.validate() + } + + override fun visitBulk(bulk: NewPlanBulkPrice) { + bulk.validate() + } + + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() + } + + override fun visitPackage(package_: NewPlanPackagePrice) { + package_.validate() + } + + override fun visitMatrix(matrix: NewPlanMatrixPrice) { + matrix.validate() + } + + override fun visitThresholdTotalAmount( + thresholdTotalAmount: NewPlanThresholdTotalAmountPrice + ) { + thresholdTotalAmount.validate() + } + + override fun visitTieredPackage(tieredPackage: NewPlanTieredPackagePrice) { + tieredPackage.validate() + } + + override fun visitTieredWithMinimum( + tieredWithMinimum: NewPlanTieredWithMinimumPrice + ) { + tieredWithMinimum.validate() + } + + override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) { + groupedTiered.validate() + } + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ) { + tieredPackageWithMinimum.validate() + } + + override fun visitPackageWithAllocation( + packageWithAllocation: NewPlanPackageWithAllocationPrice + ) { + packageWithAllocation.validate() + } + + override fun visitUnitWithPercent( + unitWithPercent: NewPlanUnitWithPercentPrice + ) { + unitWithPercent.validate() + } + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ) { + matrixWithAllocation.validate() + } + + override fun visitTieredWithProration( + tieredWithProration: TieredWithProration + ) { + tieredWithProration.validate() + } + + override fun visitUnitWithProration( + unitWithProration: NewPlanUnitWithProrationPrice + ) { + unitWithProration.validate() + } + + override fun visitGroupedAllocation( + groupedAllocation: NewPlanGroupedAllocationPrice + ) { + groupedAllocation.validate() + } + + override fun visitBulkWithProration( + bulkWithProration: NewPlanBulkWithProrationPrice + ) { + bulkWithProration.validate() + } + + override fun visitGroupedWithProratedMinimum( + groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice + ) { + groupedWithProratedMinimum.validate() + } + + override fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice + ) { + groupedWithMeteredMinimum.validate() + } + + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) { + groupedWithMinMaxThresholds.validate() + } + + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice + ) { + matrixWithDisplayName.validate() + } + + override fun visitGroupedTieredPackage( + groupedTieredPackage: NewPlanGroupedTieredPackagePrice + ) { + groupedTieredPackage.validate() + } + + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice + ) { + maxGroupTieredPackage.validate() + } + + override fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice + ) { + scalableMatrixWithUnitPricing.validate() + } + + override fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewPlanScalableMatrixWithTieredPricingPrice + ) { + scalableMatrixWithTieredPricing.validate() + } + + override fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice + ) { + cumulativeGroupedBulk.validate() + } + + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) { + cumulativeGroupedAllocation.validate() + } + + override fun visitMinimum(minimum: NewPlanMinimumCompositePrice) { + minimum.validate() + } + + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitUnit(unit: NewPlanUnitPrice) = unit.validity() + + override fun visitTiered(tiered: NewPlanTieredPrice) = tiered.validity() + + override fun visitBulk(bulk: NewPlanBulkPrice) = bulk.validity() + + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() + + override fun visitPackage(package_: NewPlanPackagePrice) = + package_.validity() + + override fun visitMatrix(matrix: NewPlanMatrixPrice) = matrix.validity() + + override fun visitThresholdTotalAmount( + thresholdTotalAmount: NewPlanThresholdTotalAmountPrice + ) = thresholdTotalAmount.validity() + + override fun visitTieredPackage(tieredPackage: NewPlanTieredPackagePrice) = + tieredPackage.validity() + + override fun visitTieredWithMinimum( + tieredWithMinimum: NewPlanTieredWithMinimumPrice + ) = tieredWithMinimum.validity() + + override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = + groupedTiered.validity() + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ) = tieredPackageWithMinimum.validity() + + override fun visitPackageWithAllocation( + packageWithAllocation: NewPlanPackageWithAllocationPrice + ) = packageWithAllocation.validity() + + override fun visitUnitWithPercent( + unitWithPercent: NewPlanUnitWithPercentPrice + ) = unitWithPercent.validity() + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ) = matrixWithAllocation.validity() + + override fun visitTieredWithProration( + tieredWithProration: TieredWithProration + ) = tieredWithProration.validity() + + override fun visitUnitWithProration( + unitWithProration: NewPlanUnitWithProrationPrice + ) = unitWithProration.validity() + + override fun visitGroupedAllocation( + groupedAllocation: NewPlanGroupedAllocationPrice + ) = groupedAllocation.validity() + + override fun visitBulkWithProration( + bulkWithProration: NewPlanBulkWithProrationPrice + ) = bulkWithProration.validity() + + override fun visitGroupedWithProratedMinimum( + groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice + ) = groupedWithProratedMinimum.validity() + + override fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice + ) = groupedWithMeteredMinimum.validity() + + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice + ) = matrixWithDisplayName.validity() + + override fun visitGroupedTieredPackage( + groupedTieredPackage: NewPlanGroupedTieredPackagePrice + ) = groupedTieredPackage.validity() + + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice + ) = maxGroupTieredPackage.validity() + + override fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice + ) = scalableMatrixWithUnitPricing.validity() + + override fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewPlanScalableMatrixWithTieredPricingPrice + ) = scalableMatrixWithTieredPricing.validity() + + override fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice + ) = cumulativeGroupedBulk.validity() + + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() + + override fun visitMinimum(minimum: NewPlanMinimumCompositePrice) = + minimum.validity() + + override fun visitPercent(percent: Percent) = percent.validity() + + override fun visitEventOutput(eventOutput: EventOutput) = + eventOutput.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Price && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput + } + + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) + + override fun toString(): String = + when { + unit != null -> "Price{unit=$unit}" + tiered != null -> "Price{tiered=$tiered}" + bulk != null -> "Price{bulk=$bulk}" + bulkWithFilters != null -> "Price{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "Price{package_=$package_}" + matrix != null -> "Price{matrix=$matrix}" + thresholdTotalAmount != null -> + "Price{thresholdTotalAmount=$thresholdTotalAmount}" + tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" + tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" + groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" + tieredPackageWithMinimum != null -> + "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" + packageWithAllocation != null -> + "Price{packageWithAllocation=$packageWithAllocation}" + unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + matrixWithAllocation != null -> + "Price{matrixWithAllocation=$matrixWithAllocation}" + tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" + unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" + groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" + groupedWithProratedMinimum != null -> + "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" + groupedWithMeteredMinimum != null -> + "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "Price{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" + matrixWithDisplayName != null -> + "Price{matrixWithDisplayName=$matrixWithDisplayName}" + groupedTieredPackage != null -> + "Price{groupedTieredPackage=$groupedTieredPackage}" + maxGroupTieredPackage != null -> + "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" + scalableMatrixWithUnitPricing != null -> + "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" + scalableMatrixWithTieredPricing != null -> + "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" + cumulativeGroupedBulk != null -> + "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" + cumulativeGroupedAllocation != null -> + "Price{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "Price{minimum=$minimum}" + percent != null -> "Price{percent=$percent}" + eventOutput != null -> "Price{eventOutput=$eventOutput}" + _json != null -> "Price{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Price") + } + + companion object { + + fun ofUnit(unit: NewPlanUnitPrice) = Price(unit = unit) + + fun ofTiered(tiered: NewPlanTieredPrice) = Price(tiered = tiered) + + fun ofBulk(bulk: NewPlanBulkPrice) = Price(bulk = bulk) + + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + Price(bulkWithFilters = bulkWithFilters) + + fun ofPackage(package_: NewPlanPackagePrice) = Price(package_ = package_) + + fun ofMatrix(matrix: NewPlanMatrixPrice) = Price(matrix = matrix) + + fun ofThresholdTotalAmount(thresholdTotalAmount: NewPlanThresholdTotalAmountPrice) = + Price(thresholdTotalAmount = thresholdTotalAmount) + + fun ofTieredPackage(tieredPackage: NewPlanTieredPackagePrice) = + Price(tieredPackage = tieredPackage) + + fun ofTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = + Price(tieredWithMinimum = tieredWithMinimum) + + fun ofGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = + Price(groupedTiered = groupedTiered) + + fun ofTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + + fun ofPackageWithAllocation( + packageWithAllocation: NewPlanPackageWithAllocationPrice + ) = Price(packageWithAllocation = packageWithAllocation) + + fun ofUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice) = + Price(unitWithPercent = unitWithPercent) + + fun ofMatrixWithAllocation(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = + Price(matrixWithAllocation = matrixWithAllocation) + + fun ofTieredWithProration(tieredWithProration: TieredWithProration) = + Price(tieredWithProration = tieredWithProration) + + fun ofUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice) = + Price(unitWithProration = unitWithProration) + + fun ofGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice) = + Price(groupedAllocation = groupedAllocation) + + fun ofBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice) = + Price(bulkWithProration = bulkWithProration) + + fun ofGroupedWithProratedMinimum( + groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice + ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) + + fun ofGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice + ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = Price(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + + fun ofMatrixWithDisplayName( + matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice + ) = Price(matrixWithDisplayName = matrixWithDisplayName) + + fun ofGroupedTieredPackage(groupedTieredPackage: NewPlanGroupedTieredPackagePrice) = + Price(groupedTieredPackage = groupedTieredPackage) + + fun ofMaxGroupTieredPackage( + maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice + ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) + + fun ofScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice + ) = Price(scalableMatrixWithUnitPricing = scalableMatrixWithUnitPricing) + + fun ofScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: NewPlanScalableMatrixWithTieredPricingPrice + ) = Price(scalableMatrixWithTieredPricing = scalableMatrixWithTieredPricing) + + fun ofCumulativeGroupedBulk( + cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice + ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) + + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = Price(cumulativeGroupedAllocation = cumulativeGroupedAllocation) + + fun ofMinimum(minimum: NewPlanMinimumCompositePrice) = Price(minimum = minimum) + + fun ofPercent(percent: Percent) = Price(percent = percent) + + fun ofEventOutput(eventOutput: EventOutput) = Price(eventOutput = eventOutput) + } + + /** + * An interface that defines how to map each variant of [Price] to a value of type [T]. + */ + interface Visitor { + + fun visitUnit(unit: NewPlanUnitPrice): T + + fun visitTiered(tiered: NewPlanTieredPrice): T + + fun visitBulk(bulk: NewPlanBulkPrice): T + + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T + + fun visitPackage(package_: NewPlanPackagePrice): T + + fun visitMatrix(matrix: NewPlanMatrixPrice): T + + fun visitThresholdTotalAmount( + thresholdTotalAmount: NewPlanThresholdTotalAmountPrice + ): T + + fun visitTieredPackage(tieredPackage: NewPlanTieredPackagePrice): T + + fun visitTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice): T + + fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice): T + + fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ): T + + fun visitPackageWithAllocation( + packageWithAllocation: NewPlanPackageWithAllocationPrice + ): T + + fun visitUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice): T + + fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ): T + + fun visitTieredWithProration(tieredWithProration: TieredWithProration): T + + fun visitUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice): T + + fun visitGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice): T + + fun visitBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice): T + + fun visitGroupedWithProratedMinimum( + groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice + ): T + + fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice + ): T + + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ): T + + fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice + ): T + + fun visitGroupedTieredPackage( + groupedTieredPackage: NewPlanGroupedTieredPackagePrice + ): T + + fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice + ): T + + fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice + ): T + + fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: NewPlanScalableMatrixWithTieredPricingPrice + ): T + + fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice + ): T + + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ): T + + fun visitMinimum(minimum: NewPlanMinimumCompositePrice): T + + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T + + /** + * Maps an unknown variant of [Price] to a value of type [T]. + * + * An instance of [Price] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown Price: $json") + } + } + + internal class Deserializer : BaseDeserializer(Price::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Price { + val json = JsonValue.fromJsonNode(node) + val modelType = json.asObject()?.get("model_type")?.asString() + + when (modelType) { + "unit" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(unit = it, _json = json) + } ?: Price(_json = json) + } + "tiered" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(tiered = it, _json = json) + } ?: Price(_json = json) + } + "bulk" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulk = it, _json = json) + } ?: Price(_json = json) + } + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulkWithFilters = it, _json = json) + } ?: Price(_json = json) + } + "package" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) + } + "matrix" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(matrix = it, _json = json) + } ?: Price(_json = json) + } + "threshold_total_amount" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(thresholdTotalAmount = it, _json = json) } + ?: Price(_json = json) + } + "tiered_package" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(tieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "tiered_with_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tieredWithMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_tiered" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(groupedTiered = it, _json = json) } + ?: Price(_json = json) + } + "tiered_package_with_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tieredPackageWithMinimum = it, _json = json) } + ?: Price(_json = json) + } + "package_with_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(packageWithAllocation = it, _json = json) } + ?: Price(_json = json) + } + "unit_with_percent" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(unitWithPercent = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(matrixWithAllocation = it, _json = json) } + ?: Price(_json = json) + } + "tiered_with_proration" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(tieredWithProration = it, _json = json) } + ?: Price(_json = json) + } + "unit_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(unitWithProration = it, _json = json) } + ?: Price(_json = json) + } + "grouped_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedAllocation = it, _json = json) } + ?: Price(_json = json) + } + "bulk_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(bulkWithProration = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_prorated_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithProratedMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_metered_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_min_max_thresholds" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithMinMaxThresholds = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_display_name" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(matrixWithDisplayName = it, _json = json) } + ?: Price(_json = json) + } + "grouped_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedTieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "max_group_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(maxGroupTieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "scalable_matrix_with_unit_pricing" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(scalableMatrixWithUnitPricing = it, _json = json) } + ?: Price(_json = json) + } + "scalable_matrix_with_tiered_pricing" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(scalableMatrixWithTieredPricing = it, _json = json) } + ?: Price(_json = json) + } + "cumulative_grouped_bulk" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(cumulativeGroupedBulk = it, _json = json) } + ?: Price(_json = json) + } + "cumulative_grouped_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(cumulativeGroupedAllocation = it, _json = json) } + ?: Price(_json = json) + } + "minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(minimum = it, _json = json) } ?: Price(_json = json) + } + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(percent = it, _json = json) + } ?: Price(_json = json) + } + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(eventOutput = it, _json = json) + } ?: Price(_json = json) + } + } + + return Price(_json = json) + } + } + + internal class Serializer : BaseSerializer(Price::class) { + + override fun serialize( + value: Price, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.unit != null -> generator.writeObject(value.unit) + value.tiered != null -> generator.writeObject(value.tiered) + value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> + generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) + value.thresholdTotalAmount != null -> + generator.writeObject(value.thresholdTotalAmount) + value.tieredPackage != null -> generator.writeObject(value.tieredPackage) + value.tieredWithMinimum != null -> + generator.writeObject(value.tieredWithMinimum) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) + value.tieredPackageWithMinimum != null -> + generator.writeObject(value.tieredPackageWithMinimum) + value.packageWithAllocation != null -> + generator.writeObject(value.packageWithAllocation) + value.unitWithPercent != null -> + generator.writeObject(value.unitWithPercent) + value.matrixWithAllocation != null -> + generator.writeObject(value.matrixWithAllocation) + value.tieredWithProration != null -> + generator.writeObject(value.tieredWithProration) + value.unitWithProration != null -> + generator.writeObject(value.unitWithProration) + value.groupedAllocation != null -> + generator.writeObject(value.groupedAllocation) + value.bulkWithProration != null -> + generator.writeObject(value.bulkWithProration) + value.groupedWithProratedMinimum != null -> + generator.writeObject(value.groupedWithProratedMinimum) + value.groupedWithMeteredMinimum != null -> + generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) + value.matrixWithDisplayName != null -> + generator.writeObject(value.matrixWithDisplayName) + value.groupedTieredPackage != null -> + generator.writeObject(value.groupedTieredPackage) + value.maxGroupTieredPackage != null -> + generator.writeObject(value.maxGroupTieredPackage) + value.scalableMatrixWithUnitPricing != null -> + generator.writeObject(value.scalableMatrixWithUnitPricing) + value.scalableMatrixWithTieredPricing != null -> + generator.writeObject(value.scalableMatrixWithTieredPricing) + value.cumulativeGroupedBulk != null -> + generator.writeObject(value.cumulativeGroupedBulk) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Price") + } + } + } + + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bulkWithFiltersConfig: JsonField, + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = + bulkWithFiltersConfig + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [BulkWithFilters]. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFilters]. */ + class Builder internal constructor() { + + private var bulkWithFiltersConfig: JsonField? = null + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + itemId = bulkWithFilters.itemId + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + billableMetricId = bulkWithFilters.billableMetricId + billedInAdvance = bulkWithFilters.billedInAdvance + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + currency = bulkWithFilters.currency + dimensionalPriceConfiguration = + bulkWithFilters.dimensionalPriceConfiguration + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoiceGroupingKey = bulkWithFilters.invoiceGroupingKey + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + metadata = bulkWithFilters.metadata + referenceId = bulkWithFilters.referenceId + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() + } + + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig( + bulkWithFiltersConfig: JsonField + ) = apply { this.bulkWithFiltersConfig = bulkWithFiltersConfig } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BulkWithFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFilters = + BulkWithFilters( + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFilters = apply { + if (validated) { + return@apply + } + + bulkWithFiltersConfig().validate() + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("bulk_with_filters")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) + + /** + * Property filters to apply (all must match) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [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 + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { + + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithFiltersConfig.additionalProperties.toMutableMap() + } + + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + + /** Bulk tiers for rating based on total usage volume */ + 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 [BulkWithFiltersConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } + + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = + propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + propertyKey() + propertyValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = + tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filters, tiers, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFilters && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFilters{bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class TieredWithProration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val tieredWithProrationConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + tieredWithProrationConfig: JsonField = + JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for tiered_with_proration pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tieredWithProrationConfig(): TieredWithProrationConfig = + tieredWithProrationConfig.getRequired("tiered_with_proration_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [tieredWithProrationConfig]. + * + * Unlike [tieredWithProrationConfig], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + fun _tieredWithProrationConfig(): JsonField = + tieredWithProrationConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [TieredWithProration]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProration]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("tiered_with_proration") + private var name: JsonField? = null + private var tieredWithProrationConfig: JsonField? = + null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tieredWithProration: TieredWithProration) = apply { + cadence = tieredWithProration.cadence + itemId = tieredWithProration.itemId + modelType = tieredWithProration.modelType + name = tieredWithProration.name + tieredWithProrationConfig = tieredWithProration.tieredWithProrationConfig + billableMetricId = tieredWithProration.billableMetricId + billedInAdvance = tieredWithProration.billedInAdvance + billingCycleConfiguration = tieredWithProration.billingCycleConfiguration + conversionRate = tieredWithProration.conversionRate + conversionRateConfig = tieredWithProration.conversionRateConfig + currency = tieredWithProration.currency + dimensionalPriceConfiguration = + tieredWithProration.dimensionalPriceConfiguration + externalPriceId = tieredWithProration.externalPriceId + fixedPriceQuantity = tieredWithProration.fixedPriceQuantity + invoiceGroupingKey = tieredWithProration.invoiceGroupingKey + invoicingCycleConfiguration = + tieredWithProration.invoicingCycleConfiguration + metadata = tieredWithProration.metadata + referenceId = tieredWithProration.referenceId + additionalProperties = + tieredWithProration.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for tiered_with_proration pricing */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: TieredWithProrationConfig + ) = tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) + + /** + * Sets [Builder.tieredWithProrationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.tieredWithProrationConfig] with a well-typed + * [TieredWithProrationConfig] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: JsonField + ) = apply { this.tieredWithProrationConfig = tieredWithProrationConfig } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TieredWithProration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProration = + TieredWithProration( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("tieredWithProrationConfig", tieredWithProrationConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProration = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("tiered_with_proration")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + tieredWithProrationConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("tiered_with_proration")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (tieredWithProrationConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for tiered_with_proration pricing */ + class TieredWithProrationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Tiers for rating based on total usage quantities into the specified tier with + * proration + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 + * [TieredWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProrationConfig]. */ + class Builder internal constructor() { + + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = + apply { + tiers = tieredWithProrationConfig.tiers.map { it.toMutableList() } + additionalProperties = + tieredWithProrationConfig.additionalProperties.toMutableMap() + } + + /** + * Tiers for rating based on total usage quantities into the specified tier + * with proration + */ + 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 [TieredWithProrationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProrationConfig = + TieredWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProrationConfig = apply { + if (validated) { + return@apply + } + + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tiered with proration tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Inclusive tier starting value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun tierLowerBound(): String = + tierLowerBound.getRequired("tier_lower_bound") + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Inclusive tier starting value */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProration && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredWithProrationConfig == other.tieredWithProrationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProration{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, tieredWithProrationConfig=$tieredWithProrationConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val groupedWithMinMaxThresholdsConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + groupedWithMinMaxThresholdsConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for grouped_with_min_max_thresholds pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired( + "grouped_with_min_max_thresholds_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - /** - * The phase to replace this adjustment from. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - /** - * Returns the raw JSON value of [adjustment]. - * - * Unlike [adjustment], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("adjustment") - @ExcludeMissing - fun _adjustment(): JsonField = adjustment + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - /** - * Returns the raw JSON value of [replacesAdjustmentId]. - * - * Unlike [replacesAdjustmentId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("replaces_adjustment_id") - @ExcludeMissing - fun _replacesAdjustmentId(): JsonField = replacesAdjustmentId + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - /** - * Returns the raw JSON value of [planPhaseOrder]. - * - * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("plan_phase_order") - @ExcludeMissing - fun _planPhaseOrder(): JsonField = planPhaseOrder + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - fun toBuilder() = Builder().from(this) + /** + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. + * + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + fun _groupedWithMinMaxThresholdsConfig(): + JsonField = groupedWithMinMaxThresholdsConfig - companion object { + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - /** - * Returns a mutable builder for constructing an instance of [ReplaceAdjustment]. - * - * The following fields are required: - * ```kotlin - * .adjustment() - * .replacesAdjustmentId() - * ``` - */ - fun builder() = Builder() - } + /** + * 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 - /** A builder for [ReplaceAdjustment]. */ - class Builder internal constructor() { + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - private var adjustment: JsonField? = null - private var replacesAdjustmentId: JsonField? = null - private var planPhaseOrder: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - internal fun from(replaceAdjustment: ReplaceAdjustment) = apply { - adjustment = replaceAdjustment.adjustment - replacesAdjustmentId = replaceAdjustment.replacesAdjustmentId - planPhaseOrder = replaceAdjustment.planPhaseOrder - additionalProperties = replaceAdjustment.additionalProperties.toMutableMap() - } + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - /** The definition of a new adjustment to create and add to the plan. */ - fun adjustment(adjustment: Adjustment) = adjustment(JsonField.of(adjustment)) + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - /** - * Sets [Builder.adjustment] to an arbitrary JSON value. - * - * You should usually call [Builder.adjustment] with a well-typed [Adjustment] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun adjustment(adjustment: JsonField) = apply { - this.adjustment = adjustment - } + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - /** - * Alias for calling [adjustment] with - * `Adjustment.ofPercentageDiscount(percentageDiscount)`. - */ - fun adjustment(percentageDiscount: NewPercentageDiscount) = - adjustment(Adjustment.ofPercentageDiscount(percentageDiscount)) + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewPercentageDiscount.builder() - * .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) - * .percentageDiscount(percentageDiscount) - * .build() - * ``` - */ - fun percentageDiscountAdjustment(percentageDiscount: Double) = - adjustment( - NewPercentageDiscount.builder() - .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) - .percentageDiscount(percentageDiscount) - .build() - ) + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - /** Alias for calling [adjustment] with `Adjustment.ofUsageDiscount(usageDiscount)`. */ - fun adjustment(usageDiscount: NewUsageDiscount) = - adjustment(Adjustment.ofUsageDiscount(usageDiscount)) + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewUsageDiscount.builder() - * .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) - * .usageDiscount(usageDiscount) - * .build() - * ``` - */ - fun usageDiscountAdjustment(usageDiscount: Double) = - adjustment( - NewUsageDiscount.builder() - .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) - .usageDiscount(usageDiscount) - .build() - ) + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - /** - * Alias for calling [adjustment] with `Adjustment.ofAmountDiscount(amountDiscount)`. - */ - fun adjustment(amountDiscount: NewAmountDiscount) = - adjustment(Adjustment.ofAmountDiscount(amountDiscount)) + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewAmountDiscount.builder() - * .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) - * .amountDiscount(amountDiscount) - * .build() - * ``` - */ - fun amountDiscountAdjustment(amountDiscount: String) = - adjustment( - NewAmountDiscount.builder() - .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) - .amountDiscount(amountDiscount) - .build() - ) + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - /** Alias for calling [adjustment] with `Adjustment.ofMinimum(minimum)`. */ - fun adjustment(minimum: NewMinimum) = adjustment(Adjustment.ofMinimum(minimum)) + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - /** Alias for calling [adjustment] with `Adjustment.ofMaximum(maximum)`. */ - fun adjustment(maximum: NewMaximum) = adjustment(Adjustment.ofMaximum(maximum)) + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewMaximum.builder() - * .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) - * .maximumAmount(maximumAmount) - * .build() - * ``` - */ - fun maximumAdjustment(maximumAmount: String) = - adjustment( - NewMaximum.builder() - .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) - .maximumAmount(maximumAmount) - .build() - ) + @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 + * [GroupedWithMinMaxThresholds]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholds]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("grouped_with_min_max_thresholds") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = + apply { + cadence = groupedWithMinMaxThresholds.cadence + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + itemId = groupedWithMinMaxThresholds.itemId + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + billableMetricId = groupedWithMinMaxThresholds.billableMetricId + billedInAdvance = groupedWithMinMaxThresholds.billedInAdvance + billingCycleConfiguration = + groupedWithMinMaxThresholds.billingCycleConfiguration + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + currency = groupedWithMinMaxThresholds.currency + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + invoiceGroupingKey = groupedWithMinMaxThresholds.invoiceGroupingKey + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + metadata = groupedWithMinMaxThresholds.metadata + referenceId = groupedWithMinMaxThresholds.referenceId + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = + groupedWithMinMaxThresholdsConfig( + JsonField.of(groupedWithMinMaxThresholdsConfig) + ) + + /** + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a + * well-typed [GroupedWithMinMaxThresholdsConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: + JsonField + ) = apply { + this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - /** The id of the adjustment on the plan to replace in the plan. */ - fun replacesAdjustmentId(replacesAdjustmentId: String) = - replacesAdjustmentId(JsonField.of(replacesAdjustmentId)) + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - /** - * Sets [Builder.replacesAdjustmentId] to an arbitrary JSON value. - * - * You should usually call [Builder.replacesAdjustmentId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun replacesAdjustmentId(replacesAdjustmentId: JsonField) = apply { - this.replacesAdjustmentId = replacesAdjustmentId - } + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - /** The phase to replace this adjustment from. */ - fun planPhaseOrder(planPhaseOrder: Long?) = - planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - /** - * Alias for [Builder.planPhaseOrder]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** - * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. - * - * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun planPhaseOrder(planPhaseOrder: JsonField) = apply { - this.planPhaseOrder = planPhaseOrder - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( + checkRequired("cadence", cadence), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + private var validated: Boolean = false - /** - * Returns an immutable instance of [ReplaceAdjustment]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .adjustment() - * .replacesAdjustmentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ReplaceAdjustment = - ReplaceAdjustment( - checkRequired("adjustment", adjustment), - checkRequired("replacesAdjustmentId", replacesAdjustmentId), - planPhaseOrder, - additionalProperties.toMutableMap(), - ) - } + fun validate(): GroupedWithMinMaxThresholds = apply { + if (validated) { + return@apply + } - private var validated: Boolean = false + cadence().validate() + groupedWithMinMaxThresholdsConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - fun validate(): ReplaceAdjustment = apply { - if (validated) { - return@apply - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - adjustment().validate() - replacesAdjustmentId() - planPhaseOrder() - validated = true - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (adjustment.asKnown()?.validity() ?: 0) + - (if (replacesAdjustmentId.asKnown() == null) 0 else 1) + - (if (planPhaseOrder.asKnown() == null) 0 else 1) + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - /** The definition of a new adjustment to create and add to the plan. */ - @JsonDeserialize(using = Adjustment.Deserializer::class) - @JsonSerialize(using = Adjustment.Serializer::class) - class Adjustment - private constructor( - private val percentageDiscount: NewPercentageDiscount? = null, - private val usageDiscount: NewUsageDiscount? = null, - private val amountDiscount: NewAmountDiscount? = null, - private val minimum: NewMinimum? = null, - private val maximum: NewMaximum? = null, - private val _json: JsonValue? = null, - ) { + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN + } - fun percentageDiscount(): NewPercentageDiscount? = percentageDiscount + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") + } - fun usageDiscount(): NewUsageDiscount? = usageDiscount + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } - fun amountDiscount(): NewAmountDiscount? = amountDiscount + known() + validated = true + } - fun minimum(): NewMinimum? = minimum + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun maximum(): NewMaximum? = maximum + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun isPercentageDiscount(): Boolean = percentageDiscount != null + return other is Cadence && value == other.value + } - fun isUsageDiscount(): Boolean = usageDiscount != null + override fun hashCode() = value.hashCode() - fun isAmountDiscount(): Boolean = amountDiscount != null + override fun toString() = value.toString() + } - fun isMinimum(): Boolean = minimum != null + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { - fun isMaximum(): Boolean = maximum != null + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun asPercentageDiscount(): NewPercentageDiscount = - percentageDiscount.getOrThrow("percentageDiscount") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + */ + fun builder() = Builder() + } - fun asUsageDiscount(): NewUsageDiscount = usageDiscount.getOrThrow("usageDiscount") + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate + additionalProperties = + groupedWithMinMaxThresholdsConfig.additionalProperties + .toMutableMap() + } - fun asAmountDiscount(): NewAmountDiscount = amountDiscount.getOrThrow("amountDiscount") + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } - fun asMinimum(): NewMinimum = minimum.getOrThrow("minimum") + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } - fun asMaximum(): NewMaximum = maximum.getOrThrow("maximum") + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } - fun _json(): JsonValue? = _json + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = + perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate + } - fun accept(visitor: Visitor): T = - when { - percentageDiscount != null -> - visitor.visitPercentageDiscount(percentageDiscount) - usageDiscount != null -> visitor.visitUsageDiscount(usageDiscount) - amountDiscount != null -> visitor.visitAmountDiscount(amountDiscount) - minimum != null -> visitor.visitMinimum(minimum) - maximum != null -> visitor.visitMaximum(maximum) - else -> visitor.unknown(_json) - } + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - private var validated: Boolean = false + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun validate(): Adjustment = apply { - if (validated) { - return@apply - } + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - accept( - object : Visitor { - override fun visitPercentageDiscount( - percentageDiscount: NewPercentageDiscount - ) { - percentageDiscount.validate() + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) { - usageDiscount.validate() + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) { - amountDiscount.validate() + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + if (validated) { + return@apply } - override fun visitMinimum(minimum: NewMinimum) { - minimum.validate() + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - override fun visitMaximum(maximum: NewMaximum) { - maximum.validate() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitPercentageDiscount( - percentageDiscount: NewPercentageDiscount - ) = percentageDiscount.validity() + override fun hashCode(): Int = hashCode - override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) = - usageDiscount.validity() + override fun toString() = + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" + } - override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) = - amountDiscount.validity() + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - override fun visitMinimum(minimum: NewMinimum) = minimum.validity() + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - override fun visitMaximum(maximum: NewMaximum) = maximum.validity() + fun toBuilder() = Builder().from(this) - override fun unknown(json: JsonValue?) = 0 + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + fun builder() = Builder() } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** A builder for [Metadata]. */ + class Builder internal constructor() { - return /* spotless:off */ other is Adjustment && percentageDiscount == other.percentageDiscount && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ - } + private var additionalProperties: MutableMap = + mutableMapOf() - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) /* spotless:on */ + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } - override fun toString(): String = - when { - percentageDiscount != null -> - "Adjustment{percentageDiscount=$percentageDiscount}" - usageDiscount != null -> "Adjustment{usageDiscount=$usageDiscount}" - amountDiscount != null -> "Adjustment{amountDiscount=$amountDiscount}" - minimum != null -> "Adjustment{minimum=$minimum}" - maximum != null -> "Adjustment{maximum=$maximum}" - _json != null -> "Adjustment{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Adjustment") - } + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - companion object { + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } - fun ofPercentageDiscount(percentageDiscount: NewPercentageDiscount) = - Adjustment(percentageDiscount = percentageDiscount) + private var validated: Boolean = false - fun ofUsageDiscount(usageDiscount: NewUsageDiscount) = - Adjustment(usageDiscount = usageDiscount) + fun validate(): Metadata = apply { + if (validated) { + return@apply + } - fun ofAmountDiscount(amountDiscount: NewAmountDiscount) = - Adjustment(amountDiscount = amountDiscount) + validated = true + } - fun ofMinimum(minimum: NewMinimum) = Adjustment(minimum = minimum) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofMaximum(maximum: NewMaximum) = Adjustment(maximum = maximum) - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } - /** - * An interface that defines how to map each variant of [Adjustment] to a value of type - * [T]. - */ - interface Visitor { + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun visitPercentageDiscount(percentageDiscount: NewPercentageDiscount): T + return other is Metadata && + additionalProperties == other.additionalProperties + } - fun visitUsageDiscount(usageDiscount: NewUsageDiscount): T + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - fun visitAmountDiscount(amountDiscount: NewAmountDiscount): T + override fun hashCode(): Int = hashCode - fun visitMinimum(minimum: NewMinimum): T + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } - fun visitMaximum(maximum: NewMaximum): T + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholds && + cadence == other.cadence && + groupedWithMinMaxThresholdsConfig == + other.groupedWithMinMaxThresholdsConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholds{cadence=$cadence, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val cumulativeGroupedAllocationConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) /** - * Maps an unknown variant of [Adjustment] to a value of type [T]. + * The cadence to bill for this price on. * - * An instance of [Adjustment] can contain an unknown variant if it was deserialized - * from data that doesn't match any known variant. For example, if the SDK is on an - * older version than the API, then the API may respond with new variants that the - * SDK is unaware of. + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for cumulative_grouped_allocation pricing * - * @throws OrbInvalidDataException in the default implementation. + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown Adjustment: $json") - } - } + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired( + "cumulative_grouped_allocation_config" + ) - internal class Deserializer : BaseDeserializer(Adjustment::class) { + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - override fun ObjectCodec.deserialize(node: JsonNode): Adjustment { - val json = JsonValue.fromJsonNode(node) - val adjustmentType = json.asObject()?.get("adjustment_type")?.asString() + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - when (adjustmentType) { - "percentage_discount" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Adjustment(percentageDiscount = it, _json = json) } - ?: Adjustment(_json = json) - } - "usage_discount" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(usageDiscount = it, _json = json) - } ?: Adjustment(_json = json) - } - "amount_discount" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(amountDiscount = it, _json = json) - } ?: Adjustment(_json = json) - } - "minimum" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(minimum = it, _json = json) - } ?: Adjustment(_json = json) - } - "maximum" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(maximum = it, _json = json) - } ?: Adjustment(_json = json) - } - } + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - return Adjustment(_json = json) - } - } + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - internal class Serializer : BaseSerializer(Adjustment::class) { + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - override fun serialize( - value: Adjustment, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.percentageDiscount != null -> - generator.writeObject(value.percentageDiscount) - value.usageDiscount != null -> generator.writeObject(value.usageDiscount) - value.amountDiscount != null -> generator.writeObject(value.amountDiscount) - value.minimum != null -> generator.writeObject(value.minimum) - value.maximum != null -> generator.writeObject(value.maximum) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Adjustment") - } - } - } - } + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - return /* spotless:off */ other is ReplaceAdjustment && adjustment == other.adjustment && replacesAdjustmentId == other.replacesAdjustmentId && planPhaseOrder == other.planPhaseOrder && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustment, replacesAdjustmentId, planPhaseOrder, additionalProperties) } - /* spotless:on */ + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - override fun hashCode(): Int = hashCode + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - override fun toString() = - "ReplaceAdjustment{adjustment=$adjustment, replacesAdjustmentId=$replacesAdjustmentId, planPhaseOrder=$planPhaseOrder, additionalProperties=$additionalProperties}" - } + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - class ReplacePrice - private constructor( - private val replacesPriceId: JsonField, - private val allocationPrice: JsonField, - private val planPhaseOrder: JsonField, - private val price: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - @JsonCreator - private constructor( - @JsonProperty("replaces_price_id") - @ExcludeMissing - replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("allocation_price") - @ExcludeMissing - allocationPrice: JsonField = JsonMissing.of(), - @JsonProperty("plan_phase_order") - @ExcludeMissing - planPhaseOrder: JsonField = JsonMissing.of(), - @JsonProperty("price") @ExcludeMissing price: JsonField = JsonMissing.of(), - ) : this(replacesPriceId, allocationPrice, planPhaseOrder, price, mutableMapOf()) + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - /** - * The id of the price on the plan to replace in the plan. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun replacesPriceId(): String = replacesPriceId.getRequired("replaces_price_id") + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - /** - * The allocation price to add to the plan. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun allocationPrice(): NewAllocationPrice? = allocationPrice.getNullable("allocation_price") + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - /** - * The phase to replace this price from. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - /** - * The price to add to the plan - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun price(): Price? = price.getNullable("price") + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - /** - * Returns the raw JSON value of [replacesPriceId]. - * - * Unlike [replacesPriceId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("replaces_price_id") - @ExcludeMissing - fun _replacesPriceId(): JsonField = replacesPriceId + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): + JsonField = cumulativeGroupedAllocationConfig - /** - * Returns the raw JSON value of [allocationPrice]. - * - * Unlike [allocationPrice], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("allocation_price") - @ExcludeMissing - fun _allocationPrice(): JsonField = allocationPrice + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - /** - * Returns the raw JSON value of [planPhaseOrder]. - * - * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("plan_phase_order") - @ExcludeMissing - fun _planPhaseOrder(): JsonField = planPhaseOrder + /** + * 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 [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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - fun toBuilder() = Builder().from(this) + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - companion object { + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - /** - * Returns a mutable builder for constructing an instance of [ReplacePrice]. - * - * The following fields are required: - * ```kotlin - * .replacesPriceId() - * ``` - */ - fun builder() = Builder() - } + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - /** A builder for [ReplacePrice]. */ - class Builder internal constructor() { + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - private var replacesPriceId: JsonField? = null - private var allocationPrice: JsonField = JsonMissing.of() - private var planPhaseOrder: JsonField = JsonMissing.of() - private var price: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - internal fun from(replacePrice: ReplacePrice) = apply { - replacesPriceId = replacePrice.replacesPriceId - allocationPrice = replacePrice.allocationPrice - planPhaseOrder = replacePrice.planPhaseOrder - price = replacePrice.price - additionalProperties = replacePrice.additionalProperties.toMutableMap() - } + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - /** The id of the price on the plan to replace in the plan. */ - fun replacesPriceId(replacesPriceId: String) = - replacesPriceId(JsonField.of(replacesPriceId)) + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - /** - * Sets [Builder.replacesPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.replacesPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun replacesPriceId(replacesPriceId: JsonField) = apply { - this.replacesPriceId = replacesPriceId - } + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - /** The allocation price to add to the plan. */ - fun allocationPrice(allocationPrice: NewAllocationPrice?) = - allocationPrice(JsonField.ofNullable(allocationPrice)) + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - /** - * Sets [Builder.allocationPrice] to an arbitrary JSON value. - * - * You should usually call [Builder.allocationPrice] with a well-typed - * [NewAllocationPrice] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun allocationPrice(allocationPrice: JsonField) = apply { - this.allocationPrice = allocationPrice - } + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - /** The phase to replace this price from. */ - fun planPhaseOrder(planPhaseOrder: Long?) = - planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** - * Alias for [Builder.planPhaseOrder]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CumulativeGroupedAllocation]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } - /** - * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. - * - * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun planPhaseOrder(planPhaseOrder: JsonField) = apply { - this.planPhaseOrder = planPhaseOrder - } + /** A builder for [CumulativeGroupedAllocation]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("cumulative_grouped_allocation") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = + apply { + cadence = cumulativeGroupedAllocation.cadence + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + itemId = cumulativeGroupedAllocation.itemId + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + billableMetricId = cumulativeGroupedAllocation.billableMetricId + billedInAdvance = cumulativeGroupedAllocation.billedInAdvance + billingCycleConfiguration = + cumulativeGroupedAllocation.billingCycleConfiguration + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + currency = cumulativeGroupedAllocation.currency + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoiceGroupingKey = cumulativeGroupedAllocation.invoiceGroupingKey + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + metadata = cumulativeGroupedAllocation.metadata + referenceId = cumulativeGroupedAllocation.referenceId + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } - /** The price to add to the plan */ - fun price(price: Price?) = price(JsonField.ofNullable(price)) + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = + cumulativeGroupedAllocationConfig( + JsonField.of(cumulativeGroupedAllocationConfig) + ) - /** - * Sets [Builder.price] to an arbitrary JSON value. - * - * You should usually call [Builder.price] with a well-typed [Price] 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 } + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a + * well-typed [CumulativeGroupedAllocationConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: + JsonField + ) = apply { + this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig + } - /** Alias for calling [price] with `Price.ofUnit(unit)`. */ - fun price(unit: NewPlanUnitPrice) = price(Price.ofUnit(unit)) + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: NewPlanPackagePrice) = price(Price.ofPackage(package_)) + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: NewPlanMatrixPrice) = price(Price.ofMatrix(matrix)) + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ - fun price(tiered: NewPlanTieredPrice) = price(Price.ofTiered(tiered)) + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: NewPlanTieredBpsPrice) = price(Price.ofTieredBps(tieredBps)) + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: NewPlanBpsPrice) = price(Price.ofBps(bps)) + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: NewPlanBulkBpsPrice) = price(Price.ofBulkBps(bulkBps)) + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: NewPlanBulkPrice) = price(Price.ofBulk(bulk)) + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - /** - * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. - */ - fun price(thresholdTotalAmount: NewPlanThresholdTotalAmountPrice) = - price(Price.ofThresholdTotalAmount(thresholdTotalAmount)) + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - /** Alias for calling [price] with `Price.ofTieredPackage(tieredPackage)`. */ - fun price(tieredPackage: NewPlanTieredPackagePrice) = - price(Price.ofTieredPackage(tieredPackage)) + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ - fun price(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = - price(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ - fun price(unitWithPercent: NewPlanUnitWithPercentPrice) = - price(Price.ofUnitWithPercent(unitWithPercent)) + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** - * Alias for calling [price] with - * `Price.ofPackageWithAllocation(packageWithAllocation)`. - */ - fun price(packageWithAllocation: NewPlanPackageWithAllocationPrice) = - price(Price.ofPackageWithAllocation(packageWithAllocation)) + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** - * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. - */ - fun price(tieredWithProration: NewPlanTierWithProrationPrice) = - price(Price.ofTieredWithProration(tieredWithProration)) + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** Alias for calling [price] with `Price.ofUnitWithProration(unitWithProration)`. */ - fun price(unitWithProration: NewPlanUnitWithProrationPrice) = - price(Price.ofUnitWithProration(unitWithProration)) + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - /** Alias for calling [price] with `Price.ofGroupedAllocation(groupedAllocation)`. */ - fun price(groupedAllocation: NewPlanGroupedAllocationPrice) = - price(Price.ofGroupedAllocation(groupedAllocation)) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** - * Alias for calling [price] with - * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. - */ - fun price(groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice) = - price(Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)) + /** + * Returns an immutable instance of [CumulativeGroupedAllocation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( + checkRequired("cadence", cadence), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - /** - * Alias for calling [price] with - * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. - */ - fun price(groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice) = - price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + private var validated: Boolean = false - /** - * Alias for calling [price] with - * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. - */ - fun price(matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice) = - price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) + fun validate(): CumulativeGroupedAllocation = apply { + if (validated) { + return@apply + } - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: NewPlanBulkWithProrationPrice) = - price(Price.ofBulkWithProration(bulkWithProration)) + cadence().validate() + cumulativeGroupedAllocationConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("cumulative_grouped_allocation")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - /** - * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. - */ - fun price(groupedTieredPackage: NewPlanGroupedTieredPackagePrice) = - price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** - * Alias for calling [price] with - * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. - */ - fun price(maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice) = - price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - /** - * Alias for calling [price] with - * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. - */ - fun price(scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice) = - price(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - /** - * Alias for calling [price] with - * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. - */ - fun price( - scalableMatrixWithTieredPricing: NewPlanScalableMatrixWithTieredPricingPrice - ) = price(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - /** - * Alias for calling [price] with - * `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. - */ - fun price(cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice) = - price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") + } - /** - * Alias for calling [price] with - * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. - */ - fun price(tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice) = - price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } - /** - * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. - */ - fun price(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = - price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + known() + validated = true + } - /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: NewPlanGroupedTieredPrice) = - price(Price.ofGroupedTiered(groupedTiered)) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + 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 Cadence && 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) - } + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * Returns an immutable instance of [ReplacePrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .replacesPriceId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ReplacePrice = - ReplacePrice( - checkRequired("replacesPriceId", replacesPriceId), - allocationPrice, - planPhaseOrder, - price, - additionalProperties.toMutableMap(), - ) - } + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + mutableMapOf(), + ) + + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CumulativeGroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - fun validate(): ReplacePrice = apply { - if (validated) { - return@apply - } + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = + cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties + .toMutableMap() + } - replacesPriceId() - allocationPrice()?.validate() - planPhaseOrder() - price()?.validate() - validated = true - } + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (replacesPriceId.asKnown() == null) 0 else 1) + - (allocationPrice.asKnown()?.validity() ?: 0) + - (if (planPhaseOrder.asKnown() == null) 0 else 1) + - (price.asKnown()?.validity() ?: 0) + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } - /** The price to add to the plan */ - @JsonDeserialize(using = Price.Deserializer::class) - @JsonSerialize(using = Price.Serializer::class) - class Price - private constructor( - private val unit: NewPlanUnitPrice? = null, - private val package_: NewPlanPackagePrice? = null, - private val matrix: NewPlanMatrixPrice? = null, - private val tiered: NewPlanTieredPrice? = null, - private val tieredBps: NewPlanTieredBpsPrice? = null, - private val bps: NewPlanBpsPrice? = null, - private val bulkBps: NewPlanBulkBpsPrice? = null, - private val bulk: NewPlanBulkPrice? = null, - private val thresholdTotalAmount: NewPlanThresholdTotalAmountPrice? = null, - private val tieredPackage: NewPlanTieredPackagePrice? = null, - private val tieredWithMinimum: NewPlanTieredWithMinimumPrice? = null, - private val unitWithPercent: NewPlanUnitWithPercentPrice? = null, - private val packageWithAllocation: NewPlanPackageWithAllocationPrice? = null, - private val tieredWithProration: NewPlanTierWithProrationPrice? = null, - private val unitWithProration: NewPlanUnitWithProrationPrice? = null, - private val groupedAllocation: NewPlanGroupedAllocationPrice? = null, - private val groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice? = null, - private val groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice? = null, - private val matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice? = null, - private val bulkWithProration: NewPlanBulkWithProrationPrice? = null, - private val groupedTieredPackage: NewPlanGroupedTieredPackagePrice? = null, - private val maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice? = null, - private val scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice? = - null, - private val scalableMatrixWithTieredPricing: - NewPlanScalableMatrixWithTieredPricingPrice? = - null, - private val cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice? = null, - private val tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice? = null, - private val matrixWithAllocation: NewPlanMatrixWithAllocationPrice? = null, - private val groupedTiered: NewPlanGroupedTieredPrice? = null, - private val _json: JsonValue? = null, - ) { + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } - fun unit(): NewPlanUnitPrice? = unit + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun package_(): NewPlanPackagePrice? = package_ + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun matrix(): NewPlanMatrixPrice? = matrix + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - fun tiered(): NewPlanTieredPrice? = tiered + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun tieredBps(): NewPlanTieredBpsPrice? = tieredBps + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun bps(): NewPlanBpsPrice? = bps + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } - fun bulkBps(): NewPlanBulkBpsPrice? = bulkBps + private var validated: Boolean = false - fun bulk(): NewPlanBulkPrice? = bulk + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply + } - fun thresholdTotalAmount(): NewPlanThresholdTotalAmountPrice? = thresholdTotalAmount + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true + } - fun tieredPackage(): NewPlanTieredPackagePrice? = tieredPackage + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun tieredWithMinimum(): NewPlanTieredWithMinimumPrice? = tieredWithMinimum + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun unitWithPercent(): NewPlanUnitWithPercentPrice? = unitWithPercent + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } - fun packageWithAllocation(): NewPlanPackageWithAllocationPrice? = packageWithAllocation + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) + } - fun tieredWithProration(): NewPlanTierWithProrationPrice? = tieredWithProration + override fun hashCode(): Int = hashCode - fun unitWithProration(): NewPlanUnitWithProrationPrice? = unitWithProration + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } - fun groupedAllocation(): NewPlanGroupedAllocationPrice? = groupedAllocation + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - fun groupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice? = - groupedWithProratedMinimum + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - fun groupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice? = - groupedWithMeteredMinimum + fun toBuilder() = Builder().from(this) - fun matrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice? = matrixWithDisplayName + companion object { - fun bulkWithProration(): NewPlanBulkWithProrationPrice? = bulkWithProration + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + fun builder() = Builder() + } - fun groupedTieredPackage(): NewPlanGroupedTieredPackagePrice? = groupedTieredPackage + /** A builder for [Metadata]. */ + class Builder internal constructor() { - fun maxGroupTieredPackage(): NewPlanMaxGroupTieredPackagePrice? = maxGroupTieredPackage + private var additionalProperties: MutableMap = + mutableMapOf() - fun scalableMatrixWithUnitPricing(): NewPlanScalableMatrixWithUnitPricingPrice? = - scalableMatrixWithUnitPricing + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } - fun scalableMatrixWithTieredPricing(): NewPlanScalableMatrixWithTieredPricingPrice? = - scalableMatrixWithTieredPricing + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun cumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice? = cumulativeGroupedBulk + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun tieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice? = - tieredPackageWithMinimum + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - fun matrixWithAllocation(): NewPlanMatrixWithAllocationPrice? = matrixWithAllocation + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun groupedTiered(): NewPlanGroupedTieredPrice? = groupedTiered + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun isUnit(): Boolean = unit != null + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } - fun isPackage(): Boolean = package_ != null + private var validated: Boolean = false - fun isMatrix(): Boolean = matrix != null + fun validate(): Metadata = apply { + if (validated) { + return@apply + } - fun isTiered(): Boolean = tiered != null + validated = true + } - fun isTieredBps(): Boolean = tieredBps != null + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun isBps(): Boolean = bps != null + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } - fun isBulkBps(): Boolean = bulkBps != null + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun isBulk(): Boolean = bulk != null + return other is Metadata && + additionalProperties == other.additionalProperties + } - fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - fun isTieredPackage(): Boolean = tieredPackage != null + override fun hashCode(): Int = hashCode - fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } - fun isUnitWithPercent(): Boolean = unitWithPercent != null + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + return other is CumulativeGroupedAllocation && + cadence == other.cadence && + cumulativeGroupedAllocationConfig == + other.cumulativeGroupedAllocationConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } - fun isTieredWithProration(): Boolean = tieredWithProration != null + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } - fun isUnitWithProration(): Boolean = unitWithProration != null + override fun hashCode(): Int = hashCode - fun isGroupedAllocation(): Boolean = groupedAllocation != null + override fun toString() = + "CumulativeGroupedAllocation{cadence=$cadence, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } - fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val percentConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) - fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - fun isBulkWithProration(): Boolean = bulkWithProration != null + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") - fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - fun isScalableMatrixWithTieredPricing(): Boolean = - scalableMatrixWithTieredPricing != null + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - fun isGroupedTiered(): Boolean = groupedTiered != null + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - fun asUnit(): NewPlanUnitPrice = unit.getOrThrow("unit") + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - fun asPackage(): NewPlanPackagePrice = package_.getOrThrow("package_") + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - fun asMatrix(): NewPlanMatrixPrice = matrix.getOrThrow("matrix") + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - fun asTiered(): NewPlanTieredPrice = tiered.getOrThrow("tiered") + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - fun asTieredBps(): NewPlanTieredBpsPrice = tieredBps.getOrThrow("tieredBps") + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - fun asBps(): NewPlanBpsPrice = bps.getOrThrow("bps") + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - fun asBulkBps(): NewPlanBulkBpsPrice = bulkBps.getOrThrow("bulkBps") + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - fun asBulk(): NewPlanBulkPrice = bulk.getOrThrow("bulk") + /** + * 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 - fun asThresholdTotalAmount(): NewPlanThresholdTotalAmountPrice = - thresholdTotalAmount.getOrThrow("thresholdTotalAmount") + /** + * Returns the raw JSON value of [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig - fun asTieredPackage(): NewPlanTieredPackagePrice = - tieredPackage.getOrThrow("tieredPackage") + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - fun asTieredWithMinimum(): NewPlanTieredWithMinimumPrice = - tieredWithMinimum.getOrThrow("tieredWithMinimum") + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - fun asUnitWithPercent(): NewPlanUnitWithPercentPrice = - unitWithPercent.getOrThrow("unitWithPercent") + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - fun asPackageWithAllocation(): NewPlanPackageWithAllocationPrice = - packageWithAllocation.getOrThrow("packageWithAllocation") + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - fun asTieredWithProration(): NewPlanTierWithProrationPrice = - tieredWithProration.getOrThrow("tieredWithProration") + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - fun asUnitWithProration(): NewPlanUnitWithProrationPrice = - unitWithProration.getOrThrow("unitWithProration") + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - fun asGroupedAllocation(): NewPlanGroupedAllocationPrice = - groupedAllocation.getOrThrow("groupedAllocation") + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - fun asGroupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice = - groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - fun asGroupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice = - groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - fun asMatrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice = - matrixWithDisplayName.getOrThrow("matrixWithDisplayName") + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - fun asBulkWithProration(): NewPlanBulkWithProrationPrice = - bulkWithProration.getOrThrow("bulkWithProration") + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - fun asGroupedTieredPackage(): NewPlanGroupedTieredPackagePrice = - groupedTieredPackage.getOrThrow("groupedTieredPackage") + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - fun asMaxGroupTieredPackage(): NewPlanMaxGroupTieredPackagePrice = - maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - fun asScalableMatrixWithUnitPricing(): NewPlanScalableMatrixWithUnitPricingPrice = - scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun asScalableMatrixWithTieredPricing(): NewPlanScalableMatrixWithTieredPricingPrice = - scalableMatrixWithTieredPricing.getOrThrow("scalableMatrixWithTieredPricing") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Percent]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + */ + fun builder() = Builder() + } - fun asCumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice = - cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + /** A builder for [Percent]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("percent") + private var name: JsonField? = null + private var percentConfig: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percent: Percent) = apply { + cadence = percent.cadence + itemId = percent.itemId + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + billableMetricId = percent.billableMetricId + billedInAdvance = percent.billedInAdvance + billingCycleConfiguration = percent.billingCycleConfiguration + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + currency = percent.currency + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoiceGroupingKey = percent.invoiceGroupingKey + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + metadata = percent.metadata + referenceId = percent.referenceId + additionalProperties = percent.additionalProperties.toMutableMap() + } - fun asTieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice = - tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed + * [PercentConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } - fun asMatrixWithAllocation(): NewPlanMatrixWithAllocationPrice = - matrixWithAllocation.getOrThrow("matrixWithAllocation") + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - fun asGroupedTiered(): NewPlanGroupedTieredPrice = - groupedTiered.getOrThrow("groupedTiered") + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - fun _json(): JsonValue? = _json + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) - tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) - bulk != null -> visitor.visitBulk(bulk) - thresholdTotalAmount != null -> - visitor.visitThresholdTotalAmount(thresholdTotalAmount) - tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) - tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) - unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) - packageWithAllocation != null -> - visitor.visitPackageWithAllocation(packageWithAllocation) - tieredWithProration != null -> - visitor.visitTieredWithProration(tieredWithProration) - unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) - groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) - groupedWithProratedMinimum != null -> - visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) - groupedWithMeteredMinimum != null -> - visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) - matrixWithDisplayName != null -> - visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) - groupedTieredPackage != null -> - visitor.visitGroupedTieredPackage(groupedTieredPackage) - maxGroupTieredPackage != null -> - visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) - scalableMatrixWithUnitPricing != null -> - visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) - scalableMatrixWithTieredPricing != null -> - visitor.visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() ) - cumulativeGroupedBulk != null -> - visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) - tieredPackageWithMinimum != null -> - visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) - matrixWithAllocation != null -> - visitor.visitMatrixWithAllocation(matrixWithAllocation) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) - else -> visitor.unknown(_json) - } - private var validated: Boolean = false + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - fun validate(): Price = apply { - if (validated) { - return@apply - } + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - accept( - object : Visitor { - override fun visitUnit(unit: NewPlanUnitPrice) { - unit.validate() - } + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - override fun visitPackage(package_: NewPlanPackagePrice) { - package_.validate() - } + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - override fun visitMatrix(matrix: NewPlanMatrixPrice) { - matrix.validate() - } + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - override fun visitTiered(tiered: NewPlanTieredPrice) { - tiered.validate() - } + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - override fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice) { - tieredBps.validate() - } + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - override fun visitBps(bps: NewPlanBpsPrice) { - bps.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - override fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice) { - bulkBps.validate() - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - override fun visitBulk(bulk: NewPlanBulkPrice) { - bulk.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitThresholdTotalAmount( - thresholdTotalAmount: NewPlanThresholdTotalAmountPrice - ) { - thresholdTotalAmount.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - override fun visitTieredPackage(tieredPackage: NewPlanTieredPackagePrice) { - tieredPackage.validate() - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - override fun visitTieredWithMinimum( - tieredWithMinimum: NewPlanTieredWithMinimumPrice - ) { - tieredWithMinimum.validate() - } + /** + * Returns an immutable instance of [Percent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Percent = + Percent( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("percentConfig", percentConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - override fun visitUnitWithPercent( - unitWithPercent: NewPlanUnitWithPercentPrice - ) { - unitWithPercent.validate() - } + private var validated: Boolean = false - override fun visitPackageWithAllocation( - packageWithAllocation: NewPlanPackageWithAllocationPrice - ) { - packageWithAllocation.validate() - } + fun validate(): Percent = apply { + if (validated) { + return@apply + } - override fun visitTieredWithProration( - tieredWithProration: NewPlanTierWithProrationPrice - ) { - tieredWithProration.validate() + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("percent")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") } + } + name() + percentConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - override fun visitUnitWithProration( - unitWithProration: NewPlanUnitWithProrationPrice - ) { - unitWithProration.validate() - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitGroupedAllocation( - groupedAllocation: NewPlanGroupedAllocationPrice - ) { - groupedAllocation.validate() - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - override fun visitGroupedWithProratedMinimum( - groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice - ) { - groupedWithProratedMinimum.validate() - } + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - override fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice - ) { - groupedWithMeteredMinimum.validate() - } + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice - ) { - matrixWithDisplayName.validate() + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN } - override fun visitBulkWithProration( - bulkWithProration: NewPlanBulkWithProrationPrice - ) { - bulkWithProration.validate() + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") } - override fun visitGroupedTieredPackage( - groupedTieredPackage: NewPlanGroupedTieredPackagePrice - ) { - groupedTieredPackage.validate() + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply } - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice - ) { - maxGroupTieredPackage.validate() + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - override fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice - ) { - scalableMatrixWithUnitPricing.validate() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - override fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewPlanScalableMatrixWithTieredPricingPrice - ) { - scalableMatrixWithTieredPricing.validate() + return other is Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent") + @ExcludeMissing + fun _percent(): JsonField = percent + + @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 + * [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PercentConfig]. */ + class Builder internal constructor() { + + private var percent: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() } - override fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice - ) { - cumulativeGroupedBulk.validate() + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ) { - tieredPackageWithMinimum.validate() + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ) { - matrixWithAllocation.validate() + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) { - groupedTiered.validate() + /** + * Returns an immutable instance of [PercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PercentConfig = apply { + if (validated) { + return@apply } + + percent() + validated = true } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: NewPlanUnitPrice) = unit.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun visitPackage(package_: NewPlanPackagePrice) = - package_.validity() + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties + } - override fun visitMatrix(matrix: NewPlanMatrixPrice) = matrix.validity() + private val hashCode: Int by lazy { + Objects.hash(percent, additionalProperties) + } - override fun visitTiered(tiered: NewPlanTieredPrice) = tiered.validity() + override fun hashCode(): Int = hashCode - override fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice) = - tieredBps.validity() + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" + } - override fun visitBps(bps: NewPlanBpsPrice) = bps.validity() + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - override fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice) = bulkBps.validity() + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - override fun visitBulk(bulk: NewPlanBulkPrice) = bulk.validity() + fun toBuilder() = Builder().from(this) - override fun visitThresholdTotalAmount( - thresholdTotalAmount: NewPlanThresholdTotalAmountPrice - ) = thresholdTotalAmount.validity() + companion object { - override fun visitTieredPackage(tieredPackage: NewPlanTieredPackagePrice) = - tieredPackage.validity() + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + fun builder() = Builder() + } - override fun visitTieredWithMinimum( - tieredWithMinimum: NewPlanTieredWithMinimumPrice - ) = tieredWithMinimum.validity() + /** A builder for [Metadata]. */ + class Builder internal constructor() { - override fun visitUnitWithPercent( - unitWithPercent: NewPlanUnitWithPercentPrice - ) = unitWithPercent.validity() + private var additionalProperties: MutableMap = + mutableMapOf() - override fun visitPackageWithAllocation( - packageWithAllocation: NewPlanPackageWithAllocationPrice - ) = packageWithAllocation.validity() + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } - override fun visitTieredWithProration( - tieredWithProration: NewPlanTierWithProrationPrice - ) = tieredWithProration.validity() + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - override fun visitUnitWithProration( - unitWithProration: NewPlanUnitWithProrationPrice - ) = unitWithProration.validity() + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - override fun visitGroupedAllocation( - groupedAllocation: NewPlanGroupedAllocationPrice - ) = groupedAllocation.validity() + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - override fun visitGroupedWithProratedMinimum( - groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice - ) = groupedWithProratedMinimum.validity() + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - override fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice - ) = groupedWithMeteredMinimum.validity() + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice - ) = matrixWithDisplayName.validity() + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } - override fun visitBulkWithProration( - bulkWithProration: NewPlanBulkWithProrationPrice - ) = bulkWithProration.validity() + private var validated: Boolean = false - override fun visitGroupedTieredPackage( - groupedTieredPackage: NewPlanGroupedTieredPackagePrice - ) = groupedTieredPackage.validity() + fun validate(): Metadata = apply { + if (validated) { + return@apply + } - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice - ) = maxGroupTieredPackage.validity() + validated = true + } - override fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice - ) = scalableMatrixWithUnitPricing.validity() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewPlanScalableMatrixWithTieredPricingPrice - ) = scalableMatrixWithTieredPricing.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } - override fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice - ) = cumulativeGroupedBulk.validity() + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ) = tieredPackageWithMinimum.validity() + return other is Metadata && + additionalProperties == other.additionalProperties + } - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ) = matrixWithAllocation.validity() + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = - groupedTiered.validity() + override fun hashCode(): Int = hashCode - override fun unknown(json: JsonValue?) = 0 + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + return other is Percent && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) } - return /* spotless:off */ other is Price && unit == other.unit && package_ == other.package_ && matrix == other.matrix && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && tieredWithMinimum == other.tieredWithMinimum && unitWithPercent == other.unitWithPercent && packageWithAllocation == other.packageWithAllocation && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && bulkWithProration == other.bulkWithProration && groupedTieredPackage == other.groupedTieredPackage && maxGroupTieredPackage == other.maxGroupTieredPackage && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk && tieredPackageWithMinimum == other.tieredPackageWithMinimum && matrixWithAllocation == other.matrixWithAllocation && groupedTiered == other.groupedTiered /* spotless:on */ + override fun hashCode(): Int = hashCode + + override fun toString() = + "Percent{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, percentConfig=$percentConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, tieredWithMinimum, unitWithPercent, packageWithAllocation, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, groupedWithMeteredMinimum, matrixWithDisplayName, bulkWithProration, groupedTieredPackage, maxGroupTieredPackage, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk, tieredPackageWithMinimum, matrixWithAllocation, groupedTiered) /* spotless:on */ + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val eventOutputConfig: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) - override fun toString(): String = - when { - unit != null -> "Price{unit=$unit}" - package_ != null -> "Price{package_=$package_}" - matrix != null -> "Price{matrix=$matrix}" - tiered != null -> "Price{tiered=$tiered}" - tieredBps != null -> "Price{tieredBps=$tieredBps}" - bps != null -> "Price{bps=$bps}" - bulkBps != null -> "Price{bulkBps=$bulkBps}" - bulk != null -> "Price{bulk=$bulk}" - thresholdTotalAmount != null -> - "Price{thresholdTotalAmount=$thresholdTotalAmount}" - tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" - tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" - unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" - packageWithAllocation != null -> - "Price{packageWithAllocation=$packageWithAllocation}" - tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" - unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" - groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" - groupedWithProratedMinimum != null -> - "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" - groupedWithMeteredMinimum != null -> - "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" - matrixWithDisplayName != null -> - "Price{matrixWithDisplayName=$matrixWithDisplayName}" - bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" - groupedTieredPackage != null -> - "Price{groupedTieredPackage=$groupedTieredPackage}" - maxGroupTieredPackage != null -> - "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" - scalableMatrixWithUnitPricing != null -> - "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" - scalableMatrixWithTieredPricing != null -> - "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" - cumulativeGroupedBulk != null -> - "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" - tieredPackageWithMinimum != null -> - "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" - matrixWithAllocation != null -> - "Price{matrixWithAllocation=$matrixWithAllocation}" - groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" - _json != null -> "Price{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Price") - } + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - companion object { + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") - fun ofUnit(unit: NewPlanUnitPrice) = Price(unit = unit) + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - fun ofPackage(package_: NewPlanPackagePrice) = Price(package_ = package_) + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - fun ofMatrix(matrix: NewPlanMatrixPrice) = Price(matrix = matrix) + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - fun ofTiered(tiered: NewPlanTieredPrice) = Price(tiered = tiered) + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - fun ofTieredBps(tieredBps: NewPlanTieredBpsPrice) = Price(tieredBps = tieredBps) + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - fun ofBps(bps: NewPlanBpsPrice) = Price(bps = bps) + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - fun ofBulkBps(bulkBps: NewPlanBulkBpsPrice) = Price(bulkBps = bulkBps) + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - fun ofBulk(bulk: NewPlanBulkPrice) = Price(bulk = bulk) + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - fun ofThresholdTotalAmount(thresholdTotalAmount: NewPlanThresholdTotalAmountPrice) = - Price(thresholdTotalAmount = thresholdTotalAmount) + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - fun ofTieredPackage(tieredPackage: NewPlanTieredPackagePrice) = - Price(tieredPackage = tieredPackage) + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - fun ofTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = - Price(tieredWithMinimum = tieredWithMinimum) + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - fun ofUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice) = - Price(unitWithPercent = unitWithPercent) + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - fun ofPackageWithAllocation( - packageWithAllocation: NewPlanPackageWithAllocationPrice - ) = Price(packageWithAllocation = packageWithAllocation) + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - fun ofTieredWithProration(tieredWithProration: NewPlanTierWithProrationPrice) = - Price(tieredWithProration = tieredWithProration) + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - fun ofUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice) = - Price(unitWithProration = unitWithProration) + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - fun ofGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice) = - Price(groupedAllocation = groupedAllocation) + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - fun ofGroupedWithProratedMinimum( - groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice - ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig - fun ofGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice - ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - fun ofMatrixWithDisplayName( - matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice - ) = Price(matrixWithDisplayName = matrixWithDisplayName) + /** + * 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 - fun ofBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice) = - Price(bulkWithProration = bulkWithProration) + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - fun ofGroupedTieredPackage(groupedTieredPackage: NewPlanGroupedTieredPackagePrice) = - Price(groupedTieredPackage = groupedTieredPackage) + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - fun ofMaxGroupTieredPackage( - maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice - ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - fun ofScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice - ) = Price(scalableMatrixWithUnitPricing = scalableMatrixWithUnitPricing) + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - fun ofScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: NewPlanScalableMatrixWithTieredPricingPrice - ) = Price(scalableMatrixWithTieredPricing = scalableMatrixWithTieredPricing) + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - fun ofCumulativeGroupedBulk( - cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice - ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - fun ofTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - fun ofMatrixWithAllocation(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = - Price(matrixWithAllocation = matrixWithAllocation) + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - fun ofGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = - Price(groupedTiered = groupedTiered) - } + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - /** - * An interface that defines how to map each variant of [Price] to a value of type [T]. - */ - interface Visitor { + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - fun visitUnit(unit: NewPlanUnitPrice): T + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - fun visitPackage(package_: NewPlanPackagePrice): T + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - fun visitMatrix(matrix: NewPlanMatrixPrice): T + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - fun visitTiered(tiered: NewPlanTieredPrice): T + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice): T + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EventOutput]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } - fun visitBps(bps: NewPlanBpsPrice): T + /** A builder for [EventOutput]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var eventOutputConfig: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("event_output") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutput: EventOutput) = apply { + cadence = eventOutput.cadence + eventOutputConfig = eventOutput.eventOutputConfig + itemId = eventOutput.itemId + modelType = eventOutput.modelType + name = eventOutput.name + billableMetricId = eventOutput.billableMetricId + billedInAdvance = eventOutput.billedInAdvance + billingCycleConfiguration = eventOutput.billingCycleConfiguration + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + currency = eventOutput.currency + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoiceGroupingKey = eventOutput.invoiceGroupingKey + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + metadata = eventOutput.metadata + referenceId = eventOutput.referenceId + additionalProperties = eventOutput.additionalProperties.toMutableMap() + } - fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice): T + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } - fun visitBulk(bulk: NewPlanBulkPrice): T + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - fun visitThresholdTotalAmount( - thresholdTotalAmount: NewPlanThresholdTotalAmountPrice - ): T + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - fun visitTieredPackage(tieredPackage: NewPlanTieredPackagePrice): T + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - fun visitTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice): T + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - fun visitUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice): T + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - fun visitPackageWithAllocation( - packageWithAllocation: NewPlanPackageWithAllocationPrice - ): T + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - fun visitTieredWithProration(tieredWithProration: NewPlanTierWithProrationPrice): T + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - fun visitUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice): T + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - fun visitGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice): T + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - fun visitGroupedWithProratedMinimum( - groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice - ): T + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice - ): T + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice - ): T + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun visitBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice): T + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun visitGroupedTieredPackage( - groupedTieredPackage: NewPlanGroupedTieredPackagePrice - ): T + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice - ): T + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice - ): T + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: NewPlanScalableMatrixWithTieredPricingPrice - ): T + /** + * Returns an immutable instance of [EventOutput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutput = + EventOutput( + checkRequired("cadence", cadence), + checkRequired("eventOutputConfig", eventOutputConfig), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice - ): T + private var validated: Boolean = false - fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ): T + fun validate(): EventOutput = apply { + if (validated) { + return@apply + } - fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ): T + cadence().validate() + eventOutputConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("event_output")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [Price] to a value of type [T]. - * - * An instance of [Price] can contain an unknown variant if it was deserialized from - * data that doesn't match any known variant. For example, if the SDK is on an older - * version than the API, then the API may respond with new variants that the SDK is - * unaware of. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown Price: $json") - } - } + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - internal class Deserializer : BaseDeserializer(Price::class) { + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - override fun ObjectCodec.deserialize(node: JsonNode): Price { - val json = JsonValue.fromJsonNode(node) - val modelType = json.asObject()?.get("model_type")?.asString() + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - when (modelType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(unit = it, _json = json) - } ?: Price(_json = json) - } - "package" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) - } - "matrix" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(matrix = it, _json = json) - } ?: Price(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(tiered = it, _json = json) - } ?: Price(_json = json) - } - "tiered_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(tieredBps = it, _json = json) } ?: Price(_json = json) + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(bps = it, _json = json) - } ?: Price(_json = json) - } - "bulk_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bulkBps = it, _json = json) } ?: Price(_json = json) + + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") } - "bulk" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(bulk = it, _json = json) - } ?: Price(_json = json) + + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply } - "threshold_total_amount" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(thresholdTotalAmount = it, _json = json) } - ?: Price(_json = json) + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "tiered_package" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(tieredPackage = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - "tiered_with_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredWithMinimum = it, _json = json) } - ?: Price(_json = json) + + return other is Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a + * unit rate will be ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = + defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events + * will also be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @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 + * [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutputConfig]. */ + class Builder internal constructor() { + + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = + eventOutputConfig.additionalProperties.toMutableMap() } - "unit_with_percent" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(unitWithPercent = it, _json = json) } - ?: Price(_json = json) + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey } - "package_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(packageWithAllocation = it, _json = json) } - ?: Price(_json = json) + + /** + * If provided, this amount will be used as the unit rate when an event does + * not have a value for the `unit_rating_key`. If not provided, events + * missing a unit rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate } - "tiered_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredWithProration = it, _json = json) } - ?: Price(_json = json) + + /** + * An optional key in the event data to group by (e.g., event ID). All + * events will also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey } - "unit_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(unitWithProration = it, _json = json) } - ?: Price(_json = json) + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - "grouped_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedAllocation = it, _json = json) } - ?: Price(_json = json) + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - "grouped_with_prorated_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedWithProratedMinimum = it, _json = json) } - ?: Price(_json = json) + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - "grouped_with_metered_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns an immutable instance of [EventOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutputConfig = apply { + if (validated) { + return@apply } - "matrix_with_display_name" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithDisplayName = it, _json = json) } - ?: Price(_json = json) + + unitRatingKey() + defaultUnitRate() + groupingKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "bulk_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(bulkWithProration = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - "grouped_tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedTieredPackage = it, _json = json) } - ?: Price(_json = json) + + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + unitRatingKey, + defaultUnitRate, + groupingKey, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() } - "max_group_tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(maxGroupTieredPackage = it, _json = json) } - ?: Price(_json = json) + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - "scalable_matrix_with_unit_pricing" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(scalableMatrixWithUnitPricing = it, _json = json) } - ?: Price(_json = json) + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - "scalable_matrix_with_tiered_pricing" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(scalableMatrixWithTieredPricing = it, _json = json) } - ?: Price(_json = json) + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - "cumulative_grouped_bulk" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(cumulativeGroupedBulk = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply } - "tiered_package_with_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredPackageWithMinimum = it, _json = json) } - ?: Price(_json = json) + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "matrix_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithAllocation = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() } - "grouped_tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(groupedTiered = it, _json = json) } - ?: Price(_json = json) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Metadata && + additionalProperties == other.additionalProperties } - return Price(_json = json) - } - } + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - internal class Serializer : BaseSerializer(Price::class) { + override fun hashCode(): Int = hashCode - override fun serialize( - value: Price, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) - value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) - value.bulk != null -> generator.writeObject(value.bulk) - value.thresholdTotalAmount != null -> - generator.writeObject(value.thresholdTotalAmount) - value.tieredPackage != null -> generator.writeObject(value.tieredPackage) - value.tieredWithMinimum != null -> - generator.writeObject(value.tieredWithMinimum) - value.unitWithPercent != null -> - generator.writeObject(value.unitWithPercent) - value.packageWithAllocation != null -> - generator.writeObject(value.packageWithAllocation) - value.tieredWithProration != null -> - generator.writeObject(value.tieredWithProration) - value.unitWithProration != null -> - generator.writeObject(value.unitWithProration) - value.groupedAllocation != null -> - generator.writeObject(value.groupedAllocation) - value.groupedWithProratedMinimum != null -> - generator.writeObject(value.groupedWithProratedMinimum) - value.groupedWithMeteredMinimum != null -> - generator.writeObject(value.groupedWithMeteredMinimum) - value.matrixWithDisplayName != null -> - generator.writeObject(value.matrixWithDisplayName) - value.bulkWithProration != null -> - generator.writeObject(value.bulkWithProration) - value.groupedTieredPackage != null -> - generator.writeObject(value.groupedTieredPackage) - value.maxGroupTieredPackage != null -> - generator.writeObject(value.maxGroupTieredPackage) - value.scalableMatrixWithUnitPricing != null -> - generator.writeObject(value.scalableMatrixWithUnitPricing) - value.scalableMatrixWithTieredPricing != null -> - generator.writeObject(value.scalableMatrixWithTieredPricing) - value.cumulativeGroupedBulk != null -> - generator.writeObject(value.cumulativeGroupedBulk) - value.tieredPackageWithMinimum != null -> - generator.writeObject(value.tieredPackageWithMinimum) - value.matrixWithAllocation != null -> - generator.writeObject(value.matrixWithAllocation) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Price") + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is EventOutput && + cadence == other.cadence && + eventOutputConfig == other.eventOutputConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutput{cadence=$cadence, eventOutputConfig=$eventOutputConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" } } @@ -5613,12 +26742,23 @@ private constructor( return true } - return /* spotless:off */ other is ReplacePrice && replacesPriceId == other.replacesPriceId && allocationPrice == other.allocationPrice && planPhaseOrder == other.planPhaseOrder && price == other.price && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ReplacePrice && + replacesPriceId == other.replacesPriceId && + allocationPrice == other.allocationPrice && + planPhaseOrder == other.planPhaseOrder && + price == other.price && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(replacesPriceId, allocationPrice, planPhaseOrder, price, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + replacesPriceId, + allocationPrice, + planPhaseOrder, + price, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -5631,10 +26771,15 @@ private constructor( return true } - return /* spotless:off */ other is BetaExternalPlanIdCreatePlanVersionParams && externalPlanId == other.externalPlanId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is BetaExternalPlanIdCreatePlanVersionParams && + externalPlanId == other.externalPlanId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalPlanId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(externalPlanId, body, additionalHeaders, additionalQueryParams) override fun toString() = "BetaExternalPlanIdCreatePlanVersionParams{externalPlanId=$externalPlanId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaExternalPlanIdFetchPlanVersionParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaExternalPlanIdFetchPlanVersionParams.kt index c93bb24c0..e9a4d057d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaExternalPlanIdFetchPlanVersionParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaExternalPlanIdFetchPlanVersionParams.kt @@ -9,9 +9,6 @@ import com.withorb.api.core.http.QueryParams import java.util.Objects /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in test - * mode. - * * This endpoint is used to fetch a plan version. It returns the phases, prices, and adjustments * present on this version of the plan. */ @@ -207,10 +204,15 @@ private constructor( return true } - return /* spotless:off */ other is BetaExternalPlanIdFetchPlanVersionParams && externalPlanId == other.externalPlanId && version == other.version && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is BetaExternalPlanIdFetchPlanVersionParams && + externalPlanId == other.externalPlanId && + version == other.version && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalPlanId, version, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(externalPlanId, version, additionalHeaders, additionalQueryParams) override fun toString() = "BetaExternalPlanIdFetchPlanVersionParams{externalPlanId=$externalPlanId, version=$version, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaExternalPlanIdSetDefaultPlanVersionParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaExternalPlanIdSetDefaultPlanVersionParams.kt index 0f0c8b3e4..5ffa0a908 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaExternalPlanIdSetDefaultPlanVersionParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaExternalPlanIdSetDefaultPlanVersionParams.kt @@ -18,12 +18,7 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects -/** - * This API endpoint is in beta and its interface may change. It is recommended for use only in test - * mode. - * - * This endpoint allows setting the default version of a plan. - */ +/** This endpoint allows setting the default version of a plan. */ class BetaExternalPlanIdSetDefaultPlanVersionParams private constructor( private val externalPlanId: String?, @@ -266,6 +261,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val version: JsonField, private val additionalProperties: MutableMap, @@ -406,12 +402,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(version, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -424,10 +420,15 @@ private constructor( return true } - return /* spotless:off */ other is BetaExternalPlanIdSetDefaultPlanVersionParams && externalPlanId == other.externalPlanId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is BetaExternalPlanIdSetDefaultPlanVersionParams && + externalPlanId == other.externalPlanId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalPlanId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(externalPlanId, body, additionalHeaders, additionalQueryParams) override fun toString() = "BetaExternalPlanIdSetDefaultPlanVersionParams{externalPlanId=$externalPlanId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaFetchPlanVersionParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaFetchPlanVersionParams.kt index 836177224..e5c5fd6a5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaFetchPlanVersionParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaFetchPlanVersionParams.kt @@ -9,9 +9,6 @@ import com.withorb.api.core.http.QueryParams import java.util.Objects /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in test - * mode. - * * This endpoint is used to fetch a plan version. It returns the phases, prices, and adjustments * present on this version of the plan. */ @@ -202,10 +199,15 @@ private constructor( return true } - return /* spotless:off */ other is BetaFetchPlanVersionParams && planId == other.planId && version == other.version && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is BetaFetchPlanVersionParams && + planId == other.planId && + version == other.version && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(planId, version, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(planId, version, additionalHeaders, additionalQueryParams) override fun toString() = "BetaFetchPlanVersionParams{planId=$planId, version=$version, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaSetDefaultPlanVersionParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaSetDefaultPlanVersionParams.kt index bfc05e1ab..c57ebe2d0 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaSetDefaultPlanVersionParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BetaSetDefaultPlanVersionParams.kt @@ -18,12 +18,7 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects -/** - * This API endpoint is in beta and its interface may change. It is recommended for use only in test - * mode. - * - * This endpoint allows setting the default version of a plan. - */ +/** This endpoint allows setting the default version of a plan. */ class BetaSetDefaultPlanVersionParams private constructor( private val planId: String?, @@ -263,6 +258,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val version: JsonField, private val additionalProperties: MutableMap, @@ -403,12 +399,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(version, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -421,10 +417,15 @@ private constructor( return true } - return /* spotless:off */ other is BetaSetDefaultPlanVersionParams && planId == other.planId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is BetaSetDefaultPlanVersionParams && + planId == other.planId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(planId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(planId, body, additionalHeaders, additionalQueryParams) override fun toString() = "BetaSetDefaultPlanVersionParams{planId=$planId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillableMetric.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillableMetric.kt index 02ae5a7b6..532508cf2 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillableMetric.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillableMetric.kt @@ -22,6 +22,7 @@ import java.util.Objects * by the query that transforms raw usage events into meaningful values for your customers. */ class BillableMetric +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val description: JsonField, @@ -430,12 +431,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -564,7 +563,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -577,12 +576,19 @@ private constructor( return true } - return /* spotless:off */ other is BillableMetric && id == other.id && description == other.description && item == other.item && metadata == other.metadata && name == other.name && status == other.status && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BillableMetric && + id == other.id && + description == other.description && + item == other.item && + metadata == other.metadata && + name == other.name && + status == other.status && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, description, item, metadata, name, status, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, description, item, metadata, name, status, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillableMetricTiny.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillableMetricTiny.kt index b71eba9ae..9ced8583f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillableMetricTiny.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillableMetricTiny.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class BillableMetricTiny +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val additionalProperties: MutableMap, @@ -151,12 +152,12 @@ private constructor( return true } - return /* spotless:off */ other is BillableMetricTiny && id == other.id && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BillableMetricTiny && + id == other.id && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillingCycleAnchorConfiguration.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillingCycleAnchorConfiguration.kt index 47d780bc2..f7e797c97 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillingCycleAnchorConfiguration.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillingCycleAnchorConfiguration.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class BillingCycleAnchorConfiguration +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val day: JsonField, private val month: JsonField, @@ -256,12 +257,14 @@ private constructor( return true } - return /* spotless:off */ other is BillingCycleAnchorConfiguration && day == other.day && month == other.month && year == other.year && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BillingCycleAnchorConfiguration && + day == other.day && + month == other.month && + year == other.year && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(day, month, year, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillingCycleConfiguration.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillingCycleConfiguration.kt index 4b4fc2146..a803a9166 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillingCycleConfiguration.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillingCycleConfiguration.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class BillingCycleConfiguration +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val duration: JsonField, private val durationUnit: JsonField, @@ -308,7 +309,7 @@ private constructor( return true } - return /* spotless:off */ other is DurationUnit && value == other.value /* spotless:on */ + return other is DurationUnit && value == other.value } override fun hashCode() = value.hashCode() @@ -321,12 +322,13 @@ private constructor( return true } - return /* spotless:off */ other is BillingCycleConfiguration && duration == other.duration && durationUnit == other.durationUnit && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BillingCycleConfiguration && + duration == other.duration && + durationUnit == other.durationUnit && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(duration, durationUnit, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillingCycleRelativeDate.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillingCycleRelativeDate.kt index a6e739553..91a529ae6 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillingCycleRelativeDate.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BillingCycleRelativeDate.kt @@ -127,7 +127,7 @@ private constructor(private val value: JsonField) : Enum { return true } - return /* spotless:off */ other is BillingCycleRelativeDate && value == other.value /* spotless:on */ + return other is BillingCycleRelativeDate && value == other.value } override fun hashCode() = value.hashCode() diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BpsConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BpsConfig.kt deleted file mode 100644 index c9be1d3ef..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BpsConfig.kt +++ /dev/null @@ -1,212 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -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.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkRequired -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class BpsConfig -private constructor( - private val bps: JsonField, - private val perUnitMaximum: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("bps") @ExcludeMissing bps: JsonField = JsonMissing.of(), - @JsonProperty("per_unit_maximum") - @ExcludeMissing - perUnitMaximum: JsonField = JsonMissing.of(), - ) : this(bps, perUnitMaximum, mutableMapOf()) - - /** - * Basis point take rate per event - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun bps(): Double = bps.getRequired("bps") - - /** - * Optional currency amount maximum to cap spend per event - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun perUnitMaximum(): String? = perUnitMaximum.getNullable("per_unit_maximum") - - /** - * Returns the raw JSON value of [bps]. - * - * Unlike [bps], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("bps") @ExcludeMissing fun _bps(): JsonField = bps - - /** - * Returns the raw JSON value of [perUnitMaximum]. - * - * Unlike [perUnitMaximum], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("per_unit_maximum") - @ExcludeMissing - fun _perUnitMaximum(): JsonField = perUnitMaximum - - @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 [BpsConfig]. - * - * The following fields are required: - * ```kotlin - * .bps() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [BpsConfig]. */ - class Builder internal constructor() { - - private var bps: JsonField? = null - private var perUnitMaximum: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(bpsConfig: BpsConfig) = apply { - bps = bpsConfig.bps - perUnitMaximum = bpsConfig.perUnitMaximum - additionalProperties = bpsConfig.additionalProperties.toMutableMap() - } - - /** Basis point take rate per event */ - fun bps(bps: Double) = bps(JsonField.of(bps)) - - /** - * Sets [Builder.bps] to an arbitrary JSON value. - * - * You should usually call [Builder.bps] with a well-typed [Double] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun bps(bps: JsonField) = apply { this.bps = bps } - - /** Optional currency amount maximum to cap spend per event */ - fun perUnitMaximum(perUnitMaximum: String?) = - perUnitMaximum(JsonField.ofNullable(perUnitMaximum)) - - /** - * Sets [Builder.perUnitMaximum] to an arbitrary JSON value. - * - * You should usually call [Builder.perUnitMaximum] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun perUnitMaximum(perUnitMaximum: JsonField) = apply { - this.perUnitMaximum = perUnitMaximum - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [BpsConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .bps() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): BpsConfig = - BpsConfig( - checkRequired("bps", bps), - perUnitMaximum, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): BpsConfig = apply { - if (validated) { - return@apply - } - - bps() - perUnitMaximum() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (bps.asKnown() == null) 0 else 1) + (if (perUnitMaximum.asKnown() == null) 0 else 1) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is BpsConfig && bps == other.bps && perUnitMaximum == other.perUnitMaximum && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bps, perUnitMaximum, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "BpsConfig{bps=$bps, perUnitMaximum=$perUnitMaximum, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BpsTier.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BpsTier.kt deleted file mode 100644 index 3dd3ebd7e..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BpsTier.kt +++ /dev/null @@ -1,296 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -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.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkRequired -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class BpsTier -private constructor( - private val bps: JsonField, - private val minimumAmount: JsonField, - private val maximumAmount: JsonField, - private val perUnitMaximum: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("bps") @ExcludeMissing bps: JsonField = JsonMissing.of(), - @JsonProperty("minimum_amount") - @ExcludeMissing - minimumAmount: JsonField = JsonMissing.of(), - @JsonProperty("maximum_amount") - @ExcludeMissing - maximumAmount: JsonField = JsonMissing.of(), - @JsonProperty("per_unit_maximum") - @ExcludeMissing - perUnitMaximum: JsonField = JsonMissing.of(), - ) : this(bps, minimumAmount, maximumAmount, perUnitMaximum, mutableMapOf()) - - /** - * Per-event basis point rate - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun bps(): Double = bps.getRequired("bps") - - /** - * Exclusive tier starting value - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun minimumAmount(): String = minimumAmount.getRequired("minimum_amount") - - /** - * Inclusive tier ending value - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun maximumAmount(): String? = maximumAmount.getNullable("maximum_amount") - - /** - * Per unit maximum to charge - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun perUnitMaximum(): String? = perUnitMaximum.getNullable("per_unit_maximum") - - /** - * Returns the raw JSON value of [bps]. - * - * Unlike [bps], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("bps") @ExcludeMissing fun _bps(): JsonField = bps - - /** - * Returns the raw JSON value of [minimumAmount]. - * - * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("minimum_amount") - @ExcludeMissing - fun _minimumAmount(): JsonField = minimumAmount - - /** - * Returns the raw JSON value of [maximumAmount]. - * - * Unlike [maximumAmount], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("maximum_amount") - @ExcludeMissing - fun _maximumAmount(): JsonField = maximumAmount - - /** - * Returns the raw JSON value of [perUnitMaximum]. - * - * Unlike [perUnitMaximum], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("per_unit_maximum") - @ExcludeMissing - fun _perUnitMaximum(): JsonField = perUnitMaximum - - @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 [BpsTier]. - * - * The following fields are required: - * ```kotlin - * .bps() - * .minimumAmount() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [BpsTier]. */ - class Builder internal constructor() { - - private var bps: JsonField? = null - private var minimumAmount: JsonField? = null - private var maximumAmount: JsonField = JsonMissing.of() - private var perUnitMaximum: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(bpsTier: BpsTier) = apply { - bps = bpsTier.bps - minimumAmount = bpsTier.minimumAmount - maximumAmount = bpsTier.maximumAmount - perUnitMaximum = bpsTier.perUnitMaximum - additionalProperties = bpsTier.additionalProperties.toMutableMap() - } - - /** Per-event basis point rate */ - fun bps(bps: Double) = bps(JsonField.of(bps)) - - /** - * Sets [Builder.bps] to an arbitrary JSON value. - * - * You should usually call [Builder.bps] with a well-typed [Double] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun bps(bps: JsonField) = apply { this.bps = bps } - - /** Exclusive tier starting value */ - fun minimumAmount(minimumAmount: String) = minimumAmount(JsonField.of(minimumAmount)) - - /** - * Sets [Builder.minimumAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.minimumAmount] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun minimumAmount(minimumAmount: JsonField) = apply { - this.minimumAmount = minimumAmount - } - - /** Inclusive tier ending value */ - fun maximumAmount(maximumAmount: String?) = - maximumAmount(JsonField.ofNullable(maximumAmount)) - - /** - * Sets [Builder.maximumAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.maximumAmount] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun maximumAmount(maximumAmount: JsonField) = apply { - this.maximumAmount = maximumAmount - } - - /** Per unit maximum to charge */ - fun perUnitMaximum(perUnitMaximum: String?) = - perUnitMaximum(JsonField.ofNullable(perUnitMaximum)) - - /** - * Sets [Builder.perUnitMaximum] to an arbitrary JSON value. - * - * You should usually call [Builder.perUnitMaximum] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun perUnitMaximum(perUnitMaximum: JsonField) = apply { - this.perUnitMaximum = perUnitMaximum - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [BpsTier]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .bps() - * .minimumAmount() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): BpsTier = - BpsTier( - checkRequired("bps", bps), - checkRequired("minimumAmount", minimumAmount), - maximumAmount, - perUnitMaximum, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): BpsTier = apply { - if (validated) { - return@apply - } - - bps() - minimumAmount() - maximumAmount() - perUnitMaximum() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (bps.asKnown() == null) 0 else 1) + - (if (minimumAmount.asKnown() == null) 0 else 1) + - (if (maximumAmount.asKnown() == null) 0 else 1) + - (if (perUnitMaximum.asKnown() == null) 0 else 1) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is BpsTier && bps == other.bps && minimumAmount == other.minimumAmount && maximumAmount == other.maximumAmount && perUnitMaximum == other.perUnitMaximum && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bps, minimumAmount, maximumAmount, perUnitMaximum, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "BpsTier{bps=$bps, minimumAmount=$minimumAmount, maximumAmount=$maximumAmount, perUnitMaximum=$perUnitMaximum, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkBpsConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkBpsConfig.kt deleted file mode 100644 index dc54babdf..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkBpsConfig.kt +++ /dev/null @@ -1,192 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -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.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkKnown -import com.withorb.api.core.checkRequired -import com.withorb.api.core.toImmutable -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class BulkBpsConfig -private constructor( - private val tiers: JsonField>, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("tiers") - @ExcludeMissing - tiers: JsonField> = JsonMissing.of() - ) : this(tiers, mutableMapOf()) - - /** - * Tiers for a bulk BPS pricing model where all usage is aggregated to a single tier based on - * total volume - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun tiers(): List = tiers.getRequired("tiers") - - /** - * 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 [BulkBpsConfig]. - * - * The following fields are required: - * ```kotlin - * .tiers() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [BulkBpsConfig]. */ - class Builder internal constructor() { - - private var tiers: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(bulkBpsConfig: BulkBpsConfig) = apply { - tiers = bulkBpsConfig.tiers.map { it.toMutableList() } - additionalProperties = bulkBpsConfig.additionalProperties.toMutableMap() - } - - /** - * Tiers for a bulk BPS pricing model where all usage is aggregated to a single tier based - * on total volume - */ - 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 [BulkBpsTier] to [tiers]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addTier(tier: BulkBpsTier) = 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 [BulkBpsConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .tiers() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): BulkBpsConfig = - BulkBpsConfig( - checkRequired("tiers", tiers).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): BulkBpsConfig = apply { - if (validated) { - return@apply - } - - tiers().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is BulkBpsConfig && tiers == other.tiers && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "BulkBpsConfig{tiers=$tiers, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkBpsTier.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkBpsTier.kt deleted file mode 100644 index 14a34cfd2..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkBpsTier.kt +++ /dev/null @@ -1,254 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -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.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkRequired -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class BulkBpsTier -private constructor( - private val bps: JsonField, - private val maximumAmount: JsonField, - private val perUnitMaximum: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("bps") @ExcludeMissing bps: JsonField = JsonMissing.of(), - @JsonProperty("maximum_amount") - @ExcludeMissing - maximumAmount: JsonField = JsonMissing.of(), - @JsonProperty("per_unit_maximum") - @ExcludeMissing - perUnitMaximum: JsonField = JsonMissing.of(), - ) : this(bps, maximumAmount, perUnitMaximum, mutableMapOf()) - - /** - * Basis points to rate on - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun bps(): Double = bps.getRequired("bps") - - /** - * Upper bound for tier - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun maximumAmount(): String? = maximumAmount.getNullable("maximum_amount") - - /** - * The maximum amount to charge for any one event - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun perUnitMaximum(): String? = perUnitMaximum.getNullable("per_unit_maximum") - - /** - * Returns the raw JSON value of [bps]. - * - * Unlike [bps], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("bps") @ExcludeMissing fun _bps(): JsonField = bps - - /** - * Returns the raw JSON value of [maximumAmount]. - * - * Unlike [maximumAmount], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("maximum_amount") - @ExcludeMissing - fun _maximumAmount(): JsonField = maximumAmount - - /** - * Returns the raw JSON value of [perUnitMaximum]. - * - * Unlike [perUnitMaximum], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("per_unit_maximum") - @ExcludeMissing - fun _perUnitMaximum(): JsonField = perUnitMaximum - - @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 [BulkBpsTier]. - * - * The following fields are required: - * ```kotlin - * .bps() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [BulkBpsTier]. */ - class Builder internal constructor() { - - private var bps: JsonField? = null - private var maximumAmount: JsonField = JsonMissing.of() - private var perUnitMaximum: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(bulkBpsTier: BulkBpsTier) = apply { - bps = bulkBpsTier.bps - maximumAmount = bulkBpsTier.maximumAmount - perUnitMaximum = bulkBpsTier.perUnitMaximum - additionalProperties = bulkBpsTier.additionalProperties.toMutableMap() - } - - /** Basis points to rate on */ - fun bps(bps: Double) = bps(JsonField.of(bps)) - - /** - * Sets [Builder.bps] to an arbitrary JSON value. - * - * You should usually call [Builder.bps] with a well-typed [Double] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun bps(bps: JsonField) = apply { this.bps = bps } - - /** Upper bound for tier */ - fun maximumAmount(maximumAmount: String?) = - maximumAmount(JsonField.ofNullable(maximumAmount)) - - /** - * Sets [Builder.maximumAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.maximumAmount] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun maximumAmount(maximumAmount: JsonField) = apply { - this.maximumAmount = maximumAmount - } - - /** The maximum amount to charge for any one event */ - fun perUnitMaximum(perUnitMaximum: String?) = - perUnitMaximum(JsonField.ofNullable(perUnitMaximum)) - - /** - * Sets [Builder.perUnitMaximum] to an arbitrary JSON value. - * - * You should usually call [Builder.perUnitMaximum] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun perUnitMaximum(perUnitMaximum: JsonField) = apply { - this.perUnitMaximum = perUnitMaximum - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [BulkBpsTier]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .bps() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): BulkBpsTier = - BulkBpsTier( - checkRequired("bps", bps), - maximumAmount, - perUnitMaximum, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): BulkBpsTier = apply { - if (validated) { - return@apply - } - - bps() - maximumAmount() - perUnitMaximum() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (bps.asKnown() == null) 0 else 1) + - (if (maximumAmount.asKnown() == null) 0 else 1) + - (if (perUnitMaximum.asKnown() == null) 0 else 1) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is BulkBpsTier && bps == other.bps && maximumAmount == other.maximumAmount && perUnitMaximum == other.perUnitMaximum && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bps, maximumAmount, perUnitMaximum, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "BulkBpsTier{bps=$bps, maximumAmount=$maximumAmount, perUnitMaximum=$perUnitMaximum, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkConfig.kt index bf2086016..49850b0e7 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkConfig.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkConfig.kt @@ -17,7 +17,9 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects +/** Configuration for bulk pricing */ class BulkConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val tiers: JsonField>, private val additionalProperties: MutableMap, @@ -172,12 +174,12 @@ private constructor( return true } - return /* spotless:off */ other is BulkConfig && tiers == other.tiers && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BulkConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkTier.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkTier.kt index f3a6f8ee6..28666fb0b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkTier.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/BulkTier.kt @@ -15,7 +15,9 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects +/** Configuration for a single bulk pricing tier */ class BulkTier +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val unitAmount: JsonField, private val maximumUnits: JsonField, @@ -208,12 +210,15 @@ private constructor( return true } - return /* spotless:off */ other is BulkTier && unitAmount == other.unitAmount && maximumUnits == other.maximumUnits && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BulkTier && + unitAmount == other.unitAmount && + maximumUnits == other.maximumUnits && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(unitAmount, maximumUnits, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(unitAmount, maximumUnits, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ChangedSubscriptionResources.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ChangedSubscriptionResources.kt index 640e10adb..d819c13d7 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ChangedSubscriptionResources.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ChangedSubscriptionResources.kt @@ -6,21 +6,34 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.BaseDeserializer +import com.withorb.api.core.BaseSerializer +import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired +import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects class ChangedSubscriptionResources +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val createdCreditNotes: JsonField>, - private val createdInvoices: JsonField>, + private val createdInvoices: JsonField>, private val voidedCreditNotes: JsonField>, private val voidedInvoices: JsonField>, private val additionalProperties: MutableMap, @@ -33,7 +46,7 @@ private constructor( createdCreditNotes: JsonField> = JsonMissing.of(), @JsonProperty("created_invoices") @ExcludeMissing - createdInvoices: JsonField> = JsonMissing.of(), + createdInvoices: JsonField> = JsonMissing.of(), @JsonProperty("voided_credit_notes") @ExcludeMissing voidedCreditNotes: JsonField> = JsonMissing.of(), @@ -57,7 +70,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun createdInvoices(): List = createdInvoices.getRequired("created_invoices") + fun createdInvoices(): List = createdInvoices.getRequired("created_invoices") /** * The credit notes that were voided as part of this operation. @@ -92,7 +105,7 @@ private constructor( */ @JsonProperty("created_invoices") @ExcludeMissing - fun _createdInvoices(): JsonField> = createdInvoices + fun _createdInvoices(): JsonField> = createdInvoices /** * Returns the raw JSON value of [voidedCreditNotes]. @@ -145,7 +158,7 @@ private constructor( class Builder internal constructor() { private var createdCreditNotes: JsonField>? = null - private var createdInvoices: JsonField>? = null + private var createdInvoices: JsonField>? = null private var voidedCreditNotes: JsonField>? = null private var voidedInvoices: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -189,26 +202,26 @@ private constructor( } /** The invoices that were created as part of this operation. */ - fun createdInvoices(createdInvoices: List) = + fun createdInvoices(createdInvoices: List) = createdInvoices(JsonField.of(createdInvoices)) /** * Sets [Builder.createdInvoices] to an arbitrary JSON value. * - * You should usually call [Builder.createdInvoices] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * You should usually call [Builder.createdInvoices] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. */ - fun createdInvoices(createdInvoices: JsonField>) = apply { + fun createdInvoices(createdInvoices: JsonField>) = apply { this.createdInvoices = createdInvoices.map { it.toMutableList() } } /** - * Adds a single [Invoice] to [createdInvoices]. + * Adds a single [CreatedInvoice] to [createdInvoices]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addCreatedInvoice(createdInvoice: Invoice) = apply { + fun addCreatedInvoice(createdInvoice: CreatedInvoice) = apply { createdInvoices = (createdInvoices ?: JsonField.of(mutableListOf())).also { checkKnown("createdInvoices", it).add(createdInvoice) @@ -346,17 +359,6712 @@ private constructor( (voidedCreditNotes.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (voidedInvoices.asKnown()?.sumOf { it.validity().toInt() } ?: 0) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + class CreatedInvoice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val amountDue: JsonField, + private val autoCollection: JsonField, + private val billingAddress: JsonField
, + private val createdAt: JsonField, + private val creditNotes: JsonField>, + private val currency: JsonField, + private val customer: JsonField, + private val customerBalanceTransactions: JsonField>, + private val customerTaxId: JsonField, + private val discount: JsonValue, + private val discounts: JsonField>, + private val dueDate: JsonField, + private val eligibleToIssueAt: JsonField, + private val hostedInvoiceUrl: JsonField, + private val invoiceDate: JsonField, + private val invoiceNumber: JsonField, + private val invoicePdf: JsonField, + private val invoiceSource: JsonField, + private val isPayableNow: JsonField, + private val issueFailedAt: JsonField, + private val issuedAt: JsonField, + private val lineItems: JsonField>, + private val maximum: JsonField, + private val maximumAmount: JsonField, + private val memo: JsonField, + private val metadata: JsonField, + private val minimum: JsonField, + private val minimumAmount: JsonField, + private val paidAt: JsonField, + private val paymentAttempts: JsonField>, + private val paymentFailedAt: JsonField, + private val paymentStartedAt: JsonField, + private val scheduledIssueAt: JsonField, + private val shippingAddress: JsonField
, + private val status: JsonField, + private val subscription: JsonField, + private val subtotal: JsonField, + private val syncFailedAt: JsonField, + private val total: JsonField, + private val voidedAt: JsonField, + private val willAutoIssue: JsonField, + private val additionalProperties: MutableMap, + ) { - return /* spotless:off */ other is ChangedSubscriptionResources && createdCreditNotes == other.createdCreditNotes && createdInvoices == other.createdInvoices && voidedCreditNotes == other.voidedCreditNotes && voidedInvoices == other.voidedInvoices && additionalProperties == other.additionalProperties /* spotless:on */ - } + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("amount_due") + @ExcludeMissing + amountDue: JsonField = JsonMissing.of(), + @JsonProperty("auto_collection") + @ExcludeMissing + autoCollection: JsonField = JsonMissing.of(), + @JsonProperty("billing_address") + @ExcludeMissing + billingAddress: JsonField
= JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("credit_notes") + @ExcludeMissing + creditNotes: JsonField> = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("customer") + @ExcludeMissing + customer: JsonField = JsonMissing.of(), + @JsonProperty("customer_balance_transactions") + @ExcludeMissing + customerBalanceTransactions: JsonField> = + JsonMissing.of(), + @JsonProperty("customer_tax_id") + @ExcludeMissing + customerTaxId: JsonField = JsonMissing.of(), + @JsonProperty("discount") @ExcludeMissing discount: JsonValue = JsonMissing.of(), + @JsonProperty("discounts") + @ExcludeMissing + discounts: JsonField> = JsonMissing.of(), + @JsonProperty("due_date") + @ExcludeMissing + dueDate: JsonField = JsonMissing.of(), + @JsonProperty("eligible_to_issue_at") + @ExcludeMissing + eligibleToIssueAt: JsonField = JsonMissing.of(), + @JsonProperty("hosted_invoice_url") + @ExcludeMissing + hostedInvoiceUrl: JsonField = JsonMissing.of(), + @JsonProperty("invoice_date") + @ExcludeMissing + invoiceDate: JsonField = JsonMissing.of(), + @JsonProperty("invoice_number") + @ExcludeMissing + invoiceNumber: JsonField = JsonMissing.of(), + @JsonProperty("invoice_pdf") + @ExcludeMissing + invoicePdf: JsonField = JsonMissing.of(), + @JsonProperty("invoice_source") + @ExcludeMissing + invoiceSource: JsonField = JsonMissing.of(), + @JsonProperty("is_payable_now") + @ExcludeMissing + isPayableNow: JsonField = JsonMissing.of(), + @JsonProperty("issue_failed_at") + @ExcludeMissing + issueFailedAt: JsonField = JsonMissing.of(), + @JsonProperty("issued_at") + @ExcludeMissing + issuedAt: JsonField = JsonMissing.of(), + @JsonProperty("line_items") + @ExcludeMissing + lineItems: JsonField> = JsonMissing.of(), + @JsonProperty("maximum") @ExcludeMissing maximum: JsonField = JsonMissing.of(), + @JsonProperty("maximum_amount") + @ExcludeMissing + maximumAmount: JsonField = JsonMissing.of(), + @JsonProperty("memo") @ExcludeMissing memo: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("minimum") @ExcludeMissing minimum: JsonField = JsonMissing.of(), + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("paid_at") + @ExcludeMissing + paidAt: JsonField = JsonMissing.of(), + @JsonProperty("payment_attempts") + @ExcludeMissing + paymentAttempts: JsonField> = JsonMissing.of(), + @JsonProperty("payment_failed_at") + @ExcludeMissing + paymentFailedAt: JsonField = JsonMissing.of(), + @JsonProperty("payment_started_at") + @ExcludeMissing + paymentStartedAt: JsonField = JsonMissing.of(), + @JsonProperty("scheduled_issue_at") + @ExcludeMissing + scheduledIssueAt: JsonField = JsonMissing.of(), + @JsonProperty("shipping_address") + @ExcludeMissing + shippingAddress: JsonField
= JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("subscription") + @ExcludeMissing + subscription: JsonField = JsonMissing.of(), + @JsonProperty("subtotal") + @ExcludeMissing + subtotal: JsonField = JsonMissing.of(), + @JsonProperty("sync_failed_at") + @ExcludeMissing + syncFailedAt: JsonField = JsonMissing.of(), + @JsonProperty("total") @ExcludeMissing total: JsonField = JsonMissing.of(), + @JsonProperty("voided_at") + @ExcludeMissing + voidedAt: JsonField = JsonMissing.of(), + @JsonProperty("will_auto_issue") + @ExcludeMissing + willAutoIssue: JsonField = JsonMissing.of(), + ) : this( + id, + amountDue, + autoCollection, + billingAddress, + createdAt, + creditNotes, + currency, + customer, + customerBalanceTransactions, + customerTaxId, + discount, + discounts, + dueDate, + eligibleToIssueAt, + hostedInvoiceUrl, + invoiceDate, + invoiceNumber, + invoicePdf, + invoiceSource, + isPayableNow, + issueFailedAt, + issuedAt, + lineItems, + maximum, + maximumAmount, + memo, + metadata, + minimum, + minimumAmount, + paidAt, + paymentAttempts, + paymentFailedAt, + paymentStartedAt, + scheduledIssueAt, + shippingAddress, + status, + subscription, + subtotal, + syncFailedAt, + total, + voidedAt, + willAutoIssue, + mutableMapOf(), + ) + + /** + * @throws OrbInvalidDataException if 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") + + /** + * This is the final amount required to be charged to the customer and reflects the + * application of the customer balance to the `total` of the invoice. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun amountDue(): String = amountDue.getRequired("amount_due") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun autoCollection(): AutoCollection = autoCollection.getRequired("auto_collection") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billingAddress(): Address? = billingAddress.getNullable("billing_address") + + /** + * The creation time of the resource in Orb. + * + * @throws OrbInvalidDataException if 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") + + /** + * A list of credit notes associated with the invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun creditNotes(): List = creditNotes.getRequired("credit_notes") + + /** + * An ISO 4217 currency string or `credits` + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun customer(): CustomerMinified = customer.getRequired("customer") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun customerBalanceTransactions(): List = + customerBalanceTransactions.getRequired("customer_balance_transactions") + + /** + * Tax IDs are commonly required to be displayed on customer invoices, which are added to + * the headers of invoices. + * + * ### Supported Tax ID Countries and Types + * |Country |Type |Description | + * |----------------------|------------|-------------------------------------------------------------------------------------------------------| + * |Albania |`al_tin` |Albania Tax Identification Number | + * |Andorra |`ad_nrt` |Andorran NRT Number | + * |Angola |`ao_tin` |Angola Tax Identification Number | + * |Argentina |`ar_cuit` |Argentinian Tax ID Number | + * |Armenia |`am_tin` |Armenia Tax Identification Number | + * |Aruba |`aw_tin` |Aruba Tax Identification Number | + * |Australia |`au_abn` |Australian Business Number (AU ABN) | + * |Australia |`au_arn` |Australian Taxation Office Reference Number | + * |Austria |`eu_vat` |European VAT Number | + * |Azerbaijan |`az_tin` |Azerbaijan Tax Identification Number | + * |Bahamas |`bs_tin` |Bahamas Tax Identification Number | + * |Bahrain |`bh_vat` |Bahraini VAT Number | + * |Bangladesh |`bd_bin` |Bangladesh Business Identification Number | + * |Barbados |`bb_tin` |Barbados Tax Identification Number | + * |Belarus |`by_tin` |Belarus TIN Number | + * |Belgium |`eu_vat` |European VAT Number | + * |Benin |`bj_ifu` |Benin Tax Identification Number (Identifiant Fiscal Unique) | + * |Bolivia |`bo_tin` |Bolivian Tax ID | + * |Bosnia and Herzegovina|`ba_tin` |Bosnia and Herzegovina Tax Identification Number | + * |Brazil |`br_cnpj` |Brazilian CNPJ Number | + * |Brazil |`br_cpf` |Brazilian CPF Number | + * |Bulgaria |`bg_uic` |Bulgaria Unified Identification Code | + * |Bulgaria |`eu_vat` |European VAT Number | + * |Burkina Faso |`bf_ifu` |Burkina Faso Tax Identification Number (Numéro d'Identifiant Fiscal Unique) | + * |Cambodia |`kh_tin` |Cambodia Tax Identification Number | + * |Cameroon |`cm_niu` |Cameroon Tax Identification Number (Numéro d'Identifiant fiscal Unique) | + * |Canada |`ca_bn` |Canadian BN | + * |Canada |`ca_gst_hst`|Canadian GST/HST Number | + * |Canada |`ca_pst_bc` |Canadian PST Number (British Columbia) | + * |Canada |`ca_pst_mb` |Canadian PST Number (Manitoba) | + * |Canada |`ca_pst_sk` |Canadian PST Number (Saskatchewan) | + * |Canada |`ca_qst` |Canadian QST Number (Québec) | + * |Cape Verde |`cv_nif` |Cape Verde Tax Identification Number (Número de Identificação Fiscal) | + * |Chile |`cl_tin` |Chilean TIN | + * |China |`cn_tin` |Chinese Tax ID | + * |Colombia |`co_nit` |Colombian NIT Number | + * |Congo-Kinshasa |`cd_nif` |Congo (DR) Tax Identification Number (Número de Identificação Fiscal) | + * |Costa Rica |`cr_tin` |Costa Rican Tax ID | + * |Croatia |`eu_vat` |European VAT Number | + * |Croatia |`hr_oib` |Croatian Personal Identification Number (OIB) | + * |Cyprus |`eu_vat` |European VAT Number | + * |Czech Republic |`eu_vat` |European VAT Number | + * |Denmark |`eu_vat` |European VAT Number | + * |Dominican Republic |`do_rcn` |Dominican RCN Number | + * |Ecuador |`ec_ruc` |Ecuadorian RUC Number | + * |Egypt |`eg_tin` |Egyptian Tax Identification Number | + * |El Salvador |`sv_nit` |El Salvadorian NIT Number | + * |Estonia |`eu_vat` |European VAT Number | + * |Ethiopia |`et_tin` |Ethiopia Tax Identification Number | + * |European Union |`eu_oss_vat`|European One Stop Shop VAT Number for non-Union scheme | + * |Finland |`eu_vat` |European VAT Number | + * |France |`eu_vat` |European VAT Number | + * |Georgia |`ge_vat` |Georgian VAT | + * |Germany |`de_stn` |German Tax Number (Steuernummer) | + * |Germany |`eu_vat` |European VAT Number | + * |Greece |`eu_vat` |European VAT Number | + * |Guinea |`gn_nif` |Guinea Tax Identification Number (Número de Identificação Fiscal) | + * |Hong Kong |`hk_br` |Hong Kong BR Number | + * |Hungary |`eu_vat` |European VAT Number | + * |Hungary |`hu_tin` |Hungary Tax Number (adószám) | + * |Iceland |`is_vat` |Icelandic VAT | + * |India |`in_gst` |Indian GST Number | + * |Indonesia |`id_npwp` |Indonesian NPWP Number | + * |Ireland |`eu_vat` |European VAT Number | + * |Israel |`il_vat` |Israel VAT | + * |Italy |`eu_vat` |European VAT Number | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | + * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | + * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | + * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | + * |Laos |`la_tin` |Laos Tax Identification Number | + * |Latvia |`eu_vat` |European VAT Number | + * |Liechtenstein |`li_uid` |Liechtensteinian UID Number | + * |Liechtenstein |`li_vat` |Liechtenstein VAT Number | + * |Lithuania |`eu_vat` |European VAT Number | + * |Luxembourg |`eu_vat` |European VAT Number | + * |Malaysia |`my_frp` |Malaysian FRP Number | + * |Malaysia |`my_itn` |Malaysian ITN | + * |Malaysia |`my_sst` |Malaysian SST Number | + * |Malta |`eu_vat` |European VAT Number | + * |Mauritania |`mr_nif` |Mauritania Tax Identification Number (Número de Identificação Fiscal) | + * |Mexico |`mx_rfc` |Mexican RFC Number | + * |Moldova |`md_vat` |Moldova VAT Number | + * |Montenegro |`me_pib` |Montenegro PIB Number | + * |Morocco |`ma_vat` |Morocco VAT Number | + * |Nepal |`np_pan` |Nepal PAN Number | + * |Netherlands |`eu_vat` |European VAT Number | + * |New Zealand |`nz_gst` |New Zealand GST Number | + * |Nigeria |`ng_tin` |Nigerian Tax Identification Number | + * |North Macedonia |`mk_vat` |North Macedonia VAT Number | + * |Northern Ireland |`eu_vat` |Northern Ireland VAT Number | + * |Norway |`no_vat` |Norwegian VAT Number | + * |Norway |`no_voec` |Norwegian VAT on e-commerce Number | + * |Oman |`om_vat` |Omani VAT Number | + * |Peru |`pe_ruc` |Peruvian RUC Number | + * |Philippines |`ph_tin` |Philippines Tax Identification Number | + * |Poland |`eu_vat` |European VAT Number | + * |Portugal |`eu_vat` |European VAT Number | + * |Romania |`eu_vat` |European VAT Number | + * |Romania |`ro_tin` |Romanian Tax ID Number | + * |Russia |`ru_inn` |Russian INN | + * |Russia |`ru_kpp` |Russian KPP | + * |Saudi Arabia |`sa_vat` |Saudi Arabia VAT | + * |Senegal |`sn_ninea` |Senegal NINEA Number | + * |Serbia |`rs_pib` |Serbian PIB Number | + * |Singapore |`sg_gst` |Singaporean GST | + * |Singapore |`sg_uen` |Singaporean UEN | + * |Slovakia |`eu_vat` |European VAT Number | + * |Slovenia |`eu_vat` |European VAT Number | + * |Slovenia |`si_tin` |Slovenia Tax Number (davčna številka) | + * |South Africa |`za_vat` |South African VAT Number | + * |South Korea |`kr_brn` |Korean BRN | + * |Spain |`es_cif` |Spanish NIF Number (previously Spanish CIF Number) | + * |Spain |`eu_vat` |European VAT Number | + * |Suriname |`sr_fin` |Suriname FIN Number | + * |Sweden |`eu_vat` |European VAT Number | + * |Switzerland |`ch_uid` |Switzerland UID Number | + * |Switzerland |`ch_vat` |Switzerland VAT Number | + * |Taiwan |`tw_vat` |Taiwanese VAT | + * |Tajikistan |`tj_tin` |Tajikistan Tax Identification Number | + * |Tanzania |`tz_vat` |Tanzania VAT Number | + * |Thailand |`th_vat` |Thai VAT | + * |Turkey |`tr_tin` |Turkish Tax Identification Number | + * |Uganda |`ug_tin` |Uganda Tax Identification Number | + * |Ukraine |`ua_vat` |Ukrainian VAT | + * |United Arab Emirates |`ae_trn` |United Arab Emirates TRN | + * |United Kingdom |`gb_vat` |United Kingdom VAT Number | + * |United States |`us_ein` |United States EIN | + * |Uruguay |`uy_ruc` |Uruguayan RUC Number | + * |Uzbekistan |`uz_tin` |Uzbekistan TIN Number | + * |Uzbekistan |`uz_vat` |Uzbekistan VAT Number | + * |Venezuela |`ve_rif` |Venezuelan RIF Number | + * |Vietnam |`vn_tin` |Vietnamese Tax ID Number | + * |Zambia |`zm_tin` |Zambia Tax Identification Number | + * |Zimbabwe |`zw_tin` |Zimbabwe Tax Identification Number | + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun customerTaxId(): CustomerTaxId? = customerTaxId.getNullable("customer_tax_id") + + /** + * This field is deprecated in favor of `discounts`. If a `discounts` list is provided, the + * first discount in the list will be returned. If the list is empty, `None` will be + * returned. + */ + @Deprecated("deprecated") + @JsonProperty("discount") + @ExcludeMissing + fun _discount(): JsonValue = discount + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun discounts(): List = discounts.getRequired("discounts") + + /** + * When the invoice payment is due. The due date is null if the invoice is not yet + * finalized. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dueDate(): OffsetDateTime? = dueDate.getNullable("due_date") + + /** + * If the invoice has a status of `draft`, this will be the time that the invoice will be + * eligible to be issued, otherwise it will be `null`. If `auto-issue` is true, the invoice + * will automatically begin issuing at this time. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun eligibleToIssueAt(): OffsetDateTime? = + eligibleToIssueAt.getNullable("eligible_to_issue_at") + + /** + * A URL for the customer-facing invoice portal. This URL expires 30 days after the + * invoice's due date, or 60 days after being re-generated through the UI. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun hostedInvoiceUrl(): String? = hostedInvoiceUrl.getNullable("hosted_invoice_url") + + /** + * The scheduled date of the invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun invoiceDate(): OffsetDateTime = invoiceDate.getRequired("invoice_date") + + /** + * Automatically generated invoice number to help track and reconcile invoices. Invoice + * numbers have a prefix such as `RFOBWG`. These can be sequential per account or customer. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun invoiceNumber(): String = invoiceNumber.getRequired("invoice_number") + + /** + * The link to download the PDF representation of the `Invoice`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoicePdf(): String? = invoicePdf.getNullable("invoice_pdf") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun invoiceSource(): InvoiceSource = invoiceSource.getRequired("invoice_source") + + /** + * True if the invoice has only in-advance fixed fees and is payable now + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun isPayableNow(): Boolean = isPayableNow.getRequired("is_payable_now") + + /** + * If the invoice failed to issue, this will be the last time it failed to issue (even if it + * is now in a different state.) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun issueFailedAt(): OffsetDateTime? = issueFailedAt.getNullable("issue_failed_at") + + /** + * If the invoice has been issued, this will be the time it transitioned to `issued` (even + * if it is now in a different state.) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun issuedAt(): OffsetDateTime? = issuedAt.getNullable("issued_at") + + /** + * The breakdown of prices in this invoice. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun lineItems(): List = lineItems.getRequired("line_items") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun maximum(): Maximum? = maximum.getNullable("maximum") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun maximumAmount(): String? = maximumAmount.getNullable("maximum_amount") + + /** + * Free-form text which is available on the invoice PDF and the Orb invoice portal. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun memo(): String? = memo.getNullable("memo") + + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and the + * entire metadata mapping can be cleared by setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun metadata(): Metadata = metadata.getRequired("metadata") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun minimum(): Minimum? = minimum.getNullable("minimum") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") + + /** + * If the invoice has a status of `paid`, this gives a timestamp when the invoice was paid. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun paidAt(): OffsetDateTime? = paidAt.getNullable("paid_at") + + /** + * A list of payment attempts associated with the invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun paymentAttempts(): List = + paymentAttempts.getRequired("payment_attempts") + + /** + * If payment was attempted on this invoice but failed, this will be the time of the most + * recent attempt. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun paymentFailedAt(): OffsetDateTime? = paymentFailedAt.getNullable("payment_failed_at") + + /** + * If payment was attempted on this invoice, this will be the start time of the most recent + * attempt. This field is especially useful for delayed-notification payment mechanisms + * (like bank transfers), where payment can take 3 days or more. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun paymentStartedAt(): OffsetDateTime? = paymentStartedAt.getNullable("payment_started_at") + + /** + * If the invoice is in draft, this timestamp will reflect when the invoice is scheduled to + * be issued. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun scheduledIssueAt(): OffsetDateTime? = scheduledIssueAt.getNullable("scheduled_issue_at") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun shippingAddress(): Address? = shippingAddress.getNullable("shipping_address") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun status(): Status = status.getRequired("status") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun subscription(): SubscriptionMinified? = subscription.getNullable("subscription") + + /** + * The total before any discounts and minimums are applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun subtotal(): String = subtotal.getRequired("subtotal") + + /** + * If the invoice failed to sync, this will be the last time an external invoicing provider + * sync was attempted. This field will always be `null` for invoices using Orb Invoicing. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun syncFailedAt(): OffsetDateTime? = syncFailedAt.getNullable("sync_failed_at") + + /** + * The total after any minimums and discounts have been applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun total(): String = total.getRequired("total") + + /** + * If the invoice has a status of `void`, this gives a timestamp when the invoice was + * voided. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun voidedAt(): OffsetDateTime? = voidedAt.getNullable("voided_at") + + /** + * This is true if the invoice will be automatically issued in the future, and false + * otherwise. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun willAutoIssue(): Boolean = willAutoIssue.getRequired("will_auto_issue") + + /** + * 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 [amountDue]. + * + * Unlike [amountDue], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("amount_due") @ExcludeMissing fun _amountDue(): JsonField = amountDue + + /** + * Returns the raw JSON value of [autoCollection]. + * + * Unlike [autoCollection], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("auto_collection") + @ExcludeMissing + fun _autoCollection(): JsonField = autoCollection + + /** + * Returns the raw JSON value of [billingAddress]. + * + * Unlike [billingAddress], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("billing_address") + @ExcludeMissing + fun _billingAddress(): JsonField
= billingAddress + + /** + * 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 [creditNotes]. + * + * Unlike [creditNotes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("credit_notes") + @ExcludeMissing + fun _creditNotes(): JsonField> = creditNotes + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [customer]. + * + * Unlike [customer], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("customer") + @ExcludeMissing + fun _customer(): JsonField = customer + + /** + * Returns the raw JSON value of [customerBalanceTransactions]. + * + * Unlike [customerBalanceTransactions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("customer_balance_transactions") + @ExcludeMissing + fun _customerBalanceTransactions(): JsonField> = + customerBalanceTransactions + + /** + * Returns the raw JSON value of [customerTaxId]. + * + * Unlike [customerTaxId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("customer_tax_id") + @ExcludeMissing + fun _customerTaxId(): JsonField = customerTaxId + + /** + * Returns the raw JSON value of [discounts]. + * + * Unlike [discounts], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("discounts") + @ExcludeMissing + fun _discounts(): JsonField> = discounts + + /** + * Returns the raw JSON value of [dueDate]. + * + * Unlike [dueDate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("due_date") + @ExcludeMissing + fun _dueDate(): JsonField = dueDate + + /** + * Returns the raw JSON value of [eligibleToIssueAt]. + * + * Unlike [eligibleToIssueAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("eligible_to_issue_at") + @ExcludeMissing + fun _eligibleToIssueAt(): JsonField = eligibleToIssueAt + + /** + * Returns the raw JSON value of [hostedInvoiceUrl]. + * + * Unlike [hostedInvoiceUrl], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("hosted_invoice_url") + @ExcludeMissing + fun _hostedInvoiceUrl(): JsonField = hostedInvoiceUrl + + /** + * Returns the raw JSON value of [invoiceDate]. + * + * Unlike [invoiceDate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("invoice_date") + @ExcludeMissing + fun _invoiceDate(): JsonField = invoiceDate + + /** + * Returns the raw JSON value of [invoiceNumber]. + * + * Unlike [invoiceNumber], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("invoice_number") + @ExcludeMissing + fun _invoiceNumber(): JsonField = invoiceNumber - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(createdCreditNotes, createdInvoices, voidedCreditNotes, voidedInvoices, additionalProperties) } - /* spotless:on */ + /** + * Returns the raw JSON value of [invoicePdf]. + * + * Unlike [invoicePdf], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("invoice_pdf") + @ExcludeMissing + fun _invoicePdf(): JsonField = invoicePdf + + /** + * Returns the raw JSON value of [invoiceSource]. + * + * Unlike [invoiceSource], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("invoice_source") + @ExcludeMissing + fun _invoiceSource(): JsonField = invoiceSource + + /** + * Returns the raw JSON value of [isPayableNow]. + * + * Unlike [isPayableNow], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("is_payable_now") + @ExcludeMissing + fun _isPayableNow(): JsonField = isPayableNow + + /** + * Returns the raw JSON value of [issueFailedAt]. + * + * Unlike [issueFailedAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("issue_failed_at") + @ExcludeMissing + fun _issueFailedAt(): JsonField = issueFailedAt + + /** + * Returns the raw JSON value of [issuedAt]. + * + * Unlike [issuedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("issued_at") + @ExcludeMissing + fun _issuedAt(): JsonField = issuedAt + + /** + * Returns the raw JSON value of [lineItems]. + * + * Unlike [lineItems], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("line_items") + @ExcludeMissing + fun _lineItems(): JsonField> = lineItems + + /** + * Returns the raw JSON value of [maximum]. + * + * Unlike [maximum], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("maximum") @ExcludeMissing fun _maximum(): JsonField = maximum + + /** + * Returns the raw JSON value of [maximumAmount]. + * + * Unlike [maximumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("maximum_amount") + @ExcludeMissing + fun _maximumAmount(): JsonField = maximumAmount + + /** + * Returns the raw JSON value of [memo]. + * + * Unlike [memo], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("memo") @ExcludeMissing fun _memo(): JsonField = memo + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [minimum]. + * + * Unlike [minimum], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("minimum") @ExcludeMissing fun _minimum(): JsonField = minimum + + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount + + /** + * Returns the raw JSON value of [paidAt]. + * + * Unlike [paidAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("paid_at") @ExcludeMissing fun _paidAt(): JsonField = paidAt + + /** + * Returns the raw JSON value of [paymentAttempts]. + * + * Unlike [paymentAttempts], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("payment_attempts") + @ExcludeMissing + fun _paymentAttempts(): JsonField> = paymentAttempts + + /** + * Returns the raw JSON value of [paymentFailedAt]. + * + * Unlike [paymentFailedAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("payment_failed_at") + @ExcludeMissing + fun _paymentFailedAt(): JsonField = paymentFailedAt + + /** + * Returns the raw JSON value of [paymentStartedAt]. + * + * Unlike [paymentStartedAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("payment_started_at") + @ExcludeMissing + fun _paymentStartedAt(): JsonField = paymentStartedAt + + /** + * Returns the raw JSON value of [scheduledIssueAt]. + * + * Unlike [scheduledIssueAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scheduled_issue_at") + @ExcludeMissing + fun _scheduledIssueAt(): JsonField = scheduledIssueAt + + /** + * Returns the raw JSON value of [shippingAddress]. + * + * Unlike [shippingAddress], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("shipping_address") + @ExcludeMissing + fun _shippingAddress(): JsonField
= shippingAddress + + /** + * 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 [subscription]. + * + * Unlike [subscription], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("subscription") + @ExcludeMissing + fun _subscription(): JsonField = subscription + + /** + * Returns the raw JSON value of [subtotal]. + * + * Unlike [subtotal], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("subtotal") @ExcludeMissing fun _subtotal(): JsonField = subtotal + + /** + * Returns the raw JSON value of [syncFailedAt]. + * + * Unlike [syncFailedAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("sync_failed_at") + @ExcludeMissing + fun _syncFailedAt(): JsonField = syncFailedAt + + /** + * Returns the raw JSON value of [total]. + * + * Unlike [total], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("total") @ExcludeMissing fun _total(): JsonField = total + + /** + * Returns the raw JSON value of [voidedAt]. + * + * Unlike [voidedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("voided_at") + @ExcludeMissing + fun _voidedAt(): JsonField = voidedAt + + /** + * Returns the raw JSON value of [willAutoIssue]. + * + * Unlike [willAutoIssue], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("will_auto_issue") + @ExcludeMissing + fun _willAutoIssue(): JsonField = willAutoIssue + + @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 [CreatedInvoice]. + * + * The following fields are required: + * ```kotlin + * .id() + * .amountDue() + * .autoCollection() + * .billingAddress() + * .createdAt() + * .creditNotes() + * .currency() + * .customer() + * .customerBalanceTransactions() + * .customerTaxId() + * .discount() + * .discounts() + * .dueDate() + * .eligibleToIssueAt() + * .hostedInvoiceUrl() + * .invoiceDate() + * .invoiceNumber() + * .invoicePdf() + * .invoiceSource() + * .isPayableNow() + * .issueFailedAt() + * .issuedAt() + * .lineItems() + * .maximum() + * .maximumAmount() + * .memo() + * .metadata() + * .minimum() + * .minimumAmount() + * .paidAt() + * .paymentAttempts() + * .paymentFailedAt() + * .paymentStartedAt() + * .scheduledIssueAt() + * .shippingAddress() + * .status() + * .subscription() + * .subtotal() + * .syncFailedAt() + * .total() + * .voidedAt() + * .willAutoIssue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CreatedInvoice]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var amountDue: JsonField? = null + private var autoCollection: JsonField? = null + private var billingAddress: JsonField
? = null + private var createdAt: JsonField? = null + private var creditNotes: JsonField>? = null + private var currency: JsonField? = null + private var customer: JsonField? = null + private var customerBalanceTransactions: + JsonField>? = + null + private var customerTaxId: JsonField? = null + private var discount: JsonValue? = null + private var discounts: JsonField>? = null + private var dueDate: JsonField? = null + private var eligibleToIssueAt: JsonField? = null + private var hostedInvoiceUrl: JsonField? = null + private var invoiceDate: JsonField? = null + private var invoiceNumber: JsonField? = null + private var invoicePdf: JsonField? = null + private var invoiceSource: JsonField? = null + private var isPayableNow: JsonField? = null + private var issueFailedAt: JsonField? = null + private var issuedAt: JsonField? = null + private var lineItems: JsonField>? = null + private var maximum: JsonField? = null + private var maximumAmount: JsonField? = null + private var memo: JsonField? = null + private var metadata: JsonField? = null + private var minimum: JsonField? = null + private var minimumAmount: JsonField? = null + private var paidAt: JsonField? = null + private var paymentAttempts: JsonField>? = null + private var paymentFailedAt: JsonField? = null + private var paymentStartedAt: JsonField? = null + private var scheduledIssueAt: JsonField? = null + private var shippingAddress: JsonField
? = null + private var status: JsonField? = null + private var subscription: JsonField? = null + private var subtotal: JsonField? = null + private var syncFailedAt: JsonField? = null + private var total: JsonField? = null + private var voidedAt: JsonField? = null + private var willAutoIssue: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(createdInvoice: CreatedInvoice) = apply { + id = createdInvoice.id + amountDue = createdInvoice.amountDue + autoCollection = createdInvoice.autoCollection + billingAddress = createdInvoice.billingAddress + createdAt = createdInvoice.createdAt + creditNotes = createdInvoice.creditNotes.map { it.toMutableList() } + currency = createdInvoice.currency + customer = createdInvoice.customer + customerBalanceTransactions = + createdInvoice.customerBalanceTransactions.map { it.toMutableList() } + customerTaxId = createdInvoice.customerTaxId + discount = createdInvoice.discount + discounts = createdInvoice.discounts.map { it.toMutableList() } + dueDate = createdInvoice.dueDate + eligibleToIssueAt = createdInvoice.eligibleToIssueAt + hostedInvoiceUrl = createdInvoice.hostedInvoiceUrl + invoiceDate = createdInvoice.invoiceDate + invoiceNumber = createdInvoice.invoiceNumber + invoicePdf = createdInvoice.invoicePdf + invoiceSource = createdInvoice.invoiceSource + isPayableNow = createdInvoice.isPayableNow + issueFailedAt = createdInvoice.issueFailedAt + issuedAt = createdInvoice.issuedAt + lineItems = createdInvoice.lineItems.map { it.toMutableList() } + maximum = createdInvoice.maximum + maximumAmount = createdInvoice.maximumAmount + memo = createdInvoice.memo + metadata = createdInvoice.metadata + minimum = createdInvoice.minimum + minimumAmount = createdInvoice.minimumAmount + paidAt = createdInvoice.paidAt + paymentAttempts = createdInvoice.paymentAttempts.map { it.toMutableList() } + paymentFailedAt = createdInvoice.paymentFailedAt + paymentStartedAt = createdInvoice.paymentStartedAt + scheduledIssueAt = createdInvoice.scheduledIssueAt + shippingAddress = createdInvoice.shippingAddress + status = createdInvoice.status + subscription = createdInvoice.subscription + subtotal = createdInvoice.subtotal + syncFailedAt = createdInvoice.syncFailedAt + total = createdInvoice.total + voidedAt = createdInvoice.voidedAt + willAutoIssue = createdInvoice.willAutoIssue + additionalProperties = createdInvoice.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 } + + /** + * This is the final amount required to be charged to the customer and reflects the + * application of the customer balance to the `total` of the invoice. + */ + fun amountDue(amountDue: String) = amountDue(JsonField.of(amountDue)) + + /** + * Sets [Builder.amountDue] to an arbitrary JSON value. + * + * You should usually call [Builder.amountDue] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun amountDue(amountDue: JsonField) = apply { this.amountDue = amountDue } + + fun autoCollection(autoCollection: AutoCollection) = + autoCollection(JsonField.of(autoCollection)) + + /** + * Sets [Builder.autoCollection] to an arbitrary JSON value. + * + * You should usually call [Builder.autoCollection] with a well-typed [AutoCollection] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun autoCollection(autoCollection: JsonField) = apply { + this.autoCollection = autoCollection + } + + fun billingAddress(billingAddress: Address?) = + billingAddress(JsonField.ofNullable(billingAddress)) + + /** + * Sets [Builder.billingAddress] to an arbitrary JSON value. + * + * You should usually call [Builder.billingAddress] with a well-typed [Address] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingAddress(billingAddress: JsonField
) = apply { + this.billingAddress = billingAddress + } + + /** The creation time of the resource in Orb. */ + 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 + } + + /** A list of credit notes associated with the invoice */ + fun creditNotes(creditNotes: List) = creditNotes(JsonField.of(creditNotes)) + + /** + * Sets [Builder.creditNotes] to an arbitrary JSON value. + * + * You should usually call [Builder.creditNotes] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun creditNotes(creditNotes: JsonField>) = apply { + this.creditNotes = creditNotes.map { it.toMutableList() } + } + + /** + * Adds a single [CreditNote] to [creditNotes]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCreditNote(creditNote: CreditNote) = apply { + creditNotes = + (creditNotes ?: JsonField.of(mutableListOf())).also { + checkKnown("creditNotes", it).add(creditNote) + } + } + + /** An ISO 4217 currency string or `credits` */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + fun customer(customer: CustomerMinified) = customer(JsonField.of(customer)) + + /** + * Sets [Builder.customer] to an arbitrary JSON value. + * + * You should usually call [Builder.customer] with a well-typed [CustomerMinified] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun customer(customer: JsonField) = apply { this.customer = customer } + + fun customerBalanceTransactions( + customerBalanceTransactions: List + ) = customerBalanceTransactions(JsonField.of(customerBalanceTransactions)) + + /** + * Sets [Builder.customerBalanceTransactions] to an arbitrary JSON value. + * + * You should usually call [Builder.customerBalanceTransactions] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun customerBalanceTransactions( + customerBalanceTransactions: JsonField> + ) = apply { + this.customerBalanceTransactions = + customerBalanceTransactions.map { it.toMutableList() } + } + + /** + * Adds a single [CustomerBalanceTransaction] to [customerBalanceTransactions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCustomerBalanceTransaction( + customerBalanceTransaction: CustomerBalanceTransaction + ) = apply { + customerBalanceTransactions = + (customerBalanceTransactions ?: JsonField.of(mutableListOf())).also { + checkKnown("customerBalanceTransactions", it) + .add(customerBalanceTransaction) + } + } + + /** + * Tax IDs are commonly required to be displayed on customer invoices, which are added + * to the headers of invoices. + * + * ### Supported Tax ID Countries and Types + * |Country |Type |Description | + * |----------------------|------------|-------------------------------------------------------------------------------------------------------| + * |Albania |`al_tin` |Albania Tax Identification Number | + * |Andorra |`ad_nrt` |Andorran NRT Number | + * |Angola |`ao_tin` |Angola Tax Identification Number | + * |Argentina |`ar_cuit` |Argentinian Tax ID Number | + * |Armenia |`am_tin` |Armenia Tax Identification Number | + * |Aruba |`aw_tin` |Aruba Tax Identification Number | + * |Australia |`au_abn` |Australian Business Number (AU ABN) | + * |Australia |`au_arn` |Australian Taxation Office Reference Number | + * |Austria |`eu_vat` |European VAT Number | + * |Azerbaijan |`az_tin` |Azerbaijan Tax Identification Number | + * |Bahamas |`bs_tin` |Bahamas Tax Identification Number | + * |Bahrain |`bh_vat` |Bahraini VAT Number | + * |Bangladesh |`bd_bin` |Bangladesh Business Identification Number | + * |Barbados |`bb_tin` |Barbados Tax Identification Number | + * |Belarus |`by_tin` |Belarus TIN Number | + * |Belgium |`eu_vat` |European VAT Number | + * |Benin |`bj_ifu` |Benin Tax Identification Number (Identifiant Fiscal Unique) | + * |Bolivia |`bo_tin` |Bolivian Tax ID | + * |Bosnia and Herzegovina|`ba_tin` |Bosnia and Herzegovina Tax Identification Number | + * |Brazil |`br_cnpj` |Brazilian CNPJ Number | + * |Brazil |`br_cpf` |Brazilian CPF Number | + * |Bulgaria |`bg_uic` |Bulgaria Unified Identification Code | + * |Bulgaria |`eu_vat` |European VAT Number | + * |Burkina Faso |`bf_ifu` |Burkina Faso Tax Identification Number (Numéro d'Identifiant Fiscal Unique) | + * |Cambodia |`kh_tin` |Cambodia Tax Identification Number | + * |Cameroon |`cm_niu` |Cameroon Tax Identification Number (Numéro d'Identifiant fiscal Unique) | + * |Canada |`ca_bn` |Canadian BN | + * |Canada |`ca_gst_hst`|Canadian GST/HST Number | + * |Canada |`ca_pst_bc` |Canadian PST Number (British Columbia) | + * |Canada |`ca_pst_mb` |Canadian PST Number (Manitoba) | + * |Canada |`ca_pst_sk` |Canadian PST Number (Saskatchewan) | + * |Canada |`ca_qst` |Canadian QST Number (Québec) | + * |Cape Verde |`cv_nif` |Cape Verde Tax Identification Number (Número de Identificação Fiscal) | + * |Chile |`cl_tin` |Chilean TIN | + * |China |`cn_tin` |Chinese Tax ID | + * |Colombia |`co_nit` |Colombian NIT Number | + * |Congo-Kinshasa |`cd_nif` |Congo (DR) Tax Identification Number (Número de Identificação Fiscal) | + * |Costa Rica |`cr_tin` |Costa Rican Tax ID | + * |Croatia |`eu_vat` |European VAT Number | + * |Croatia |`hr_oib` |Croatian Personal Identification Number (OIB) | + * |Cyprus |`eu_vat` |European VAT Number | + * |Czech Republic |`eu_vat` |European VAT Number | + * |Denmark |`eu_vat` |European VAT Number | + * |Dominican Republic |`do_rcn` |Dominican RCN Number | + * |Ecuador |`ec_ruc` |Ecuadorian RUC Number | + * |Egypt |`eg_tin` |Egyptian Tax Identification Number | + * |El Salvador |`sv_nit` |El Salvadorian NIT Number | + * |Estonia |`eu_vat` |European VAT Number | + * |Ethiopia |`et_tin` |Ethiopia Tax Identification Number | + * |European Union |`eu_oss_vat`|European One Stop Shop VAT Number for non-Union scheme | + * |Finland |`eu_vat` |European VAT Number | + * |France |`eu_vat` |European VAT Number | + * |Georgia |`ge_vat` |Georgian VAT | + * |Germany |`de_stn` |German Tax Number (Steuernummer) | + * |Germany |`eu_vat` |European VAT Number | + * |Greece |`eu_vat` |European VAT Number | + * |Guinea |`gn_nif` |Guinea Tax Identification Number (Número de Identificação Fiscal) | + * |Hong Kong |`hk_br` |Hong Kong BR Number | + * |Hungary |`eu_vat` |European VAT Number | + * |Hungary |`hu_tin` |Hungary Tax Number (adószám) | + * |Iceland |`is_vat` |Icelandic VAT | + * |India |`in_gst` |Indian GST Number | + * |Indonesia |`id_npwp` |Indonesian NPWP Number | + * |Ireland |`eu_vat` |European VAT Number | + * |Israel |`il_vat` |Israel VAT | + * |Italy |`eu_vat` |European VAT Number | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | + * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | + * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | + * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | + * |Laos |`la_tin` |Laos Tax Identification Number | + * |Latvia |`eu_vat` |European VAT Number | + * |Liechtenstein |`li_uid` |Liechtensteinian UID Number | + * |Liechtenstein |`li_vat` |Liechtenstein VAT Number | + * |Lithuania |`eu_vat` |European VAT Number | + * |Luxembourg |`eu_vat` |European VAT Number | + * |Malaysia |`my_frp` |Malaysian FRP Number | + * |Malaysia |`my_itn` |Malaysian ITN | + * |Malaysia |`my_sst` |Malaysian SST Number | + * |Malta |`eu_vat` |European VAT Number | + * |Mauritania |`mr_nif` |Mauritania Tax Identification Number (Número de Identificação Fiscal) | + * |Mexico |`mx_rfc` |Mexican RFC Number | + * |Moldova |`md_vat` |Moldova VAT Number | + * |Montenegro |`me_pib` |Montenegro PIB Number | + * |Morocco |`ma_vat` |Morocco VAT Number | + * |Nepal |`np_pan` |Nepal PAN Number | + * |Netherlands |`eu_vat` |European VAT Number | + * |New Zealand |`nz_gst` |New Zealand GST Number | + * |Nigeria |`ng_tin` |Nigerian Tax Identification Number | + * |North Macedonia |`mk_vat` |North Macedonia VAT Number | + * |Northern Ireland |`eu_vat` |Northern Ireland VAT Number | + * |Norway |`no_vat` |Norwegian VAT Number | + * |Norway |`no_voec` |Norwegian VAT on e-commerce Number | + * |Oman |`om_vat` |Omani VAT Number | + * |Peru |`pe_ruc` |Peruvian RUC Number | + * |Philippines |`ph_tin` |Philippines Tax Identification Number | + * |Poland |`eu_vat` |European VAT Number | + * |Portugal |`eu_vat` |European VAT Number | + * |Romania |`eu_vat` |European VAT Number | + * |Romania |`ro_tin` |Romanian Tax ID Number | + * |Russia |`ru_inn` |Russian INN | + * |Russia |`ru_kpp` |Russian KPP | + * |Saudi Arabia |`sa_vat` |Saudi Arabia VAT | + * |Senegal |`sn_ninea` |Senegal NINEA Number | + * |Serbia |`rs_pib` |Serbian PIB Number | + * |Singapore |`sg_gst` |Singaporean GST | + * |Singapore |`sg_uen` |Singaporean UEN | + * |Slovakia |`eu_vat` |European VAT Number | + * |Slovenia |`eu_vat` |European VAT Number | + * |Slovenia |`si_tin` |Slovenia Tax Number (davčna številka) | + * |South Africa |`za_vat` |South African VAT Number | + * |South Korea |`kr_brn` |Korean BRN | + * |Spain |`es_cif` |Spanish NIF Number (previously Spanish CIF Number) | + * |Spain |`eu_vat` |European VAT Number | + * |Suriname |`sr_fin` |Suriname FIN Number | + * |Sweden |`eu_vat` |European VAT Number | + * |Switzerland |`ch_uid` |Switzerland UID Number | + * |Switzerland |`ch_vat` |Switzerland VAT Number | + * |Taiwan |`tw_vat` |Taiwanese VAT | + * |Tajikistan |`tj_tin` |Tajikistan Tax Identification Number | + * |Tanzania |`tz_vat` |Tanzania VAT Number | + * |Thailand |`th_vat` |Thai VAT | + * |Turkey |`tr_tin` |Turkish Tax Identification Number | + * |Uganda |`ug_tin` |Uganda Tax Identification Number | + * |Ukraine |`ua_vat` |Ukrainian VAT | + * |United Arab Emirates |`ae_trn` |United Arab Emirates TRN | + * |United Kingdom |`gb_vat` |United Kingdom VAT Number | + * |United States |`us_ein` |United States EIN | + * |Uruguay |`uy_ruc` |Uruguayan RUC Number | + * |Uzbekistan |`uz_tin` |Uzbekistan TIN Number | + * |Uzbekistan |`uz_vat` |Uzbekistan VAT Number | + * |Venezuela |`ve_rif` |Venezuelan RIF Number | + * |Vietnam |`vn_tin` |Vietnamese Tax ID Number | + * |Zambia |`zm_tin` |Zambia Tax Identification Number | + * |Zimbabwe |`zw_tin` |Zimbabwe Tax Identification Number | + */ + fun customerTaxId(customerTaxId: CustomerTaxId?) = + customerTaxId(JsonField.ofNullable(customerTaxId)) + + /** + * Sets [Builder.customerTaxId] to an arbitrary JSON value. + * + * You should usually call [Builder.customerTaxId] with a well-typed [CustomerTaxId] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun customerTaxId(customerTaxId: JsonField) = apply { + this.customerTaxId = customerTaxId + } + + /** + * This field is deprecated in favor of `discounts`. If a `discounts` list is provided, + * the first discount in the list will be returned. If the list is empty, `None` will be + * returned. + */ + @Deprecated("deprecated") + fun discount(discount: JsonValue) = apply { this.discount = discount } + + fun discounts(discounts: List) = + discounts(JsonField.of(discounts)) + + /** + * Sets [Builder.discounts] to an arbitrary JSON value. + * + * You should usually call [Builder.discounts] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun discounts(discounts: JsonField>) = apply { + this.discounts = discounts.map { it.toMutableList() } + } + + /** + * Adds a single [InvoiceLevelDiscount] to [discounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDiscount(discount: InvoiceLevelDiscount) = apply { + discounts = + (discounts ?: JsonField.of(mutableListOf())).also { + checkKnown("discounts", it).add(discount) + } + } + + /** + * Alias for calling [addDiscount] with `InvoiceLevelDiscount.ofPercentage(percentage)`. + */ + fun addDiscount(percentage: PercentageDiscount) = + addDiscount(InvoiceLevelDiscount.ofPercentage(percentage)) + + /** + * Alias for calling [addDiscount] with the following: + * ```kotlin + * PercentageDiscount.builder() + * .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + * .percentageDiscount(percentageDiscount) + * .build() + * ``` + */ + fun addPercentageDiscount(percentageDiscount: Double) = + addDiscount( + PercentageDiscount.builder() + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(percentageDiscount) + .build() + ) + + /** Alias for calling [addDiscount] with `InvoiceLevelDiscount.ofAmount(amount)`. */ + fun addDiscount(amount: AmountDiscount) = + addDiscount(InvoiceLevelDiscount.ofAmount(amount)) + + /** + * Alias for calling [addDiscount] with the following: + * ```kotlin + * AmountDiscount.builder() + * .discountType(AmountDiscount.DiscountType.AMOUNT) + * .amountDiscount(amountDiscount) + * .build() + * ``` + */ + fun addAmountDiscount(amountDiscount: String) = + addDiscount( + AmountDiscount.builder() + .discountType(AmountDiscount.DiscountType.AMOUNT) + .amountDiscount(amountDiscount) + .build() + ) + + /** Alias for calling [addDiscount] with `InvoiceLevelDiscount.ofTrial(trial)`. */ + fun addDiscount(trial: TrialDiscount) = addDiscount(InvoiceLevelDiscount.ofTrial(trial)) + + /** + * When the invoice payment is due. The due date is null if the invoice is not yet + * finalized. + */ + fun dueDate(dueDate: OffsetDateTime?) = dueDate(JsonField.ofNullable(dueDate)) + + /** + * Sets [Builder.dueDate] to an arbitrary JSON value. + * + * You should usually call [Builder.dueDate] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun dueDate(dueDate: JsonField) = apply { this.dueDate = dueDate } + + /** + * If the invoice has a status of `draft`, this will be the time that the invoice will + * be eligible to be issued, otherwise it will be `null`. If `auto-issue` is true, the + * invoice will automatically begin issuing at this time. + */ + fun eligibleToIssueAt(eligibleToIssueAt: OffsetDateTime?) = + eligibleToIssueAt(JsonField.ofNullable(eligibleToIssueAt)) + + /** + * Sets [Builder.eligibleToIssueAt] to an arbitrary JSON value. + * + * You should usually call [Builder.eligibleToIssueAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun eligibleToIssueAt(eligibleToIssueAt: JsonField) = apply { + this.eligibleToIssueAt = eligibleToIssueAt + } + + /** + * A URL for the customer-facing invoice portal. This URL expires 30 days after the + * invoice's due date, or 60 days after being re-generated through the UI. + */ + fun hostedInvoiceUrl(hostedInvoiceUrl: String?) = + hostedInvoiceUrl(JsonField.ofNullable(hostedInvoiceUrl)) + + /** + * Sets [Builder.hostedInvoiceUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.hostedInvoiceUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun hostedInvoiceUrl(hostedInvoiceUrl: JsonField) = apply { + this.hostedInvoiceUrl = hostedInvoiceUrl + } + + /** The scheduled date of the invoice */ + fun invoiceDate(invoiceDate: OffsetDateTime) = invoiceDate(JsonField.of(invoiceDate)) + + /** + * Sets [Builder.invoiceDate] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceDate] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun invoiceDate(invoiceDate: JsonField) = apply { + this.invoiceDate = invoiceDate + } + + /** + * Automatically generated invoice number to help track and reconcile invoices. Invoice + * numbers have a prefix such as `RFOBWG`. These can be sequential per account or + * customer. + */ + fun invoiceNumber(invoiceNumber: String) = invoiceNumber(JsonField.of(invoiceNumber)) + + /** + * Sets [Builder.invoiceNumber] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceNumber] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun invoiceNumber(invoiceNumber: JsonField) = apply { + this.invoiceNumber = invoiceNumber + } + + /** The link to download the PDF representation of the `Invoice`. */ + fun invoicePdf(invoicePdf: String?) = invoicePdf(JsonField.ofNullable(invoicePdf)) + + /** + * Sets [Builder.invoicePdf] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicePdf] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun invoicePdf(invoicePdf: JsonField) = apply { this.invoicePdf = invoicePdf } + + fun invoiceSource(invoiceSource: InvoiceSource) = + invoiceSource(JsonField.of(invoiceSource)) + + /** + * Sets [Builder.invoiceSource] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceSource] with a well-typed [InvoiceSource] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun invoiceSource(invoiceSource: JsonField) = apply { + this.invoiceSource = invoiceSource + } + + /** True if the invoice has only in-advance fixed fees and is payable now */ + fun isPayableNow(isPayableNow: Boolean) = isPayableNow(JsonField.of(isPayableNow)) + + /** + * Sets [Builder.isPayableNow] to an arbitrary JSON value. + * + * You should usually call [Builder.isPayableNow] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isPayableNow(isPayableNow: JsonField) = apply { + this.isPayableNow = isPayableNow + } + + /** + * If the invoice failed to issue, this will be the last time it failed to issue (even + * if it is now in a different state.) + */ + fun issueFailedAt(issueFailedAt: OffsetDateTime?) = + issueFailedAt(JsonField.ofNullable(issueFailedAt)) + + /** + * Sets [Builder.issueFailedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.issueFailedAt] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun issueFailedAt(issueFailedAt: JsonField) = apply { + this.issueFailedAt = issueFailedAt + } + + /** + * If the invoice has been issued, this will be the time it transitioned to `issued` + * (even if it is now in a different state.) + */ + fun issuedAt(issuedAt: OffsetDateTime?) = issuedAt(JsonField.ofNullable(issuedAt)) + + /** + * Sets [Builder.issuedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.issuedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun issuedAt(issuedAt: JsonField) = apply { this.issuedAt = issuedAt } + + /** The breakdown of prices in this invoice. */ + fun lineItems(lineItems: List) = lineItems(JsonField.of(lineItems)) + + /** + * Sets [Builder.lineItems] to an arbitrary JSON value. + * + * You should usually call [Builder.lineItems] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lineItems(lineItems: JsonField>) = apply { + this.lineItems = lineItems.map { it.toMutableList() } + } + + /** + * Adds a single [LineItem] to [lineItems]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addLineItem(lineItem: LineItem) = apply { + lineItems = + (lineItems ?: JsonField.of(mutableListOf())).also { + checkKnown("lineItems", it).add(lineItem) + } + } + + fun maximum(maximum: Maximum?) = maximum(JsonField.ofNullable(maximum)) + + /** + * Sets [Builder.maximum] to an arbitrary JSON value. + * + * You should usually call [Builder.maximum] with a well-typed [Maximum] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maximum(maximum: JsonField) = apply { this.maximum = maximum } + + fun maximumAmount(maximumAmount: String?) = + maximumAmount(JsonField.ofNullable(maximumAmount)) + + /** + * Sets [Builder.maximumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maximumAmount(maximumAmount: JsonField) = apply { + this.maximumAmount = maximumAmount + } + + /** Free-form text which is available on the invoice PDF and the Orb invoice portal. */ + fun memo(memo: String?) = memo(JsonField.ofNullable(memo)) + + /** + * Sets [Builder.memo] to an arbitrary JSON value. + * + * You should usually call [Builder.memo] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun memo(memo: JsonField) = apply { this.memo = memo } + + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and + * the entire metadata mapping can be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun minimum(minimum: Minimum?) = minimum(JsonField.ofNullable(minimum)) + + /** + * Sets [Builder.minimum] to an arbitrary JSON value. + * + * You should usually call [Builder.minimum] with a well-typed [Minimum] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimum(minimum: JsonField) = apply { this.minimum = minimum } + + fun minimumAmount(minimumAmount: String?) = + minimumAmount(JsonField.ofNullable(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } + + /** + * If the invoice has a status of `paid`, this gives a timestamp when the invoice was + * paid. + */ + fun paidAt(paidAt: OffsetDateTime?) = paidAt(JsonField.ofNullable(paidAt)) + + /** + * Sets [Builder.paidAt] to an arbitrary JSON value. + * + * You should usually call [Builder.paidAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun paidAt(paidAt: JsonField) = apply { this.paidAt = paidAt } + + /** A list of payment attempts associated with the invoice */ + fun paymentAttempts(paymentAttempts: List) = + paymentAttempts(JsonField.of(paymentAttempts)) + + /** + * Sets [Builder.paymentAttempts] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentAttempts] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun paymentAttempts(paymentAttempts: JsonField>) = apply { + this.paymentAttempts = paymentAttempts.map { it.toMutableList() } + } + + /** + * Adds a single [PaymentAttempt] to [paymentAttempts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPaymentAttempt(paymentAttempt: PaymentAttempt) = apply { + paymentAttempts = + (paymentAttempts ?: JsonField.of(mutableListOf())).also { + checkKnown("paymentAttempts", it).add(paymentAttempt) + } + } + + /** + * If payment was attempted on this invoice but failed, this will be the time of the + * most recent attempt. + */ + fun paymentFailedAt(paymentFailedAt: OffsetDateTime?) = + paymentFailedAt(JsonField.ofNullable(paymentFailedAt)) + + /** + * Sets [Builder.paymentFailedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentFailedAt] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun paymentFailedAt(paymentFailedAt: JsonField) = apply { + this.paymentFailedAt = paymentFailedAt + } + + /** + * If payment was attempted on this invoice, this will be the start time of the most + * recent attempt. This field is especially useful for delayed-notification payment + * mechanisms (like bank transfers), where payment can take 3 days or more. + */ + fun paymentStartedAt(paymentStartedAt: OffsetDateTime?) = + paymentStartedAt(JsonField.ofNullable(paymentStartedAt)) + + /** + * Sets [Builder.paymentStartedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentStartedAt] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun paymentStartedAt(paymentStartedAt: JsonField) = apply { + this.paymentStartedAt = paymentStartedAt + } + + /** + * If the invoice is in draft, this timestamp will reflect when the invoice is scheduled + * to be issued. + */ + fun scheduledIssueAt(scheduledIssueAt: OffsetDateTime?) = + scheduledIssueAt(JsonField.ofNullable(scheduledIssueAt)) + + /** + * Sets [Builder.scheduledIssueAt] to an arbitrary JSON value. + * + * You should usually call [Builder.scheduledIssueAt] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun scheduledIssueAt(scheduledIssueAt: JsonField) = apply { + this.scheduledIssueAt = scheduledIssueAt + } + + fun shippingAddress(shippingAddress: Address?) = + shippingAddress(JsonField.ofNullable(shippingAddress)) + + /** + * Sets [Builder.shippingAddress] to an arbitrary JSON value. + * + * You should usually call [Builder.shippingAddress] with a well-typed [Address] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun shippingAddress(shippingAddress: JsonField
) = apply { + this.shippingAddress = shippingAddress + } + + fun status(status: Status) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [Status] 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 subscription(subscription: SubscriptionMinified?) = + subscription(JsonField.ofNullable(subscription)) + + /** + * Sets [Builder.subscription] to an arbitrary JSON value. + * + * You should usually call [Builder.subscription] with a well-typed + * [SubscriptionMinified] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun subscription(subscription: JsonField) = apply { + this.subscription = subscription + } + + /** The total before any discounts and minimums are applied. */ + fun subtotal(subtotal: String) = subtotal(JsonField.of(subtotal)) + + /** + * Sets [Builder.subtotal] to an arbitrary JSON value. + * + * You should usually call [Builder.subtotal] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun subtotal(subtotal: JsonField) = apply { this.subtotal = subtotal } + + /** + * If the invoice failed to sync, this will be the last time an external invoicing + * provider sync was attempted. This field will always be `null` for invoices using Orb + * Invoicing. + */ + fun syncFailedAt(syncFailedAt: OffsetDateTime?) = + syncFailedAt(JsonField.ofNullable(syncFailedAt)) + + /** + * Sets [Builder.syncFailedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.syncFailedAt] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun syncFailedAt(syncFailedAt: JsonField) = apply { + this.syncFailedAt = syncFailedAt + } + + /** The total after any minimums and discounts have been applied. */ + fun total(total: String) = total(JsonField.of(total)) + + /** + * Sets [Builder.total] to an arbitrary JSON value. + * + * You should usually call [Builder.total] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun total(total: JsonField) = apply { this.total = total } + + /** + * If the invoice has a status of `void`, this gives a timestamp when the invoice was + * voided. + */ + fun voidedAt(voidedAt: OffsetDateTime?) = voidedAt(JsonField.ofNullable(voidedAt)) + + /** + * Sets [Builder.voidedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.voidedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun voidedAt(voidedAt: JsonField) = apply { this.voidedAt = voidedAt } + + /** + * This is true if the invoice will be automatically issued in the future, and false + * otherwise. + */ + fun willAutoIssue(willAutoIssue: Boolean) = willAutoIssue(JsonField.of(willAutoIssue)) + + /** + * Sets [Builder.willAutoIssue] to an arbitrary JSON value. + * + * You should usually call [Builder.willAutoIssue] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun willAutoIssue(willAutoIssue: JsonField) = apply { + this.willAutoIssue = willAutoIssue + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CreatedInvoice]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .id() + * .amountDue() + * .autoCollection() + * .billingAddress() + * .createdAt() + * .creditNotes() + * .currency() + * .customer() + * .customerBalanceTransactions() + * .customerTaxId() + * .discount() + * .discounts() + * .dueDate() + * .eligibleToIssueAt() + * .hostedInvoiceUrl() + * .invoiceDate() + * .invoiceNumber() + * .invoicePdf() + * .invoiceSource() + * .isPayableNow() + * .issueFailedAt() + * .issuedAt() + * .lineItems() + * .maximum() + * .maximumAmount() + * .memo() + * .metadata() + * .minimum() + * .minimumAmount() + * .paidAt() + * .paymentAttempts() + * .paymentFailedAt() + * .paymentStartedAt() + * .scheduledIssueAt() + * .shippingAddress() + * .status() + * .subscription() + * .subtotal() + * .syncFailedAt() + * .total() + * .voidedAt() + * .willAutoIssue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CreatedInvoice = + CreatedInvoice( + checkRequired("id", id), + checkRequired("amountDue", amountDue), + checkRequired("autoCollection", autoCollection), + checkRequired("billingAddress", billingAddress), + checkRequired("createdAt", createdAt), + checkRequired("creditNotes", creditNotes).map { it.toImmutable() }, + checkRequired("currency", currency), + checkRequired("customer", customer), + checkRequired("customerBalanceTransactions", customerBalanceTransactions).map { + it.toImmutable() + }, + checkRequired("customerTaxId", customerTaxId), + checkRequired("discount", discount), + checkRequired("discounts", discounts).map { it.toImmutable() }, + checkRequired("dueDate", dueDate), + checkRequired("eligibleToIssueAt", eligibleToIssueAt), + checkRequired("hostedInvoiceUrl", hostedInvoiceUrl), + checkRequired("invoiceDate", invoiceDate), + checkRequired("invoiceNumber", invoiceNumber), + checkRequired("invoicePdf", invoicePdf), + checkRequired("invoiceSource", invoiceSource), + checkRequired("isPayableNow", isPayableNow), + checkRequired("issueFailedAt", issueFailedAt), + checkRequired("issuedAt", issuedAt), + checkRequired("lineItems", lineItems).map { it.toImmutable() }, + checkRequired("maximum", maximum), + checkRequired("maximumAmount", maximumAmount), + checkRequired("memo", memo), + checkRequired("metadata", metadata), + checkRequired("minimum", minimum), + checkRequired("minimumAmount", minimumAmount), + checkRequired("paidAt", paidAt), + checkRequired("paymentAttempts", paymentAttempts).map { it.toImmutable() }, + checkRequired("paymentFailedAt", paymentFailedAt), + checkRequired("paymentStartedAt", paymentStartedAt), + checkRequired("scheduledIssueAt", scheduledIssueAt), + checkRequired("shippingAddress", shippingAddress), + checkRequired("status", status), + checkRequired("subscription", subscription), + checkRequired("subtotal", subtotal), + checkRequired("syncFailedAt", syncFailedAt), + checkRequired("total", total), + checkRequired("voidedAt", voidedAt), + checkRequired("willAutoIssue", willAutoIssue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CreatedInvoice = apply { + if (validated) { + return@apply + } + + id() + amountDue() + autoCollection().validate() + billingAddress()?.validate() + createdAt() + creditNotes().forEach { it.validate() } + currency() + customer().validate() + customerBalanceTransactions().forEach { it.validate() } + customerTaxId()?.validate() + discounts().forEach { it.validate() } + dueDate() + eligibleToIssueAt() + hostedInvoiceUrl() + invoiceDate() + invoiceNumber() + invoicePdf() + invoiceSource().validate() + isPayableNow() + issueFailedAt() + issuedAt() + lineItems().forEach { it.validate() } + maximum()?.validate() + maximumAmount() + memo() + metadata().validate() + minimum()?.validate() + minimumAmount() + paidAt() + paymentAttempts().forEach { it.validate() } + paymentFailedAt() + paymentStartedAt() + scheduledIssueAt() + shippingAddress()?.validate() + status().validate() + subscription()?.validate() + subtotal() + syncFailedAt() + total() + voidedAt() + willAutoIssue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (id.asKnown() == null) 0 else 1) + + (if (amountDue.asKnown() == null) 0 else 1) + + (autoCollection.asKnown()?.validity() ?: 0) + + (billingAddress.asKnown()?.validity() ?: 0) + + (if (createdAt.asKnown() == null) 0 else 1) + + (creditNotes.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (customer.asKnown()?.validity() ?: 0) + + (customerBalanceTransactions.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (customerTaxId.asKnown()?.validity() ?: 0) + + (discounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (dueDate.asKnown() == null) 0 else 1) + + (if (eligibleToIssueAt.asKnown() == null) 0 else 1) + + (if (hostedInvoiceUrl.asKnown() == null) 0 else 1) + + (if (invoiceDate.asKnown() == null) 0 else 1) + + (if (invoiceNumber.asKnown() == null) 0 else 1) + + (if (invoicePdf.asKnown() == null) 0 else 1) + + (invoiceSource.asKnown()?.validity() ?: 0) + + (if (isPayableNow.asKnown() == null) 0 else 1) + + (if (issueFailedAt.asKnown() == null) 0 else 1) + + (if (issuedAt.asKnown() == null) 0 else 1) + + (lineItems.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (maximum.asKnown()?.validity() ?: 0) + + (if (maximumAmount.asKnown() == null) 0 else 1) + + (if (memo.asKnown() == null) 0 else 1) + + (metadata.asKnown()?.validity() ?: 0) + + (minimum.asKnown()?.validity() ?: 0) + + (if (minimumAmount.asKnown() == null) 0 else 1) + + (if (paidAt.asKnown() == null) 0 else 1) + + (paymentAttempts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (paymentFailedAt.asKnown() == null) 0 else 1) + + (if (paymentStartedAt.asKnown() == null) 0 else 1) + + (if (scheduledIssueAt.asKnown() == null) 0 else 1) + + (shippingAddress.asKnown()?.validity() ?: 0) + + (status.asKnown()?.validity() ?: 0) + + (subscription.asKnown()?.validity() ?: 0) + + (if (subtotal.asKnown() == null) 0 else 1) + + (if (syncFailedAt.asKnown() == null) 0 else 1) + + (if (total.asKnown() == null) 0 else 1) + + (if (voidedAt.asKnown() == null) 0 else 1) + + (if (willAutoIssue.asKnown() == null) 0 else 1) + + class AutoCollection + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val nextAttemptAt: JsonField, + private val numAttempts: JsonField, + private val previouslyAttemptedAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") + @ExcludeMissing + enabled: JsonField = JsonMissing.of(), + @JsonProperty("next_attempt_at") + @ExcludeMissing + nextAttemptAt: JsonField = JsonMissing.of(), + @JsonProperty("num_attempts") + @ExcludeMissing + numAttempts: JsonField = JsonMissing.of(), + @JsonProperty("previously_attempted_at") + @ExcludeMissing + previouslyAttemptedAt: JsonField = JsonMissing.of(), + ) : this(enabled, nextAttemptAt, numAttempts, previouslyAttemptedAt, mutableMapOf()) + + /** + * True only if auto-collection is enabled for this invoice. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun enabled(): Boolean? = enabled.getNullable("enabled") + + /** + * If the invoice is scheduled for auto-collection, this field will reflect when the + * next attempt will occur. If dunning has been exhausted, or auto-collection is not + * enabled for this invoice, this field will be `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextAttemptAt(): OffsetDateTime? = nextAttemptAt.getNullable("next_attempt_at") + + /** + * Number of auto-collection payment attempts. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun numAttempts(): Long? = numAttempts.getNullable("num_attempts") + + /** + * If Orb has ever attempted payment auto-collection for this invoice, this field will + * reflect when that attempt occurred. In conjunction with `next_attempt_at`, this can + * be used to tell whether the invoice is currently in dunning (that is, + * `previously_attempted_at` is non-null, and `next_attempt_time` is non-null), or if + * dunning has been exhausted (`previously_attempted_at` is non-null, but + * `next_attempt_time` is null). + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun previouslyAttemptedAt(): OffsetDateTime? = + previouslyAttemptedAt.getNullable("previously_attempted_at") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + /** + * Returns the raw JSON value of [nextAttemptAt]. + * + * Unlike [nextAttemptAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("next_attempt_at") + @ExcludeMissing + fun _nextAttemptAt(): JsonField = nextAttemptAt + + /** + * Returns the raw JSON value of [numAttempts]. + * + * Unlike [numAttempts], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("num_attempts") + @ExcludeMissing + fun _numAttempts(): JsonField = numAttempts + + /** + * Returns the raw JSON value of [previouslyAttemptedAt]. + * + * Unlike [previouslyAttemptedAt], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("previously_attempted_at") + @ExcludeMissing + fun _previouslyAttemptedAt(): JsonField = previouslyAttemptedAt + + @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 [AutoCollection]. + * + * The following fields are required: + * ```kotlin + * .enabled() + * .nextAttemptAt() + * .numAttempts() + * .previouslyAttemptedAt() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [AutoCollection]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var nextAttemptAt: JsonField? = null + private var numAttempts: JsonField? = null + private var previouslyAttemptedAt: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(autoCollection: AutoCollection) = apply { + enabled = autoCollection.enabled + nextAttemptAt = autoCollection.nextAttemptAt + numAttempts = autoCollection.numAttempts + previouslyAttemptedAt = autoCollection.previouslyAttemptedAt + additionalProperties = autoCollection.additionalProperties.toMutableMap() + } + + /** True only if auto-collection is enabled for this invoice. */ + fun enabled(enabled: Boolean?) = enabled(JsonField.ofNullable(enabled)) + + /** + * Alias for [Builder.enabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun enabled(enabled: Boolean) = enabled(enabled as Boolean?) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + /** + * If the invoice is scheduled for auto-collection, this field will reflect when the + * next attempt will occur. If dunning has been exhausted, or auto-collection is not + * enabled for this invoice, this field will be `null`. + */ + fun nextAttemptAt(nextAttemptAt: OffsetDateTime?) = + nextAttemptAt(JsonField.ofNullable(nextAttemptAt)) + + /** + * Sets [Builder.nextAttemptAt] to an arbitrary JSON value. + * + * You should usually call [Builder.nextAttemptAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun nextAttemptAt(nextAttemptAt: JsonField) = apply { + this.nextAttemptAt = nextAttemptAt + } + + /** Number of auto-collection payment attempts. */ + fun numAttempts(numAttempts: Long?) = numAttempts(JsonField.ofNullable(numAttempts)) + + /** + * Alias for [Builder.numAttempts]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun numAttempts(numAttempts: Long) = numAttempts(numAttempts as Long?) + + /** + * Sets [Builder.numAttempts] to an arbitrary JSON value. + * + * You should usually call [Builder.numAttempts] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun numAttempts(numAttempts: JsonField) = apply { + this.numAttempts = numAttempts + } + + /** + * If Orb has ever attempted payment auto-collection for this invoice, this field + * will reflect when that attempt occurred. In conjunction with `next_attempt_at`, + * this can be used to tell whether the invoice is currently in dunning (that is, + * `previously_attempted_at` is non-null, and `next_attempt_time` is non-null), or + * if dunning has been exhausted (`previously_attempted_at` is non-null, but + * `next_attempt_time` is null). + */ + fun previouslyAttemptedAt(previouslyAttemptedAt: OffsetDateTime?) = + previouslyAttemptedAt(JsonField.ofNullable(previouslyAttemptedAt)) + + /** + * Sets [Builder.previouslyAttemptedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.previouslyAttemptedAt] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun previouslyAttemptedAt(previouslyAttemptedAt: JsonField) = + apply { + this.previouslyAttemptedAt = previouslyAttemptedAt + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [AutoCollection]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .enabled() + * .nextAttemptAt() + * .numAttempts() + * .previouslyAttemptedAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AutoCollection = + AutoCollection( + checkRequired("enabled", enabled), + checkRequired("nextAttemptAt", nextAttemptAt), + checkRequired("numAttempts", numAttempts), + checkRequired("previouslyAttemptedAt", previouslyAttemptedAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): AutoCollection = apply { + if (validated) { + return@apply + } + + enabled() + nextAttemptAt() + numAttempts() + previouslyAttemptedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (enabled.asKnown() == null) 0 else 1) + + (if (nextAttemptAt.asKnown() == null) 0 else 1) + + (if (numAttempts.asKnown() == null) 0 else 1) + + (if (previouslyAttemptedAt.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AutoCollection && + enabled == other.enabled && + nextAttemptAt == other.nextAttemptAt && + numAttempts == other.numAttempts && + previouslyAttemptedAt == other.previouslyAttemptedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + enabled, + nextAttemptAt, + numAttempts, + previouslyAttemptedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AutoCollection{enabled=$enabled, nextAttemptAt=$nextAttemptAt, numAttempts=$numAttempts, previouslyAttemptedAt=$previouslyAttemptedAt, additionalProperties=$additionalProperties}" + } + + class CreditNote + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val creditNoteNumber: JsonField, + private val memo: JsonField, + private val reason: JsonField, + private val total: JsonField, + private val type: JsonField, + private val voidedAt: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("credit_note_number") + @ExcludeMissing + creditNoteNumber: JsonField = JsonMissing.of(), + @JsonProperty("memo") @ExcludeMissing memo: JsonField = JsonMissing.of(), + @JsonProperty("reason") + @ExcludeMissing + reason: JsonField = JsonMissing.of(), + @JsonProperty("total") @ExcludeMissing total: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("voided_at") + @ExcludeMissing + voidedAt: JsonField = JsonMissing.of(), + ) : this(id, creditNoteNumber, memo, reason, total, type, voidedAt, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if 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 OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun creditNoteNumber(): String = creditNoteNumber.getRequired("credit_note_number") + + /** + * An optional memo supplied on the credit note. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun memo(): String? = memo.getNullable("memo") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun reason(): String = reason.getRequired("reason") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun total(): String = total.getRequired("total") + + /** + * @throws OrbInvalidDataException if 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(): String = type.getRequired("type") + + /** + * If the credit note has a status of `void`, this gives a timestamp when the credit + * note was voided. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun voidedAt(): OffsetDateTime? = voidedAt.getNullable("voided_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 [creditNoteNumber]. + * + * Unlike [creditNoteNumber], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("credit_note_number") + @ExcludeMissing + fun _creditNoteNumber(): JsonField = creditNoteNumber + + /** + * Returns the raw JSON value of [memo]. + * + * Unlike [memo], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("memo") @ExcludeMissing fun _memo(): JsonField = memo + + /** + * Returns the raw JSON value of [reason]. + * + * Unlike [reason], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("reason") @ExcludeMissing fun _reason(): JsonField = reason + + /** + * Returns the raw JSON value of [total]. + * + * Unlike [total], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("total") @ExcludeMissing fun _total(): JsonField = total + + /** + * 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 [voidedAt]. + * + * Unlike [voidedAt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("voided_at") + @ExcludeMissing + fun _voidedAt(): JsonField = voidedAt + + @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 [CreditNote]. + * + * The following fields are required: + * ```kotlin + * .id() + * .creditNoteNumber() + * .memo() + * .reason() + * .total() + * .type() + * .voidedAt() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CreditNote]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var creditNoteNumber: JsonField? = null + private var memo: JsonField? = null + private var reason: JsonField? = null + private var total: JsonField? = null + private var type: JsonField? = null + private var voidedAt: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(creditNote: CreditNote) = apply { + id = creditNote.id + creditNoteNumber = creditNote.creditNoteNumber + memo = creditNote.memo + reason = creditNote.reason + total = creditNote.total + type = creditNote.type + voidedAt = creditNote.voidedAt + additionalProperties = creditNote.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 creditNoteNumber(creditNoteNumber: String) = + creditNoteNumber(JsonField.of(creditNoteNumber)) + + /** + * Sets [Builder.creditNoteNumber] to an arbitrary JSON value. + * + * You should usually call [Builder.creditNoteNumber] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun creditNoteNumber(creditNoteNumber: JsonField) = apply { + this.creditNoteNumber = creditNoteNumber + } + + /** An optional memo supplied on the credit note. */ + fun memo(memo: String?) = memo(JsonField.ofNullable(memo)) + + /** + * Sets [Builder.memo] to an arbitrary JSON value. + * + * You should usually call [Builder.memo] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun memo(memo: JsonField) = apply { this.memo = memo } + + fun reason(reason: String) = reason(JsonField.of(reason)) + + /** + * Sets [Builder.reason] to an arbitrary JSON value. + * + * You should usually call [Builder.reason] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun reason(reason: JsonField) = apply { this.reason = reason } + + fun total(total: String) = total(JsonField.of(total)) + + /** + * Sets [Builder.total] to an arbitrary JSON value. + * + * You should usually call [Builder.total] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun total(total: JsonField) = apply { this.total = total } + + 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 } + + /** + * If the credit note has a status of `void`, this gives a timestamp when the credit + * note was voided. + */ + fun voidedAt(voidedAt: OffsetDateTime?) = voidedAt(JsonField.ofNullable(voidedAt)) + + /** + * Sets [Builder.voidedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.voidedAt] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun voidedAt(voidedAt: JsonField) = apply { + this.voidedAt = voidedAt + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CreditNote]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .id() + * .creditNoteNumber() + * .memo() + * .reason() + * .total() + * .type() + * .voidedAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CreditNote = + CreditNote( + checkRequired("id", id), + checkRequired("creditNoteNumber", creditNoteNumber), + checkRequired("memo", memo), + checkRequired("reason", reason), + checkRequired("total", total), + checkRequired("type", type), + checkRequired("voidedAt", voidedAt), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CreditNote = apply { + if (validated) { + return@apply + } + + id() + creditNoteNumber() + memo() + reason() + total() + type() + voidedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (id.asKnown() == null) 0 else 1) + + (if (creditNoteNumber.asKnown() == null) 0 else 1) + + (if (memo.asKnown() == null) 0 else 1) + + (if (reason.asKnown() == null) 0 else 1) + + (if (total.asKnown() == null) 0 else 1) + + (if (type.asKnown() == null) 0 else 1) + + (if (voidedAt.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CreditNote && + id == other.id && + creditNoteNumber == other.creditNoteNumber && + memo == other.memo && + reason == other.reason && + total == other.total && + type == other.type && + voidedAt == other.voidedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + creditNoteNumber, + memo, + reason, + total, + type, + voidedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CreditNote{id=$id, creditNoteNumber=$creditNoteNumber, memo=$memo, reason=$reason, total=$total, type=$type, voidedAt=$voidedAt, additionalProperties=$additionalProperties}" + } + + class CustomerBalanceTransaction + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val action: JsonField, + private val amount: JsonField, + private val createdAt: JsonField, + private val creditNote: JsonField, + private val description: JsonField, + private val endingBalance: JsonField, + private val invoice: JsonField, + private val startingBalance: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("action") + @ExcludeMissing + action: JsonField = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("credit_note") + @ExcludeMissing + creditNote: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("ending_balance") + @ExcludeMissing + endingBalance: JsonField = JsonMissing.of(), + @JsonProperty("invoice") + @ExcludeMissing + invoice: JsonField = JsonMissing.of(), + @JsonProperty("starting_balance") + @ExcludeMissing + startingBalance: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this( + id, + action, + amount, + createdAt, + creditNote, + description, + endingBalance, + invoice, + startingBalance, + type, + mutableMapOf(), + ) + + /** + * A unique id for this transaction. + * + * @throws OrbInvalidDataException if 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 OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun action(): Action = action.getRequired("action") + + /** + * The value of the amount changed in the transaction. + * + * @throws OrbInvalidDataException if 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(): String = amount.getRequired("amount") + + /** + * The creation time of this transaction. + * + * @throws OrbInvalidDataException if 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 OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun creditNote(): CreditNoteTiny? = creditNote.getNullable("credit_note") + + /** + * An optional description provided for manual customer balance adjustments. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): String? = description.getNullable("description") + + /** + * The new value of the customer's balance prior to the transaction, in the customer's + * currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun endingBalance(): String = endingBalance.getRequired("ending_balance") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoice(): InvoiceTiny? = invoice.getNullable("invoice") + + /** + * The original value of the customer's balance prior to the transaction, in the + * customer's currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun startingBalance(): String = startingBalance.getRequired("starting_balance") + + /** + * @throws OrbInvalidDataException if 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 [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 [action]. + * + * Unlike [action], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action + + /** + * 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 [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 [creditNote]. + * + * Unlike [creditNote], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("credit_note") + @ExcludeMissing + fun _creditNote(): JsonField = creditNote + + /** + * 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 [endingBalance]. + * + * Unlike [endingBalance], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("ending_balance") + @ExcludeMissing + fun _endingBalance(): JsonField = endingBalance + + /** + * Returns the raw JSON value of [invoice]. + * + * Unlike [invoice], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("invoice") + @ExcludeMissing + fun _invoice(): JsonField = invoice + + /** + * Returns the raw JSON value of [startingBalance]. + * + * Unlike [startingBalance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("starting_balance") + @ExcludeMissing + fun _startingBalance(): JsonField = startingBalance + + /** + * 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 + * [CustomerBalanceTransaction]. + * + * The following fields are required: + * ```kotlin + * .id() + * .action() + * .amount() + * .createdAt() + * .creditNote() + * .description() + * .endingBalance() + * .invoice() + * .startingBalance() + * .type() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CustomerBalanceTransaction]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var action: JsonField? = null + private var amount: JsonField? = null + private var createdAt: JsonField? = null + private var creditNote: JsonField? = null + private var description: JsonField? = null + private var endingBalance: JsonField? = null + private var invoice: JsonField? = null + private var startingBalance: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(customerBalanceTransaction: CustomerBalanceTransaction) = apply { + id = customerBalanceTransaction.id + action = customerBalanceTransaction.action + amount = customerBalanceTransaction.amount + createdAt = customerBalanceTransaction.createdAt + creditNote = customerBalanceTransaction.creditNote + description = customerBalanceTransaction.description + endingBalance = customerBalanceTransaction.endingBalance + invoice = customerBalanceTransaction.invoice + startingBalance = customerBalanceTransaction.startingBalance + type = customerBalanceTransaction.type + additionalProperties = + customerBalanceTransaction.additionalProperties.toMutableMap() + } + + /** A unique id for this transaction. */ + 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 action(action: Action) = action(JsonField.of(action)) + + /** + * Sets [Builder.action] to an arbitrary JSON value. + * + * You should usually call [Builder.action] with a well-typed [Action] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun action(action: JsonField) = apply { this.action = action } + + /** The value of the amount changed in the transaction. */ + fun amount(amount: String) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [String] 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 } + + /** The creation time of this transaction. */ + 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 creditNote(creditNote: CreditNoteTiny?) = + creditNote(JsonField.ofNullable(creditNote)) + + /** + * Sets [Builder.creditNote] to an arbitrary JSON value. + * + * You should usually call [Builder.creditNote] with a well-typed [CreditNoteTiny] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun creditNote(creditNote: JsonField) = apply { + this.creditNote = creditNote + } + + /** An optional description provided for manual customer balance adjustments. */ + fun description(description: String?) = + description(JsonField.ofNullable(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 + } + + /** + * The new value of the customer's balance prior to the transaction, in the + * customer's currency. + */ + fun endingBalance(endingBalance: String) = + endingBalance(JsonField.of(endingBalance)) + + /** + * Sets [Builder.endingBalance] to an arbitrary JSON value. + * + * You should usually call [Builder.endingBalance] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun endingBalance(endingBalance: JsonField) = apply { + this.endingBalance = endingBalance + } + + fun invoice(invoice: InvoiceTiny?) = invoice(JsonField.ofNullable(invoice)) + + /** + * Sets [Builder.invoice] to an arbitrary JSON value. + * + * You should usually call [Builder.invoice] with a well-typed [InvoiceTiny] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun invoice(invoice: JsonField) = apply { this.invoice = invoice } + + /** + * The original value of the customer's balance prior to the transaction, in the + * customer's currency. + */ + fun startingBalance(startingBalance: String) = + startingBalance(JsonField.of(startingBalance)) + + /** + * Sets [Builder.startingBalance] to an arbitrary JSON value. + * + * You should usually call [Builder.startingBalance] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun startingBalance(startingBalance: JsonField) = apply { + this.startingBalance = startingBalance + } + + 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 [CustomerBalanceTransaction]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .id() + * .action() + * .amount() + * .createdAt() + * .creditNote() + * .description() + * .endingBalance() + * .invoice() + * .startingBalance() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerBalanceTransaction = + CustomerBalanceTransaction( + checkRequired("id", id), + checkRequired("action", action), + checkRequired("amount", amount), + checkRequired("createdAt", createdAt), + checkRequired("creditNote", creditNote), + checkRequired("description", description), + checkRequired("endingBalance", endingBalance), + checkRequired("invoice", invoice), + checkRequired("startingBalance", startingBalance), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CustomerBalanceTransaction = apply { + if (validated) { + return@apply + } + + id() + action().validate() + amount() + createdAt() + creditNote()?.validate() + description() + endingBalance() + invoice()?.validate() + startingBalance() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (id.asKnown() == null) 0 else 1) + + (action.asKnown()?.validity() ?: 0) + + (if (amount.asKnown() == null) 0 else 1) + + (if (createdAt.asKnown() == null) 0 else 1) + + (creditNote.asKnown()?.validity() ?: 0) + + (if (description.asKnown() == null) 0 else 1) + + (if (endingBalance.asKnown() == null) 0 else 1) + + (invoice.asKnown()?.validity() ?: 0) + + (if (startingBalance.asKnown() == null) 0 else 1) + + (type.asKnown()?.validity() ?: 0) + + class Action @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 { + + val APPLIED_TO_INVOICE = of("applied_to_invoice") + + val MANUAL_ADJUSTMENT = of("manual_adjustment") + + val PRORATED_REFUND = of("prorated_refund") + + val REVERT_PRORATED_REFUND = of("revert_prorated_refund") + + val RETURN_FROM_VOIDING = of("return_from_voiding") + + val CREDIT_NOTE_APPLIED = of("credit_note_applied") + + val CREDIT_NOTE_VOIDED = of("credit_note_voided") + + val OVERPAYMENT_REFUND = of("overpayment_refund") + + val EXTERNAL_PAYMENT = of("external_payment") + + val SMALL_INVOICE_CARRYOVER = of("small_invoice_carryover") + + fun of(value: String) = Action(JsonField.of(value)) + } + + /** An enum containing [Action]'s known values. */ + enum class Known { + APPLIED_TO_INVOICE, + MANUAL_ADJUSTMENT, + PRORATED_REFUND, + REVERT_PRORATED_REFUND, + RETURN_FROM_VOIDING, + CREDIT_NOTE_APPLIED, + CREDIT_NOTE_VOIDED, + OVERPAYMENT_REFUND, + EXTERNAL_PAYMENT, + SMALL_INVOICE_CARRYOVER, + } + + /** + * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Action] 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 { + APPLIED_TO_INVOICE, + MANUAL_ADJUSTMENT, + PRORATED_REFUND, + REVERT_PRORATED_REFUND, + RETURN_FROM_VOIDING, + CREDIT_NOTE_APPLIED, + CREDIT_NOTE_VOIDED, + OVERPAYMENT_REFUND, + EXTERNAL_PAYMENT, + SMALL_INVOICE_CARRYOVER, + /** + * An enum member indicating that [Action] 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) { + APPLIED_TO_INVOICE -> Value.APPLIED_TO_INVOICE + MANUAL_ADJUSTMENT -> Value.MANUAL_ADJUSTMENT + PRORATED_REFUND -> Value.PRORATED_REFUND + REVERT_PRORATED_REFUND -> Value.REVERT_PRORATED_REFUND + RETURN_FROM_VOIDING -> Value.RETURN_FROM_VOIDING + CREDIT_NOTE_APPLIED -> Value.CREDIT_NOTE_APPLIED + CREDIT_NOTE_VOIDED -> Value.CREDIT_NOTE_VOIDED + OVERPAYMENT_REFUND -> Value.OVERPAYMENT_REFUND + EXTERNAL_PAYMENT -> Value.EXTERNAL_PAYMENT + SMALL_INVOICE_CARRYOVER -> Value.SMALL_INVOICE_CARRYOVER + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + APPLIED_TO_INVOICE -> Known.APPLIED_TO_INVOICE + MANUAL_ADJUSTMENT -> Known.MANUAL_ADJUSTMENT + PRORATED_REFUND -> Known.PRORATED_REFUND + REVERT_PRORATED_REFUND -> Known.REVERT_PRORATED_REFUND + RETURN_FROM_VOIDING -> Known.RETURN_FROM_VOIDING + CREDIT_NOTE_APPLIED -> Known.CREDIT_NOTE_APPLIED + CREDIT_NOTE_VOIDED -> Known.CREDIT_NOTE_VOIDED + OVERPAYMENT_REFUND -> Known.OVERPAYMENT_REFUND + EXTERNAL_PAYMENT -> Known.EXTERNAL_PAYMENT + SMALL_INVOICE_CARRYOVER -> Known.SMALL_INVOICE_CARRYOVER + else -> throw OrbInvalidDataException("Unknown Action: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Action = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Action && 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 { + + val INCREMENT = of("increment") + + val DECREMENT = of("decrement") + + fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + INCREMENT, + DECREMENT, + } + + /** + * 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 { + INCREMENT, + DECREMENT, + /** + * 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) { + INCREMENT -> Value.INCREMENT + DECREMENT -> Value.DECREMENT + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCREMENT -> Known.INCREMENT + DECREMENT -> Known.DECREMENT + else -> throw OrbInvalidDataException("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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 CustomerBalanceTransaction && + id == other.id && + action == other.action && + amount == other.amount && + createdAt == other.createdAt && + creditNote == other.creditNote && + description == other.description && + endingBalance == other.endingBalance && + invoice == other.invoice && + startingBalance == other.startingBalance && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + action, + amount, + createdAt, + creditNote, + description, + endingBalance, + invoice, + startingBalance, + type, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomerBalanceTransaction{id=$id, action=$action, amount=$amount, createdAt=$createdAt, creditNote=$creditNote, description=$description, endingBalance=$endingBalance, invoice=$invoice, startingBalance=$startingBalance, type=$type, additionalProperties=$additionalProperties}" + } + + class InvoiceSource @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 { + + val SUBSCRIPTION = of("subscription") + + val PARTIAL = of("partial") + + val ONE_OFF = of("one_off") + + fun of(value: String) = InvoiceSource(JsonField.of(value)) + } + + /** An enum containing [InvoiceSource]'s known values. */ + enum class Known { + SUBSCRIPTION, + PARTIAL, + ONE_OFF, + } + + /** + * An enum containing [InvoiceSource]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [InvoiceSource] 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 { + SUBSCRIPTION, + PARTIAL, + ONE_OFF, + /** + * An enum member indicating that [InvoiceSource] 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) { + SUBSCRIPTION -> Value.SUBSCRIPTION + PARTIAL -> Value.PARTIAL + ONE_OFF -> Value.ONE_OFF + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SUBSCRIPTION -> Known.SUBSCRIPTION + PARTIAL -> Known.PARTIAL + ONE_OFF -> Known.ONE_OFF + else -> throw OrbInvalidDataException("Unknown InvoiceSource: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): InvoiceSource = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 InvoiceSource && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class LineItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val adjustedSubtotal: JsonField, + private val adjustments: JsonField>, + private val amount: JsonField, + private val creditsApplied: JsonField, + private val endDate: JsonField, + private val filter: JsonField, + private val grouping: JsonField, + private val name: JsonField, + private val partiallyInvoicedAmount: JsonField, + private val price: JsonField, + private val quantity: JsonField, + private val startDate: JsonField, + private val subLineItems: JsonField>, + private val subtotal: JsonField, + private val taxAmounts: JsonField>, + private val usageCustomerIds: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("adjusted_subtotal") + @ExcludeMissing + adjustedSubtotal: JsonField = JsonMissing.of(), + @JsonProperty("adjustments") + @ExcludeMissing + adjustments: JsonField> = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("credits_applied") + @ExcludeMissing + creditsApplied: JsonField = JsonMissing.of(), + @JsonProperty("end_date") + @ExcludeMissing + endDate: JsonField = JsonMissing.of(), + @JsonProperty("filter") + @ExcludeMissing + filter: JsonField = JsonMissing.of(), + @JsonProperty("grouping") + @ExcludeMissing + grouping: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("partially_invoiced_amount") + @ExcludeMissing + partiallyInvoicedAmount: JsonField = JsonMissing.of(), + @JsonProperty("price") @ExcludeMissing price: JsonField = JsonMissing.of(), + @JsonProperty("quantity") + @ExcludeMissing + quantity: JsonField = JsonMissing.of(), + @JsonProperty("start_date") + @ExcludeMissing + startDate: JsonField = JsonMissing.of(), + @JsonProperty("sub_line_items") + @ExcludeMissing + subLineItems: JsonField> = JsonMissing.of(), + @JsonProperty("subtotal") + @ExcludeMissing + subtotal: JsonField = JsonMissing.of(), + @JsonProperty("tax_amounts") + @ExcludeMissing + taxAmounts: JsonField> = JsonMissing.of(), + @JsonProperty("usage_customer_ids") + @ExcludeMissing + usageCustomerIds: JsonField> = JsonMissing.of(), + ) : this( + id, + adjustedSubtotal, + adjustments, + amount, + creditsApplied, + endDate, + filter, + grouping, + name, + partiallyInvoicedAmount, + price, + quantity, + startDate, + subLineItems, + subtotal, + taxAmounts, + usageCustomerIds, + mutableMapOf(), + ) + + /** + * A unique ID for this line item. + * + * @throws OrbInvalidDataException if 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 line amount after any adjustments and before overage conversion, credits and + * partial invoicing. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun adjustedSubtotal(): String = adjustedSubtotal.getRequired("adjusted_subtotal") + + /** + * All adjustments applied to the line item in the order they were applied based on + * invoice calculations (ie. usage discounts -> amount discounts -> percentage discounts + * -> minimums -> maximums). + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun adjustments(): List = adjustments.getRequired("adjustments") + + /** + * The final amount for a line item after all adjustments and pre paid credits have been + * applied. + * + * @throws OrbInvalidDataException if 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(): String = amount.getRequired("amount") + + /** + * The number of prepaid credits applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun creditsApplied(): String = creditsApplied.getRequired("credits_applied") + + /** + * The end date of the range of time applied for this line item's price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun endDate(): OffsetDateTime = endDate.getRequired("end_date") + + /** + * An additional filter that was used to calculate the usage for this line item. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun filter(): String? = filter.getNullable("filter") + + /** + * [DEPRECATED] For configured prices that are split by a grouping key, this will be + * populated with the key and a value. The `amount` and `subtotal` will be the values + * for this particular grouping. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun grouping(): String? = grouping.getNullable("grouping") + + /** + * The name of the price associated with this line item. + * + * @throws OrbInvalidDataException if 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") + + /** + * Any amount applied from a partial invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun partiallyInvoicedAmount(): String = + partiallyInvoicedAmount.getRequired("partially_invoiced_amount") + + /** + * The Price resource represents a price that can be billed on a subscription, resulting + * in a charge on an invoice in the form of an invoice line item. Prices take a quantity + * and determine an amount to bill. + * + * Orb supports a few different pricing models out of the box. Each of these models is + * serialized differently in a given Price object. The model_type field determines the + * key for the configuration object that is present. + * + * For more on the types of prices, see + * [the core concepts documentation](/core-concepts#plan-and-price) + * + * @throws OrbInvalidDataException if 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(): Price = price.getRequired("price") + + /** + * Either the fixed fee quantity or the usage during the service period. + * + * @throws OrbInvalidDataException if 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") + + /** + * The start date of the range of time applied for this line item's price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun startDate(): OffsetDateTime = startDate.getRequired("start_date") + + /** + * For complex pricing structures, the line item can be broken down further in + * `sub_line_items`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun subLineItems(): List = subLineItems.getRequired("sub_line_items") + + /** + * The line amount before any adjustments. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun subtotal(): String = subtotal.getRequired("subtotal") + + /** + * An array of tax rates and their incurred tax amounts. Empty if no tax integration is + * configured. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun taxAmounts(): List = taxAmounts.getRequired("tax_amounts") + + /** + * A list of customer ids that were used to calculate the usage for this line item. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun usageCustomerIds(): List? = + usageCustomerIds.getNullable("usage_customer_ids") + + /** + * 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 [adjustedSubtotal]. + * + * Unlike [adjustedSubtotal], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("adjusted_subtotal") + @ExcludeMissing + fun _adjustedSubtotal(): JsonField = adjustedSubtotal + + /** + * Returns the raw JSON value of [adjustments]. + * + * Unlike [adjustments], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("adjustments") + @ExcludeMissing + fun _adjustments(): JsonField> = adjustments + + /** + * 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 [creditsApplied]. + * + * Unlike [creditsApplied], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("credits_applied") + @ExcludeMissing + fun _creditsApplied(): JsonField = creditsApplied + + /** + * Returns the raw JSON value of [endDate]. + * + * Unlike [endDate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("end_date") + @ExcludeMissing + fun _endDate(): JsonField = endDate + + /** + * Returns the raw JSON value of [filter]. + * + * Unlike [filter], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filter") @ExcludeMissing fun _filter(): JsonField = filter + + /** + * Returns the raw JSON value of [grouping]. + * + * Unlike [grouping], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("grouping") @ExcludeMissing fun _grouping(): JsonField = grouping + + /** + * 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 [partiallyInvoicedAmount]. + * + * Unlike [partiallyInvoicedAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("partially_invoiced_amount") + @ExcludeMissing + fun _partiallyInvoicedAmount(): JsonField = partiallyInvoicedAmount + + /** + * 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 [startDate]. + * + * Unlike [startDate], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("start_date") + @ExcludeMissing + fun _startDate(): JsonField = startDate + + /** + * Returns the raw JSON value of [subLineItems]. + * + * Unlike [subLineItems], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("sub_line_items") + @ExcludeMissing + fun _subLineItems(): JsonField> = subLineItems + + /** + * Returns the raw JSON value of [subtotal]. + * + * Unlike [subtotal], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("subtotal") @ExcludeMissing fun _subtotal(): JsonField = subtotal + + /** + * Returns the raw JSON value of [taxAmounts]. + * + * Unlike [taxAmounts], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tax_amounts") + @ExcludeMissing + fun _taxAmounts(): JsonField> = taxAmounts + + /** + * Returns the raw JSON value of [usageCustomerIds]. + * + * Unlike [usageCustomerIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("usage_customer_ids") + @ExcludeMissing + fun _usageCustomerIds(): JsonField> = usageCustomerIds + + @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 [LineItem]. + * + * The following fields are required: + * ```kotlin + * .id() + * .adjustedSubtotal() + * .adjustments() + * .amount() + * .creditsApplied() + * .endDate() + * .filter() + * .grouping() + * .name() + * .partiallyInvoicedAmount() + * .price() + * .quantity() + * .startDate() + * .subLineItems() + * .subtotal() + * .taxAmounts() + * .usageCustomerIds() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [LineItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var adjustedSubtotal: JsonField? = null + private var adjustments: JsonField>? = null + private var amount: JsonField? = null + private var creditsApplied: JsonField? = null + private var endDate: JsonField? = null + private var filter: JsonField? = null + private var grouping: JsonField? = null + private var name: JsonField? = null + private var partiallyInvoicedAmount: JsonField? = null + private var price: JsonField? = null + private var quantity: JsonField? = null + private var startDate: JsonField? = null + private var subLineItems: JsonField>? = null + private var subtotal: JsonField? = null + private var taxAmounts: JsonField>? = null + private var usageCustomerIds: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(lineItem: LineItem) = apply { + id = lineItem.id + adjustedSubtotal = lineItem.adjustedSubtotal + adjustments = lineItem.adjustments.map { it.toMutableList() } + amount = lineItem.amount + creditsApplied = lineItem.creditsApplied + endDate = lineItem.endDate + filter = lineItem.filter + grouping = lineItem.grouping + name = lineItem.name + partiallyInvoicedAmount = lineItem.partiallyInvoicedAmount + price = lineItem.price + quantity = lineItem.quantity + startDate = lineItem.startDate + subLineItems = lineItem.subLineItems.map { it.toMutableList() } + subtotal = lineItem.subtotal + taxAmounts = lineItem.taxAmounts.map { it.toMutableList() } + usageCustomerIds = lineItem.usageCustomerIds.map { it.toMutableList() } + additionalProperties = lineItem.additionalProperties.toMutableMap() + } + + /** A unique ID for this line item. */ + 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 line amount after any adjustments and before overage conversion, credits and + * partial invoicing. + */ + fun adjustedSubtotal(adjustedSubtotal: String) = + adjustedSubtotal(JsonField.of(adjustedSubtotal)) + + /** + * Sets [Builder.adjustedSubtotal] to an arbitrary JSON value. + * + * You should usually call [Builder.adjustedSubtotal] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun adjustedSubtotal(adjustedSubtotal: JsonField) = apply { + this.adjustedSubtotal = adjustedSubtotal + } + + /** + * All adjustments applied to the line item in the order they were applied based on + * invoice calculations (ie. usage discounts -> amount discounts -> percentage + * discounts -> minimums -> maximums). + */ + fun adjustments(adjustments: List) = + adjustments(JsonField.of(adjustments)) + + /** + * Sets [Builder.adjustments] to an arbitrary JSON value. + * + * You should usually call [Builder.adjustments] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun adjustments(adjustments: JsonField>) = apply { + this.adjustments = adjustments.map { it.toMutableList() } + } + + /** + * Adds a single [Adjustment] to [adjustments]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAdjustment(adjustment: Adjustment) = apply { + adjustments = + (adjustments ?: JsonField.of(mutableListOf())).also { + checkKnown("adjustments", it).add(adjustment) + } + } + + /** + * Alias for calling [addAdjustment] with + * `Adjustment.ofUsageDiscount(usageDiscount)`. + */ + fun addAdjustment(usageDiscount: MonetaryUsageDiscountAdjustment) = + addAdjustment(Adjustment.ofUsageDiscount(usageDiscount)) + + /** + * Alias for calling [addAdjustment] with + * `Adjustment.ofAmountDiscount(amountDiscount)`. + */ + fun addAdjustment(amountDiscount: MonetaryAmountDiscountAdjustment) = + addAdjustment(Adjustment.ofAmountDiscount(amountDiscount)) + + /** + * Alias for calling [addAdjustment] with + * `Adjustment.ofPercentageDiscount(percentageDiscount)`. + */ + fun addAdjustment(percentageDiscount: MonetaryPercentageDiscountAdjustment) = + addAdjustment(Adjustment.ofPercentageDiscount(percentageDiscount)) + + /** Alias for calling [addAdjustment] with `Adjustment.ofMinimum(minimum)`. */ + fun addAdjustment(minimum: MonetaryMinimumAdjustment) = + addAdjustment(Adjustment.ofMinimum(minimum)) + + /** Alias for calling [addAdjustment] with `Adjustment.ofMaximum(maximum)`. */ + fun addAdjustment(maximum: MonetaryMaximumAdjustment) = + addAdjustment(Adjustment.ofMaximum(maximum)) + + /** + * The final amount for a line item after all adjustments and pre paid credits have + * been applied. + */ + fun amount(amount: String) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [String] 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 } + + /** The number of prepaid credits applied. */ + fun creditsApplied(creditsApplied: String) = + creditsApplied(JsonField.of(creditsApplied)) + + /** + * Sets [Builder.creditsApplied] to an arbitrary JSON value. + * + * You should usually call [Builder.creditsApplied] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun creditsApplied(creditsApplied: JsonField) = apply { + this.creditsApplied = creditsApplied + } + + /** The end date of the range of time applied for this line item's price. */ + fun endDate(endDate: OffsetDateTime) = endDate(JsonField.of(endDate)) + + /** + * Sets [Builder.endDate] to an arbitrary JSON value. + * + * You should usually call [Builder.endDate] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun endDate(endDate: JsonField) = apply { this.endDate = endDate } + + /** An additional filter that was used to calculate the usage for this line item. */ + fun filter(filter: String?) = filter(JsonField.ofNullable(filter)) + + /** + * Sets [Builder.filter] to an arbitrary JSON value. + * + * You should usually call [Builder.filter] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun filter(filter: JsonField) = apply { this.filter = filter } + + /** + * [DEPRECATED] For configured prices that are split by a grouping key, this will be + * populated with the key and a value. The `amount` and `subtotal` will be the + * values for this particular grouping. + */ + fun grouping(grouping: String?) = grouping(JsonField.ofNullable(grouping)) + + /** + * Sets [Builder.grouping] to an arbitrary JSON value. + * + * You should usually call [Builder.grouping] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun grouping(grouping: JsonField) = apply { this.grouping = grouping } + + /** The name of the price associated with this line item. */ + 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 } + + /** Any amount applied from a partial invoice */ + fun partiallyInvoicedAmount(partiallyInvoicedAmount: String) = + partiallyInvoicedAmount(JsonField.of(partiallyInvoicedAmount)) + + /** + * Sets [Builder.partiallyInvoicedAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.partiallyInvoicedAmount] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun partiallyInvoicedAmount(partiallyInvoicedAmount: JsonField) = apply { + this.partiallyInvoicedAmount = partiallyInvoicedAmount + } + + /** + * The Price resource represents a price that can be billed on a subscription, + * resulting in a charge on an invoice in the form of an invoice line item. Prices + * take a quantity and determine an amount to bill. + * + * Orb supports a few different pricing models out of the box. Each of these models + * is serialized differently in a given Price object. The model_type field + * determines the key for the configuration object that is present. + * + * For more on the types of prices, see + * [the core concepts documentation](/core-concepts#plan-and-price) + */ + fun price(price: Price) = price(JsonField.of(price)) + + /** + * Sets [Builder.price] to an arbitrary JSON value. + * + * You should usually call [Builder.price] with a well-typed [Price] 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 } + + /** Alias for calling [price] with `Price.ofUnit(unit)`. */ + fun price(unit: Price.UnitPrice) = price(Price.ofUnit(unit)) + + /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ + fun price(tiered: Price.Tiered) = price(Price.ofTiered(tiered)) + + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: Price.Bulk) = price(Price.ofBulk(bulk)) + + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) + + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: Price.Package) = price(Price.ofPackage(package_)) + + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: Price.Matrix) = price(Price.ofMatrix(matrix)) + + /** + * Alias for calling [price] with + * `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. + */ + fun price(thresholdTotalAmount: Price.ThresholdTotalAmount) = + price(Price.ofThresholdTotalAmount(thresholdTotalAmount)) + + /** Alias for calling [price] with `Price.ofTieredPackage(tieredPackage)`. */ + fun price(tieredPackage: Price.TieredPackage) = + price(Price.ofTieredPackage(tieredPackage)) + + /** + * Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. + */ + fun price(tieredWithMinimum: Price.TieredWithMinimum) = + price(Price.ofTieredWithMinimum(tieredWithMinimum)) + + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: Price.GroupedTiered) = + price(Price.ofGroupedTiered(groupedTiered)) + + /** + * Alias for calling [price] with + * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + */ + fun price(tieredPackageWithMinimum: Price.TieredPackageWithMinimum) = + price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofPackageWithAllocation(packageWithAllocation)`. + */ + fun price(packageWithAllocation: Price.PackageWithAllocation) = + price(Price.ofPackageWithAllocation(packageWithAllocation)) + + /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ + fun price(unitWithPercent: Price.UnitWithPercent) = + price(Price.ofUnitWithPercent(unitWithPercent)) + + /** + * Alias for calling [price] with + * `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun price(matrixWithAllocation: Price.MatrixWithAllocation) = + price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + + /** + * Alias for calling [price] with + * `Price.ofTieredWithProration(tieredWithProration)`. + */ + fun price(tieredWithProration: Price.TieredWithProration) = + price(Price.ofTieredWithProration(tieredWithProration)) + + /** + * Alias for calling [price] with `Price.ofUnitWithProration(unitWithProration)`. + */ + fun price(unitWithProration: Price.UnitWithProration) = + price(Price.ofUnitWithProration(unitWithProration)) + + /** + * Alias for calling [price] with `Price.ofGroupedAllocation(groupedAllocation)`. + */ + fun price(groupedAllocation: Price.GroupedAllocation) = + price(Price.ofGroupedAllocation(groupedAllocation)) + + /** + * Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. + */ + fun price(bulkWithProration: Price.BulkWithProration) = + price(Price.ofBulkWithProration(bulkWithProration)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. + */ + fun price(groupedWithProratedMinimum: Price.GroupedWithProratedMinimum) = + price(Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. + */ + fun price(groupedWithMeteredMinimum: Price.GroupedWithMeteredMinimum) = + price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + + /** + * Alias for calling [price] with + * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. + */ + fun price(matrixWithDisplayName: Price.MatrixWithDisplayName) = + price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedTieredPackage(groupedTieredPackage)`. + */ + fun price(groupedTieredPackage: Price.GroupedTieredPackage) = + price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + + /** + * Alias for calling [price] with + * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. + */ + fun price(maxGroupTieredPackage: Price.MaxGroupTieredPackage) = + price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + + /** + * Alias for calling [price] with + * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. + */ + fun price(scalableMatrixWithUnitPricing: Price.ScalableMatrixWithUnitPricing) = + price(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) + + /** + * Alias for calling [price] with + * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. + */ + fun price(scalableMatrixWithTieredPricing: Price.ScalableMatrixWithTieredPricing) = + price(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) + + /** + * Alias for calling [price] with + * `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. + */ + fun price(cumulativeGroupedBulk: Price.CumulativeGroupedBulk) = + price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + + /** + * Alias for calling [price] with + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. + */ + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: Price.Minimum) = price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) + + /** Either the fixed fee quantity or the usage during the service period. */ + 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 } + + /** The start date of the range of time applied for this line item's price. */ + fun startDate(startDate: OffsetDateTime) = startDate(JsonField.of(startDate)) + + /** + * Sets [Builder.startDate] to an arbitrary JSON value. + * + * You should usually call [Builder.startDate] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun startDate(startDate: JsonField) = apply { + this.startDate = startDate + } + + /** + * For complex pricing structures, the line item can be broken down further in + * `sub_line_items`. + */ + fun subLineItems(subLineItems: List) = + subLineItems(JsonField.of(subLineItems)) + + /** + * Sets [Builder.subLineItems] to an arbitrary JSON value. + * + * You should usually call [Builder.subLineItems] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun subLineItems(subLineItems: JsonField>) = apply { + this.subLineItems = subLineItems.map { it.toMutableList() } + } + + /** + * Adds a single [SubLineItem] to [subLineItems]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSubLineItem(subLineItem: SubLineItem) = apply { + subLineItems = + (subLineItems ?: JsonField.of(mutableListOf())).also { + checkKnown("subLineItems", it).add(subLineItem) + } + } + + /** Alias for calling [addSubLineItem] with `SubLineItem.ofMatrix(matrix)`. */ + fun addSubLineItem(matrix: MatrixSubLineItem) = + addSubLineItem(SubLineItem.ofMatrix(matrix)) + + /** Alias for calling [addSubLineItem] with `SubLineItem.ofTier(tier)`. */ + fun addSubLineItem(tier: TierSubLineItem) = addSubLineItem(SubLineItem.ofTier(tier)) + + /** Alias for calling [addSubLineItem] with `SubLineItem.ofNull(null_)`. */ + fun addSubLineItem(null_: OtherSubLineItem) = + addSubLineItem(SubLineItem.ofNull(null_)) + + /** The line amount before any adjustments. */ + fun subtotal(subtotal: String) = subtotal(JsonField.of(subtotal)) + + /** + * Sets [Builder.subtotal] to an arbitrary JSON value. + * + * You should usually call [Builder.subtotal] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun subtotal(subtotal: JsonField) = apply { this.subtotal = subtotal } + + /** + * An array of tax rates and their incurred tax amounts. Empty if no tax integration + * is configured. + */ + fun taxAmounts(taxAmounts: List) = taxAmounts(JsonField.of(taxAmounts)) + + /** + * Sets [Builder.taxAmounts] to an arbitrary JSON value. + * + * You should usually call [Builder.taxAmounts] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun taxAmounts(taxAmounts: JsonField>) = apply { + this.taxAmounts = taxAmounts.map { it.toMutableList() } + } + + /** + * Adds a single [TaxAmount] to [taxAmounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTaxAmount(taxAmount: TaxAmount) = apply { + taxAmounts = + (taxAmounts ?: JsonField.of(mutableListOf())).also { + checkKnown("taxAmounts", it).add(taxAmount) + } + } + + /** + * A list of customer ids that were used to calculate the usage for this line item. + */ + fun usageCustomerIds(usageCustomerIds: List?) = + usageCustomerIds(JsonField.ofNullable(usageCustomerIds)) + + /** + * Sets [Builder.usageCustomerIds] to an arbitrary JSON value. + * + * You should usually call [Builder.usageCustomerIds] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun usageCustomerIds(usageCustomerIds: JsonField>) = apply { + this.usageCustomerIds = usageCustomerIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [usageCustomerIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUsageCustomerId(usageCustomerId: String) = apply { + usageCustomerIds = + (usageCustomerIds ?: JsonField.of(mutableListOf())).also { + checkKnown("usageCustomerIds", it).add(usageCustomerId) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [LineItem]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .id() + * .adjustedSubtotal() + * .adjustments() + * .amount() + * .creditsApplied() + * .endDate() + * .filter() + * .grouping() + * .name() + * .partiallyInvoicedAmount() + * .price() + * .quantity() + * .startDate() + * .subLineItems() + * .subtotal() + * .taxAmounts() + * .usageCustomerIds() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): LineItem = + LineItem( + checkRequired("id", id), + checkRequired("adjustedSubtotal", adjustedSubtotal), + checkRequired("adjustments", adjustments).map { it.toImmutable() }, + checkRequired("amount", amount), + checkRequired("creditsApplied", creditsApplied), + checkRequired("endDate", endDate), + checkRequired("filter", filter), + checkRequired("grouping", grouping), + checkRequired("name", name), + checkRequired("partiallyInvoicedAmount", partiallyInvoicedAmount), + checkRequired("price", price), + checkRequired("quantity", quantity), + checkRequired("startDate", startDate), + checkRequired("subLineItems", subLineItems).map { it.toImmutable() }, + checkRequired("subtotal", subtotal), + checkRequired("taxAmounts", taxAmounts).map { it.toImmutable() }, + checkRequired("usageCustomerIds", usageCustomerIds).map { + it.toImmutable() + }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): LineItem = apply { + if (validated) { + return@apply + } + + id() + adjustedSubtotal() + adjustments().forEach { it.validate() } + amount() + creditsApplied() + endDate() + filter() + grouping() + name() + partiallyInvoicedAmount() + price().validate() + quantity() + startDate() + subLineItems().forEach { it.validate() } + subtotal() + taxAmounts().forEach { it.validate() } + usageCustomerIds() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (id.asKnown() == null) 0 else 1) + + (if (adjustedSubtotal.asKnown() == null) 0 else 1) + + (adjustments.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (amount.asKnown() == null) 0 else 1) + + (if (creditsApplied.asKnown() == null) 0 else 1) + + (if (endDate.asKnown() == null) 0 else 1) + + (if (filter.asKnown() == null) 0 else 1) + + (if (grouping.asKnown() == null) 0 else 1) + + (if (name.asKnown() == null) 0 else 1) + + (if (partiallyInvoicedAmount.asKnown() == null) 0 else 1) + + (price.asKnown()?.validity() ?: 0) + + (if (quantity.asKnown() == null) 0 else 1) + + (if (startDate.asKnown() == null) 0 else 1) + + (subLineItems.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (subtotal.asKnown() == null) 0 else 1) + + (taxAmounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (usageCustomerIds.asKnown()?.size ?: 0) + + @JsonDeserialize(using = Adjustment.Deserializer::class) + @JsonSerialize(using = Adjustment.Serializer::class) + class Adjustment + private constructor( + private val usageDiscount: MonetaryUsageDiscountAdjustment? = null, + private val amountDiscount: MonetaryAmountDiscountAdjustment? = null, + private val percentageDiscount: MonetaryPercentageDiscountAdjustment? = null, + private val minimum: MonetaryMinimumAdjustment? = null, + private val maximum: MonetaryMaximumAdjustment? = null, + private val _json: JsonValue? = null, + ) { + + fun usageDiscount(): MonetaryUsageDiscountAdjustment? = usageDiscount + + fun amountDiscount(): MonetaryAmountDiscountAdjustment? = amountDiscount + + fun percentageDiscount(): MonetaryPercentageDiscountAdjustment? = percentageDiscount + + fun minimum(): MonetaryMinimumAdjustment? = minimum + + fun maximum(): MonetaryMaximumAdjustment? = maximum + + fun isUsageDiscount(): Boolean = usageDiscount != null + + fun isAmountDiscount(): Boolean = amountDiscount != null + + fun isPercentageDiscount(): Boolean = percentageDiscount != null + + fun isMinimum(): Boolean = minimum != null + + fun isMaximum(): Boolean = maximum != null + + fun asUsageDiscount(): MonetaryUsageDiscountAdjustment = + usageDiscount.getOrThrow("usageDiscount") + + fun asAmountDiscount(): MonetaryAmountDiscountAdjustment = + amountDiscount.getOrThrow("amountDiscount") + + fun asPercentageDiscount(): MonetaryPercentageDiscountAdjustment = + percentageDiscount.getOrThrow("percentageDiscount") + + fun asMinimum(): MonetaryMinimumAdjustment = minimum.getOrThrow("minimum") + + fun asMaximum(): MonetaryMaximumAdjustment = maximum.getOrThrow("maximum") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + usageDiscount != null -> visitor.visitUsageDiscount(usageDiscount) + amountDiscount != null -> visitor.visitAmountDiscount(amountDiscount) + percentageDiscount != null -> + visitor.visitPercentageDiscount(percentageDiscount) + minimum != null -> visitor.visitMinimum(minimum) + maximum != null -> visitor.visitMaximum(maximum) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Adjustment = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitUsageDiscount( + usageDiscount: MonetaryUsageDiscountAdjustment + ) { + usageDiscount.validate() + } + + override fun visitAmountDiscount( + amountDiscount: MonetaryAmountDiscountAdjustment + ) { + amountDiscount.validate() + } + + override fun visitPercentageDiscount( + percentageDiscount: MonetaryPercentageDiscountAdjustment + ) { + percentageDiscount.validate() + } + + override fun visitMinimum(minimum: MonetaryMinimumAdjustment) { + minimum.validate() + } + + override fun visitMaximum(maximum: MonetaryMaximumAdjustment) { + maximum.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitUsageDiscount( + usageDiscount: MonetaryUsageDiscountAdjustment + ) = usageDiscount.validity() + + override fun visitAmountDiscount( + amountDiscount: MonetaryAmountDiscountAdjustment + ) = amountDiscount.validity() + + override fun visitPercentageDiscount( + percentageDiscount: MonetaryPercentageDiscountAdjustment + ) = percentageDiscount.validity() + + override fun visitMinimum(minimum: MonetaryMinimumAdjustment) = + minimum.validity() + + override fun visitMaximum(maximum: MonetaryMaximumAdjustment) = + maximum.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Adjustment && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + percentageDiscount == other.percentageDiscount && + minimum == other.minimum && + maximum == other.maximum + } + + override fun hashCode(): Int = + Objects.hash( + usageDiscount, + amountDiscount, + percentageDiscount, + minimum, + maximum, + ) + + override fun toString(): String = + when { + usageDiscount != null -> "Adjustment{usageDiscount=$usageDiscount}" + amountDiscount != null -> "Adjustment{amountDiscount=$amountDiscount}" + percentageDiscount != null -> + "Adjustment{percentageDiscount=$percentageDiscount}" + minimum != null -> "Adjustment{minimum=$minimum}" + maximum != null -> "Adjustment{maximum=$maximum}" + _json != null -> "Adjustment{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Adjustment") + } + + companion object { + + fun ofUsageDiscount(usageDiscount: MonetaryUsageDiscountAdjustment) = + Adjustment(usageDiscount = usageDiscount) + + fun ofAmountDiscount(amountDiscount: MonetaryAmountDiscountAdjustment) = + Adjustment(amountDiscount = amountDiscount) + + fun ofPercentageDiscount( + percentageDiscount: MonetaryPercentageDiscountAdjustment + ) = Adjustment(percentageDiscount = percentageDiscount) + + fun ofMinimum(minimum: MonetaryMinimumAdjustment) = + Adjustment(minimum = minimum) + + fun ofMaximum(maximum: MonetaryMaximumAdjustment) = + Adjustment(maximum = maximum) + } + + /** + * An interface that defines how to map each variant of [Adjustment] to a value of + * type [T]. + */ + interface Visitor { + + fun visitUsageDiscount(usageDiscount: MonetaryUsageDiscountAdjustment): T + + fun visitAmountDiscount(amountDiscount: MonetaryAmountDiscountAdjustment): T + + fun visitPercentageDiscount( + percentageDiscount: MonetaryPercentageDiscountAdjustment + ): T + + fun visitMinimum(minimum: MonetaryMinimumAdjustment): T + + fun visitMaximum(maximum: MonetaryMaximumAdjustment): T + + /** + * Maps an unknown variant of [Adjustment] to a value of type [T]. + * + * An instance of [Adjustment] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if + * the SDK is on an older version than the API, then the API may respond with + * new variants that the SDK is unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown Adjustment: $json") + } + } + + internal class Deserializer : BaseDeserializer(Adjustment::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Adjustment { + val json = JsonValue.fromJsonNode(node) + val adjustmentType = json.asObject()?.get("adjustment_type")?.asString() + + when (adjustmentType) { + "usage_discount" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Adjustment(usageDiscount = it, _json = json) } + ?: Adjustment(_json = json) + } + "amount_discount" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Adjustment(amountDiscount = it, _json = json) } + ?: Adjustment(_json = json) + } + "percentage_discount" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Adjustment(percentageDiscount = it, _json = json) } + ?: Adjustment(_json = json) + } + "minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Adjustment(minimum = it, _json = json) } + ?: Adjustment(_json = json) + } + "maximum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Adjustment(maximum = it, _json = json) } + ?: Adjustment(_json = json) + } + } + + return Adjustment(_json = json) + } + } + + internal class Serializer : BaseSerializer(Adjustment::class) { + + override fun serialize( + value: Adjustment, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.usageDiscount != null -> + generator.writeObject(value.usageDiscount) + value.amountDiscount != null -> + generator.writeObject(value.amountDiscount) + value.percentageDiscount != null -> + generator.writeObject(value.percentageDiscount) + value.minimum != null -> generator.writeObject(value.minimum) + value.maximum != null -> generator.writeObject(value.maximum) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Adjustment") + } + } + } + } + + @JsonDeserialize(using = SubLineItem.Deserializer::class) + @JsonSerialize(using = SubLineItem.Serializer::class) + class SubLineItem + private constructor( + private val matrix: MatrixSubLineItem? = null, + private val tier: TierSubLineItem? = null, + private val null_: OtherSubLineItem? = null, + private val _json: JsonValue? = null, + ) { + + fun matrix(): MatrixSubLineItem? = matrix + + fun tier(): TierSubLineItem? = tier + + fun null_(): OtherSubLineItem? = null_ + + fun isMatrix(): Boolean = matrix != null + + fun isTier(): Boolean = tier != null + + fun isNull(): Boolean = null_ != null + + fun asMatrix(): MatrixSubLineItem = matrix.getOrThrow("matrix") + + fun asTier(): TierSubLineItem = tier.getOrThrow("tier") + + fun asNull(): OtherSubLineItem = null_.getOrThrow("null_") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + matrix != null -> visitor.visitMatrix(matrix) + tier != null -> visitor.visitTier(tier) + null_ != null -> visitor.visitNull(null_) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): SubLineItem = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitMatrix(matrix: MatrixSubLineItem) { + matrix.validate() + } + + override fun visitTier(tier: TierSubLineItem) { + tier.validate() + } + + override fun visitNull(null_: OtherSubLineItem) { + null_.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitMatrix(matrix: MatrixSubLineItem) = matrix.validity() + + override fun visitTier(tier: TierSubLineItem) = tier.validity() + + override fun visitNull(null_: OtherSubLineItem) = null_.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SubLineItem && + matrix == other.matrix && + tier == other.tier && + null_ == other.null_ + } + + override fun hashCode(): Int = Objects.hash(matrix, tier, null_) + + override fun toString(): String = + when { + matrix != null -> "SubLineItem{matrix=$matrix}" + tier != null -> "SubLineItem{tier=$tier}" + null_ != null -> "SubLineItem{null_=$null_}" + _json != null -> "SubLineItem{_unknown=$_json}" + else -> throw IllegalStateException("Invalid SubLineItem") + } + + companion object { + + fun ofMatrix(matrix: MatrixSubLineItem) = SubLineItem(matrix = matrix) + + fun ofTier(tier: TierSubLineItem) = SubLineItem(tier = tier) + + fun ofNull(null_: OtherSubLineItem) = SubLineItem(null_ = null_) + } + + /** + * An interface that defines how to map each variant of [SubLineItem] to a value of + * type [T]. + */ + interface Visitor { + + fun visitMatrix(matrix: MatrixSubLineItem): T + + fun visitTier(tier: TierSubLineItem): T + + fun visitNull(null_: OtherSubLineItem): T + + /** + * Maps an unknown variant of [SubLineItem] to a value of type [T]. + * + * An instance of [SubLineItem] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if + * the SDK is on an older version than the API, then the API may respond with + * new variants that the SDK is unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown SubLineItem: $json") + } + } + + internal class Deserializer : BaseDeserializer(SubLineItem::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): SubLineItem { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject()?.get("type")?.asString() + + when (type) { + "matrix" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { SubLineItem(matrix = it, _json = json) } + ?: SubLineItem(_json = json) + } + "tier" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { SubLineItem(tier = it, _json = json) } + ?: SubLineItem(_json = json) + } + "'null'" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { SubLineItem(null_ = it, _json = json) } + ?: SubLineItem(_json = json) + } + } + + return SubLineItem(_json = json) + } + } + + internal class Serializer : BaseSerializer(SubLineItem::class) { + + override fun serialize( + value: SubLineItem, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.matrix != null -> generator.writeObject(value.matrix) + value.tier != null -> generator.writeObject(value.tier) + value.null_ != null -> generator.writeObject(value.null_) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid SubLineItem") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is LineItem && + id == other.id && + adjustedSubtotal == other.adjustedSubtotal && + adjustments == other.adjustments && + amount == other.amount && + creditsApplied == other.creditsApplied && + endDate == other.endDate && + filter == other.filter && + grouping == other.grouping && + name == other.name && + partiallyInvoicedAmount == other.partiallyInvoicedAmount && + price == other.price && + quantity == other.quantity && + startDate == other.startDate && + subLineItems == other.subLineItems && + subtotal == other.subtotal && + taxAmounts == other.taxAmounts && + usageCustomerIds == other.usageCustomerIds && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustedSubtotal, + adjustments, + amount, + creditsApplied, + endDate, + filter, + grouping, + name, + partiallyInvoicedAmount, + price, + quantity, + startDate, + subLineItems, + subtotal, + taxAmounts, + usageCustomerIds, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "LineItem{id=$id, adjustedSubtotal=$adjustedSubtotal, adjustments=$adjustments, amount=$amount, creditsApplied=$creditsApplied, endDate=$endDate, filter=$filter, grouping=$grouping, name=$name, partiallyInvoicedAmount=$partiallyInvoicedAmount, price=$price, quantity=$quantity, startDate=$startDate, subLineItems=$subLineItems, subtotal=$subtotal, taxAmounts=$taxAmounts, usageCustomerIds=$usageCustomerIds, additionalProperties=$additionalProperties}" + } + + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and the + * entire metadata mapping can be cleared by setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + class PaymentAttempt + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val amount: JsonField, + private val createdAt: JsonField, + private val paymentProvider: JsonField, + private val paymentProviderId: JsonField, + private val receiptPdf: JsonField, + private val succeeded: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("amount") + @ExcludeMissing + amount: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("payment_provider") + @ExcludeMissing + paymentProvider: JsonField = JsonMissing.of(), + @JsonProperty("payment_provider_id") + @ExcludeMissing + paymentProviderId: JsonField = JsonMissing.of(), + @JsonProperty("receipt_pdf") + @ExcludeMissing + receiptPdf: JsonField = JsonMissing.of(), + @JsonProperty("succeeded") + @ExcludeMissing + succeeded: JsonField = JsonMissing.of(), + ) : this( + id, + amount, + createdAt, + paymentProvider, + paymentProviderId, + receiptPdf, + succeeded, + mutableMapOf(), + ) + + /** + * The ID of the payment attempt. + * + * @throws OrbInvalidDataException if 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 the payment attempt. + * + * @throws OrbInvalidDataException if 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(): String = amount.getRequired("amount") + + /** + * The time at which the payment attempt was created. + * + * @throws OrbInvalidDataException if 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") + + /** + * The payment provider that attempted to collect the payment. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun paymentProvider(): PaymentProvider? = + paymentProvider.getNullable("payment_provider") + + /** + * The ID of the payment attempt in the payment provider. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun paymentProviderId(): String? = paymentProviderId.getNullable("payment_provider_id") + + /** + * URL to the downloadable PDF version of the receipt. This field will be `null` for + * payment attempts that did not succeed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun receiptPdf(): String? = receiptPdf.getNullable("receipt_pdf") + + /** + * Whether the payment attempt succeeded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun succeeded(): Boolean = succeeded.getRequired("succeeded") + + /** + * 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 [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 [paymentProvider]. + * + * Unlike [paymentProvider], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("payment_provider") + @ExcludeMissing + fun _paymentProvider(): JsonField = paymentProvider + + /** + * Returns the raw JSON value of [paymentProviderId]. + * + * Unlike [paymentProviderId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("payment_provider_id") + @ExcludeMissing + fun _paymentProviderId(): JsonField = paymentProviderId + + /** + * Returns the raw JSON value of [receiptPdf]. + * + * Unlike [receiptPdf], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("receipt_pdf") + @ExcludeMissing + fun _receiptPdf(): JsonField = receiptPdf + + /** + * Returns the raw JSON value of [succeeded]. + * + * Unlike [succeeded], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("succeeded") + @ExcludeMissing + fun _succeeded(): JsonField = succeeded + + @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 [PaymentAttempt]. + * + * The following fields are required: + * ```kotlin + * .id() + * .amount() + * .createdAt() + * .paymentProvider() + * .paymentProviderId() + * .receiptPdf() + * .succeeded() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PaymentAttempt]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var amount: JsonField? = null + private var createdAt: JsonField? = null + private var paymentProvider: JsonField? = null + private var paymentProviderId: JsonField? = null + private var receiptPdf: JsonField? = null + private var succeeded: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(paymentAttempt: PaymentAttempt) = apply { + id = paymentAttempt.id + amount = paymentAttempt.amount + createdAt = paymentAttempt.createdAt + paymentProvider = paymentAttempt.paymentProvider + paymentProviderId = paymentAttempt.paymentProviderId + receiptPdf = paymentAttempt.receiptPdf + succeeded = paymentAttempt.succeeded + additionalProperties = paymentAttempt.additionalProperties.toMutableMap() + } + + /** The ID of the payment attempt. */ + 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 the payment attempt. */ + fun amount(amount: String) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [String] 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 } + + /** The time at which the payment attempt was created. */ + 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 + } + + /** The payment provider that attempted to collect the payment. */ + fun paymentProvider(paymentProvider: PaymentProvider?) = + paymentProvider(JsonField.ofNullable(paymentProvider)) + + /** + * Sets [Builder.paymentProvider] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentProvider] with a well-typed + * [PaymentProvider] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun paymentProvider(paymentProvider: JsonField) = apply { + this.paymentProvider = paymentProvider + } + + /** The ID of the payment attempt in the payment provider. */ + fun paymentProviderId(paymentProviderId: String?) = + paymentProviderId(JsonField.ofNullable(paymentProviderId)) + + /** + * Sets [Builder.paymentProviderId] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentProviderId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun paymentProviderId(paymentProviderId: JsonField) = apply { + this.paymentProviderId = paymentProviderId + } + + /** + * URL to the downloadable PDF version of the receipt. This field will be `null` for + * payment attempts that did not succeed. + */ + fun receiptPdf(receiptPdf: String?) = receiptPdf(JsonField.ofNullable(receiptPdf)) + + /** + * Sets [Builder.receiptPdf] to an arbitrary JSON value. + * + * You should usually call [Builder.receiptPdf] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun receiptPdf(receiptPdf: JsonField) = apply { + this.receiptPdf = receiptPdf + } + + /** Whether the payment attempt succeeded. */ + fun succeeded(succeeded: Boolean) = succeeded(JsonField.of(succeeded)) + + /** + * Sets [Builder.succeeded] to an arbitrary JSON value. + * + * You should usually call [Builder.succeeded] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun succeeded(succeeded: JsonField) = apply { this.succeeded = succeeded } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PaymentAttempt]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .id() + * .amount() + * .createdAt() + * .paymentProvider() + * .paymentProviderId() + * .receiptPdf() + * .succeeded() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PaymentAttempt = + PaymentAttempt( + checkRequired("id", id), + checkRequired("amount", amount), + checkRequired("createdAt", createdAt), + checkRequired("paymentProvider", paymentProvider), + checkRequired("paymentProviderId", paymentProviderId), + checkRequired("receiptPdf", receiptPdf), + checkRequired("succeeded", succeeded), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PaymentAttempt = apply { + if (validated) { + return@apply + } + + id() + amount() + createdAt() + paymentProvider()?.validate() + paymentProviderId() + receiptPdf() + succeeded() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (id.asKnown() == null) 0 else 1) + + (if (amount.asKnown() == null) 0 else 1) + + (if (createdAt.asKnown() == null) 0 else 1) + + (paymentProvider.asKnown()?.validity() ?: 0) + + (if (paymentProviderId.asKnown() == null) 0 else 1) + + (if (receiptPdf.asKnown() == null) 0 else 1) + + (if (succeeded.asKnown() == null) 0 else 1) + + /** The payment provider that attempted to collect the payment. */ + class PaymentProvider + @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 { + + val STRIPE = of("stripe") + + fun of(value: String) = PaymentProvider(JsonField.of(value)) + } + + /** An enum containing [PaymentProvider]'s known values. */ + enum class Known { + STRIPE + } + + /** + * An enum containing [PaymentProvider]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [PaymentProvider] 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 [PaymentProvider] 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + STRIPE -> Known.STRIPE + else -> throw OrbInvalidDataException("Unknown PaymentProvider: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): PaymentProvider = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 PaymentProvider && 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 PaymentAttempt && + id == other.id && + amount == other.amount && + createdAt == other.createdAt && + paymentProvider == other.paymentProvider && + paymentProviderId == other.paymentProviderId && + receiptPdf == other.receiptPdf && + succeeded == other.succeeded && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + createdAt, + paymentProvider, + paymentProviderId, + receiptPdf, + succeeded, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PaymentAttempt{id=$id, amount=$amount, createdAt=$createdAt, paymentProvider=$paymentProvider, paymentProviderId=$paymentProviderId, receiptPdf=$receiptPdf, succeeded=$succeeded, additionalProperties=$additionalProperties}" + } + + class Status @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 { + + val ISSUED = of("issued") + + val PAID = of("paid") + + val SYNCED = of("synced") + + val VOID = of("void") + + val DRAFT = of("draft") + + fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + ISSUED, + PAID, + SYNCED, + VOID, + DRAFT, + } + + /** + * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Status] 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 { + ISSUED, + PAID, + SYNCED, + VOID, + DRAFT, + /** + * An enum member indicating that [Status] 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) { + ISSUED -> Value.ISSUED + PAID -> Value.PAID + SYNCED -> Value.SYNCED + VOID -> Value.VOID + DRAFT -> Value.DRAFT + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ISSUED -> Known.ISSUED + PAID -> Known.PAID + SYNCED -> Known.SYNCED + VOID -> Known.VOID + DRAFT -> Known.DRAFT + else -> throw OrbInvalidDataException("Unknown Status: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Status = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Status && 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 CreatedInvoice && + id == other.id && + amountDue == other.amountDue && + autoCollection == other.autoCollection && + billingAddress == other.billingAddress && + createdAt == other.createdAt && + creditNotes == other.creditNotes && + currency == other.currency && + customer == other.customer && + customerBalanceTransactions == other.customerBalanceTransactions && + customerTaxId == other.customerTaxId && + discount == other.discount && + discounts == other.discounts && + dueDate == other.dueDate && + eligibleToIssueAt == other.eligibleToIssueAt && + hostedInvoiceUrl == other.hostedInvoiceUrl && + invoiceDate == other.invoiceDate && + invoiceNumber == other.invoiceNumber && + invoicePdf == other.invoicePdf && + invoiceSource == other.invoiceSource && + isPayableNow == other.isPayableNow && + issueFailedAt == other.issueFailedAt && + issuedAt == other.issuedAt && + lineItems == other.lineItems && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + memo == other.memo && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + paidAt == other.paidAt && + paymentAttempts == other.paymentAttempts && + paymentFailedAt == other.paymentFailedAt && + paymentStartedAt == other.paymentStartedAt && + scheduledIssueAt == other.scheduledIssueAt && + shippingAddress == other.shippingAddress && + status == other.status && + subscription == other.subscription && + subtotal == other.subtotal && + syncFailedAt == other.syncFailedAt && + total == other.total && + voidedAt == other.voidedAt && + willAutoIssue == other.willAutoIssue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + amountDue, + autoCollection, + billingAddress, + createdAt, + creditNotes, + currency, + customer, + customerBalanceTransactions, + customerTaxId, + discount, + discounts, + dueDate, + eligibleToIssueAt, + hostedInvoiceUrl, + invoiceDate, + invoiceNumber, + invoicePdf, + invoiceSource, + isPayableNow, + issueFailedAt, + issuedAt, + lineItems, + maximum, + maximumAmount, + memo, + metadata, + minimum, + minimumAmount, + paidAt, + paymentAttempts, + paymentFailedAt, + paymentStartedAt, + scheduledIssueAt, + shippingAddress, + status, + subscription, + subtotal, + syncFailedAt, + total, + voidedAt, + willAutoIssue, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CreatedInvoice{id=$id, amountDue=$amountDue, autoCollection=$autoCollection, billingAddress=$billingAddress, createdAt=$createdAt, creditNotes=$creditNotes, currency=$currency, customer=$customer, customerBalanceTransactions=$customerBalanceTransactions, customerTaxId=$customerTaxId, discount=$discount, discounts=$discounts, dueDate=$dueDate, eligibleToIssueAt=$eligibleToIssueAt, hostedInvoiceUrl=$hostedInvoiceUrl, invoiceDate=$invoiceDate, invoiceNumber=$invoiceNumber, invoicePdf=$invoicePdf, invoiceSource=$invoiceSource, isPayableNow=$isPayableNow, issueFailedAt=$issueFailedAt, issuedAt=$issuedAt, lineItems=$lineItems, maximum=$maximum, maximumAmount=$maximumAmount, memo=$memo, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, paidAt=$paidAt, paymentAttempts=$paymentAttempts, paymentFailedAt=$paymentFailedAt, paymentStartedAt=$paymentStartedAt, scheduledIssueAt=$scheduledIssueAt, shippingAddress=$shippingAddress, status=$status, subscription=$subscription, subtotal=$subtotal, syncFailedAt=$syncFailedAt, total=$total, voidedAt=$voidedAt, willAutoIssue=$willAutoIssue, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChangedSubscriptionResources && + createdCreditNotes == other.createdCreditNotes && + createdInvoices == other.createdInvoices && + voidedCreditNotes == other.voidedCreditNotes && + voidedInvoices == other.voidedInvoices && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + createdCreditNotes, + createdInvoices, + voidedCreditNotes, + voidedInvoices, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateConfig.kt new file mode 100644 index 000000000..fb442be2a --- /dev/null +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateConfig.kt @@ -0,0 +1,183 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.BaseDeserializer +import com.withorb.api.core.BaseSerializer +import com.withorb.api.core.JsonValue +import com.withorb.api.core.getOrThrow +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Objects + +@JsonDeserialize(using = ConversionRateConfig.Deserializer::class) +@JsonSerialize(using = ConversionRateConfig.Serializer::class) +class ConversionRateConfig +private constructor( + private val unit: UnitConversionRateConfig? = null, + private val tiered: TieredConversionRateConfig? = null, + private val _json: JsonValue? = null, +) { + + fun unit(): UnitConversionRateConfig? = unit + + fun tiered(): TieredConversionRateConfig? = tiered + + fun isUnit(): Boolean = unit != null + + fun isTiered(): Boolean = tiered != null + + fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + + fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + unit != null -> visitor.visitUnit(unit) + tiered != null -> visitor.visitTiered(tiered) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): ConversionRateConfig = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitUnit(unit: UnitConversionRateConfig) { + unit.validate() + } + + override fun visitTiered(tiered: TieredConversionRateConfig) { + tiered.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + + override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ConversionRateConfig && unit == other.unit && tiered == other.tiered + } + + override fun hashCode(): Int = Objects.hash(unit, tiered) + + override fun toString(): String = + when { + unit != null -> "ConversionRateConfig{unit=$unit}" + tiered != null -> "ConversionRateConfig{tiered=$tiered}" + _json != null -> "ConversionRateConfig{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ConversionRateConfig") + } + + companion object { + + fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + + fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) + } + + /** + * An interface that defines how to map each variant of [ConversionRateConfig] to a value of + * type [T]. + */ + interface Visitor { + + fun visitUnit(unit: UnitConversionRateConfig): T + + fun visitTiered(tiered: TieredConversionRateConfig): T + + /** + * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * + * An instance of [ConversionRateConfig] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if the SDK is + * on an older version than the API, then the API may respond with new variants that the SDK + * is unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + } + } + + internal class Deserializer : + BaseDeserializer(ConversionRateConfig::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { + val json = JsonValue.fromJsonNode(node) + val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + + when (conversionRateType) { + "unit" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + ConversionRateConfig(unit = it, _json = json) + } ?: ConversionRateConfig(_json = json) + } + "tiered" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + ConversionRateConfig(tiered = it, _json = json) + } ?: ConversionRateConfig(_json = json) + } + } + + return ConversionRateConfig(_json = json) + } + } + + internal class Serializer : BaseSerializer(ConversionRateConfig::class) { + + override fun serialize( + value: ConversionRateConfig, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.unit != null -> generator.writeObject(value.unit) + value.tiered != null -> generator.writeObject(value.tiered) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ConversionRateConfig") + } + } + } +} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateTier.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateTier.kt index e03a1fc89..8c1a6758e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateTier.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateTier.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class ConversionRateTier +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val firstUnit: JsonField, private val unitAmount: JsonField, @@ -237,12 +238,16 @@ private constructor( return true } - return /* spotless:off */ other is ConversionRateTier && firstUnit == other.firstUnit && unitAmount == other.unitAmount && lastUnit == other.lastUnit && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ConversionRateTier && + firstUnit == other.firstUnit && + unitAmount == other.unitAmount && + lastUnit == other.lastUnit && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(firstUnit, unitAmount, lastUnit, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(firstUnit, unitAmount, lastUnit, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateTieredConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateTieredConfig.kt index 0e156090a..e0b163c3b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateTieredConfig.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateTieredConfig.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class ConversionRateTieredConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val tiers: JsonField>, private val additionalProperties: MutableMap, @@ -174,12 +175,12 @@ private constructor( return true } - return /* spotless:off */ other is ConversionRateTieredConfig && tiers == other.tiers && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ConversionRateTieredConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateUnitConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateUnitConfig.kt index bd0c37b04..210c25c18 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateUnitConfig.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ConversionRateUnitConfig.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class ConversionRateUnitConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val unitAmount: JsonField, private val additionalProperties: MutableMap, @@ -160,12 +161,12 @@ private constructor( return true } - return /* spotless:off */ other is ConversionRateUnitConfig && unitAmount == other.unitAmount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ConversionRateUnitConfig && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(unitAmount, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Coupon.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Coupon.kt index 25904bba7..8a438565c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Coupon.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Coupon.kt @@ -33,6 +33,7 @@ import java.util.Objects * long it remains available for use by end users. */ class Coupon +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val archivedAt: JsonField, @@ -573,10 +574,10 @@ private constructor( return true } - return /* spotless:off */ other is Discount && percentage == other.percentage && amount == other.amount /* spotless:on */ + return other is Discount && percentage == other.percentage && amount == other.amount } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentage, amount) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(percentage, amount) override fun toString(): String = when { @@ -662,12 +663,29 @@ private constructor( return true } - return /* spotless:off */ other is Coupon && id == other.id && archivedAt == other.archivedAt && discount == other.discount && durationInMonths == other.durationInMonths && maxRedemptions == other.maxRedemptions && redemptionCode == other.redemptionCode && timesRedeemed == other.timesRedeemed && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Coupon && + id == other.id && + archivedAt == other.archivedAt && + discount == other.discount && + durationInMonths == other.durationInMonths && + maxRedemptions == other.maxRedemptions && + redemptionCode == other.redemptionCode && + timesRedeemed == other.timesRedeemed && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, archivedAt, discount, durationInMonths, maxRedemptions, redemptionCode, timesRedeemed, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + archivedAt, + discount, + durationInMonths, + maxRedemptions, + redemptionCode, + timesRedeemed, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponArchiveParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponArchiveParams.kt index bc3854184..e7efcb1ab 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponArchiveParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponArchiveParams.kt @@ -211,10 +211,15 @@ private constructor( return true } - return /* spotless:off */ other is CouponArchiveParams && couponId == other.couponId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is CouponArchiveParams && + couponId == other.couponId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(couponId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(couponId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "CouponArchiveParams{couponId=$couponId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponCreateParams.kt index e3ae258a6..d0749f79d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponCreateParams.kt @@ -397,6 +397,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val discount: JsonField, private val redemptionCode: JsonField, @@ -722,12 +723,23 @@ private constructor( return true } - return /* spotless:off */ other is Body && discount == other.discount && redemptionCode == other.redemptionCode && durationInMonths == other.durationInMonths && maxRedemptions == other.maxRedemptions && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + discount == other.discount && + redemptionCode == other.redemptionCode && + durationInMonths == other.durationInMonths && + maxRedemptions == other.maxRedemptions && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(discount, redemptionCode, durationInMonths, maxRedemptions, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + discount, + redemptionCode, + durationInMonths, + maxRedemptions, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -816,10 +828,10 @@ private constructor( return true } - return /* spotless:off */ other is Discount && percentage == other.percentage && amount == other.amount /* spotless:on */ + return other is Discount && percentage == other.percentage && amount == other.amount } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentage, amount) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(percentage, amount) override fun toString(): String = when { @@ -900,6 +912,7 @@ private constructor( } class Percentage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val discountType: JsonValue, private val percentageDiscount: JsonField, @@ -1095,12 +1108,15 @@ private constructor( return true } - return /* spotless:off */ other is Percentage && discountType == other.discountType && percentageDiscount == other.percentageDiscount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Percentage && + discountType == other.discountType && + percentageDiscount == other.percentageDiscount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(discountType, percentageDiscount, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(discountType, percentageDiscount, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1109,6 +1125,7 @@ private constructor( } class Amount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amountDiscount: JsonField, private val discountType: JsonValue, @@ -1304,12 +1321,15 @@ private constructor( return true } - return /* spotless:off */ other is Amount && amountDiscount == other.amountDiscount && discountType == other.discountType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Amount && + amountDiscount == other.amountDiscount && + discountType == other.discountType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amountDiscount, discountType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(amountDiscount, discountType, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1323,10 +1343,13 @@ private constructor( return true } - return /* spotless:off */ other is CouponCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CouponCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "CouponCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponFetchParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponFetchParams.kt index 54557cea0..380e74269 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponFetchParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponFetchParams.kt @@ -173,10 +173,13 @@ private constructor( return true } - return /* spotless:off */ other is CouponFetchParams && couponId == other.couponId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CouponFetchParams && + couponId == other.couponId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(couponId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(couponId, additionalHeaders, additionalQueryParams) override fun toString() = "CouponFetchParams{couponId=$couponId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListPage.kt index 8eeaffd9d..e48df727c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListPage.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is CouponListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CouponListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CouponListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListPageAsync.kt index 9e7497a43..417b6176b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListPageAsync.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is CouponListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CouponListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CouponListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListPageResponse.kt index 9d84e15ec..87e2ab472 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CouponListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -214,12 +215,15 @@ private constructor( return true } - return /* spotless:off */ other is CouponListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CouponListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListParams.kt index 1e438a68f..2af9ee208 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponListParams.kt @@ -237,10 +237,24 @@ private constructor( return true } - return /* spotless:off */ other is CouponListParams && cursor == other.cursor && limit == other.limit && redemptionCode == other.redemptionCode && showArchived == other.showArchived && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CouponListParams && + cursor == other.cursor && + limit == other.limit && + redemptionCode == other.redemptionCode && + showArchived == other.showArchived && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(cursor, limit, redemptionCode, showArchived, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + cursor, + limit, + redemptionCode, + showArchived, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "CouponListParams{cursor=$cursor, limit=$limit, redemptionCode=$redemptionCode, showArchived=$showArchived, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponRedemption.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponRedemption.kt index 44b037e7f..033ad5b57 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponRedemption.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponRedemption.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class CouponRedemption +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val couponId: JsonField, private val endDate: JsonField, @@ -228,12 +229,16 @@ private constructor( return true } - return /* spotless:off */ other is CouponRedemption && couponId == other.couponId && endDate == other.endDate && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CouponRedemption && + couponId == other.couponId && + endDate == other.endDate && + startDate == other.startDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(couponId, endDate, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(couponId, endDate, startDate, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPage.kt index bfe0a3671..e5c64b119 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPage.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is CouponSubscriptionListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CouponSubscriptionListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CouponSubscriptionListPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPageAsync.kt index 4beaa02a5..cadbc8b8e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPageAsync.kt @@ -122,10 +122,13 @@ private constructor( return true } - return /* spotless:off */ other is CouponSubscriptionListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CouponSubscriptionListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CouponSubscriptionListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListParams.kt index fc1c974a6..5f371a1d9 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListParams.kt @@ -221,10 +221,16 @@ private constructor( return true } - return /* spotless:off */ other is CouponSubscriptionListParams && couponId == other.couponId && cursor == other.cursor && limit == other.limit && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CouponSubscriptionListParams && + couponId == other.couponId && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(couponId, cursor, limit, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(couponId, cursor, limit, additionalHeaders, additionalQueryParams) override fun toString() = "CouponSubscriptionListParams{couponId=$couponId, cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditBlockExpiryLedgerEntry.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditBlockExpiryLedgerEntry.kt index 1c75e5ef4..ecd3224cc 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditBlockExpiryLedgerEntry.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditBlockExpiryLedgerEntry.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class CreditBlockExpiryLedgerEntry +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, @@ -735,7 +736,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryStatus && value == other.value /* spotless:on */ + return other is EntryStatus && value == other.value } override fun hashCode() = value.hashCode() @@ -855,7 +856,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryType && value == other.value /* spotless:on */ + return other is EntryType && value == other.value } override fun hashCode() = value.hashCode() @@ -955,12 +956,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -972,12 +971,41 @@ private constructor( return true } - return /* spotless:off */ other is CreditBlockExpiryLedgerEntry && id == other.id && amount == other.amount && createdAt == other.createdAt && creditBlock == other.creditBlock && currency == other.currency && customer == other.customer && description == other.description && endingBalance == other.endingBalance && entryStatus == other.entryStatus && entryType == other.entryType && ledgerSequenceNumber == other.ledgerSequenceNumber && metadata == other.metadata && startingBalance == other.startingBalance && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CreditBlockExpiryLedgerEntry && + id == other.id && + amount == other.amount && + createdAt == other.createdAt && + creditBlock == other.creditBlock && + currency == other.currency && + customer == other.customer && + description == other.description && + endingBalance == other.endingBalance && + entryStatus == other.entryStatus && + entryType == other.entryType && + ledgerSequenceNumber == other.ledgerSequenceNumber && + metadata == other.metadata && + startingBalance == other.startingBalance && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, createdAt, creditBlock, currency, customer, description, endingBalance, entryStatus, entryType, ledgerSequenceNumber, metadata, startingBalance, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + createdAt, + creditBlock, + currency, + customer, + description, + endingBalance, + entryStatus, + entryType, + ledgerSequenceNumber, + metadata, + startingBalance, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNote.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNote.kt index f03dbe503..4518992f5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNote.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNote.kt @@ -24,6 +24,7 @@ import java.util.Objects * a particular invoice. */ class CreditNote +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val createdAt: JsonField, @@ -784,6 +785,7 @@ private constructor( (discounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) class LineItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, @@ -1318,6 +1320,7 @@ private constructor( (if (startTimeInclusive.asKnown() == null) 0 else 1) class Discount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amountApplied: JsonField, @@ -1843,7 +1846,7 @@ private constructor( return true } - return /* spotless:off */ other is DiscountType && value == other.value /* spotless:on */ + return other is DiscountType && value == other.value } override fun hashCode() = value.hashCode() @@ -1856,13 +1859,30 @@ private constructor( return true } - return /* spotless:off */ other is Discount && id == other.id && amountApplied == other.amountApplied && appliesToPriceIds == other.appliesToPriceIds && discountType == other.discountType && percentageDiscount == other.percentageDiscount && amountDiscount == other.amountDiscount && reason == other.reason && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Discount && + id == other.id && + amountApplied == other.amountApplied && + appliesToPriceIds == other.appliesToPriceIds && + discountType == other.discountType && + percentageDiscount == other.percentageDiscount && + amountDiscount == other.amountDiscount && + reason == other.reason && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + amountApplied, + appliesToPriceIds, + discountType, + percentageDiscount, + amountDiscount, + reason, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amountApplied, appliesToPriceIds, discountType, percentageDiscount, amountDiscount, reason, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = @@ -1874,12 +1894,35 @@ private constructor( return true } - return /* spotless:off */ other is LineItem && id == other.id && amount == other.amount && itemId == other.itemId && name == other.name && quantity == other.quantity && subtotal == other.subtotal && taxAmounts == other.taxAmounts && discounts == other.discounts && endTimeExclusive == other.endTimeExclusive && startTimeInclusive == other.startTimeInclusive && additionalProperties == other.additionalProperties /* spotless:on */ + return other is LineItem && + id == other.id && + amount == other.amount && + itemId == other.itemId && + name == other.name && + quantity == other.quantity && + subtotal == other.subtotal && + taxAmounts == other.taxAmounts && + discounts == other.discounts && + endTimeExclusive == other.endTimeExclusive && + startTimeInclusive == other.startTimeInclusive && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, itemId, name, quantity, subtotal, taxAmounts, discounts, endTimeExclusive, startTimeInclusive, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + itemId, + name, + quantity, + subtotal, + taxAmounts, + discounts, + endTimeExclusive, + startTimeInclusive, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1889,6 +1932,7 @@ private constructor( /** The maximum amount applied on the original invoice */ class MaximumAmountAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amountApplied: JsonField, private val discountType: JsonField, @@ -2318,7 +2362,7 @@ private constructor( return true } - return /* spotless:off */ other is DiscountType && value == other.value /* spotless:on */ + return other is DiscountType && value == other.value } override fun hashCode() = value.hashCode() @@ -2327,6 +2371,7 @@ private constructor( } class AppliesToPrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -2505,12 +2550,13 @@ private constructor( return true } - return /* spotless:off */ other is AppliesToPrice && id == other.id && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AppliesToPrice && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, name, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2523,12 +2569,25 @@ private constructor( return true } - return /* spotless:off */ other is MaximumAmountAdjustment && amountApplied == other.amountApplied && discountType == other.discountType && percentageDiscount == other.percentageDiscount && appliesToPrices == other.appliesToPrices && reason == other.reason && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MaximumAmountAdjustment && + amountApplied == other.amountApplied && + discountType == other.discountType && + percentageDiscount == other.percentageDiscount && + appliesToPrices == other.appliesToPrices && + reason == other.reason && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amountApplied, discountType, percentageDiscount, appliesToPrices, reason, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amountApplied, + discountType, + percentageDiscount, + appliesToPrices, + reason, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2664,7 +2723,7 @@ private constructor( return true } - return /* spotless:off */ other is Reason && value == other.value /* spotless:on */ + return other is Reason && value == other.value } override fun hashCode() = value.hashCode() @@ -2788,7 +2847,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -2797,6 +2856,7 @@ private constructor( } class Discount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amountApplied: JsonField, private val discountType: JsonField, @@ -3226,7 +3286,7 @@ private constructor( return true } - return /* spotless:off */ other is DiscountType && value == other.value /* spotless:on */ + return other is DiscountType && value == other.value } override fun hashCode() = value.hashCode() @@ -3235,6 +3295,7 @@ private constructor( } class AppliesToPrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -3413,12 +3474,13 @@ private constructor( return true } - return /* spotless:off */ other is AppliesToPrice && id == other.id && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AppliesToPrice && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, name, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3431,12 +3493,25 @@ private constructor( return true } - return /* spotless:off */ other is Discount && amountApplied == other.amountApplied && discountType == other.discountType && percentageDiscount == other.percentageDiscount && appliesToPrices == other.appliesToPrices && reason == other.reason && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Discount && + amountApplied == other.amountApplied && + discountType == other.discountType && + percentageDiscount == other.percentageDiscount && + appliesToPrices == other.appliesToPrices && + reason == other.reason && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amountApplied, discountType, percentageDiscount, appliesToPrices, reason, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amountApplied, + discountType, + percentageDiscount, + appliesToPrices, + reason, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -3449,12 +3524,47 @@ private constructor( return true } - return /* spotless:off */ other is CreditNote && id == other.id && createdAt == other.createdAt && creditNoteNumber == other.creditNoteNumber && creditNotePdf == other.creditNotePdf && customer == other.customer && invoiceId == other.invoiceId && lineItems == other.lineItems && maximumAmountAdjustment == other.maximumAmountAdjustment && memo == other.memo && minimumAmountRefunded == other.minimumAmountRefunded && reason == other.reason && subtotal == other.subtotal && total == other.total && type == other.type && voidedAt == other.voidedAt && discounts == other.discounts && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CreditNote && + id == other.id && + createdAt == other.createdAt && + creditNoteNumber == other.creditNoteNumber && + creditNotePdf == other.creditNotePdf && + customer == other.customer && + invoiceId == other.invoiceId && + lineItems == other.lineItems && + maximumAmountAdjustment == other.maximumAmountAdjustment && + memo == other.memo && + minimumAmountRefunded == other.minimumAmountRefunded && + reason == other.reason && + subtotal == other.subtotal && + total == other.total && + type == other.type && + voidedAt == other.voidedAt && + discounts == other.discounts && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, createdAt, creditNoteNumber, creditNotePdf, customer, invoiceId, lineItems, maximumAmountAdjustment, memo, minimumAmountRefunded, reason, subtotal, total, type, voidedAt, discounts, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + creditNoteNumber, + creditNotePdf, + customer, + invoiceId, + lineItems, + maximumAmountAdjustment, + memo, + minimumAmountRefunded, + reason, + subtotal, + total, + type, + voidedAt, + discounts, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteCreateParams.kt index b7f9ccade..bc3100336 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteCreateParams.kt @@ -401,6 +401,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val lineItems: JsonField>, private val reason: JsonField, @@ -720,12 +721,18 @@ private constructor( return true } - return /* spotless:off */ other is Body && lineItems == other.lineItems && reason == other.reason && endDate == other.endDate && memo == other.memo && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + lineItems == other.lineItems && + reason == other.reason && + endDate == other.endDate && + memo == other.memo && + startDate == other.startDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(lineItems, reason, endDate, memo, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(lineItems, reason, endDate, memo, startDate, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -734,6 +741,7 @@ private constructor( } class LineItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val invoiceLineItemId: JsonField, @@ -1012,12 +1020,17 @@ private constructor( return true } - return /* spotless:off */ other is LineItem && amount == other.amount && invoiceLineItemId == other.invoiceLineItemId && endDate == other.endDate && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is LineItem && + amount == other.amount && + invoiceLineItemId == other.invoiceLineItemId && + endDate == other.endDate && + startDate == other.startDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, invoiceLineItemId, endDate, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(amount, invoiceLineItemId, endDate, startDate, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1154,7 +1167,7 @@ private constructor( return true } - return /* spotless:off */ other is Reason && value == other.value /* spotless:on */ + return other is Reason && value == other.value } override fun hashCode() = value.hashCode() @@ -1167,10 +1180,13 @@ private constructor( return true } - return /* spotless:off */ other is CreditNoteCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CreditNoteCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "CreditNoteCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteFetchParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteFetchParams.kt index 04ad4dc72..080b9f54b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteFetchParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteFetchParams.kt @@ -177,10 +177,14 @@ private constructor( return true } - return /* spotless:off */ other is CreditNoteFetchParams && creditNoteId == other.creditNoteId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CreditNoteFetchParams && + creditNoteId == other.creditNoteId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(creditNoteId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(creditNoteId, additionalHeaders, additionalQueryParams) override fun toString() = "CreditNoteFetchParams{creditNoteId=$creditNoteId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPage.kt index 652b36fb4..34179c748 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPage.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is CreditNoteListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CreditNoteListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CreditNoteListPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageAsync.kt index 8c7838267..ed3a64b33 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageAsync.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is CreditNoteListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CreditNoteListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CreditNoteListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageResponse.kt index fc18270fe..33ef8e858 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CreditNoteListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -214,12 +215,15 @@ private constructor( return true } - return /* spotless:off */ other is CreditNoteListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CreditNoteListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListParams.kt index 4c21de8ef..d23b2afc3 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteListParams.kt @@ -250,10 +250,28 @@ private constructor( return true } - return /* spotless:off */ other is CreditNoteListParams && createdAtGt == other.createdAtGt && createdAtGte == other.createdAtGte && createdAtLt == other.createdAtLt && createdAtLte == other.createdAtLte && cursor == other.cursor && limit == other.limit && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CreditNoteListParams && + createdAtGt == other.createdAtGt && + createdAtGte == other.createdAtGte && + createdAtLt == other.createdAtLt && + createdAtLte == other.createdAtLte && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(createdAtGt, createdAtGte, createdAtLt, createdAtLte, cursor, limit, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + createdAtGt, + createdAtGte, + createdAtLt, + createdAtLte, + cursor, + limit, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "CreditNoteListParams{createdAtGt=$createdAtGt, createdAtGte=$createdAtGte, createdAtLt=$createdAtLt, createdAtLte=$createdAtLte, cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteTiny.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteTiny.kt index c2cbd8985..150c55699 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteTiny.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CreditNoteTiny.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class CreditNoteTiny +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val additionalProperties: MutableMap, @@ -154,12 +155,12 @@ private constructor( return true } - return /* spotless:off */ other is CreditNoteTiny && id == other.id && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CreditNoteTiny && + id == other.id && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomExpiration.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomExpiration.kt index d98093cb6..6ba138519 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomExpiration.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomExpiration.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class CustomExpiration +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val duration: JsonField, private val durationUnit: JsonField, @@ -308,7 +309,7 @@ private constructor( return true } - return /* spotless:off */ other is DurationUnit && value == other.value /* spotless:on */ + return other is DurationUnit && value == other.value } override fun hashCode() = value.hashCode() @@ -321,12 +322,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomExpiration && duration == other.duration && durationUnit == other.durationUnit && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomExpiration && + duration == other.duration && + durationUnit == other.durationUnit && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(duration, durationUnit, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Customer.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Customer.kt index c91f7576f..f40c200ee 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Customer.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Customer.kt @@ -38,10 +38,12 @@ import java.util.Objects * timezone parameter influences within Orb. */ class Customer +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val additionalEmails: JsonField>, private val autoCollection: JsonField, + private val autoIssuance: JsonField, private val balance: JsonField, private val billingAddress: JsonField
, private val createdAt: JsonField, @@ -60,6 +62,8 @@ private constructor( private val taxId: JsonField, private val timezone: JsonField, private val accountingSyncConfiguration: JsonField, + private val automaticTaxEnabled: JsonField, + private val paymentConfiguration: JsonField, private val reportingConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -73,6 +77,9 @@ private constructor( @JsonProperty("auto_collection") @ExcludeMissing autoCollection: JsonField = JsonMissing.of(), + @JsonProperty("auto_issuance") + @ExcludeMissing + autoIssuance: JsonField = JsonMissing.of(), @JsonProperty("balance") @ExcludeMissing balance: JsonField = JsonMissing.of(), @JsonProperty("billing_address") @ExcludeMissing @@ -111,6 +118,12 @@ private constructor( @JsonProperty("accounting_sync_configuration") @ExcludeMissing accountingSyncConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + automaticTaxEnabled: JsonField = JsonMissing.of(), + @JsonProperty("payment_configuration") + @ExcludeMissing + paymentConfiguration: JsonField = JsonMissing.of(), @JsonProperty("reporting_configuration") @ExcludeMissing reportingConfiguration: JsonField = JsonMissing.of(), @@ -118,6 +131,7 @@ private constructor( id, additionalEmails, autoCollection, + autoIssuance, balance, billingAddress, createdAt, @@ -136,6 +150,8 @@ private constructor( taxId, timezone, accountingSyncConfiguration, + automaticTaxEnabled, + paymentConfiguration, reportingConfiguration, mutableMapOf(), ) @@ -158,6 +174,16 @@ private constructor( */ fun autoCollection(): Boolean = autoCollection.getRequired("auto_collection") + /** + * Whether invoices for this customer should be automatically issued. If true, invoices will be + * automatically issued. If false, invoices will require manual approval. If null, inherits the + * account-level setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun autoIssuance(): Boolean? = autoIssuance.getNullable("auto_issuance") + /** * The customer's current balance in their currency. * @@ -345,9 +371,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -439,6 +465,25 @@ private constructor( fun accountingSyncConfiguration(): AccountingSyncConfiguration? = accountingSyncConfiguration.getNullable("accounting_sync_configuration") + /** + * Whether automatic tax calculation is enabled for this customer. This field is nullable for + * backwards compatibility but will always return a boolean value. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun automaticTaxEnabled(): Boolean? = automaticTaxEnabled.getNullable("automatic_tax_enabled") + + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a supported + * payment provider such as Stripe. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun paymentConfiguration(): PaymentConfiguration? = + paymentConfiguration.getNullable("payment_configuration") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -472,6 +517,15 @@ private constructor( @ExcludeMissing fun _autoCollection(): JsonField = autoCollection + /** + * Returns the raw JSON value of [autoIssuance]. + * + * Unlike [autoIssuance], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("auto_issuance") + @ExcludeMissing + fun _autoIssuance(): JsonField = autoIssuance + /** * Returns the raw JSON value of [balance]. * @@ -621,6 +675,26 @@ private constructor( fun _accountingSyncConfiguration(): JsonField = accountingSyncConfiguration + /** + * Returns the raw JSON value of [automaticTaxEnabled]. + * + * Unlike [automaticTaxEnabled], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + fun _automaticTaxEnabled(): JsonField = automaticTaxEnabled + + /** + * Returns the raw JSON value of [paymentConfiguration]. + * + * Unlike [paymentConfiguration], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("payment_configuration") + @ExcludeMissing + fun _paymentConfiguration(): JsonField = paymentConfiguration + /** * Returns the raw JSON value of [reportingConfiguration]. * @@ -653,6 +727,7 @@ private constructor( * .id() * .additionalEmails() * .autoCollection() + * .autoIssuance() * .balance() * .billingAddress() * .createdAt() @@ -681,6 +756,7 @@ private constructor( private var id: JsonField? = null private var additionalEmails: JsonField>? = null private var autoCollection: JsonField? = null + private var autoIssuance: JsonField? = null private var balance: JsonField? = null private var billingAddress: JsonField
? = null private var createdAt: JsonField? = null @@ -700,6 +776,8 @@ private constructor( private var timezone: JsonField? = null private var accountingSyncConfiguration: JsonField = JsonMissing.of() + private var automaticTaxEnabled: JsonField = JsonMissing.of() + private var paymentConfiguration: JsonField = JsonMissing.of() private var reportingConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -707,6 +785,7 @@ private constructor( id = customer.id additionalEmails = customer.additionalEmails.map { it.toMutableList() } autoCollection = customer.autoCollection + autoIssuance = customer.autoIssuance balance = customer.balance billingAddress = customer.billingAddress createdAt = customer.createdAt @@ -725,6 +804,8 @@ private constructor( taxId = customer.taxId timezone = customer.timezone accountingSyncConfiguration = customer.accountingSyncConfiguration + automaticTaxEnabled = customer.automaticTaxEnabled + paymentConfiguration = customer.paymentConfiguration reportingConfiguration = customer.reportingConfiguration additionalProperties = customer.additionalProperties.toMutableMap() } @@ -778,6 +859,31 @@ private constructor( this.autoCollection = autoCollection } + /** + * Whether invoices for this customer should be automatically issued. If true, invoices will + * be automatically issued. If false, invoices will require manual approval. If null, + * inherits the account-level setting. + */ + fun autoIssuance(autoIssuance: Boolean?) = autoIssuance(JsonField.ofNullable(autoIssuance)) + + /** + * Alias for [Builder.autoIssuance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun autoIssuance(autoIssuance: Boolean) = autoIssuance(autoIssuance as Boolean?) + + /** + * Sets [Builder.autoIssuance] to an arbitrary JSON value. + * + * You should usually call [Builder.autoIssuance] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun autoIssuance(autoIssuance: JsonField) = apply { + this.autoIssuance = autoIssuance + } + /** The customer's current balance in their currency. */ fun balance(balance: String) = balance(JsonField.of(balance)) @@ -1065,9 +1171,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -1177,6 +1283,50 @@ private constructor( accountingSyncConfiguration: JsonField ) = apply { this.accountingSyncConfiguration = accountingSyncConfiguration } + /** + * Whether automatic tax calculation is enabled for this customer. This field is nullable + * for backwards compatibility but will always return a boolean value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean?) = + automaticTaxEnabled(JsonField.ofNullable(automaticTaxEnabled)) + + /** + * Alias for [Builder.automaticTaxEnabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean) = + automaticTaxEnabled(automaticTaxEnabled as Boolean?) + + /** + * Sets [Builder.automaticTaxEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticTaxEnabled] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: JsonField) = apply { + this.automaticTaxEnabled = automaticTaxEnabled + } + + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a + * supported payment provider such as Stripe. + */ + fun paymentConfiguration(paymentConfiguration: PaymentConfiguration?) = + paymentConfiguration(JsonField.ofNullable(paymentConfiguration)) + + /** + * Sets [Builder.paymentConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentConfiguration] with a well-typed + * [PaymentConfiguration] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun paymentConfiguration(paymentConfiguration: JsonField) = apply { + this.paymentConfiguration = paymentConfiguration + } + fun reportingConfiguration(reportingConfiguration: ReportingConfiguration?) = reportingConfiguration(JsonField.ofNullable(reportingConfiguration)) @@ -1221,6 +1371,7 @@ private constructor( * .id() * .additionalEmails() * .autoCollection() + * .autoIssuance() * .balance() * .billingAddress() * .createdAt() @@ -1247,6 +1398,7 @@ private constructor( checkRequired("id", id), checkRequired("additionalEmails", additionalEmails).map { it.toImmutable() }, checkRequired("autoCollection", autoCollection), + checkRequired("autoIssuance", autoIssuance), checkRequired("balance", balance), checkRequired("billingAddress", billingAddress), checkRequired("createdAt", createdAt), @@ -1265,6 +1417,8 @@ private constructor( checkRequired("taxId", taxId), checkRequired("timezone", timezone), accountingSyncConfiguration, + automaticTaxEnabled, + paymentConfiguration, reportingConfiguration, additionalProperties.toMutableMap(), ) @@ -1280,6 +1434,7 @@ private constructor( id() additionalEmails() autoCollection() + autoIssuance() balance() billingAddress()?.validate() createdAt() @@ -1298,6 +1453,8 @@ private constructor( taxId()?.validate() timezone() accountingSyncConfiguration()?.validate() + automaticTaxEnabled() + paymentConfiguration()?.validate() reportingConfiguration()?.validate() validated = true } @@ -1319,6 +1476,7 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (additionalEmails.asKnown()?.size ?: 0) + (if (autoCollection.asKnown() == null) 0 else 1) + + (if (autoIssuance.asKnown() == null) 0 else 1) + (if (balance.asKnown() == null) 0 else 1) + (billingAddress.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -1337,10 +1495,13 @@ private constructor( (taxId.asKnown()?.validity() ?: 0) + (if (timezone.asKnown() == null) 0 else 1) + (accountingSyncConfiguration.asKnown()?.validity() ?: 0) + + (if (automaticTaxEnabled.asKnown() == null) 0 else 1) + + (paymentConfiguration.asKnown()?.validity() ?: 0) + (reportingConfiguration.asKnown()?.validity() ?: 0) /** The hierarchical relationships for this customer. */ class Hierarchy + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val children: JsonField>, private val parent: JsonField, @@ -1535,12 +1696,13 @@ private constructor( return true } - return /* spotless:off */ other is Hierarchy && children == other.children && parent == other.parent && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Hierarchy && + children == other.children && + parent == other.parent && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(children, parent, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1640,12 +1802,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1794,7 +1954,7 @@ private constructor( return true } - return /* spotless:off */ other is PaymentProvider && value == other.value /* spotless:on */ + return other is PaymentProvider && value == other.value } override fun hashCode() = value.hashCode() @@ -1803,6 +1963,7 @@ private constructor( } class AccountingSyncConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val accountingProviders: JsonField>, private val excluded: JsonField, @@ -2002,6 +2163,7 @@ private constructor( (if (excluded.asKnown() == null) 0 else 1) class AccountingProvider + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val externalProviderId: JsonField, private val providerType: JsonField, @@ -2315,7 +2477,7 @@ private constructor( return true } - return /* spotless:off */ other is ProviderType && value == other.value /* spotless:on */ + return other is ProviderType && value == other.value } override fun hashCode() = value.hashCode() @@ -2328,12 +2490,15 @@ private constructor( return true } - return /* spotless:off */ other is AccountingProvider && externalProviderId == other.externalProviderId && providerType == other.providerType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AccountingProvider && + externalProviderId == other.externalProviderId && + providerType == other.providerType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(externalProviderId, providerType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(externalProviderId, providerType, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2346,12 +2511,15 @@ private constructor( return true } - return /* spotless:off */ other is AccountingSyncConfiguration && accountingProviders == other.accountingProviders && excluded == other.excluded && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AccountingSyncConfiguration && + accountingProviders == other.accountingProviders && + excluded == other.excluded && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(accountingProviders, excluded, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(accountingProviders, excluded, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2359,7 +2527,548 @@ private constructor( "AccountingSyncConfiguration{accountingProviders=$accountingProviders, excluded=$excluded, additionalProperties=$additionalProperties}" } + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a supported + * payment provider such as Stripe. + */ + class PaymentConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val paymentProviders: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("payment_providers") + @ExcludeMissing + paymentProviders: JsonField> = JsonMissing.of() + ) : this(paymentProviders, mutableMapOf()) + + /** + * Provider-specific payment configuration. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun paymentProviders(): List? = + paymentProviders.getNullable("payment_providers") + + /** + * Returns the raw JSON value of [paymentProviders]. + * + * Unlike [paymentProviders], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("payment_providers") + @ExcludeMissing + fun _paymentProviders(): JsonField> = paymentProviders + + @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 [PaymentConfiguration]. */ + fun builder() = Builder() + } + + /** A builder for [PaymentConfiguration]. */ + class Builder internal constructor() { + + private var paymentProviders: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(paymentConfiguration: PaymentConfiguration) = apply { + paymentProviders = paymentConfiguration.paymentProviders.map { it.toMutableList() } + additionalProperties = paymentConfiguration.additionalProperties.toMutableMap() + } + + /** Provider-specific payment configuration. */ + fun paymentProviders(paymentProviders: List) = + paymentProviders(JsonField.of(paymentProviders)) + + /** + * Sets [Builder.paymentProviders] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentProviders] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun paymentProviders(paymentProviders: JsonField>) = apply { + this.paymentProviders = paymentProviders.map { it.toMutableList() } + } + + /** + * Adds a single [PaymentProvider] to [paymentProviders]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPaymentProvider(paymentProvider: PaymentProvider) = apply { + paymentProviders = + (paymentProviders ?: JsonField.of(mutableListOf())).also { + checkKnown("paymentProviders", it).add(paymentProvider) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PaymentConfiguration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): PaymentConfiguration = + PaymentConfiguration( + (paymentProviders ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PaymentConfiguration = apply { + if (validated) { + return@apply + } + + paymentProviders()?.forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (paymentProviders.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + class PaymentProvider + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val providerType: JsonField, + private val excludedPaymentMethodTypes: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("provider_type") + @ExcludeMissing + providerType: JsonField = JsonMissing.of(), + @JsonProperty("excluded_payment_method_types") + @ExcludeMissing + excludedPaymentMethodTypes: JsonField> = JsonMissing.of(), + ) : this(providerType, excludedPaymentMethodTypes, mutableMapOf()) + + /** + * The payment provider to configure. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun providerType(): ProviderType = providerType.getRequired("provider_type") + + /** + * List of Stripe payment method types to exclude for this customer. Excluded payment + * methods will not be available for the customer to select during payment, and will not + * be used for auto-collection. If a customer's default payment method becomes excluded, + * Orb will attempt to use the next available compatible payment method for + * auto-collection. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun excludedPaymentMethodTypes(): List? = + excludedPaymentMethodTypes.getNullable("excluded_payment_method_types") + + /** + * Returns the raw JSON value of [providerType]. + * + * Unlike [providerType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("provider_type") + @ExcludeMissing + fun _providerType(): JsonField = providerType + + /** + * Returns the raw JSON value of [excludedPaymentMethodTypes]. + * + * Unlike [excludedPaymentMethodTypes], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("excluded_payment_method_types") + @ExcludeMissing + fun _excludedPaymentMethodTypes(): JsonField> = excludedPaymentMethodTypes + + @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 [PaymentProvider]. + * + * The following fields are required: + * ```kotlin + * .providerType() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PaymentProvider]. */ + class Builder internal constructor() { + + private var providerType: JsonField? = null + private var excludedPaymentMethodTypes: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(paymentProvider: PaymentProvider) = apply { + providerType = paymentProvider.providerType + excludedPaymentMethodTypes = + paymentProvider.excludedPaymentMethodTypes.map { it.toMutableList() } + additionalProperties = paymentProvider.additionalProperties.toMutableMap() + } + + /** The payment provider to configure. */ + fun providerType(providerType: ProviderType) = + providerType(JsonField.of(providerType)) + + /** + * Sets [Builder.providerType] to an arbitrary JSON value. + * + * You should usually call [Builder.providerType] with a well-typed [ProviderType] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun providerType(providerType: JsonField) = apply { + this.providerType = providerType + } + + /** + * List of Stripe payment method types to exclude for this customer. Excluded + * payment methods will not be available for the customer to select during payment, + * and will not be used for auto-collection. If a customer's default payment method + * becomes excluded, Orb will attempt to use the next available compatible payment + * method for auto-collection. + */ + fun excludedPaymentMethodTypes(excludedPaymentMethodTypes: List) = + excludedPaymentMethodTypes(JsonField.of(excludedPaymentMethodTypes)) + + /** + * Sets [Builder.excludedPaymentMethodTypes] to an arbitrary JSON value. + * + * You should usually call [Builder.excludedPaymentMethodTypes] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun excludedPaymentMethodTypes( + excludedPaymentMethodTypes: JsonField> + ) = apply { + this.excludedPaymentMethodTypes = + excludedPaymentMethodTypes.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [excludedPaymentMethodTypes]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExcludedPaymentMethodType(excludedPaymentMethodType: String) = apply { + excludedPaymentMethodTypes = + (excludedPaymentMethodTypes ?: JsonField.of(mutableListOf())).also { + checkKnown("excludedPaymentMethodTypes", it) + .add(excludedPaymentMethodType) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PaymentProvider]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .providerType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PaymentProvider = + PaymentProvider( + checkRequired("providerType", providerType), + (excludedPaymentMethodTypes ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PaymentProvider = apply { + if (validated) { + return@apply + } + + providerType().validate() + excludedPaymentMethodTypes() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (providerType.asKnown()?.validity() ?: 0) + + (excludedPaymentMethodTypes.asKnown()?.size ?: 0) + + /** The payment provider to configure. */ + class ProviderType + @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 { + + val STRIPE = of("stripe") + + fun of(value: String) = ProviderType(JsonField.of(value)) + } + + /** An enum containing [ProviderType]'s known values. */ + enum class Known { + STRIPE + } + + /** + * An enum containing [ProviderType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [ProviderType] 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 [ProviderType] 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + STRIPE -> Known.STRIPE + else -> throw OrbInvalidDataException("Unknown ProviderType: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): ProviderType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 ProviderType && 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 PaymentProvider && + providerType == other.providerType && + excludedPaymentMethodTypes == other.excludedPaymentMethodTypes && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(providerType, excludedPaymentMethodTypes, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PaymentProvider{providerType=$providerType, excludedPaymentMethodTypes=$excludedPaymentMethodTypes, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PaymentConfiguration && + paymentProviders == other.paymentProviders && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(paymentProviders, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PaymentConfiguration{paymentProviders=$paymentProviders, additionalProperties=$additionalProperties}" + } + class ReportingConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val exempt: JsonField, private val additionalProperties: MutableMap, @@ -2500,12 +3209,12 @@ private constructor( return true } - return /* spotless:off */ other is ReportingConfiguration && exempt == other.exempt && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ReportingConfiguration && + exempt == other.exempt && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(exempt, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2518,15 +3227,68 @@ private constructor( return true } - return /* spotless:off */ other is Customer && id == other.id && additionalEmails == other.additionalEmails && autoCollection == other.autoCollection && balance == other.balance && billingAddress == other.billingAddress && createdAt == other.createdAt && currency == other.currency && email == other.email && emailDelivery == other.emailDelivery && exemptFromAutomatedTax == other.exemptFromAutomatedTax && externalCustomerId == other.externalCustomerId && hierarchy == other.hierarchy && metadata == other.metadata && name == other.name && paymentProvider == other.paymentProvider && paymentProviderId == other.paymentProviderId && portalUrl == other.portalUrl && shippingAddress == other.shippingAddress && taxId == other.taxId && timezone == other.timezone && accountingSyncConfiguration == other.accountingSyncConfiguration && reportingConfiguration == other.reportingConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Customer && + id == other.id && + additionalEmails == other.additionalEmails && + autoCollection == other.autoCollection && + autoIssuance == other.autoIssuance && + balance == other.balance && + billingAddress == other.billingAddress && + createdAt == other.createdAt && + currency == other.currency && + email == other.email && + emailDelivery == other.emailDelivery && + exemptFromAutomatedTax == other.exemptFromAutomatedTax && + externalCustomerId == other.externalCustomerId && + hierarchy == other.hierarchy && + metadata == other.metadata && + name == other.name && + paymentProvider == other.paymentProvider && + paymentProviderId == other.paymentProviderId && + portalUrl == other.portalUrl && + shippingAddress == other.shippingAddress && + taxId == other.taxId && + timezone == other.timezone && + accountingSyncConfiguration == other.accountingSyncConfiguration && + automaticTaxEnabled == other.automaticTaxEnabled && + paymentConfiguration == other.paymentConfiguration && + reportingConfiguration == other.reportingConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, additionalEmails, autoCollection, balance, billingAddress, createdAt, currency, email, emailDelivery, exemptFromAutomatedTax, externalCustomerId, hierarchy, metadata, name, paymentProvider, paymentProviderId, portalUrl, shippingAddress, taxId, timezone, accountingSyncConfiguration, reportingConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + additionalEmails, + autoCollection, + autoIssuance, + balance, + billingAddress, + createdAt, + currency, + email, + emailDelivery, + exemptFromAutomatedTax, + externalCustomerId, + hierarchy, + metadata, + name, + paymentProvider, + paymentProviderId, + portalUrl, + shippingAddress, + taxId, + timezone, + accountingSyncConfiguration, + automaticTaxEnabled, + paymentConfiguration, + reportingConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Customer{id=$id, additionalEmails=$additionalEmails, autoCollection=$autoCollection, balance=$balance, billingAddress=$billingAddress, createdAt=$createdAt, currency=$currency, email=$email, emailDelivery=$emailDelivery, exemptFromAutomatedTax=$exemptFromAutomatedTax, externalCustomerId=$externalCustomerId, hierarchy=$hierarchy, metadata=$metadata, name=$name, paymentProvider=$paymentProvider, paymentProviderId=$paymentProviderId, portalUrl=$portalUrl, shippingAddress=$shippingAddress, taxId=$taxId, timezone=$timezone, accountingSyncConfiguration=$accountingSyncConfiguration, reportingConfiguration=$reportingConfiguration, additionalProperties=$additionalProperties}" + "Customer{id=$id, additionalEmails=$additionalEmails, autoCollection=$autoCollection, autoIssuance=$autoIssuance, balance=$balance, billingAddress=$billingAddress, createdAt=$createdAt, currency=$currency, email=$email, emailDelivery=$emailDelivery, exemptFromAutomatedTax=$exemptFromAutomatedTax, externalCustomerId=$externalCustomerId, hierarchy=$hierarchy, metadata=$metadata, name=$name, paymentProvider=$paymentProvider, paymentProviderId=$paymentProviderId, portalUrl=$portalUrl, shippingAddress=$shippingAddress, taxId=$taxId, timezone=$timezone, accountingSyncConfiguration=$accountingSyncConfiguration, automaticTaxEnabled=$automaticTaxEnabled, paymentConfiguration=$paymentConfiguration, reportingConfiguration=$reportingConfiguration, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionCreateParams.kt index badcd4d5a..af42ee80d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionCreateParams.kt @@ -314,6 +314,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val type: JsonField, @@ -528,12 +529,16 @@ private constructor( return true } - return /* spotless:off */ other is Body && amount == other.amount && type == other.type && description == other.description && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + amount == other.amount && + type == other.type && + description == other.description && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, type, description, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(amount, type, description, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -657,7 +662,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -670,10 +675,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerBalanceTransactionCreateParams && customerId == other.customerId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerBalanceTransactionCreateParams && + customerId == other.customerId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(customerId, body, additionalHeaders, additionalQueryParams) override fun toString() = "CustomerBalanceTransactionCreateParams{customerId=$customerId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionCreateResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionCreateResponse.kt index 16d3914ce..6e64798aa 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionCreateResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionCreateResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CustomerBalanceTransactionCreateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val action: JsonField, @@ -544,6 +545,8 @@ private constructor( val EXTERNAL_PAYMENT = of("external_payment") + val SMALL_INVOICE_CARRYOVER = of("small_invoice_carryover") + fun of(value: String) = Action(JsonField.of(value)) } @@ -558,6 +561,7 @@ private constructor( CREDIT_NOTE_VOIDED, OVERPAYMENT_REFUND, EXTERNAL_PAYMENT, + SMALL_INVOICE_CARRYOVER, } /** @@ -579,6 +583,7 @@ private constructor( CREDIT_NOTE_VOIDED, OVERPAYMENT_REFUND, EXTERNAL_PAYMENT, + SMALL_INVOICE_CARRYOVER, /** An enum member indicating that [Action] was instantiated with an unknown value. */ _UNKNOWN, } @@ -601,6 +606,7 @@ private constructor( CREDIT_NOTE_VOIDED -> Value.CREDIT_NOTE_VOIDED OVERPAYMENT_REFUND -> Value.OVERPAYMENT_REFUND EXTERNAL_PAYMENT -> Value.EXTERNAL_PAYMENT + SMALL_INVOICE_CARRYOVER -> Value.SMALL_INVOICE_CARRYOVER else -> Value._UNKNOWN } @@ -623,6 +629,7 @@ private constructor( CREDIT_NOTE_VOIDED -> Known.CREDIT_NOTE_VOIDED OVERPAYMENT_REFUND -> Known.OVERPAYMENT_REFUND EXTERNAL_PAYMENT -> Known.EXTERNAL_PAYMENT + SMALL_INVOICE_CARRYOVER -> Known.SMALL_INVOICE_CARRYOVER else -> throw OrbInvalidDataException("Unknown Action: $value") } @@ -670,7 +677,7 @@ private constructor( return true } - return /* spotless:off */ other is Action && value == other.value /* spotless:on */ + return other is Action && value == other.value } override fun hashCode() = value.hashCode() @@ -794,7 +801,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -807,12 +814,35 @@ private constructor( return true } - return /* spotless:off */ other is CustomerBalanceTransactionCreateResponse && id == other.id && action == other.action && amount == other.amount && createdAt == other.createdAt && creditNote == other.creditNote && description == other.description && endingBalance == other.endingBalance && invoice == other.invoice && startingBalance == other.startingBalance && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerBalanceTransactionCreateResponse && + id == other.id && + action == other.action && + amount == other.amount && + createdAt == other.createdAt && + creditNote == other.creditNote && + description == other.description && + endingBalance == other.endingBalance && + invoice == other.invoice && + startingBalance == other.startingBalance && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, action, amount, createdAt, creditNote, description, endingBalance, invoice, startingBalance, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + action, + amount, + createdAt, + creditNote, + description, + endingBalance, + invoice, + startingBalance, + type, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPage.kt index 2dd6f1756..e6d8312be 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPage.kt @@ -126,10 +126,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerBalanceTransactionListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerBalanceTransactionListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerBalanceTransactionListPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageAsync.kt index fff662d2f..582659d15 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageAsync.kt @@ -129,10 +129,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerBalanceTransactionListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerBalanceTransactionListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerBalanceTransactionListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageResponse.kt index 7987a76f5..b8f418d9e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CustomerBalanceTransactionListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -222,12 +223,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerBalanceTransactionListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerBalanceTransactionListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListParams.kt index b65b6f9b4..e0553b567 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListParams.kt @@ -293,10 +293,30 @@ private constructor( return true } - return /* spotless:off */ other is CustomerBalanceTransactionListParams && customerId == other.customerId && cursor == other.cursor && limit == other.limit && operationTimeGt == other.operationTimeGt && operationTimeGte == other.operationTimeGte && operationTimeLt == other.operationTimeLt && operationTimeLte == other.operationTimeLte && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerBalanceTransactionListParams && + customerId == other.customerId && + cursor == other.cursor && + limit == other.limit && + operationTimeGt == other.operationTimeGt && + operationTimeGte == other.operationTimeGte && + operationTimeLt == other.operationTimeLt && + operationTimeLte == other.operationTimeLte && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, cursor, limit, operationTimeGt, operationTimeGte, operationTimeLt, operationTimeLte, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + customerId, + cursor, + limit, + operationTimeGt, + operationTimeGte, + operationTimeLt, + operationTimeLte, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "CustomerBalanceTransactionListParams{customerId=$customerId, cursor=$cursor, limit=$limit, operationTimeGt=$operationTimeGt, operationTimeGte=$operationTimeGte, operationTimeLt=$operationTimeLt, operationTimeLte=$operationTimeLte, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListResponse.kt index 2ab9cbc7a..1a36133da 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CustomerBalanceTransactionListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val action: JsonField, @@ -544,6 +545,8 @@ private constructor( val EXTERNAL_PAYMENT = of("external_payment") + val SMALL_INVOICE_CARRYOVER = of("small_invoice_carryover") + fun of(value: String) = Action(JsonField.of(value)) } @@ -558,6 +561,7 @@ private constructor( CREDIT_NOTE_VOIDED, OVERPAYMENT_REFUND, EXTERNAL_PAYMENT, + SMALL_INVOICE_CARRYOVER, } /** @@ -579,6 +583,7 @@ private constructor( CREDIT_NOTE_VOIDED, OVERPAYMENT_REFUND, EXTERNAL_PAYMENT, + SMALL_INVOICE_CARRYOVER, /** An enum member indicating that [Action] was instantiated with an unknown value. */ _UNKNOWN, } @@ -601,6 +606,7 @@ private constructor( CREDIT_NOTE_VOIDED -> Value.CREDIT_NOTE_VOIDED OVERPAYMENT_REFUND -> Value.OVERPAYMENT_REFUND EXTERNAL_PAYMENT -> Value.EXTERNAL_PAYMENT + SMALL_INVOICE_CARRYOVER -> Value.SMALL_INVOICE_CARRYOVER else -> Value._UNKNOWN } @@ -623,6 +629,7 @@ private constructor( CREDIT_NOTE_VOIDED -> Known.CREDIT_NOTE_VOIDED OVERPAYMENT_REFUND -> Known.OVERPAYMENT_REFUND EXTERNAL_PAYMENT -> Known.EXTERNAL_PAYMENT + SMALL_INVOICE_CARRYOVER -> Known.SMALL_INVOICE_CARRYOVER else -> throw OrbInvalidDataException("Unknown Action: $value") } @@ -670,7 +677,7 @@ private constructor( return true } - return /* spotless:off */ other is Action && value == other.value /* spotless:on */ + return other is Action && value == other.value } override fun hashCode() = value.hashCode() @@ -794,7 +801,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -807,12 +814,35 @@ private constructor( return true } - return /* spotless:off */ other is CustomerBalanceTransactionListResponse && id == other.id && action == other.action && amount == other.amount && createdAt == other.createdAt && creditNote == other.creditNote && description == other.description && endingBalance == other.endingBalance && invoice == other.invoice && startingBalance == other.startingBalance && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerBalanceTransactionListResponse && + id == other.id && + action == other.action && + amount == other.amount && + createdAt == other.createdAt && + creditNote == other.creditNote && + description == other.description && + endingBalance == other.endingBalance && + invoice == other.invoice && + startingBalance == other.startingBalance && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, action, amount, createdAt, creditNote, description, endingBalance, invoice, startingBalance, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + action, + amount, + createdAt, + creditNote, + description, + endingBalance, + invoice, + startingBalance, + type, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListByExternalIdParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListByExternalIdParams.kt index aae999d1a..e99215b2f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListByExternalIdParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListByExternalIdParams.kt @@ -33,7 +33,6 @@ import java.util.Objects * committed spend. * * ## Fetching subscriptions - * * By default, this endpoint fetches the currently active subscription for the customer, and returns * cost information for the subscription's current billing period, broken down by each participating * price. If there are no currently active subscriptions, this will instead default to the most @@ -46,17 +45,15 @@ import java.util.Objects * and prices for both subscriptions will be included in the breakdown. * * ## Prepaid plans - * * For plans that include prices which deduct credits rather than accrue in-arrears charges in a * billable currency, this endpoint will return the total deduction amount, in credits, for the * specified timeframe. * * ## Cumulative subtotals and totals - * * Since the subtotal and total must factor in any billing-period level discounts and minimums, it's * most meaningful to consider costs relative to the start of the subscription's billing period. As * a result, by default this endpoint returns cumulative totals since the beginning of the billing - * period. In particular, the `timeframe_start` of a returned timeframe window is _always_ the + * period. In particular, the `timeframe_start` of a returned timeframe window is *always* the * beginning of the billing period and `timeframe_end` is incremented one day at a time to build the * result. * @@ -74,7 +71,6 @@ import java.util.Objects * | 2023-02-01 | 2023-02-06 | 36 | \$90.00 | \$90.00 | * * ### Periodic values - * * When the query parameter `view_mode=periodic` is specified, Orb will return an incremental * day-by-day view of costs. In this case, there will always be a one-day difference between * `timeframe_start` and `timeframe_end` for the timeframes returned. This is a transform on top of @@ -84,7 +80,6 @@ import java.util.Objects * cost. * * ## Timeframe bounds - * * For an active subscription, both timeframes should be specified in the request. If a subscription * starts or ends within the timeframe, the response will only include windows where the * subscription is active. If a subscription has ended, no timeframe bounds need to be specified and @@ -115,7 +110,6 @@ import java.util.Objects * You can see this sliced timeframe visualized [here](https://i.imgur.com/TXhYgme.png). * * ### Matrix prices - * * When a price uses matrix pricing, it's important to view costs grouped by those matrix * dimensions. Orb will return `price_groups` with the `grouping_key` and `secondary_grouping_key` * based on the matrix price definition, for each `grouping_value` and `secondary_grouping_value` @@ -473,7 +467,7 @@ private constructor( return true } - return /* spotless:off */ other is ViewMode && value == other.value /* spotless:on */ + return other is ViewMode && value == other.value } override fun hashCode() = value.hashCode() @@ -486,10 +480,26 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCostListByExternalIdParams && externalCustomerId == other.externalCustomerId && currency == other.currency && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && viewMode == other.viewMode && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerCostListByExternalIdParams && + externalCustomerId == other.externalCustomerId && + currency == other.currency && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + viewMode == other.viewMode && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalCustomerId, currency, timeframeEnd, timeframeStart, viewMode, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + externalCustomerId, + currency, + timeframeEnd, + timeframeStart, + viewMode, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "CustomerCostListByExternalIdParams{externalCustomerId=$externalCustomerId, currency=$currency, timeframeEnd=$timeframeEnd, timeframeStart=$timeframeStart, viewMode=$viewMode, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListByExternalIdResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListByExternalIdResponse.kt index de75479c2..3f59a5344 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListByExternalIdResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListByExternalIdResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CustomerCostListByExternalIdResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val additionalProperties: MutableMap, @@ -177,12 +178,12 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCostListByExternalIdResponse && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCostListByExternalIdResponse && + data == other.data && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListParams.kt index edf6865d9..78abea34f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListParams.kt @@ -33,7 +33,6 @@ import java.util.Objects * committed spend. * * ## Fetching subscriptions - * * By default, this endpoint fetches the currently active subscription for the customer, and returns * cost information for the subscription's current billing period, broken down by each participating * price. If there are no currently active subscriptions, this will instead default to the most @@ -46,17 +45,15 @@ import java.util.Objects * and prices for both subscriptions will be included in the breakdown. * * ## Prepaid plans - * * For plans that include prices which deduct credits rather than accrue in-arrears charges in a * billable currency, this endpoint will return the total deduction amount, in credits, for the * specified timeframe. * * ## Cumulative subtotals and totals - * * Since the subtotal and total must factor in any billing-period level discounts and minimums, it's * most meaningful to consider costs relative to the start of the subscription's billing period. As * a result, by default this endpoint returns cumulative totals since the beginning of the billing - * period. In particular, the `timeframe_start` of a returned timeframe window is _always_ the + * period. In particular, the `timeframe_start` of a returned timeframe window is *always* the * beginning of the billing period and `timeframe_end` is incremented one day at a time to build the * result. * @@ -74,7 +71,6 @@ import java.util.Objects * | 2023-02-01 | 2023-02-06 | 36 | \$90.00 | \$90.00 | * * ### Periodic values - * * When the query parameter `view_mode=periodic` is specified, Orb will return an incremental * day-by-day view of costs. In this case, there will always be a one-day difference between * `timeframe_start` and `timeframe_end` for the timeframes returned. This is a transform on top of @@ -84,7 +80,6 @@ import java.util.Objects * cost. * * ## Timeframe bounds - * * For an active subscription, both timeframes should be specified in the request. If a subscription * starts or ends within the timeframe, the response will only include windows where the * subscription is active. If a subscription has ended, no timeframe bounds need to be specified and @@ -115,7 +110,6 @@ import java.util.Objects * You can see this sliced timeframe visualized [here](https://i.imgur.com/TXhYgme.png). * * ### Matrix prices - * * When a price uses matrix pricing, it's important to view costs grouped by those matrix * dimensions. Orb will return `price_groups` with the `grouping_key` and `secondary_grouping_key` * based on the matrix price definition, for each `grouping_value` and `secondary_grouping_value` @@ -466,7 +460,7 @@ private constructor( return true } - return /* spotless:off */ other is ViewMode && value == other.value /* spotless:on */ + return other is ViewMode && value == other.value } override fun hashCode() = value.hashCode() @@ -479,10 +473,26 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCostListParams && customerId == other.customerId && currency == other.currency && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && viewMode == other.viewMode && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerCostListParams && + customerId == other.customerId && + currency == other.currency && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + viewMode == other.viewMode && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, currency, timeframeEnd, timeframeStart, viewMode, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + customerId, + currency, + timeframeEnd, + timeframeStart, + viewMode, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "CustomerCostListParams{customerId=$customerId, currency=$currency, timeframeEnd=$timeframeEnd, timeframeStart=$timeframeStart, viewMode=$viewMode, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListResponse.kt index cc4bc15b1..085343418 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCostListResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CustomerCostListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val additionalProperties: MutableMap, @@ -173,12 +174,12 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCostListResponse && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCostListResponse && + data == other.data && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreateParams.kt index 6184c5dcb..38ba68cef 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreateParams.kt @@ -36,11 +36,11 @@ import java.util.Objects * See [Customer](/core-concepts##customer) for an overview of the customer resource. * * This endpoint is critical in the following Orb functionality: - * - Automated charges can be configured by setting `payment_provider` and `payment_provider_id` to + * * Automated charges can be configured by setting `payment_provider` and `payment_provider_id` to * automatically issue invoices - * - [Customer ID Aliases](/events-and-metrics/customer-aliases) can be configured by setting + * * [Customer ID Aliases](/events-and-metrics/customer-aliases) can be configured by setting * `external_customer_id` - * - [Timezone localization](/essentials/timezones) can be configured on a per-customer basis by + * * [Timezone localization](/essentials/timezones) can be configured on a per-customer basis by * setting the `timezone` parameter */ class CustomerCreateParams @@ -76,7 +76,8 @@ private constructor( /** * Additional email addresses for this customer. If populated, these email addresses will be - * CC'd for customer communications. + * CC'd for customer communications. The total number of email addresses (including the primary + * email) cannot exceed 50. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -93,6 +94,17 @@ private constructor( */ fun autoCollection(): Boolean? = body.autoCollection() + /** + * Used to determine if invoices for this customer will be automatically issued. If true, + * invoices will be automatically issued. If false, invoices will require manual approval. If + * `null` is specified, the customer's auto issuance setting will be inherited from the + * account-level setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun autoIssuance(): Boolean? = body.autoIssuance() + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -142,6 +154,15 @@ private constructor( */ fun metadata(): Metadata? = body.metadata() + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a supported + * payment provider such as Stripe. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun paymentConfiguration(): PaymentConfiguration? = body.paymentConfiguration() + /** * This is used for creating charges or invoices in an external system via Orb. When not in test * mode, the connection must first be configured in the Orb webapp. @@ -251,9 +272,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -376,6 +397,13 @@ private constructor( */ fun _autoCollection(): JsonField = body._autoCollection() + /** + * Returns the raw JSON value of [autoIssuance]. + * + * Unlike [autoIssuance], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _autoIssuance(): JsonField = body._autoIssuance() + /** * Returns the raw JSON value of [billingAddress]. * @@ -419,6 +447,14 @@ private constructor( */ fun _metadata(): JsonField = body._metadata() + /** + * Returns the raw JSON value of [paymentConfiguration]. + * + * Unlike [paymentConfiguration], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _paymentConfiguration(): JsonField = body._paymentConfiguration() + /** * Returns the raw JSON value of [paymentProvider]. * @@ -565,7 +601,8 @@ private constructor( /** * Additional email addresses for this customer. If populated, these email addresses will be - * CC'd for customer communications. + * CC'd for customer communications. The total number of email addresses (including the + * primary email) cannot exceed 50. */ fun additionalEmails(additionalEmails: List?) = apply { body.additionalEmails(additionalEmails) @@ -616,6 +653,32 @@ private constructor( body.autoCollection(autoCollection) } + /** + * Used to determine if invoices for this customer will be automatically issued. If true, + * invoices will be automatically issued. If false, invoices will require manual approval. + * If `null` is specified, the customer's auto issuance setting will be inherited from the + * account-level setting. + */ + fun autoIssuance(autoIssuance: Boolean?) = apply { body.autoIssuance(autoIssuance) } + + /** + * Alias for [Builder.autoIssuance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun autoIssuance(autoIssuance: Boolean) = autoIssuance(autoIssuance as Boolean?) + + /** + * Sets [Builder.autoIssuance] to an arbitrary JSON value. + * + * You should usually call [Builder.autoIssuance] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun autoIssuance(autoIssuance: JsonField) = apply { + body.autoIssuance(autoIssuance) + } + fun billingAddress(billingAddress: AddressInput?) = apply { body.billingAddress(billingAddress) } @@ -715,6 +778,25 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a + * supported payment provider such as Stripe. + */ + fun paymentConfiguration(paymentConfiguration: PaymentConfiguration?) = apply { + body.paymentConfiguration(paymentConfiguration) + } + + /** + * Sets [Builder.paymentConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentConfiguration] with a well-typed + * [PaymentConfiguration] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun paymentConfiguration(paymentConfiguration: JsonField) = apply { + body.paymentConfiguration(paymentConfiguration) + } + /** * This is used for creating charges or invoices in an external system via Orb. When not in * test mode, the connection must first be configured in the Orb webapp. @@ -853,6 +935,55 @@ private constructor( body.sphereTaxConfiguration(taxExempt) } + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofNumeral(numeral)`. */ + fun taxConfiguration(numeral: TaxConfiguration.Numeral) = apply { + body.taxConfiguration(numeral) + } + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Numeral.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun numeralTaxConfiguration(taxExempt: Boolean) = apply { + body.numeralTaxConfiguration(taxExempt) + } + + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofAnrok(anrok)`. */ + fun taxConfiguration(anrok: TaxConfiguration.Anrok) = apply { body.taxConfiguration(anrok) } + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Anrok.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun anrokTaxConfiguration(taxExempt: Boolean) = apply { + body.anrokTaxConfiguration(taxExempt) + } + + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofStripe(stripe)`. */ + fun taxConfiguration(stripe: TaxConfiguration.Stripe) = apply { + body.taxConfiguration(stripe) + } + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Stripe.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun stripeTaxConfiguration(taxExempt: Boolean) = apply { + body.stripeTaxConfiguration(taxExempt) + } + /** * Tax IDs are commonly required to be displayed on customer invoices, which are added to * the headers of invoices. @@ -926,9 +1057,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -1169,18 +1300,21 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val email: JsonField, private val name: JsonField, private val accountingSyncConfiguration: JsonField, private val additionalEmails: JsonField>, private val autoCollection: JsonField, + private val autoIssuance: JsonField, private val billingAddress: JsonField, private val currency: JsonField, private val emailDelivery: JsonField, private val externalCustomerId: JsonField, private val hierarchy: JsonField, private val metadata: JsonField, + private val paymentConfiguration: JsonField, private val paymentProvider: JsonField, private val paymentProviderId: JsonField, private val reportingConfiguration: JsonField, @@ -1205,6 +1339,9 @@ private constructor( @JsonProperty("auto_collection") @ExcludeMissing autoCollection: JsonField = JsonMissing.of(), + @JsonProperty("auto_issuance") + @ExcludeMissing + autoIssuance: JsonField = JsonMissing.of(), @JsonProperty("billing_address") @ExcludeMissing billingAddress: JsonField = JsonMissing.of(), @@ -1223,6 +1360,9 @@ private constructor( @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("payment_configuration") + @ExcludeMissing + paymentConfiguration: JsonField = JsonMissing.of(), @JsonProperty("payment_provider") @ExcludeMissing paymentProvider: JsonField = JsonMissing.of(), @@ -1248,12 +1388,14 @@ private constructor( accountingSyncConfiguration, additionalEmails, autoCollection, + autoIssuance, billingAddress, currency, emailDelivery, externalCustomerId, hierarchy, metadata, + paymentConfiguration, paymentProvider, paymentProviderId, reportingConfiguration, @@ -1290,7 +1432,8 @@ private constructor( /** * Additional email addresses for this customer. If populated, these email addresses will be - * CC'd for customer communications. + * CC'd for customer communications. The total number of email addresses (including the + * primary email) cannot exceed 50. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1307,6 +1450,17 @@ private constructor( */ fun autoCollection(): Boolean? = autoCollection.getNullable("auto_collection") + /** + * Used to determine if invoices for this customer will be automatically issued. If true, + * invoices will be automatically issued. If false, invoices will require manual approval. + * If `null` is specified, the customer's auto issuance setting will be inherited from the + * account-level setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun autoIssuance(): Boolean? = autoIssuance.getNullable("auto_issuance") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1356,6 +1510,16 @@ private constructor( */ fun metadata(): Metadata? = metadata.getNullable("metadata") + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a + * supported payment provider such as Stripe. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun paymentConfiguration(): PaymentConfiguration? = + paymentConfiguration.getNullable("payment_configuration") + /** * This is used for creating charges or invoices in an external system via Orb. When not in * test mode, the connection must first be configured in the Orb webapp. @@ -1467,9 +1631,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -1599,6 +1763,16 @@ private constructor( @ExcludeMissing fun _autoCollection(): JsonField = autoCollection + /** + * Returns the raw JSON value of [autoIssuance]. + * + * Unlike [autoIssuance], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("auto_issuance") + @ExcludeMissing + fun _autoIssuance(): JsonField = autoIssuance + /** * Returns the raw JSON value of [billingAddress]. * @@ -1652,6 +1826,16 @@ private constructor( */ @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + /** + * Returns the raw JSON value of [paymentConfiguration]. + * + * Unlike [paymentConfiguration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("payment_configuration") + @ExcludeMissing + fun _paymentConfiguration(): JsonField = paymentConfiguration + /** * Returns the raw JSON value of [paymentProvider]. * @@ -1751,12 +1935,14 @@ private constructor( JsonMissing.of() private var additionalEmails: JsonField>? = null private var autoCollection: JsonField = JsonMissing.of() + private var autoIssuance: JsonField = JsonMissing.of() private var billingAddress: JsonField = JsonMissing.of() private var currency: JsonField = JsonMissing.of() private var emailDelivery: JsonField = JsonMissing.of() private var externalCustomerId: JsonField = JsonMissing.of() private var hierarchy: JsonField = JsonMissing.of() private var metadata: JsonField = JsonMissing.of() + private var paymentConfiguration: JsonField = JsonMissing.of() private var paymentProvider: JsonField = JsonMissing.of() private var paymentProviderId: JsonField = JsonMissing.of() private var reportingConfiguration: JsonField = @@ -1773,12 +1959,14 @@ private constructor( accountingSyncConfiguration = body.accountingSyncConfiguration additionalEmails = body.additionalEmails.map { it.toMutableList() } autoCollection = body.autoCollection + autoIssuance = body.autoIssuance billingAddress = body.billingAddress currency = body.currency emailDelivery = body.emailDelivery externalCustomerId = body.externalCustomerId hierarchy = body.hierarchy metadata = body.metadata + paymentConfiguration = body.paymentConfiguration paymentProvider = body.paymentProvider paymentProviderId = body.paymentProviderId reportingConfiguration = body.reportingConfiguration @@ -1834,7 +2022,8 @@ private constructor( /** * Additional email addresses for this customer. If populated, these email addresses - * will be CC'd for customer communications. + * will be CC'd for customer communications. The total number of email addresses + * (including the primary email) cannot exceed 50. */ fun additionalEmails(additionalEmails: List?) = additionalEmails(JsonField.ofNullable(additionalEmails)) @@ -1888,6 +2077,33 @@ private constructor( this.autoCollection = autoCollection } + /** + * Used to determine if invoices for this customer will be automatically issued. If + * true, invoices will be automatically issued. If false, invoices will require manual + * approval. If `null` is specified, the customer's auto issuance setting will be + * inherited from the account-level setting. + */ + fun autoIssuance(autoIssuance: Boolean?) = + autoIssuance(JsonField.ofNullable(autoIssuance)) + + /** + * Alias for [Builder.autoIssuance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun autoIssuance(autoIssuance: Boolean) = autoIssuance(autoIssuance as Boolean?) + + /** + * Sets [Builder.autoIssuance] to an arbitrary JSON value. + * + * You should usually call [Builder.autoIssuance] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun autoIssuance(autoIssuance: JsonField) = apply { + this.autoIssuance = autoIssuance + } + fun billingAddress(billingAddress: AddressInput?) = billingAddress(JsonField.ofNullable(billingAddress)) @@ -1988,6 +2204,25 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a + * supported payment provider such as Stripe. + */ + fun paymentConfiguration(paymentConfiguration: PaymentConfiguration?) = + paymentConfiguration(JsonField.ofNullable(paymentConfiguration)) + + /** + * Sets [Builder.paymentConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentConfiguration] with a well-typed + * [PaymentConfiguration] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun paymentConfiguration(paymentConfiguration: JsonField) = + apply { + this.paymentConfiguration = paymentConfiguration + } + /** * This is used for creating charges or invoices in an external system via Orb. When not * in test mode, the connection must first be configured in the Orb webapp. @@ -2129,6 +2364,51 @@ private constructor( .build() ) + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofNumeral(numeral)`. */ + fun taxConfiguration(numeral: TaxConfiguration.Numeral) = + taxConfiguration(TaxConfiguration.ofNumeral(numeral)) + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Numeral.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun numeralTaxConfiguration(taxExempt: Boolean) = + taxConfiguration(TaxConfiguration.Numeral.builder().taxExempt(taxExempt).build()) + + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofAnrok(anrok)`. */ + fun taxConfiguration(anrok: TaxConfiguration.Anrok) = + taxConfiguration(TaxConfiguration.ofAnrok(anrok)) + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Anrok.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun anrokTaxConfiguration(taxExempt: Boolean) = + taxConfiguration(TaxConfiguration.Anrok.builder().taxExempt(taxExempt).build()) + + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofStripe(stripe)`. */ + fun taxConfiguration(stripe: TaxConfiguration.Stripe) = + taxConfiguration(TaxConfiguration.ofStripe(stripe)) + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Stripe.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun stripeTaxConfiguration(taxExempt: Boolean) = + taxConfiguration(TaxConfiguration.Stripe.builder().taxExempt(taxExempt).build()) + /** * Tax IDs are commonly required to be displayed on customer invoices, which are added * to the headers of invoices. @@ -2202,9 +2482,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -2340,12 +2620,14 @@ private constructor( accountingSyncConfiguration, (additionalEmails ?: JsonMissing.of()).map { it.toImmutable() }, autoCollection, + autoIssuance, billingAddress, currency, emailDelivery, externalCustomerId, hierarchy, metadata, + paymentConfiguration, paymentProvider, paymentProviderId, reportingConfiguration, @@ -2369,12 +2651,14 @@ private constructor( accountingSyncConfiguration()?.validate() additionalEmails() autoCollection() + autoIssuance() billingAddress()?.validate() currency() emailDelivery() externalCustomerId() hierarchy()?.validate() metadata()?.validate() + paymentConfiguration()?.validate() paymentProvider()?.validate() paymentProviderId() reportingConfiguration()?.validate() @@ -2405,12 +2689,14 @@ private constructor( (accountingSyncConfiguration.asKnown()?.validity() ?: 0) + (additionalEmails.asKnown()?.size ?: 0) + (if (autoCollection.asKnown() == null) 0 else 1) + + (if (autoIssuance.asKnown() == null) 0 else 1) + (billingAddress.asKnown()?.validity() ?: 0) + (if (currency.asKnown() == null) 0 else 1) + (if (emailDelivery.asKnown() == null) 0 else 1) + (if (externalCustomerId.asKnown() == null) 0 else 1) + (hierarchy.asKnown()?.validity() ?: 0) + (metadata.asKnown()?.validity() ?: 0) + + (paymentConfiguration.asKnown()?.validity() ?: 0) + (paymentProvider.asKnown()?.validity() ?: 0) + (if (paymentProviderId.asKnown() == null) 0 else 1) + (reportingConfiguration.asKnown()?.validity() ?: 0) + @@ -2424,17 +2710,60 @@ private constructor( return true } - return /* spotless:off */ other is Body && email == other.email && name == other.name && accountingSyncConfiguration == other.accountingSyncConfiguration && additionalEmails == other.additionalEmails && autoCollection == other.autoCollection && billingAddress == other.billingAddress && currency == other.currency && emailDelivery == other.emailDelivery && externalCustomerId == other.externalCustomerId && hierarchy == other.hierarchy && metadata == other.metadata && paymentProvider == other.paymentProvider && paymentProviderId == other.paymentProviderId && reportingConfiguration == other.reportingConfiguration && shippingAddress == other.shippingAddress && taxConfiguration == other.taxConfiguration && taxId == other.taxId && timezone == other.timezone && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + email == other.email && + name == other.name && + accountingSyncConfiguration == other.accountingSyncConfiguration && + additionalEmails == other.additionalEmails && + autoCollection == other.autoCollection && + autoIssuance == other.autoIssuance && + billingAddress == other.billingAddress && + currency == other.currency && + emailDelivery == other.emailDelivery && + externalCustomerId == other.externalCustomerId && + hierarchy == other.hierarchy && + metadata == other.metadata && + paymentConfiguration == other.paymentConfiguration && + paymentProvider == other.paymentProvider && + paymentProviderId == other.paymentProviderId && + reportingConfiguration == other.reportingConfiguration && + shippingAddress == other.shippingAddress && + taxConfiguration == other.taxConfiguration && + taxId == other.taxId && + timezone == other.timezone && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(email, name, accountingSyncConfiguration, additionalEmails, autoCollection, billingAddress, currency, emailDelivery, externalCustomerId, hierarchy, metadata, paymentProvider, paymentProviderId, reportingConfiguration, shippingAddress, taxConfiguration, taxId, timezone, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + email, + name, + accountingSyncConfiguration, + additionalEmails, + autoCollection, + autoIssuance, + billingAddress, + currency, + emailDelivery, + externalCustomerId, + hierarchy, + metadata, + paymentConfiguration, + paymentProvider, + paymentProviderId, + reportingConfiguration, + shippingAddress, + taxConfiguration, + taxId, + timezone, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Body{email=$email, name=$name, accountingSyncConfiguration=$accountingSyncConfiguration, additionalEmails=$additionalEmails, autoCollection=$autoCollection, billingAddress=$billingAddress, currency=$currency, emailDelivery=$emailDelivery, externalCustomerId=$externalCustomerId, hierarchy=$hierarchy, metadata=$metadata, paymentProvider=$paymentProvider, paymentProviderId=$paymentProviderId, reportingConfiguration=$reportingConfiguration, shippingAddress=$shippingAddress, taxConfiguration=$taxConfiguration, taxId=$taxId, timezone=$timezone, additionalProperties=$additionalProperties}" + "Body{email=$email, name=$name, accountingSyncConfiguration=$accountingSyncConfiguration, additionalEmails=$additionalEmails, autoCollection=$autoCollection, autoIssuance=$autoIssuance, billingAddress=$billingAddress, currency=$currency, emailDelivery=$emailDelivery, externalCustomerId=$externalCustomerId, hierarchy=$hierarchy, metadata=$metadata, paymentConfiguration=$paymentConfiguration, paymentProvider=$paymentProvider, paymentProviderId=$paymentProviderId, reportingConfiguration=$reportingConfiguration, shippingAddress=$shippingAddress, taxConfiguration=$taxConfiguration, taxId=$taxId, timezone=$timezone, additionalProperties=$additionalProperties}" } /** @@ -2529,12 +2858,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2542,88 +2869,628 @@ private constructor( } /** - * This is used for creating charges or invoices in an external system via Orb. When not in test - * mode, the connection must first be configured in the Orb webapp. + * Payment configuration for the customer, applicable when using Orb Invoicing with a supported + * payment provider such as Stripe. */ - class PaymentProvider @JsonCreator private constructor(private val value: JsonField) : - Enum { + class PaymentConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val paymentProviders: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("payment_providers") + @ExcludeMissing + paymentProviders: JsonField> = JsonMissing.of() + ) : this(paymentProviders, mutableMapOf()) /** - * Returns this class instance's raw value. + * Provider-specific payment configuration. * - * 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 OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { + fun paymentProviders(): List? = + paymentProviders.getNullable("payment_providers") - val QUICKBOOKS = of("quickbooks") + /** + * Returns the raw JSON value of [paymentProviders]. + * + * Unlike [paymentProviders], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("payment_providers") + @ExcludeMissing + fun _paymentProviders(): JsonField> = paymentProviders - val BILL_COM = of("bill.com") + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - val STRIPE_CHARGE = of("stripe_charge") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - val STRIPE_INVOICE = of("stripe_invoice") + fun toBuilder() = Builder().from(this) - val NETSUITE = of("netsuite") + companion object { - fun of(value: String) = PaymentProvider(JsonField.of(value)) + /** Returns a mutable builder for constructing an instance of [PaymentConfiguration]. */ + fun builder() = Builder() } - /** An enum containing [PaymentProvider]'s known values. */ - enum class Known { - QUICKBOOKS, - BILL_COM, - STRIPE_CHARGE, - STRIPE_INVOICE, - NETSUITE, - } + /** A builder for [PaymentConfiguration]. */ + class Builder internal constructor() { + + private var paymentProviders: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(paymentConfiguration: PaymentConfiguration) = apply { + paymentProviders = paymentConfiguration.paymentProviders.map { it.toMutableList() } + additionalProperties = paymentConfiguration.additionalProperties.toMutableMap() + } + + /** Provider-specific payment configuration. */ + fun paymentProviders(paymentProviders: List) = + paymentProviders(JsonField.of(paymentProviders)) - /** - * An enum containing [PaymentProvider]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [PaymentProvider] 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 { - QUICKBOOKS, - BILL_COM, - STRIPE_CHARGE, - STRIPE_INVOICE, - NETSUITE, /** - * An enum member indicating that [PaymentProvider] was instantiated with an unknown - * value. + * Sets [Builder.paymentProviders] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentProviders] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. */ - _UNKNOWN, - } + fun paymentProviders(paymentProviders: JsonField>) = apply { + this.paymentProviders = paymentProviders.map { it.toMutableList() } + } - /** - * 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) { - QUICKBOOKS -> Value.QUICKBOOKS - BILL_COM -> Value.BILL_COM - STRIPE_CHARGE -> Value.STRIPE_CHARGE - STRIPE_INVOICE -> Value.STRIPE_INVOICE - NETSUITE -> Value.NETSUITE - else -> Value._UNKNOWN + /** + * Adds a single [PaymentProvider] to [paymentProviders]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPaymentProvider(paymentProvider: PaymentProvider) = apply { + paymentProviders = + (paymentProviders ?: JsonField.of(mutableListOf())).also { + checkKnown("paymentProviders", it).add(paymentProvider) + } } - /** - * Returns an enum member corresponding to this class instance's 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 [PaymentConfiguration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): PaymentConfiguration = + PaymentConfiguration( + (paymentProviders ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PaymentConfiguration = apply { + if (validated) { + return@apply + } + + paymentProviders()?.forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (paymentProviders.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + class PaymentProvider + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val providerType: JsonField, + private val excludedPaymentMethodTypes: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("provider_type") + @ExcludeMissing + providerType: JsonField = JsonMissing.of(), + @JsonProperty("excluded_payment_method_types") + @ExcludeMissing + excludedPaymentMethodTypes: JsonField> = JsonMissing.of(), + ) : this(providerType, excludedPaymentMethodTypes, mutableMapOf()) + + /** + * The payment provider to configure. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun providerType(): ProviderType = providerType.getRequired("provider_type") + + /** + * List of Stripe payment method types to exclude for this customer. Excluded payment + * methods will not be available for the customer to select during payment, and will not + * be used for auto-collection. If a customer's default payment method becomes excluded, + * Orb will attempt to use the next available compatible payment method for + * auto-collection. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun excludedPaymentMethodTypes(): List? = + excludedPaymentMethodTypes.getNullable("excluded_payment_method_types") + + /** + * Returns the raw JSON value of [providerType]. + * + * Unlike [providerType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("provider_type") + @ExcludeMissing + fun _providerType(): JsonField = providerType + + /** + * Returns the raw JSON value of [excludedPaymentMethodTypes]. + * + * Unlike [excludedPaymentMethodTypes], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("excluded_payment_method_types") + @ExcludeMissing + fun _excludedPaymentMethodTypes(): JsonField> = excludedPaymentMethodTypes + + @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 [PaymentProvider]. + * + * The following fields are required: + * ```kotlin + * .providerType() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PaymentProvider]. */ + class Builder internal constructor() { + + private var providerType: JsonField? = null + private var excludedPaymentMethodTypes: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(paymentProvider: PaymentProvider) = apply { + providerType = paymentProvider.providerType + excludedPaymentMethodTypes = + paymentProvider.excludedPaymentMethodTypes.map { it.toMutableList() } + additionalProperties = paymentProvider.additionalProperties.toMutableMap() + } + + /** The payment provider to configure. */ + fun providerType(providerType: ProviderType) = + providerType(JsonField.of(providerType)) + + /** + * Sets [Builder.providerType] to an arbitrary JSON value. + * + * You should usually call [Builder.providerType] with a well-typed [ProviderType] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun providerType(providerType: JsonField) = apply { + this.providerType = providerType + } + + /** + * List of Stripe payment method types to exclude for this customer. Excluded + * payment methods will not be available for the customer to select during payment, + * and will not be used for auto-collection. If a customer's default payment method + * becomes excluded, Orb will attempt to use the next available compatible payment + * method for auto-collection. + */ + fun excludedPaymentMethodTypes(excludedPaymentMethodTypes: List) = + excludedPaymentMethodTypes(JsonField.of(excludedPaymentMethodTypes)) + + /** + * Sets [Builder.excludedPaymentMethodTypes] to an arbitrary JSON value. + * + * You should usually call [Builder.excludedPaymentMethodTypes] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun excludedPaymentMethodTypes( + excludedPaymentMethodTypes: JsonField> + ) = apply { + this.excludedPaymentMethodTypes = + excludedPaymentMethodTypes.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [excludedPaymentMethodTypes]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExcludedPaymentMethodType(excludedPaymentMethodType: String) = apply { + excludedPaymentMethodTypes = + (excludedPaymentMethodTypes ?: JsonField.of(mutableListOf())).also { + checkKnown("excludedPaymentMethodTypes", it) + .add(excludedPaymentMethodType) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PaymentProvider]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .providerType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PaymentProvider = + PaymentProvider( + checkRequired("providerType", providerType), + (excludedPaymentMethodTypes ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PaymentProvider = apply { + if (validated) { + return@apply + } + + providerType().validate() + excludedPaymentMethodTypes() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (providerType.asKnown()?.validity() ?: 0) + + (excludedPaymentMethodTypes.asKnown()?.size ?: 0) + + /** The payment provider to configure. */ + class ProviderType + @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 { + + val STRIPE = of("stripe") + + fun of(value: String) = ProviderType(JsonField.of(value)) + } + + /** An enum containing [ProviderType]'s known values. */ + enum class Known { + STRIPE + } + + /** + * An enum containing [ProviderType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [ProviderType] 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 [ProviderType] 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + STRIPE -> Known.STRIPE + else -> throw OrbInvalidDataException("Unknown ProviderType: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): ProviderType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 ProviderType && 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 PaymentProvider && + providerType == other.providerType && + excludedPaymentMethodTypes == other.excludedPaymentMethodTypes && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(providerType, excludedPaymentMethodTypes, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PaymentProvider{providerType=$providerType, excludedPaymentMethodTypes=$excludedPaymentMethodTypes, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PaymentConfiguration && + paymentProviders == other.paymentProviders && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(paymentProviders, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PaymentConfiguration{paymentProviders=$paymentProviders, additionalProperties=$additionalProperties}" + } + + /** + * This is used for creating charges or invoices in an external system via Orb. When not in test + * mode, the connection must first be configured in the Orb webapp. + */ + class PaymentProvider @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 { + + val QUICKBOOKS = of("quickbooks") + + val BILL_COM = of("bill.com") + + val STRIPE_CHARGE = of("stripe_charge") + + val STRIPE_INVOICE = of("stripe_invoice") + + val NETSUITE = of("netsuite") + + fun of(value: String) = PaymentProvider(JsonField.of(value)) + } + + /** An enum containing [PaymentProvider]'s known values. */ + enum class Known { + QUICKBOOKS, + BILL_COM, + STRIPE_CHARGE, + STRIPE_INVOICE, + NETSUITE, + } + + /** + * An enum containing [PaymentProvider]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [PaymentProvider] 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 { + QUICKBOOKS, + BILL_COM, + STRIPE_CHARGE, + STRIPE_INVOICE, + NETSUITE, + /** + * An enum member indicating that [PaymentProvider] 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) { + QUICKBOOKS -> Value.QUICKBOOKS + BILL_COM -> Value.BILL_COM + STRIPE_CHARGE -> Value.STRIPE_CHARGE + STRIPE_INVOICE -> Value.STRIPE_INVOICE + NETSUITE -> Value.NETSUITE + 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. * @@ -2683,7 +3550,7 @@ private constructor( return true } - return /* spotless:off */ other is PaymentProvider && value == other.value /* spotless:on */ + return other is PaymentProvider && value == other.value } override fun hashCode() = value.hashCode() @@ -2698,6 +3565,9 @@ private constructor( private val avalara: NewAvalaraTaxConfiguration? = null, private val taxjar: NewTaxJarConfiguration? = null, private val sphere: NewSphereConfiguration? = null, + private val numeral: Numeral? = null, + private val anrok: Anrok? = null, + private val stripe: Stripe? = null, private val _json: JsonValue? = null, ) { @@ -2707,18 +3577,36 @@ private constructor( fun sphere(): NewSphereConfiguration? = sphere + fun numeral(): Numeral? = numeral + + fun anrok(): Anrok? = anrok + + fun stripe(): Stripe? = stripe + fun isAvalara(): Boolean = avalara != null fun isTaxjar(): Boolean = taxjar != null fun isSphere(): Boolean = sphere != null + fun isNumeral(): Boolean = numeral != null + + fun isAnrok(): Boolean = anrok != null + + fun isStripe(): Boolean = stripe != null + fun asAvalara(): NewAvalaraTaxConfiguration = avalara.getOrThrow("avalara") fun asTaxjar(): NewTaxJarConfiguration = taxjar.getOrThrow("taxjar") fun asSphere(): NewSphereConfiguration = sphere.getOrThrow("sphere") + fun asNumeral(): Numeral = numeral.getOrThrow("numeral") + + fun asAnrok(): Anrok = anrok.getOrThrow("anrok") + + fun asStripe(): Stripe = stripe.getOrThrow("stripe") + fun _json(): JsonValue? = _json fun accept(visitor: Visitor): T = @@ -2726,6 +3614,9 @@ private constructor( avalara != null -> visitor.visitAvalara(avalara) taxjar != null -> visitor.visitTaxjar(taxjar) sphere != null -> visitor.visitSphere(sphere) + numeral != null -> visitor.visitNumeral(numeral) + anrok != null -> visitor.visitAnrok(anrok) + stripe != null -> visitor.visitStripe(stripe) else -> visitor.unknown(_json) } @@ -2749,6 +3640,18 @@ private constructor( override fun visitSphere(sphere: NewSphereConfiguration) { sphere.validate() } + + override fun visitNumeral(numeral: Numeral) { + numeral.validate() + } + + override fun visitAnrok(anrok: Anrok) { + anrok.validate() + } + + override fun visitStripe(stripe: Stripe) { + stripe.validate() + } } ) validated = true @@ -2778,6 +3681,12 @@ private constructor( override fun visitSphere(sphere: NewSphereConfiguration) = sphere.validity() + override fun visitNumeral(numeral: Numeral) = numeral.validity() + + override fun visitAnrok(anrok: Anrok) = anrok.validity() + + override fun visitStripe(stripe: Stripe) = stripe.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -2787,16 +3696,25 @@ private constructor( return true } - return /* spotless:off */ other is TaxConfiguration && avalara == other.avalara && taxjar == other.taxjar && sphere == other.sphere /* spotless:on */ + return other is TaxConfiguration && + avalara == other.avalara && + taxjar == other.taxjar && + sphere == other.sphere && + numeral == other.numeral && + anrok == other.anrok && + stripe == other.stripe } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(avalara, taxjar, sphere) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(avalara, taxjar, sphere, numeral, anrok, stripe) override fun toString(): String = when { avalara != null -> "TaxConfiguration{avalara=$avalara}" taxjar != null -> "TaxConfiguration{taxjar=$taxjar}" sphere != null -> "TaxConfiguration{sphere=$sphere}" + numeral != null -> "TaxConfiguration{numeral=$numeral}" + anrok != null -> "TaxConfiguration{anrok=$anrok}" + stripe != null -> "TaxConfiguration{stripe=$stripe}" _json != null -> "TaxConfiguration{_unknown=$_json}" else -> throw IllegalStateException("Invalid TaxConfiguration") } @@ -2808,6 +3726,12 @@ private constructor( fun ofTaxjar(taxjar: NewTaxJarConfiguration) = TaxConfiguration(taxjar = taxjar) fun ofSphere(sphere: NewSphereConfiguration) = TaxConfiguration(sphere = sphere) + + fun ofNumeral(numeral: Numeral) = TaxConfiguration(numeral = numeral) + + fun ofAnrok(anrok: Anrok) = TaxConfiguration(anrok = anrok) + + fun ofStripe(stripe: Stripe) = TaxConfiguration(stripe = stripe) } /** @@ -2822,6 +3746,12 @@ private constructor( fun visitSphere(sphere: NewSphereConfiguration): T + fun visitNumeral(numeral: Numeral): T + + fun visitAnrok(anrok: Anrok): T + + fun visitStripe(stripe: Stripe): T + /** * Maps an unknown variant of [TaxConfiguration] to a value of type [T]. * @@ -2859,6 +3789,21 @@ private constructor( TaxConfiguration(sphere = it, _json = json) } ?: TaxConfiguration(_json = json) } + "numeral" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TaxConfiguration(numeral = it, _json = json) + } ?: TaxConfiguration(_json = json) + } + "anrok" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TaxConfiguration(anrok = it, _json = json) + } ?: TaxConfiguration(_json = json) + } + "stripe" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TaxConfiguration(stripe = it, _json = json) + } ?: TaxConfiguration(_json = json) + } } return TaxConfiguration(_json = json) @@ -2876,11 +3821,806 @@ private constructor( value.avalara != null -> generator.writeObject(value.avalara) value.taxjar != null -> generator.writeObject(value.taxjar) value.sphere != null -> generator.writeObject(value.sphere) + value.numeral != null -> generator.writeObject(value.numeral) + value.anrok != null -> generator.writeObject(value.anrok) + value.stripe != null -> generator.writeObject(value.stripe) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid TaxConfiguration") } } } + + class Numeral + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val taxExempt: JsonField, + private val taxProvider: JsonValue, + private val automaticTaxEnabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tax_exempt") + @ExcludeMissing + taxExempt: JsonField = JsonMissing.of(), + @JsonProperty("tax_provider") + @ExcludeMissing + taxProvider: JsonValue = JsonMissing.of(), + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + automaticTaxEnabled: JsonField = JsonMissing.of(), + ) : this(taxExempt, taxProvider, automaticTaxEnabled, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun taxExempt(): Boolean = taxExempt.getRequired("tax_exempt") + + /** + * Expected to always return the following: + * ```kotlin + * JsonValue.from("numeral") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("tax_provider") + @ExcludeMissing + fun _taxProvider(): JsonValue = taxProvider + + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun automaticTaxEnabled(): Boolean? = + automaticTaxEnabled.getNullable("automatic_tax_enabled") + + /** + * Returns the raw JSON value of [taxExempt]. + * + * Unlike [taxExempt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tax_exempt") + @ExcludeMissing + fun _taxExempt(): JsonField = taxExempt + + /** + * Returns the raw JSON value of [automaticTaxEnabled]. + * + * Unlike [automaticTaxEnabled], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + fun _automaticTaxEnabled(): JsonField = automaticTaxEnabled + + @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 [Numeral]. + * + * The following fields are required: + * ```kotlin + * .taxExempt() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Numeral]. */ + class Builder internal constructor() { + + private var taxExempt: JsonField? = null + private var taxProvider: JsonValue = JsonValue.from("numeral") + private var automaticTaxEnabled: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(numeral: Numeral) = apply { + taxExempt = numeral.taxExempt + taxProvider = numeral.taxProvider + automaticTaxEnabled = numeral.automaticTaxEnabled + additionalProperties = numeral.additionalProperties.toMutableMap() + } + + fun taxExempt(taxExempt: Boolean) = taxExempt(JsonField.of(taxExempt)) + + /** + * Sets [Builder.taxExempt] to an arbitrary JSON value. + * + * You should usually call [Builder.taxExempt] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun taxExempt(taxExempt: JsonField) = apply { this.taxExempt = taxExempt } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("numeral") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun taxProvider(taxProvider: JsonValue) = apply { this.taxProvider = taxProvider } + + /** + * Whether to automatically calculate tax for this customer. When null, inherits + * from account-level setting. When true or false, overrides the account setting. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean?) = + automaticTaxEnabled(JsonField.ofNullable(automaticTaxEnabled)) + + /** + * Alias for [Builder.automaticTaxEnabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean) = + automaticTaxEnabled(automaticTaxEnabled as Boolean?) + + /** + * Sets [Builder.automaticTaxEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticTaxEnabled] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: JsonField) = apply { + this.automaticTaxEnabled = automaticTaxEnabled + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Numeral]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .taxExempt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Numeral = + Numeral( + checkRequired("taxExempt", taxExempt), + taxProvider, + automaticTaxEnabled, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Numeral = apply { + if (validated) { + return@apply + } + + taxExempt() + _taxProvider().let { + if (it != JsonValue.from("numeral")) { + throw OrbInvalidDataException("'taxProvider' is invalid, received $it") + } + } + automaticTaxEnabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (taxExempt.asKnown() == null) 0 else 1) + + taxProvider.let { if (it == JsonValue.from("numeral")) 1 else 0 } + + (if (automaticTaxEnabled.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Numeral && + taxExempt == other.taxExempt && + taxProvider == other.taxProvider && + automaticTaxEnabled == other.automaticTaxEnabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(taxExempt, taxProvider, automaticTaxEnabled, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Numeral{taxExempt=$taxExempt, taxProvider=$taxProvider, automaticTaxEnabled=$automaticTaxEnabled, additionalProperties=$additionalProperties}" + } + + class Anrok + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val taxExempt: JsonField, + private val taxProvider: JsonValue, + private val automaticTaxEnabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tax_exempt") + @ExcludeMissing + taxExempt: JsonField = JsonMissing.of(), + @JsonProperty("tax_provider") + @ExcludeMissing + taxProvider: JsonValue = JsonMissing.of(), + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + automaticTaxEnabled: JsonField = JsonMissing.of(), + ) : this(taxExempt, taxProvider, automaticTaxEnabled, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun taxExempt(): Boolean = taxExempt.getRequired("tax_exempt") + + /** + * Expected to always return the following: + * ```kotlin + * JsonValue.from("anrok") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("tax_provider") + @ExcludeMissing + fun _taxProvider(): JsonValue = taxProvider + + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun automaticTaxEnabled(): Boolean? = + automaticTaxEnabled.getNullable("automatic_tax_enabled") + + /** + * Returns the raw JSON value of [taxExempt]. + * + * Unlike [taxExempt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tax_exempt") + @ExcludeMissing + fun _taxExempt(): JsonField = taxExempt + + /** + * Returns the raw JSON value of [automaticTaxEnabled]. + * + * Unlike [automaticTaxEnabled], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + fun _automaticTaxEnabled(): JsonField = automaticTaxEnabled + + @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 [Anrok]. + * + * The following fields are required: + * ```kotlin + * .taxExempt() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Anrok]. */ + class Builder internal constructor() { + + private var taxExempt: JsonField? = null + private var taxProvider: JsonValue = JsonValue.from("anrok") + private var automaticTaxEnabled: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(anrok: Anrok) = apply { + taxExempt = anrok.taxExempt + taxProvider = anrok.taxProvider + automaticTaxEnabled = anrok.automaticTaxEnabled + additionalProperties = anrok.additionalProperties.toMutableMap() + } + + fun taxExempt(taxExempt: Boolean) = taxExempt(JsonField.of(taxExempt)) + + /** + * Sets [Builder.taxExempt] to an arbitrary JSON value. + * + * You should usually call [Builder.taxExempt] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun taxExempt(taxExempt: JsonField) = apply { this.taxExempt = taxExempt } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("anrok") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun taxProvider(taxProvider: JsonValue) = apply { this.taxProvider = taxProvider } + + /** + * Whether to automatically calculate tax for this customer. When null, inherits + * from account-level setting. When true or false, overrides the account setting. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean?) = + automaticTaxEnabled(JsonField.ofNullable(automaticTaxEnabled)) + + /** + * Alias for [Builder.automaticTaxEnabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean) = + automaticTaxEnabled(automaticTaxEnabled as Boolean?) + + /** + * Sets [Builder.automaticTaxEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticTaxEnabled] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: JsonField) = apply { + this.automaticTaxEnabled = automaticTaxEnabled + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Anrok]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .taxExempt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Anrok = + Anrok( + checkRequired("taxExempt", taxExempt), + taxProvider, + automaticTaxEnabled, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Anrok = apply { + if (validated) { + return@apply + } + + taxExempt() + _taxProvider().let { + if (it != JsonValue.from("anrok")) { + throw OrbInvalidDataException("'taxProvider' is invalid, received $it") + } + } + automaticTaxEnabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (taxExempt.asKnown() == null) 0 else 1) + + taxProvider.let { if (it == JsonValue.from("anrok")) 1 else 0 } + + (if (automaticTaxEnabled.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Anrok && + taxExempt == other.taxExempt && + taxProvider == other.taxProvider && + automaticTaxEnabled == other.automaticTaxEnabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(taxExempt, taxProvider, automaticTaxEnabled, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Anrok{taxExempt=$taxExempt, taxProvider=$taxProvider, automaticTaxEnabled=$automaticTaxEnabled, additionalProperties=$additionalProperties}" + } + + class Stripe + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val taxExempt: JsonField, + private val taxProvider: JsonValue, + private val automaticTaxEnabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tax_exempt") + @ExcludeMissing + taxExempt: JsonField = JsonMissing.of(), + @JsonProperty("tax_provider") + @ExcludeMissing + taxProvider: JsonValue = JsonMissing.of(), + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + automaticTaxEnabled: JsonField = JsonMissing.of(), + ) : this(taxExempt, taxProvider, automaticTaxEnabled, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun taxExempt(): Boolean = taxExempt.getRequired("tax_exempt") + + /** + * Expected to always return the following: + * ```kotlin + * JsonValue.from("stripe") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("tax_provider") + @ExcludeMissing + fun _taxProvider(): JsonValue = taxProvider + + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun automaticTaxEnabled(): Boolean? = + automaticTaxEnabled.getNullable("automatic_tax_enabled") + + /** + * Returns the raw JSON value of [taxExempt]. + * + * Unlike [taxExempt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tax_exempt") + @ExcludeMissing + fun _taxExempt(): JsonField = taxExempt + + /** + * Returns the raw JSON value of [automaticTaxEnabled]. + * + * Unlike [automaticTaxEnabled], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + fun _automaticTaxEnabled(): JsonField = automaticTaxEnabled + + @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: + * ```kotlin + * .taxExempt() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Stripe]. */ + class Builder internal constructor() { + + private var taxExempt: JsonField? = null + private var taxProvider: JsonValue = JsonValue.from("stripe") + private var automaticTaxEnabled: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(stripe: Stripe) = apply { + taxExempt = stripe.taxExempt + taxProvider = stripe.taxProvider + automaticTaxEnabled = stripe.automaticTaxEnabled + additionalProperties = stripe.additionalProperties.toMutableMap() + } + + fun taxExempt(taxExempt: Boolean) = taxExempt(JsonField.of(taxExempt)) + + /** + * Sets [Builder.taxExempt] to an arbitrary JSON value. + * + * You should usually call [Builder.taxExempt] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun taxExempt(taxExempt: JsonField) = apply { this.taxExempt = taxExempt } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("stripe") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun taxProvider(taxProvider: JsonValue) = apply { this.taxProvider = taxProvider } + + /** + * Whether to automatically calculate tax for this customer. When null, inherits + * from account-level setting. When true or false, overrides the account setting. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean?) = + automaticTaxEnabled(JsonField.ofNullable(automaticTaxEnabled)) + + /** + * Alias for [Builder.automaticTaxEnabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean) = + automaticTaxEnabled(automaticTaxEnabled as Boolean?) + + /** + * Sets [Builder.automaticTaxEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticTaxEnabled] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: JsonField) = apply { + this.automaticTaxEnabled = automaticTaxEnabled + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .taxExempt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Stripe = + Stripe( + checkRequired("taxExempt", taxExempt), + taxProvider, + automaticTaxEnabled, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Stripe = apply { + if (validated) { + return@apply + } + + taxExempt() + _taxProvider().let { + if (it != JsonValue.from("stripe")) { + throw OrbInvalidDataException("'taxProvider' is invalid, received $it") + } + } + automaticTaxEnabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (taxExempt.asKnown() == null) 0 else 1) + + taxProvider.let { if (it == JsonValue.from("stripe")) 1 else 0 } + + (if (automaticTaxEnabled.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Stripe && + taxExempt == other.taxExempt && + taxProvider == other.taxProvider && + automaticTaxEnabled == other.automaticTaxEnabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(taxExempt, taxProvider, automaticTaxEnabled, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Stripe{taxExempt=$taxExempt, taxProvider=$taxProvider, automaticTaxEnabled=$automaticTaxEnabled, additionalProperties=$additionalProperties}" + } } override fun equals(other: Any?): Boolean { @@ -2888,10 +4628,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "CustomerCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParams.kt index 790745c85..5ce49bf71 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParams.kt @@ -22,6 +22,7 @@ import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.Params import com.withorb.api.core.allMaxBy +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired import com.withorb.api.core.getOrThrow import com.withorb.api.core.http.Headers @@ -48,7 +49,6 @@ import java.util.Objects * credits (based on `amount` and `per_unit_cost_basis`). * * ## Adding credits - * * Adding credits is done by creating an entry of type `increment`. This requires the caller to * specify a number of credits as well as an optional expiry date in `YYYY-MM-DD` format. Orb also * recommends specifying a description to assist with auditing. When adding credits, the caller can @@ -72,7 +72,6 @@ import java.util.Objects * before adding the remaining amount to the desired credit block. * * ### Invoicing for credits - * * By default, Orb manipulates the credit ledger but does not charge for credits. However, if you * pass `invoice_settings` in the body of this request, Orb will also generate a one-off invoice for * the customer for the credits pre-purchase. Note that you _must_ provide the @@ -80,7 +79,6 @@ import java.util.Objects * cost basis with the number of credit units added. * * ## Deducting Credits - * * Orb allows you to deduct credits from a customer by creating an entry of type `decrement`. Orb * matches the algorithm for automatic deductions for determining which credit blocks to decrement * from. In the case that the deduction leads to multiple ledger entries, the response from this @@ -98,7 +96,6 @@ import java.util.Objects * ``` * * ## Changing credits expiry - * * If you'd like to change when existing credits expire, you should create a ledger entry of type * `expiration_change`. For this entry, the required parameter `expiry_date` identifies the * _originating_ block, and the required parameter `target_expiry_date` identifies when the @@ -498,10 +495,16 @@ private constructor( return true } - return /* spotless:off */ other is Body && increment == other.increment && decrement == other.decrement && expirationChange == other.expirationChange && void == other.void && amendment == other.amendment /* spotless:on */ + return other is Body && + increment == other.increment && + decrement == other.decrement && + expirationChange == other.expirationChange && + void == other.void && + amendment == other.amendment } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(increment, decrement, expirationChange, void, amendment) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(increment, decrement, expirationChange, void, amendment) override fun toString(): String = when { @@ -613,6 +616,7 @@ private constructor( } class Increment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val entryType: JsonValue, @@ -620,6 +624,7 @@ private constructor( private val description: JsonField, private val effectiveDate: JsonField, private val expiryDate: JsonField, + private val filters: JsonField>, private val invoiceSettings: JsonField, private val metadata: JsonField, private val perUnitCostBasis: JsonField, @@ -644,6 +649,9 @@ private constructor( @JsonProperty("expiry_date") @ExcludeMissing expiryDate: JsonField = JsonMissing.of(), + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), @JsonProperty("invoice_settings") @ExcludeMissing invoiceSettings: JsonField = JsonMissing.of(), @@ -660,6 +668,7 @@ private constructor( description, effectiveDate, expiryDate, + filters, invoiceSettings, metadata, perUnitCostBasis, @@ -723,6 +732,15 @@ private constructor( */ fun expiryDate(): OffsetDateTime? = expiryDate.getNullable("expiry_date") + /** + * Optional filter to specify which items this credit block applies to. If not + * specified, the block will apply to all items for the pricing unit. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun filters(): List? = filters.getNullable("filters") + /** * Passing `invoice_settings` automatically generates an invoice for the newly added * credits. If `invoice_settings` is passed, you must specify per_unit_cost_basis, as @@ -798,6 +816,15 @@ private constructor( @ExcludeMissing fun _expiryDate(): JsonField = expiryDate + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + /** * Returns the raw JSON value of [invoiceSettings]. * @@ -862,6 +889,7 @@ private constructor( private var description: JsonField = JsonMissing.of() private var effectiveDate: JsonField = JsonMissing.of() private var expiryDate: JsonField = JsonMissing.of() + private var filters: JsonField>? = null private var invoiceSettings: JsonField = JsonMissing.of() private var metadata: JsonField = JsonMissing.of() private var perUnitCostBasis: JsonField = JsonMissing.of() @@ -874,6 +902,7 @@ private constructor( description = increment.description effectiveDate = increment.effectiveDate expiryDate = increment.expiryDate + filters = increment.filters.map { it.toMutableList() } invoiceSettings = increment.invoiceSettings metadata = increment.metadata perUnitCostBasis = increment.perUnitCostBasis @@ -976,6 +1005,35 @@ private constructor( this.expiryDate = expiryDate } + /** + * Optional filter to specify which items this credit block applies to. If not + * specified, the block will apply to all items for the pricing unit. + */ + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + /** * Passing `invoice_settings` automatically generates an invoice for the newly added * credits. If `invoice_settings` is passed, you must specify per_unit_cost_basis, @@ -1071,6 +1129,7 @@ private constructor( description, effectiveDate, expiryDate, + (filters ?: JsonMissing.of()).map { it.toImmutable() }, invoiceSettings, metadata, perUnitCostBasis, @@ -1095,6 +1154,7 @@ private constructor( description() effectiveDate() expiryDate() + filters()?.forEach { it.validate() } invoiceSettings()?.validate() metadata()?.validate() perUnitCostBasis() @@ -1122,21 +1182,556 @@ private constructor( (if (description.asKnown() == null) 0 else 1) + (if (effectiveDate.asKnown() == null) 0 else 1) + (if (expiryDate.asKnown() == null) 0 else 1) + + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (invoiceSettings.asKnown()?.validity() ?: 0) + (metadata.asKnown()?.validity() ?: 0) + (if (perUnitCostBasis.asKnown() == null) 0 else 1) + /** A PriceFilter that only allows item_id field for block filters. */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") + @ExcludeMissing + field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price the block applies to. Only item_id is supported. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("values") + @ExcludeMissing + fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** + * The property of the price the block applies to. Only item_id is supported. + */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price the block applies to. Only item_id is supported. */ + class Field @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 { + + val ITEM_ID = of("item_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + ITEM_ID + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + ITEM_ID, + /** + * An enum member indicating that [Field] 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) { + ITEM_ID -> Value.ITEM_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known + * and don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ITEM_ID -> Known.ITEM_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or + * if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + /** * Passing `invoice_settings` automatically generates an invoice for the newly added * credits. If `invoice_settings` is passed, you must specify per_unit_cost_basis, as * the calculation of the invoice total is done on that basis. */ class InvoiceSettings + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val autoCollection: JsonField, - private val netTerms: JsonField, + private val customDueDate: JsonField, private val invoiceDate: JsonField, + private val itemId: JsonField, private val memo: JsonField, + private val netTerms: JsonField, private val requireSuccessfulPayment: JsonField, private val additionalProperties: MutableMap, ) { @@ -1146,23 +1741,31 @@ private constructor( @JsonProperty("auto_collection") @ExcludeMissing autoCollection: JsonField = JsonMissing.of(), - @JsonProperty("net_terms") + @JsonProperty("custom_due_date") @ExcludeMissing - netTerms: JsonField = JsonMissing.of(), + customDueDate: JsonField = JsonMissing.of(), @JsonProperty("invoice_date") @ExcludeMissing invoiceDate: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), @JsonProperty("memo") @ExcludeMissing memo: JsonField = JsonMissing.of(), + @JsonProperty("net_terms") + @ExcludeMissing + netTerms: JsonField = JsonMissing.of(), @JsonProperty("require_successful_payment") @ExcludeMissing requireSuccessfulPayment: JsonField = JsonMissing.of(), ) : this( autoCollection, - netTerms, + customDueDate, invoiceDate, + itemId, memo, + netTerms, requireSuccessfulPayment, mutableMapOf(), ) @@ -1178,14 +1781,13 @@ private constructor( fun autoCollection(): Boolean = autoCollection.getRequired("auto_collection") /** - * The net terms determines the difference between the invoice date and the issue - * date for the invoice. If you intend the invoice to be due on issue, set this - * to 0. + * An optional custom due date for the invoice. If not set, the due date will be + * calculated based on the `net_terms` value. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun netTerms(): Long? = netTerms.getNullable("net_terms") + fun customDueDate(): CustomDueDate? = customDueDate.getNullable("custom_due_date") /** * An ISO 8601 format date that denotes when this invoice should be dated in the @@ -1197,6 +1799,15 @@ private constructor( */ fun invoiceDate(): InvoiceDate? = invoiceDate.getNullable("invoice_date") + /** + * The ID of the Item to be used for the invoice line item. If not provided, a + * default 'Credits' item will be used. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun itemId(): String? = itemId.getNullable("item_id") + /** * An optional memo to display on the invoice. * @@ -1205,6 +1816,18 @@ private constructor( */ fun memo(): String? = memo.getNullable("memo") + /** + * The net terms determines the due date of the invoice. Due date is calculated + * based on the invoice or issuance date, depending on the account's configured due + * date calculation method. A value of '0' here represents that the invoice is due + * on issue, whereas a value of '30' represents that the customer has 30 days to pay + * the invoice. Do not set this field if you want to set a custom due date. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun netTerms(): Long? = netTerms.getNullable("net_terms") + /** * If true, the new credit block will require that the corresponding invoice is paid * before it can be drawn down from. @@ -1226,14 +1849,14 @@ private constructor( fun _autoCollection(): JsonField = autoCollection /** - * Returns the raw JSON value of [netTerms]. + * Returns the raw JSON value of [customDueDate]. * - * Unlike [netTerms], this method doesn't throw if the JSON field has an unexpected - * type. + * Unlike [customDueDate], this method doesn't throw if the JSON field has an + * unexpected type. */ - @JsonProperty("net_terms") + @JsonProperty("custom_due_date") @ExcludeMissing - fun _netTerms(): JsonField = netTerms + fun _customDueDate(): JsonField = customDueDate /** * Returns the raw JSON value of [invoiceDate]. @@ -1245,6 +1868,14 @@ private constructor( @ExcludeMissing fun _invoiceDate(): JsonField = invoiceDate + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + /** * Returns the raw JSON value of [memo]. * @@ -1253,6 +1884,16 @@ private constructor( */ @JsonProperty("memo") @ExcludeMissing fun _memo(): JsonField = memo + /** + * Returns the raw JSON value of [netTerms]. + * + * Unlike [netTerms], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("net_terms") + @ExcludeMissing + fun _netTerms(): JsonField = netTerms + /** * Returns the raw JSON value of [requireSuccessfulPayment]. * @@ -1283,7 +1924,6 @@ private constructor( * The following fields are required: * ```kotlin * .autoCollection() - * .netTerms() * ``` */ fun builder() = Builder() @@ -1293,17 +1933,21 @@ private constructor( class Builder internal constructor() { private var autoCollection: JsonField? = null - private var netTerms: JsonField? = null + private var customDueDate: JsonField = JsonMissing.of() private var invoiceDate: JsonField = JsonMissing.of() + private var itemId: JsonField = JsonMissing.of() private var memo: JsonField = JsonMissing.of() + private var netTerms: JsonField = JsonMissing.of() private var requireSuccessfulPayment: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(invoiceSettings: InvoiceSettings) = apply { autoCollection = invoiceSettings.autoCollection - netTerms = invoiceSettings.netTerms + customDueDate = invoiceSettings.customDueDate invoiceDate = invoiceSettings.invoiceDate + itemId = invoiceSettings.itemId memo = invoiceSettings.memo + netTerms = invoiceSettings.netTerms requireSuccessfulPayment = invoiceSettings.requireSuccessfulPayment additionalProperties = invoiceSettings.additionalProperties.toMutableMap() } @@ -1327,27 +1971,31 @@ private constructor( } /** - * The net terms determines the difference between the invoice date and the - * issue date for the invoice. If you intend the invoice to be due on issue, set - * this to 0. + * An optional custom due date for the invoice. If not set, the due date will be + * calculated based on the `net_terms` value. */ - fun netTerms(netTerms: Long?) = netTerms(JsonField.ofNullable(netTerms)) + fun customDueDate(customDueDate: CustomDueDate?) = + customDueDate(JsonField.ofNullable(customDueDate)) /** - * Alias for [Builder.netTerms]. + * Sets [Builder.customDueDate] to an arbitrary JSON value. * - * This unboxed primitive overload exists for backwards compatibility. + * You should usually call [Builder.customDueDate] with a well-typed + * [CustomDueDate] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. */ - fun netTerms(netTerms: Long) = netTerms(netTerms as Long?) + fun customDueDate(customDueDate: JsonField) = apply { + this.customDueDate = customDueDate + } + + /** Alias for calling [customDueDate] with `CustomDueDate.ofDate(date)`. */ + fun customDueDate(date: LocalDate) = customDueDate(CustomDueDate.ofDate(date)) /** - * Sets [Builder.netTerms] to an arbitrary JSON value. - * - * You should usually call [Builder.netTerms] with a well-typed [Long] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. + * Alias for calling [customDueDate] with `CustomDueDate.ofDateTime(dateTime)`. */ - fun netTerms(netTerms: JsonField) = apply { this.netTerms = netTerms } + fun customDueDate(dateTime: OffsetDateTime) = + customDueDate(CustomDueDate.ofDateTime(dateTime)) /** * An ISO 8601 format date that denotes when this invoice should be dated in the @@ -1375,6 +2023,21 @@ private constructor( fun invoiceDate(dateTime: OffsetDateTime) = invoiceDate(InvoiceDate.ofDateTime(dateTime)) + /** + * The ID of the Item to be used for the invoice line item. If not provided, a + * default 'Credits' item will be used. + */ + fun itemId(itemId: String?) = itemId(JsonField.ofNullable(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** An optional memo to display on the invoice. */ fun memo(memo: String?) = memo(JsonField.ofNullable(memo)) @@ -1387,6 +2050,32 @@ private constructor( */ fun memo(memo: JsonField) = apply { this.memo = memo } + /** + * The net terms determines the due date of the invoice. Due date is calculated + * based on the invoice or issuance date, depending on the account's configured + * due date calculation method. A value of '0' here represents that the invoice + * is due on issue, whereas a value of '30' represents that the customer has 30 + * days to pay the invoice. Do not set this field if you want to set a custom + * due date. + */ + fun netTerms(netTerms: Long?) = netTerms(JsonField.ofNullable(netTerms)) + + /** + * Alias for [Builder.netTerms]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun netTerms(netTerms: Long) = netTerms(netTerms as Long?) + + /** + * Sets [Builder.netTerms] to an arbitrary JSON value. + * + * You should usually call [Builder.netTerms] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun netTerms(netTerms: JsonField) = apply { this.netTerms = netTerms } + /** * If true, the new credit block will require that the corresponding invoice is * paid before it can be drawn down from. @@ -1436,7 +2125,6 @@ private constructor( * The following fields are required: * ```kotlin * .autoCollection() - * .netTerms() * ``` * * @throws IllegalStateException if any required field is unset. @@ -1444,9 +2132,11 @@ private constructor( fun build(): InvoiceSettings = InvoiceSettings( checkRequired("autoCollection", autoCollection), - checkRequired("netTerms", netTerms), + customDueDate, invoiceDate, + itemId, memo, + netTerms, requireSuccessfulPayment, additionalProperties.toMutableMap(), ) @@ -1460,9 +2150,11 @@ private constructor( } autoCollection() - netTerms() + customDueDate()?.validate() invoiceDate()?.validate() + itemId() memo() + netTerms() requireSuccessfulPayment() validated = true } @@ -1483,11 +2175,192 @@ private constructor( */ internal fun validity(): Int = (if (autoCollection.asKnown() == null) 0 else 1) + - (if (netTerms.asKnown() == null) 0 else 1) + + (customDueDate.asKnown()?.validity() ?: 0) + (invoiceDate.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + (if (memo.asKnown() == null) 0 else 1) + + (if (netTerms.asKnown() == null) 0 else 1) + (if (requireSuccessfulPayment.asKnown() == null) 0 else 1) + /** + * An optional custom due date for the invoice. If not set, the due date will be + * calculated based on the `net_terms` value. + */ + @JsonDeserialize(using = CustomDueDate.Deserializer::class) + @JsonSerialize(using = CustomDueDate.Serializer::class) + class CustomDueDate + private constructor( + private val date: LocalDate? = null, + private val dateTime: OffsetDateTime? = null, + private val _json: JsonValue? = null, + ) { + + fun date(): LocalDate? = date + + fun dateTime(): OffsetDateTime? = dateTime + + fun isDate(): Boolean = date != null + + fun isDateTime(): Boolean = dateTime != null + + fun asDate(): LocalDate = date.getOrThrow("date") + + fun asDateTime(): OffsetDateTime = dateTime.getOrThrow("dateTime") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + date != null -> visitor.visitDate(date) + dateTime != null -> visitor.visitDateTime(dateTime) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): CustomDueDate = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitDate(date: LocalDate) {} + + override fun visitDateTime(dateTime: OffsetDateTime) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitDate(date: LocalDate) = 1 + + override fun visitDateTime(dateTime: OffsetDateTime) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomDueDate && + date == other.date && + dateTime == other.dateTime + } + + override fun hashCode(): Int = Objects.hash(date, dateTime) + + override fun toString(): String = + when { + date != null -> "CustomDueDate{date=$date}" + dateTime != null -> "CustomDueDate{dateTime=$dateTime}" + _json != null -> "CustomDueDate{_unknown=$_json}" + else -> throw IllegalStateException("Invalid CustomDueDate") + } + + companion object { + + fun ofDate(date: LocalDate) = CustomDueDate(date = date) + + fun ofDateTime(dateTime: OffsetDateTime) = + CustomDueDate(dateTime = dateTime) + } + + /** + * An interface that defines how to map each variant of [CustomDueDate] to a + * value of type [T]. + */ + interface Visitor { + + fun visitDate(date: LocalDate): T + + fun visitDateTime(dateTime: OffsetDateTime): T + + /** + * Maps an unknown variant of [CustomDueDate] to a value of type [T]. + * + * An instance of [CustomDueDate] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, + * if the SDK is on an older version than the API, then the API may respond + * with new variants that the SDK is unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown CustomDueDate: $json") + } + } + + internal class Deserializer : + BaseDeserializer(CustomDueDate::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): CustomDueDate { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + CustomDueDate(date = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { CustomDueDate(dateTime = it, _json = json) }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing + // from object). + 0 -> CustomDueDate(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then + // use the first completely valid match, or simply the first match + // if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : + BaseSerializer(CustomDueDate::class) { + + override fun serialize( + value: CustomDueDate, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.date != null -> generator.writeObject(value.date) + value.dateTime != null -> generator.writeObject(value.dateTime) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid CustomDueDate") + } + } + } + } + /** * An ISO 8601 format date that denotes when this invoice should be dated in the * customer's timezone. If not provided, the invoice date will default to the credit @@ -1570,10 +2443,12 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceDate && date == other.date && dateTime == other.dateTime /* spotless:on */ + return other is InvoiceDate && + date == other.date && + dateTime == other.dateTime } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(date, dateTime) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(date, dateTime) override fun toString(): String = when { @@ -1669,17 +2544,34 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceSettings && autoCollection == other.autoCollection && netTerms == other.netTerms && invoiceDate == other.invoiceDate && memo == other.memo && requireSuccessfulPayment == other.requireSuccessfulPayment && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InvoiceSettings && + autoCollection == other.autoCollection && + customDueDate == other.customDueDate && + invoiceDate == other.invoiceDate && + itemId == other.itemId && + memo == other.memo && + netTerms == other.netTerms && + requireSuccessfulPayment == other.requireSuccessfulPayment && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(autoCollection, netTerms, invoiceDate, memo, requireSuccessfulPayment, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + autoCollection, + customDueDate, + invoiceDate, + itemId, + memo, + netTerms, + requireSuccessfulPayment, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "InvoiceSettings{autoCollection=$autoCollection, netTerms=$netTerms, invoiceDate=$invoiceDate, memo=$memo, requireSuccessfulPayment=$requireSuccessfulPayment, additionalProperties=$additionalProperties}" + "InvoiceSettings{autoCollection=$autoCollection, customDueDate=$customDueDate, invoiceDate=$invoiceDate, itemId=$itemId, memo=$memo, netTerms=$netTerms, requireSuccessfulPayment=$requireSuccessfulPayment, additionalProperties=$additionalProperties}" } /** @@ -1779,12 +2671,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1796,20 +2686,44 @@ private constructor( return true } - return /* spotless:off */ other is Increment && amount == other.amount && entryType == other.entryType && currency == other.currency && description == other.description && effectiveDate == other.effectiveDate && expiryDate == other.expiryDate && invoiceSettings == other.invoiceSettings && metadata == other.metadata && perUnitCostBasis == other.perUnitCostBasis && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Increment && + amount == other.amount && + entryType == other.entryType && + currency == other.currency && + description == other.description && + effectiveDate == other.effectiveDate && + expiryDate == other.expiryDate && + filters == other.filters && + invoiceSettings == other.invoiceSettings && + metadata == other.metadata && + perUnitCostBasis == other.perUnitCostBasis && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, entryType, currency, description, effectiveDate, expiryDate, invoiceSettings, metadata, perUnitCostBasis, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amount, + entryType, + currency, + description, + effectiveDate, + expiryDate, + filters, + invoiceSettings, + metadata, + perUnitCostBasis, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Increment{amount=$amount, entryType=$entryType, currency=$currency, description=$description, effectiveDate=$effectiveDate, expiryDate=$expiryDate, invoiceSettings=$invoiceSettings, metadata=$metadata, perUnitCostBasis=$perUnitCostBasis, additionalProperties=$additionalProperties}" + "Increment{amount=$amount, entryType=$entryType, currency=$currency, description=$description, effectiveDate=$effectiveDate, expiryDate=$expiryDate, filters=$filters, invoiceSettings=$invoiceSettings, metadata=$metadata, perUnitCostBasis=$perUnitCostBasis, additionalProperties=$additionalProperties}" } class Decrement + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val entryType: JsonValue, @@ -2226,12 +3140,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2243,12 +3155,25 @@ private constructor( return true } - return /* spotless:off */ other is Decrement && amount == other.amount && entryType == other.entryType && currency == other.currency && description == other.description && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Decrement && + amount == other.amount && + entryType == other.entryType && + currency == other.currency && + description == other.description && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, entryType, currency, description, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amount, + entryType, + currency, + description, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2257,6 +3182,7 @@ private constructor( } class ExpirationChange + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val entryType: JsonValue, private val targetExpiryDate: JsonField, @@ -2821,12 +3747,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2838,12 +3762,31 @@ private constructor( return true } - return /* spotless:off */ other is ExpirationChange && entryType == other.entryType && targetExpiryDate == other.targetExpiryDate && amount == other.amount && blockId == other.blockId && currency == other.currency && description == other.description && expiryDate == other.expiryDate && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ExpirationChange && + entryType == other.entryType && + targetExpiryDate == other.targetExpiryDate && + amount == other.amount && + blockId == other.blockId && + currency == other.currency && + description == other.description && + expiryDate == other.expiryDate && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(entryType, targetExpiryDate, amount, blockId, currency, description, expiryDate, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + entryType, + targetExpiryDate, + amount, + blockId, + currency, + description, + expiryDate, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2852,6 +3795,7 @@ private constructor( } class Void + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val blockId: JsonField, @@ -3358,12 +4302,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3487,7 +4429,7 @@ private constructor( return true } - return /* spotless:off */ other is VoidReason && value == other.value /* spotless:on */ + return other is VoidReason && value == other.value } override fun hashCode() = value.hashCode() @@ -3500,12 +4442,29 @@ private constructor( return true } - return /* spotless:off */ other is Void && amount == other.amount && blockId == other.blockId && entryType == other.entryType && currency == other.currency && description == other.description && metadata == other.metadata && voidReason == other.voidReason && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Void && + amount == other.amount && + blockId == other.blockId && + entryType == other.entryType && + currency == other.currency && + description == other.description && + metadata == other.metadata && + voidReason == other.voidReason && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, blockId, entryType, currency, description, metadata, voidReason, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amount, + blockId, + entryType, + currency, + description, + metadata, + voidReason, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -3514,6 +4473,7 @@ private constructor( } class Amendment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val blockId: JsonField, @@ -3969,12 +4929,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3986,12 +4944,27 @@ private constructor( return true } - return /* spotless:off */ other is Amendment && amount == other.amount && blockId == other.blockId && entryType == other.entryType && currency == other.currency && description == other.description && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Amendment && + amount == other.amount && + blockId == other.blockId && + entryType == other.entryType && + currency == other.currency && + description == other.description && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, blockId, entryType, currency, description, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amount, + blockId, + entryType, + currency, + description, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -4005,10 +4978,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerCreateEntryByExternalIdParams && externalCustomerId == other.externalCustomerId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerCreditLedgerCreateEntryByExternalIdParams && + externalCustomerId == other.externalCustomerId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalCustomerId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(externalCustomerId, body, additionalHeaders, additionalQueryParams) override fun toString() = "CustomerCreditLedgerCreateEntryByExternalIdParams{externalCustomerId=$externalCustomerId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdResponse.kt index d26af9036..1d93f593f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdResponse.kt @@ -178,10 +178,26 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerCreateEntryByExternalIdResponse && increment == other.increment && decrement == other.decrement && expirationChange == other.expirationChange && creditBlockExpiry == other.creditBlockExpiry && void == other.void && voidInitiated == other.voidInitiated && amendment == other.amendment /* spotless:on */ + return other is CustomerCreditLedgerCreateEntryByExternalIdResponse && + increment == other.increment && + decrement == other.decrement && + expirationChange == other.expirationChange && + creditBlockExpiry == other.creditBlockExpiry && + void == other.void && + voidInitiated == other.voidInitiated && + amendment == other.amendment } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(increment, decrement, expirationChange, creditBlockExpiry, void, voidInitiated, amendment) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + increment, + decrement, + expirationChange, + creditBlockExpiry, + void, + voidInitiated, + amendment, + ) override fun toString(): String = when { diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParams.kt index d59142cc8..448633936 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParams.kt @@ -22,6 +22,7 @@ import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.Params import com.withorb.api.core.allMaxBy +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired import com.withorb.api.core.getOrThrow import com.withorb.api.core.http.Headers @@ -48,7 +49,6 @@ import java.util.Objects * credits (based on `amount` and `per_unit_cost_basis`). * * ## Adding credits - * * Adding credits is done by creating an entry of type `increment`. This requires the caller to * specify a number of credits as well as an optional expiry date in `YYYY-MM-DD` format. Orb also * recommends specifying a description to assist with auditing. When adding credits, the caller can @@ -72,7 +72,6 @@ import java.util.Objects * before adding the remaining amount to the desired credit block. * * ### Invoicing for credits - * * By default, Orb manipulates the credit ledger but does not charge for credits. However, if you * pass `invoice_settings` in the body of this request, Orb will also generate a one-off invoice for * the customer for the credits pre-purchase. Note that you _must_ provide the @@ -80,7 +79,6 @@ import java.util.Objects * cost basis with the number of credit units added. * * ## Deducting Credits - * * Orb allows you to deduct credits from a customer by creating an entry of type `decrement`. Orb * matches the algorithm for automatic deductions for determining which credit blocks to decrement * from. In the case that the deduction leads to multiple ledger entries, the response from this @@ -98,7 +96,6 @@ import java.util.Objects * ``` * * ## Changing credits expiry - * * If you'd like to change when existing credits expire, you should create a ledger entry of type * `expiration_change`. For this entry, the required parameter `expiry_date` identifies the * _originating_ block, and the required parameter `target_expiry_date` identifies when the @@ -493,10 +490,16 @@ private constructor( return true } - return /* spotless:off */ other is Body && increment == other.increment && decrement == other.decrement && expirationChange == other.expirationChange && void == other.void && amendment == other.amendment /* spotless:on */ + return other is Body && + increment == other.increment && + decrement == other.decrement && + expirationChange == other.expirationChange && + void == other.void && + amendment == other.amendment } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(increment, decrement, expirationChange, void, amendment) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(increment, decrement, expirationChange, void, amendment) override fun toString(): String = when { @@ -608,6 +611,7 @@ private constructor( } class Increment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val entryType: JsonValue, @@ -615,6 +619,7 @@ private constructor( private val description: JsonField, private val effectiveDate: JsonField, private val expiryDate: JsonField, + private val filters: JsonField>, private val invoiceSettings: JsonField, private val metadata: JsonField, private val perUnitCostBasis: JsonField, @@ -639,6 +644,9 @@ private constructor( @JsonProperty("expiry_date") @ExcludeMissing expiryDate: JsonField = JsonMissing.of(), + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), @JsonProperty("invoice_settings") @ExcludeMissing invoiceSettings: JsonField = JsonMissing.of(), @@ -655,6 +663,7 @@ private constructor( description, effectiveDate, expiryDate, + filters, invoiceSettings, metadata, perUnitCostBasis, @@ -718,6 +727,15 @@ private constructor( */ fun expiryDate(): OffsetDateTime? = expiryDate.getNullable("expiry_date") + /** + * Optional filter to specify which items this credit block applies to. If not + * specified, the block will apply to all items for the pricing unit. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun filters(): List? = filters.getNullable("filters") + /** * Passing `invoice_settings` automatically generates an invoice for the newly added * credits. If `invoice_settings` is passed, you must specify per_unit_cost_basis, as @@ -793,6 +811,15 @@ private constructor( @ExcludeMissing fun _expiryDate(): JsonField = expiryDate + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + /** * Returns the raw JSON value of [invoiceSettings]. * @@ -857,6 +884,7 @@ private constructor( private var description: JsonField = JsonMissing.of() private var effectiveDate: JsonField = JsonMissing.of() private var expiryDate: JsonField = JsonMissing.of() + private var filters: JsonField>? = null private var invoiceSettings: JsonField = JsonMissing.of() private var metadata: JsonField = JsonMissing.of() private var perUnitCostBasis: JsonField = JsonMissing.of() @@ -869,6 +897,7 @@ private constructor( description = increment.description effectiveDate = increment.effectiveDate expiryDate = increment.expiryDate + filters = increment.filters.map { it.toMutableList() } invoiceSettings = increment.invoiceSettings metadata = increment.metadata perUnitCostBasis = increment.perUnitCostBasis @@ -971,6 +1000,35 @@ private constructor( this.expiryDate = expiryDate } + /** + * Optional filter to specify which items this credit block applies to. If not + * specified, the block will apply to all items for the pricing unit. + */ + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + /** * Passing `invoice_settings` automatically generates an invoice for the newly added * credits. If `invoice_settings` is passed, you must specify per_unit_cost_basis, @@ -1066,6 +1124,7 @@ private constructor( description, effectiveDate, expiryDate, + (filters ?: JsonMissing.of()).map { it.toImmutable() }, invoiceSettings, metadata, perUnitCostBasis, @@ -1090,6 +1149,7 @@ private constructor( description() effectiveDate() expiryDate() + filters()?.forEach { it.validate() } invoiceSettings()?.validate() metadata()?.validate() perUnitCostBasis() @@ -1117,21 +1177,556 @@ private constructor( (if (description.asKnown() == null) 0 else 1) + (if (effectiveDate.asKnown() == null) 0 else 1) + (if (expiryDate.asKnown() == null) 0 else 1) + + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (invoiceSettings.asKnown()?.validity() ?: 0) + (metadata.asKnown()?.validity() ?: 0) + (if (perUnitCostBasis.asKnown() == null) 0 else 1) + /** A PriceFilter that only allows item_id field for block filters. */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") + @ExcludeMissing + field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price the block applies to. Only item_id is supported. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("values") + @ExcludeMissing + fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** + * The property of the price the block applies to. Only item_id is supported. + */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price the block applies to. Only item_id is supported. */ + class Field @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 { + + val ITEM_ID = of("item_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + ITEM_ID + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + ITEM_ID, + /** + * An enum member indicating that [Field] 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) { + ITEM_ID -> Value.ITEM_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known + * and don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ITEM_ID -> Known.ITEM_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or + * if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + /** * Passing `invoice_settings` automatically generates an invoice for the newly added * credits. If `invoice_settings` is passed, you must specify per_unit_cost_basis, as * the calculation of the invoice total is done on that basis. */ class InvoiceSettings + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val autoCollection: JsonField, - private val netTerms: JsonField, + private val customDueDate: JsonField, private val invoiceDate: JsonField, + private val itemId: JsonField, private val memo: JsonField, + private val netTerms: JsonField, private val requireSuccessfulPayment: JsonField, private val additionalProperties: MutableMap, ) { @@ -1141,23 +1736,31 @@ private constructor( @JsonProperty("auto_collection") @ExcludeMissing autoCollection: JsonField = JsonMissing.of(), - @JsonProperty("net_terms") + @JsonProperty("custom_due_date") @ExcludeMissing - netTerms: JsonField = JsonMissing.of(), + customDueDate: JsonField = JsonMissing.of(), @JsonProperty("invoice_date") @ExcludeMissing invoiceDate: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), @JsonProperty("memo") @ExcludeMissing memo: JsonField = JsonMissing.of(), + @JsonProperty("net_terms") + @ExcludeMissing + netTerms: JsonField = JsonMissing.of(), @JsonProperty("require_successful_payment") @ExcludeMissing requireSuccessfulPayment: JsonField = JsonMissing.of(), ) : this( autoCollection, - netTerms, + customDueDate, invoiceDate, + itemId, memo, + netTerms, requireSuccessfulPayment, mutableMapOf(), ) @@ -1173,14 +1776,13 @@ private constructor( fun autoCollection(): Boolean = autoCollection.getRequired("auto_collection") /** - * The net terms determines the difference between the invoice date and the issue - * date for the invoice. If you intend the invoice to be due on issue, set this - * to 0. + * An optional custom due date for the invoice. If not set, the due date will be + * calculated based on the `net_terms` value. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun netTerms(): Long? = netTerms.getNullable("net_terms") + fun customDueDate(): CustomDueDate? = customDueDate.getNullable("custom_due_date") /** * An ISO 8601 format date that denotes when this invoice should be dated in the @@ -1192,6 +1794,15 @@ private constructor( */ fun invoiceDate(): InvoiceDate? = invoiceDate.getNullable("invoice_date") + /** + * The ID of the Item to be used for the invoice line item. If not provided, a + * default 'Credits' item will be used. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun itemId(): String? = itemId.getNullable("item_id") + /** * An optional memo to display on the invoice. * @@ -1200,6 +1811,18 @@ private constructor( */ fun memo(): String? = memo.getNullable("memo") + /** + * The net terms determines the due date of the invoice. Due date is calculated + * based on the invoice or issuance date, depending on the account's configured due + * date calculation method. A value of '0' here represents that the invoice is due + * on issue, whereas a value of '30' represents that the customer has 30 days to pay + * the invoice. Do not set this field if you want to set a custom due date. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun netTerms(): Long? = netTerms.getNullable("net_terms") + /** * If true, the new credit block will require that the corresponding invoice is paid * before it can be drawn down from. @@ -1221,14 +1844,14 @@ private constructor( fun _autoCollection(): JsonField = autoCollection /** - * Returns the raw JSON value of [netTerms]. + * Returns the raw JSON value of [customDueDate]. * - * Unlike [netTerms], this method doesn't throw if the JSON field has an unexpected - * type. + * Unlike [customDueDate], this method doesn't throw if the JSON field has an + * unexpected type. */ - @JsonProperty("net_terms") + @JsonProperty("custom_due_date") @ExcludeMissing - fun _netTerms(): JsonField = netTerms + fun _customDueDate(): JsonField = customDueDate /** * Returns the raw JSON value of [invoiceDate]. @@ -1240,6 +1863,14 @@ private constructor( @ExcludeMissing fun _invoiceDate(): JsonField = invoiceDate + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + /** * Returns the raw JSON value of [memo]. * @@ -1248,6 +1879,16 @@ private constructor( */ @JsonProperty("memo") @ExcludeMissing fun _memo(): JsonField = memo + /** + * Returns the raw JSON value of [netTerms]. + * + * Unlike [netTerms], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("net_terms") + @ExcludeMissing + fun _netTerms(): JsonField = netTerms + /** * Returns the raw JSON value of [requireSuccessfulPayment]. * @@ -1278,7 +1919,6 @@ private constructor( * The following fields are required: * ```kotlin * .autoCollection() - * .netTerms() * ``` */ fun builder() = Builder() @@ -1288,17 +1928,21 @@ private constructor( class Builder internal constructor() { private var autoCollection: JsonField? = null - private var netTerms: JsonField? = null + private var customDueDate: JsonField = JsonMissing.of() private var invoiceDate: JsonField = JsonMissing.of() + private var itemId: JsonField = JsonMissing.of() private var memo: JsonField = JsonMissing.of() + private var netTerms: JsonField = JsonMissing.of() private var requireSuccessfulPayment: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(invoiceSettings: InvoiceSettings) = apply { autoCollection = invoiceSettings.autoCollection - netTerms = invoiceSettings.netTerms + customDueDate = invoiceSettings.customDueDate invoiceDate = invoiceSettings.invoiceDate + itemId = invoiceSettings.itemId memo = invoiceSettings.memo + netTerms = invoiceSettings.netTerms requireSuccessfulPayment = invoiceSettings.requireSuccessfulPayment additionalProperties = invoiceSettings.additionalProperties.toMutableMap() } @@ -1322,27 +1966,31 @@ private constructor( } /** - * The net terms determines the difference between the invoice date and the - * issue date for the invoice. If you intend the invoice to be due on issue, set - * this to 0. + * An optional custom due date for the invoice. If not set, the due date will be + * calculated based on the `net_terms` value. */ - fun netTerms(netTerms: Long?) = netTerms(JsonField.ofNullable(netTerms)) + fun customDueDate(customDueDate: CustomDueDate?) = + customDueDate(JsonField.ofNullable(customDueDate)) /** - * Alias for [Builder.netTerms]. + * Sets [Builder.customDueDate] to an arbitrary JSON value. * - * This unboxed primitive overload exists for backwards compatibility. + * You should usually call [Builder.customDueDate] with a well-typed + * [CustomDueDate] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. */ - fun netTerms(netTerms: Long) = netTerms(netTerms as Long?) + fun customDueDate(customDueDate: JsonField) = apply { + this.customDueDate = customDueDate + } + + /** Alias for calling [customDueDate] with `CustomDueDate.ofDate(date)`. */ + fun customDueDate(date: LocalDate) = customDueDate(CustomDueDate.ofDate(date)) /** - * Sets [Builder.netTerms] to an arbitrary JSON value. - * - * You should usually call [Builder.netTerms] with a well-typed [Long] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. + * Alias for calling [customDueDate] with `CustomDueDate.ofDateTime(dateTime)`. */ - fun netTerms(netTerms: JsonField) = apply { this.netTerms = netTerms } + fun customDueDate(dateTime: OffsetDateTime) = + customDueDate(CustomDueDate.ofDateTime(dateTime)) /** * An ISO 8601 format date that denotes when this invoice should be dated in the @@ -1370,6 +2018,21 @@ private constructor( fun invoiceDate(dateTime: OffsetDateTime) = invoiceDate(InvoiceDate.ofDateTime(dateTime)) + /** + * The ID of the Item to be used for the invoice line item. If not provided, a + * default 'Credits' item will be used. + */ + fun itemId(itemId: String?) = itemId(JsonField.ofNullable(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** An optional memo to display on the invoice. */ fun memo(memo: String?) = memo(JsonField.ofNullable(memo)) @@ -1382,6 +2045,32 @@ private constructor( */ fun memo(memo: JsonField) = apply { this.memo = memo } + /** + * The net terms determines the due date of the invoice. Due date is calculated + * based on the invoice or issuance date, depending on the account's configured + * due date calculation method. A value of '0' here represents that the invoice + * is due on issue, whereas a value of '30' represents that the customer has 30 + * days to pay the invoice. Do not set this field if you want to set a custom + * due date. + */ + fun netTerms(netTerms: Long?) = netTerms(JsonField.ofNullable(netTerms)) + + /** + * Alias for [Builder.netTerms]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun netTerms(netTerms: Long) = netTerms(netTerms as Long?) + + /** + * Sets [Builder.netTerms] to an arbitrary JSON value. + * + * You should usually call [Builder.netTerms] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun netTerms(netTerms: JsonField) = apply { this.netTerms = netTerms } + /** * If true, the new credit block will require that the corresponding invoice is * paid before it can be drawn down from. @@ -1431,7 +2120,6 @@ private constructor( * The following fields are required: * ```kotlin * .autoCollection() - * .netTerms() * ``` * * @throws IllegalStateException if any required field is unset. @@ -1439,9 +2127,11 @@ private constructor( fun build(): InvoiceSettings = InvoiceSettings( checkRequired("autoCollection", autoCollection), - checkRequired("netTerms", netTerms), + customDueDate, invoiceDate, + itemId, memo, + netTerms, requireSuccessfulPayment, additionalProperties.toMutableMap(), ) @@ -1455,9 +2145,11 @@ private constructor( } autoCollection() - netTerms() + customDueDate()?.validate() invoiceDate()?.validate() + itemId() memo() + netTerms() requireSuccessfulPayment() validated = true } @@ -1478,11 +2170,192 @@ private constructor( */ internal fun validity(): Int = (if (autoCollection.asKnown() == null) 0 else 1) + - (if (netTerms.asKnown() == null) 0 else 1) + + (customDueDate.asKnown()?.validity() ?: 0) + (invoiceDate.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + (if (memo.asKnown() == null) 0 else 1) + + (if (netTerms.asKnown() == null) 0 else 1) + (if (requireSuccessfulPayment.asKnown() == null) 0 else 1) + /** + * An optional custom due date for the invoice. If not set, the due date will be + * calculated based on the `net_terms` value. + */ + @JsonDeserialize(using = CustomDueDate.Deserializer::class) + @JsonSerialize(using = CustomDueDate.Serializer::class) + class CustomDueDate + private constructor( + private val date: LocalDate? = null, + private val dateTime: OffsetDateTime? = null, + private val _json: JsonValue? = null, + ) { + + fun date(): LocalDate? = date + + fun dateTime(): OffsetDateTime? = dateTime + + fun isDate(): Boolean = date != null + + fun isDateTime(): Boolean = dateTime != null + + fun asDate(): LocalDate = date.getOrThrow("date") + + fun asDateTime(): OffsetDateTime = dateTime.getOrThrow("dateTime") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + date != null -> visitor.visitDate(date) + dateTime != null -> visitor.visitDateTime(dateTime) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): CustomDueDate = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitDate(date: LocalDate) {} + + override fun visitDateTime(dateTime: OffsetDateTime) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitDate(date: LocalDate) = 1 + + override fun visitDateTime(dateTime: OffsetDateTime) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CustomDueDate && + date == other.date && + dateTime == other.dateTime + } + + override fun hashCode(): Int = Objects.hash(date, dateTime) + + override fun toString(): String = + when { + date != null -> "CustomDueDate{date=$date}" + dateTime != null -> "CustomDueDate{dateTime=$dateTime}" + _json != null -> "CustomDueDate{_unknown=$_json}" + else -> throw IllegalStateException("Invalid CustomDueDate") + } + + companion object { + + fun ofDate(date: LocalDate) = CustomDueDate(date = date) + + fun ofDateTime(dateTime: OffsetDateTime) = + CustomDueDate(dateTime = dateTime) + } + + /** + * An interface that defines how to map each variant of [CustomDueDate] to a + * value of type [T]. + */ + interface Visitor { + + fun visitDate(date: LocalDate): T + + fun visitDateTime(dateTime: OffsetDateTime): T + + /** + * Maps an unknown variant of [CustomDueDate] to a value of type [T]. + * + * An instance of [CustomDueDate] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, + * if the SDK is on an older version than the API, then the API may respond + * with new variants that the SDK is unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown CustomDueDate: $json") + } + } + + internal class Deserializer : + BaseDeserializer(CustomDueDate::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): CustomDueDate { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + CustomDueDate(date = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { CustomDueDate(dateTime = it, _json = json) }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing + // from object). + 0 -> CustomDueDate(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then + // use the first completely valid match, or simply the first match + // if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : + BaseSerializer(CustomDueDate::class) { + + override fun serialize( + value: CustomDueDate, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.date != null -> generator.writeObject(value.date) + value.dateTime != null -> generator.writeObject(value.dateTime) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid CustomDueDate") + } + } + } + } + /** * An ISO 8601 format date that denotes when this invoice should be dated in the * customer's timezone. If not provided, the invoice date will default to the credit @@ -1565,10 +2438,12 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceDate && date == other.date && dateTime == other.dateTime /* spotless:on */ + return other is InvoiceDate && + date == other.date && + dateTime == other.dateTime } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(date, dateTime) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(date, dateTime) override fun toString(): String = when { @@ -1664,17 +2539,34 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceSettings && autoCollection == other.autoCollection && netTerms == other.netTerms && invoiceDate == other.invoiceDate && memo == other.memo && requireSuccessfulPayment == other.requireSuccessfulPayment && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InvoiceSettings && + autoCollection == other.autoCollection && + customDueDate == other.customDueDate && + invoiceDate == other.invoiceDate && + itemId == other.itemId && + memo == other.memo && + netTerms == other.netTerms && + requireSuccessfulPayment == other.requireSuccessfulPayment && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(autoCollection, netTerms, invoiceDate, memo, requireSuccessfulPayment, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + autoCollection, + customDueDate, + invoiceDate, + itemId, + memo, + netTerms, + requireSuccessfulPayment, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "InvoiceSettings{autoCollection=$autoCollection, netTerms=$netTerms, invoiceDate=$invoiceDate, memo=$memo, requireSuccessfulPayment=$requireSuccessfulPayment, additionalProperties=$additionalProperties}" + "InvoiceSettings{autoCollection=$autoCollection, customDueDate=$customDueDate, invoiceDate=$invoiceDate, itemId=$itemId, memo=$memo, netTerms=$netTerms, requireSuccessfulPayment=$requireSuccessfulPayment, additionalProperties=$additionalProperties}" } /** @@ -1774,12 +2666,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1791,20 +2681,44 @@ private constructor( return true } - return /* spotless:off */ other is Increment && amount == other.amount && entryType == other.entryType && currency == other.currency && description == other.description && effectiveDate == other.effectiveDate && expiryDate == other.expiryDate && invoiceSettings == other.invoiceSettings && metadata == other.metadata && perUnitCostBasis == other.perUnitCostBasis && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Increment && + amount == other.amount && + entryType == other.entryType && + currency == other.currency && + description == other.description && + effectiveDate == other.effectiveDate && + expiryDate == other.expiryDate && + filters == other.filters && + invoiceSettings == other.invoiceSettings && + metadata == other.metadata && + perUnitCostBasis == other.perUnitCostBasis && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, entryType, currency, description, effectiveDate, expiryDate, invoiceSettings, metadata, perUnitCostBasis, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amount, + entryType, + currency, + description, + effectiveDate, + expiryDate, + filters, + invoiceSettings, + metadata, + perUnitCostBasis, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Increment{amount=$amount, entryType=$entryType, currency=$currency, description=$description, effectiveDate=$effectiveDate, expiryDate=$expiryDate, invoiceSettings=$invoiceSettings, metadata=$metadata, perUnitCostBasis=$perUnitCostBasis, additionalProperties=$additionalProperties}" + "Increment{amount=$amount, entryType=$entryType, currency=$currency, description=$description, effectiveDate=$effectiveDate, expiryDate=$expiryDate, filters=$filters, invoiceSettings=$invoiceSettings, metadata=$metadata, perUnitCostBasis=$perUnitCostBasis, additionalProperties=$additionalProperties}" } class Decrement + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val entryType: JsonValue, @@ -2221,12 +3135,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2238,12 +3150,25 @@ private constructor( return true } - return /* spotless:off */ other is Decrement && amount == other.amount && entryType == other.entryType && currency == other.currency && description == other.description && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Decrement && + amount == other.amount && + entryType == other.entryType && + currency == other.currency && + description == other.description && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, entryType, currency, description, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amount, + entryType, + currency, + description, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2252,6 +3177,7 @@ private constructor( } class ExpirationChange + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val entryType: JsonValue, private val targetExpiryDate: JsonField, @@ -2816,12 +3742,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2833,12 +3757,31 @@ private constructor( return true } - return /* spotless:off */ other is ExpirationChange && entryType == other.entryType && targetExpiryDate == other.targetExpiryDate && amount == other.amount && blockId == other.blockId && currency == other.currency && description == other.description && expiryDate == other.expiryDate && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ExpirationChange && + entryType == other.entryType && + targetExpiryDate == other.targetExpiryDate && + amount == other.amount && + blockId == other.blockId && + currency == other.currency && + description == other.description && + expiryDate == other.expiryDate && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(entryType, targetExpiryDate, amount, blockId, currency, description, expiryDate, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + entryType, + targetExpiryDate, + amount, + blockId, + currency, + description, + expiryDate, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2847,6 +3790,7 @@ private constructor( } class Void + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val blockId: JsonField, @@ -3353,12 +4297,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3482,7 +4424,7 @@ private constructor( return true } - return /* spotless:off */ other is VoidReason && value == other.value /* spotless:on */ + return other is VoidReason && value == other.value } override fun hashCode() = value.hashCode() @@ -3495,12 +4437,29 @@ private constructor( return true } - return /* spotless:off */ other is Void && amount == other.amount && blockId == other.blockId && entryType == other.entryType && currency == other.currency && description == other.description && metadata == other.metadata && voidReason == other.voidReason && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Void && + amount == other.amount && + blockId == other.blockId && + entryType == other.entryType && + currency == other.currency && + description == other.description && + metadata == other.metadata && + voidReason == other.voidReason && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, blockId, entryType, currency, description, metadata, voidReason, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amount, + blockId, + entryType, + currency, + description, + metadata, + voidReason, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -3509,6 +4468,7 @@ private constructor( } class Amendment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val blockId: JsonField, @@ -3964,12 +4924,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3981,12 +4939,27 @@ private constructor( return true } - return /* spotless:off */ other is Amendment && amount == other.amount && blockId == other.blockId && entryType == other.entryType && currency == other.currency && description == other.description && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Amendment && + amount == other.amount && + blockId == other.blockId && + entryType == other.entryType && + currency == other.currency && + description == other.description && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, blockId, entryType, currency, description, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amount, + blockId, + entryType, + currency, + description, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -4000,10 +4973,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerCreateEntryParams && customerId == other.customerId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerCreditLedgerCreateEntryParams && + customerId == other.customerId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(customerId, body, additionalHeaders, additionalQueryParams) override fun toString() = "CustomerCreditLedgerCreateEntryParams{customerId=$customerId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryResponse.kt index 3be0c9ae4..a7f4523af 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryResponse.kt @@ -178,10 +178,26 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerCreateEntryResponse && increment == other.increment && decrement == other.decrement && expirationChange == other.expirationChange && creditBlockExpiry == other.creditBlockExpiry && void == other.void && voidInitiated == other.voidInitiated && amendment == other.amendment /* spotless:on */ + return other is CustomerCreditLedgerCreateEntryResponse && + increment == other.increment && + decrement == other.decrement && + expirationChange == other.expirationChange && + creditBlockExpiry == other.creditBlockExpiry && + void == other.void && + voidInitiated == other.voidInitiated && + amendment == other.amendment } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(increment, decrement, expirationChange, creditBlockExpiry, void, voidInitiated, amendment) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + increment, + decrement, + expirationChange, + creditBlockExpiry, + void, + voidInitiated, + amendment, + ) override fun toString(): String = when { diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPage.kt index 2d92b28e5..1e9f4a442 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPage.kt @@ -130,10 +130,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerListByExternalIdPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerCreditLedgerListByExternalIdPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerCreditLedgerListByExternalIdPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageAsync.kt index 0d01458ba..d2cd4e7a0 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageAsync.kt @@ -132,10 +132,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerListByExternalIdPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerCreditLedgerListByExternalIdPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerCreditLedgerListByExternalIdPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponse.kt index a248895d3..97914623d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CustomerCreditLedgerListByExternalIdPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -278,12 +279,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerListByExternalIdPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCreditLedgerListByExternalIdPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdParams.kt index a4ac857d0..cde28d925 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdParams.kt @@ -24,14 +24,12 @@ import java.util.Objects * There are four major types of modifications to credit balance, detailed below. * * ## Increment - * * Credits (which optionally expire on a future date) can be added via the API ([Add Ledger * Entry](create-ledger-entry)). The ledger entry for such an action will always contain the total * eligible starting and ending balance for the customer at the time the entry was added to the * ledger. * * ## Decrement - * * Deductions can occur as a result of an API call to create a ledger entry (see * [Add Ledger Entry](create-ledger-entry)), or automatically as a result of incurring usage. Both * ledger entries present the `decrement` entry type. @@ -43,13 +41,13 @@ import java.util.Objects * ingestion, used to pinpoint _why_ credit deduction took place and to ensure that credits are * never deducted without an associated usage event. * - * By default, Orb uses an algorithm that automatically deducts from the _soonest expiring credit - * block_ first in order to ensure that all credits are utilized appropriately. As an example, if + * By default, Orb uses an algorithm that automatically deducts from the *soonest expiring credit + * block* first in order to ensure that all credits are utilized appropriately. As an example, if * trial credits with an expiration date of 2 weeks from now are present for a customer, they will * be used before any deductions take place from a non-expiring credit block. * * If there are multiple blocks with the same expiration date, Orb will deduct from the block with - * the _lower cost basis_ first (e.g. trial credits with a \$0 cost basis before paid credits with a + * the *lower cost basis* first (e.g. trial credits with a \$0 cost basis before paid credits with a * \$5.00 cost basis). * * It's also possible for a single usage event's deduction to _span_ credit blocks. In this case, @@ -59,34 +57,29 @@ import java.util.Objects * a result of a decrement. * * ## Expiration change - * * The expiry of credits can be changed as a result of the API (See * [Add Ledger Entry](create-ledger-entry)). This will create a ledger entry that specifies the * balance as well as the initial and target expiry dates. * * Note that for this entry type, `starting_balance` will equal `ending_balance`, and the `amount` * represents the balance transferred. The credit block linked to the ledger entry is the source - * credit block from which there was an expiration change + * credit block from which there was an expiration change. * * ## Credits expiry - * * When a set of credits expire on pre-set expiration date, the customer's balance automatically * reflects this change and adds an entry to the ledger indicating this event. Note that credit * expiry should always happen close to a date boundary in the customer's timezone. * * ## Void initiated - * * Credit blocks can be voided via the API. The `amount` on this entry corresponds to the number of * credits that were remaining in the block at time of void. `void_reason` will be populated if the * void is created with a reason. * * ## Void - * * When a set of credits is voided, the customer's balance automatically reflects this change and * adds an entry to the ledger indicating this event. * * ## Amendment - * * When credits are added to a customer's balance as a result of a correction, this entry will be * added to the ledger to indicate the adjustment of credits. */ @@ -501,7 +494,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryStatus && value == other.value /* spotless:on */ + return other is EntryStatus && value == other.value } override fun hashCode() = value.hashCode() @@ -657,7 +650,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryType && value == other.value /* spotless:on */ + return other is EntryType && value == other.value } override fun hashCode() = value.hashCode() @@ -670,10 +663,38 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerListByExternalIdParams && externalCustomerId == other.externalCustomerId && createdAtGt == other.createdAtGt && createdAtGte == other.createdAtGte && createdAtLt == other.createdAtLt && createdAtLte == other.createdAtLte && currency == other.currency && cursor == other.cursor && entryStatus == other.entryStatus && entryType == other.entryType && limit == other.limit && minimumAmount == other.minimumAmount && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerCreditLedgerListByExternalIdParams && + externalCustomerId == other.externalCustomerId && + createdAtGt == other.createdAtGt && + createdAtGte == other.createdAtGte && + createdAtLt == other.createdAtLt && + createdAtLte == other.createdAtLte && + currency == other.currency && + cursor == other.cursor && + entryStatus == other.entryStatus && + entryType == other.entryType && + limit == other.limit && + minimumAmount == other.minimumAmount && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalCustomerId, createdAtGt, createdAtGte, createdAtLt, createdAtLte, currency, cursor, entryStatus, entryType, limit, minimumAmount, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + externalCustomerId, + createdAtGt, + createdAtGte, + createdAtLt, + createdAtLte, + currency, + cursor, + entryStatus, + entryType, + limit, + minimumAmount, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "CustomerCreditLedgerListByExternalIdParams{externalCustomerId=$externalCustomerId, createdAtGt=$createdAtGt, createdAtGte=$createdAtGte, createdAtLt=$createdAtLt, createdAtLte=$createdAtLte, currency=$currency, cursor=$cursor, entryStatus=$entryStatus, entryType=$entryType, limit=$limit, minimumAmount=$minimumAmount, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdResponse.kt index cf48ff33d..21d3a3eba 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdResponse.kt @@ -178,10 +178,26 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerListByExternalIdResponse && increment == other.increment && decrement == other.decrement && expirationChange == other.expirationChange && creditBlockExpiry == other.creditBlockExpiry && void == other.void && voidInitiated == other.voidInitiated && amendment == other.amendment /* spotless:on */ + return other is CustomerCreditLedgerListByExternalIdResponse && + increment == other.increment && + decrement == other.decrement && + expirationChange == other.expirationChange && + creditBlockExpiry == other.creditBlockExpiry && + void == other.void && + voidInitiated == other.voidInitiated && + amendment == other.amendment } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(increment, decrement, expirationChange, creditBlockExpiry, void, voidInitiated, amendment) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + increment, + decrement, + expirationChange, + creditBlockExpiry, + void, + voidInitiated, + amendment, + ) override fun toString(): String = when { diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPage.kt index c7aa09d43..fd056d355 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPage.kt @@ -122,10 +122,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerCreditLedgerListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerCreditLedgerListPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageAsync.kt index 1011f5706..3ba390fc5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageAsync.kt @@ -125,10 +125,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerCreditLedgerListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerCreditLedgerListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponse.kt index 30af421fe..8c1f2daa3 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CustomerCreditLedgerListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -267,12 +268,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCreditLedgerListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListParams.kt index 89edeba4c..fdb2c0b13 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListParams.kt @@ -24,14 +24,12 @@ import java.util.Objects * There are four major types of modifications to credit balance, detailed below. * * ## Increment - * * Credits (which optionally expire on a future date) can be added via the API ([Add Ledger * Entry](create-ledger-entry)). The ledger entry for such an action will always contain the total * eligible starting and ending balance for the customer at the time the entry was added to the * ledger. * * ## Decrement - * * Deductions can occur as a result of an API call to create a ledger entry (see * [Add Ledger Entry](create-ledger-entry)), or automatically as a result of incurring usage. Both * ledger entries present the `decrement` entry type. @@ -43,13 +41,13 @@ import java.util.Objects * ingestion, used to pinpoint _why_ credit deduction took place and to ensure that credits are * never deducted without an associated usage event. * - * By default, Orb uses an algorithm that automatically deducts from the _soonest expiring credit - * block_ first in order to ensure that all credits are utilized appropriately. As an example, if + * By default, Orb uses an algorithm that automatically deducts from the *soonest expiring credit + * block* first in order to ensure that all credits are utilized appropriately. As an example, if * trial credits with an expiration date of 2 weeks from now are present for a customer, they will * be used before any deductions take place from a non-expiring credit block. * * If there are multiple blocks with the same expiration date, Orb will deduct from the block with - * the _lower cost basis_ first (e.g. trial credits with a \$0 cost basis before paid credits with a + * the *lower cost basis* first (e.g. trial credits with a \$0 cost basis before paid credits with a * \$5.00 cost basis). * * It's also possible for a single usage event's deduction to _span_ credit blocks. In this case, @@ -59,34 +57,29 @@ import java.util.Objects * a result of a decrement. * * ## Expiration change - * * The expiry of credits can be changed as a result of the API (See * [Add Ledger Entry](create-ledger-entry)). This will create a ledger entry that specifies the * balance as well as the initial and target expiry dates. * * Note that for this entry type, `starting_balance` will equal `ending_balance`, and the `amount` * represents the balance transferred. The credit block linked to the ledger entry is the source - * credit block from which there was an expiration change + * credit block from which there was an expiration change. * * ## Credits expiry - * * When a set of credits expire on pre-set expiration date, the customer's balance automatically * reflects this change and adds an entry to the ledger indicating this event. Note that credit * expiry should always happen close to a date boundary in the customer's timezone. * * ## Void initiated - * * Credit blocks can be voided via the API. The `amount` on this entry corresponds to the number of * credits that were remaining in the block at time of void. `void_reason` will be populated if the * void is created with a reason. * * ## Void - * * When a set of credits is voided, the customer's balance automatically reflects this change and * adds an entry to the ledger indicating this event. * * ## Amendment - * * When credits are added to a customer's balance as a result of a correction, this entry will be * added to the ledger to indicate the adjustment of credits. */ @@ -495,7 +488,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryStatus && value == other.value /* spotless:on */ + return other is EntryStatus && value == other.value } override fun hashCode() = value.hashCode() @@ -651,7 +644,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryType && value == other.value /* spotless:on */ + return other is EntryType && value == other.value } override fun hashCode() = value.hashCode() @@ -664,10 +657,38 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerListParams && customerId == other.customerId && createdAtGt == other.createdAtGt && createdAtGte == other.createdAtGte && createdAtLt == other.createdAtLt && createdAtLte == other.createdAtLte && currency == other.currency && cursor == other.cursor && entryStatus == other.entryStatus && entryType == other.entryType && limit == other.limit && minimumAmount == other.minimumAmount && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerCreditLedgerListParams && + customerId == other.customerId && + createdAtGt == other.createdAtGt && + createdAtGte == other.createdAtGte && + createdAtLt == other.createdAtLt && + createdAtLte == other.createdAtLte && + currency == other.currency && + cursor == other.cursor && + entryStatus == other.entryStatus && + entryType == other.entryType && + limit == other.limit && + minimumAmount == other.minimumAmount && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, createdAtGt, createdAtGte, createdAtLt, createdAtLte, currency, cursor, entryStatus, entryType, limit, minimumAmount, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + customerId, + createdAtGt, + createdAtGte, + createdAtLt, + createdAtLte, + currency, + cursor, + entryStatus, + entryType, + limit, + minimumAmount, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "CustomerCreditLedgerListParams{customerId=$customerId, createdAtGt=$createdAtGt, createdAtGte=$createdAtGte, createdAtLt=$createdAtLt, createdAtLte=$createdAtLte, currency=$currency, cursor=$cursor, entryStatus=$entryStatus, entryType=$entryType, limit=$limit, minimumAmount=$minimumAmount, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListResponse.kt index 324a61d6f..1312dde4d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListResponse.kt @@ -178,10 +178,26 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditLedgerListResponse && increment == other.increment && decrement == other.decrement && expirationChange == other.expirationChange && creditBlockExpiry == other.creditBlockExpiry && void == other.void && voidInitiated == other.voidInitiated && amendment == other.amendment /* spotless:on */ + return other is CustomerCreditLedgerListResponse && + increment == other.increment && + decrement == other.decrement && + expirationChange == other.expirationChange && + creditBlockExpiry == other.creditBlockExpiry && + void == other.void && + voidInitiated == other.voidInitiated && + amendment == other.amendment } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(increment, decrement, expirationChange, creditBlockExpiry, void, voidInitiated, amendment) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + increment, + decrement, + expirationChange, + creditBlockExpiry, + void, + voidInitiated, + amendment, + ) override fun toString(): String = when { diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPage.kt index ebaa10011..aa2f0bc9b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPage.kt @@ -127,10 +127,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditListByExternalIdPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerCreditListByExternalIdPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerCreditListByExternalIdPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageAsync.kt index dc8e1ff83..9f7acb88d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageAsync.kt @@ -129,10 +129,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditListByExternalIdPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerCreditListByExternalIdPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerCreditListByExternalIdPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponse.kt index f13939a8c..2da2b405a 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CustomerCreditListByExternalIdPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -222,12 +223,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditListByExternalIdPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCreditListByExternalIdPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdParams.kt index 2dc457a3f..eef95cfd7 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdParams.kt @@ -267,10 +267,26 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditListByExternalIdParams && externalCustomerId == other.externalCustomerId && currency == other.currency && cursor == other.cursor && includeAllBlocks == other.includeAllBlocks && limit == other.limit && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerCreditListByExternalIdParams && + externalCustomerId == other.externalCustomerId && + currency == other.currency && + cursor == other.cursor && + includeAllBlocks == other.includeAllBlocks && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalCustomerId, currency, cursor, includeAllBlocks, limit, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + externalCustomerId, + currency, + cursor, + includeAllBlocks, + limit, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "CustomerCreditListByExternalIdParams{externalCustomerId=$externalCustomerId, currency=$currency, cursor=$cursor, includeAllBlocks=$includeAllBlocks, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdResponse.kt index 01ae4cb75..0ff7dc002 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdResponse.kt @@ -11,18 +11,22 @@ import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.time.OffsetDateTime import java.util.Collections import java.util.Objects class CustomerCreditListByExternalIdResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val balance: JsonField, private val effectiveDate: JsonField, private val expiryDate: JsonField, + private val filters: JsonField>, private val maximumInitialBalance: JsonField, private val perUnitCostBasis: JsonField, private val status: JsonField, @@ -39,6 +43,9 @@ private constructor( @JsonProperty("expiry_date") @ExcludeMissing expiryDate: JsonField = JsonMissing.of(), + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), @JsonProperty("maximum_initial_balance") @ExcludeMissing maximumInitialBalance: JsonField = JsonMissing.of(), @@ -51,6 +58,7 @@ private constructor( balance, effectiveDate, expiryDate, + filters, maximumInitialBalance, perUnitCostBasis, status, @@ -81,6 +89,12 @@ private constructor( */ fun expiryDate(): OffsetDateTime? = expiryDate.getNullable("expiry_date") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -132,6 +146,13 @@ private constructor( @ExcludeMissing fun _expiryDate(): JsonField = expiryDate + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters + /** * Returns the raw JSON value of [maximumInitialBalance]. * @@ -183,6 +204,7 @@ private constructor( * .balance() * .effectiveDate() * .expiryDate() + * .filters() * .maximumInitialBalance() * .perUnitCostBasis() * .status() @@ -198,6 +220,7 @@ private constructor( private var balance: JsonField? = null private var effectiveDate: JsonField? = null private var expiryDate: JsonField? = null + private var filters: JsonField>? = null private var maximumInitialBalance: JsonField? = null private var perUnitCostBasis: JsonField? = null private var status: JsonField? = null @@ -210,6 +233,7 @@ private constructor( balance = customerCreditListByExternalIdResponse.balance effectiveDate = customerCreditListByExternalIdResponse.effectiveDate expiryDate = customerCreditListByExternalIdResponse.expiryDate + filters = customerCreditListByExternalIdResponse.filters.map { it.toMutableList() } maximumInitialBalance = customerCreditListByExternalIdResponse.maximumInitialBalance perUnitCostBasis = customerCreditListByExternalIdResponse.perUnitCostBasis status = customerCreditListByExternalIdResponse.status @@ -264,6 +288,31 @@ private constructor( this.expiryDate = expiryDate } + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + fun maximumInitialBalance(maximumInitialBalance: Double?) = maximumInitialBalance(JsonField.ofNullable(maximumInitialBalance)) @@ -340,6 +389,7 @@ private constructor( * .balance() * .effectiveDate() * .expiryDate() + * .filters() * .maximumInitialBalance() * .perUnitCostBasis() * .status() @@ -353,6 +403,7 @@ private constructor( checkRequired("balance", balance), checkRequired("effectiveDate", effectiveDate), checkRequired("expiryDate", expiryDate), + checkRequired("filters", filters).map { it.toImmutable() }, checkRequired("maximumInitialBalance", maximumInitialBalance), checkRequired("perUnitCostBasis", perUnitCostBasis), checkRequired("status", status), @@ -371,6 +422,7 @@ private constructor( balance() effectiveDate() expiryDate() + filters().forEach { it.validate() } maximumInitialBalance() perUnitCostBasis() status().validate() @@ -395,10 +447,516 @@ private constructor( (if (balance.asKnown() == null) 0 else 1) + (if (effectiveDate.asKnown() == null) 0 else 1) + (if (expiryDate.asKnown() == null) 0 else 1) + + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (maximumInitialBalance.asKnown() == null) 0 else 1) + (if (perUnitCostBasis.asKnown() == null) 0 else 1) + (status.asKnown()?.validity() ?: 0) + /** A PriceFilter that only allows item_id field for block filters. */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price the block applies to. Only item_id is supported. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price the block applies to. Only item_id is supported. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price the block applies to. Only item_id is supported. */ + class Field @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 { + + val ITEM_ID = of("item_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + ITEM_ID + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + ITEM_ID, + /** + * An enum member indicating that [Field] 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) { + ITEM_ID -> Value.ITEM_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ITEM_ID -> Known.ITEM_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + class Status @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -515,7 +1073,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -528,15 +1086,34 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditListByExternalIdResponse && id == other.id && balance == other.balance && effectiveDate == other.effectiveDate && expiryDate == other.expiryDate && maximumInitialBalance == other.maximumInitialBalance && perUnitCostBasis == other.perUnitCostBasis && status == other.status && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCreditListByExternalIdResponse && + id == other.id && + balance == other.balance && + effectiveDate == other.effectiveDate && + expiryDate == other.expiryDate && + filters == other.filters && + maximumInitialBalance == other.maximumInitialBalance && + perUnitCostBasis == other.perUnitCostBasis && + status == other.status && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, balance, effectiveDate, expiryDate, maximumInitialBalance, perUnitCostBasis, status, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + balance, + effectiveDate, + expiryDate, + filters, + maximumInitialBalance, + perUnitCostBasis, + status, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "CustomerCreditListByExternalIdResponse{id=$id, balance=$balance, effectiveDate=$effectiveDate, expiryDate=$expiryDate, maximumInitialBalance=$maximumInitialBalance, perUnitCostBasis=$perUnitCostBasis, status=$status, additionalProperties=$additionalProperties}" + "CustomerCreditListByExternalIdResponse{id=$id, balance=$balance, effectiveDate=$effectiveDate, expiryDate=$expiryDate, filters=$filters, maximumInitialBalance=$maximumInitialBalance, perUnitCostBasis=$perUnitCostBasis, status=$status, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPage.kt index e032eaead..55e947864 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPage.kt @@ -120,10 +120,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerCreditListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerCreditListPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageAsync.kt index 8ac48dd15..32f6b48bc 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageAsync.kt @@ -120,10 +120,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerCreditListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerCreditListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageResponse.kt index 5271b0e11..1c8bf0023 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CustomerCreditListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -220,12 +221,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCreditListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListParams.kt index 32af494c1..0920dd6f5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListParams.kt @@ -259,10 +259,26 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditListParams && customerId == other.customerId && currency == other.currency && cursor == other.cursor && includeAllBlocks == other.includeAllBlocks && limit == other.limit && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerCreditListParams && + customerId == other.customerId && + currency == other.currency && + cursor == other.cursor && + includeAllBlocks == other.includeAllBlocks && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, currency, cursor, includeAllBlocks, limit, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + customerId, + currency, + cursor, + includeAllBlocks, + limit, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "CustomerCreditListParams{customerId=$customerId, currency=$currency, cursor=$cursor, includeAllBlocks=$includeAllBlocks, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListResponse.kt index 3cd166182..3f0ddaa3b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListResponse.kt @@ -11,18 +11,22 @@ import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.time.OffsetDateTime import java.util.Collections import java.util.Objects class CustomerCreditListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val balance: JsonField, private val effectiveDate: JsonField, private val expiryDate: JsonField, + private val filters: JsonField>, private val maximumInitialBalance: JsonField, private val perUnitCostBasis: JsonField, private val status: JsonField, @@ -39,6 +43,9 @@ private constructor( @JsonProperty("expiry_date") @ExcludeMissing expiryDate: JsonField = JsonMissing.of(), + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), @JsonProperty("maximum_initial_balance") @ExcludeMissing maximumInitialBalance: JsonField = JsonMissing.of(), @@ -51,6 +58,7 @@ private constructor( balance, effectiveDate, expiryDate, + filters, maximumInitialBalance, perUnitCostBasis, status, @@ -81,6 +89,12 @@ private constructor( */ fun expiryDate(): OffsetDateTime? = expiryDate.getNullable("expiry_date") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -132,6 +146,13 @@ private constructor( @ExcludeMissing fun _expiryDate(): JsonField = expiryDate + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters + /** * Returns the raw JSON value of [maximumInitialBalance]. * @@ -182,6 +203,7 @@ private constructor( * .balance() * .effectiveDate() * .expiryDate() + * .filters() * .maximumInitialBalance() * .perUnitCostBasis() * .status() @@ -197,6 +219,7 @@ private constructor( private var balance: JsonField? = null private var effectiveDate: JsonField? = null private var expiryDate: JsonField? = null + private var filters: JsonField>? = null private var maximumInitialBalance: JsonField? = null private var perUnitCostBasis: JsonField? = null private var status: JsonField? = null @@ -207,6 +230,7 @@ private constructor( balance = customerCreditListResponse.balance effectiveDate = customerCreditListResponse.effectiveDate expiryDate = customerCreditListResponse.expiryDate + filters = customerCreditListResponse.filters.map { it.toMutableList() } maximumInitialBalance = customerCreditListResponse.maximumInitialBalance perUnitCostBasis = customerCreditListResponse.perUnitCostBasis status = customerCreditListResponse.status @@ -260,6 +284,31 @@ private constructor( this.expiryDate = expiryDate } + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + fun maximumInitialBalance(maximumInitialBalance: Double?) = maximumInitialBalance(JsonField.ofNullable(maximumInitialBalance)) @@ -336,6 +385,7 @@ private constructor( * .balance() * .effectiveDate() * .expiryDate() + * .filters() * .maximumInitialBalance() * .perUnitCostBasis() * .status() @@ -349,6 +399,7 @@ private constructor( checkRequired("balance", balance), checkRequired("effectiveDate", effectiveDate), checkRequired("expiryDate", expiryDate), + checkRequired("filters", filters).map { it.toImmutable() }, checkRequired("maximumInitialBalance", maximumInitialBalance), checkRequired("perUnitCostBasis", perUnitCostBasis), checkRequired("status", status), @@ -367,6 +418,7 @@ private constructor( balance() effectiveDate() expiryDate() + filters().forEach { it.validate() } maximumInitialBalance() perUnitCostBasis() status().validate() @@ -391,10 +443,516 @@ private constructor( (if (balance.asKnown() == null) 0 else 1) + (if (effectiveDate.asKnown() == null) 0 else 1) + (if (expiryDate.asKnown() == null) 0 else 1) + + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (maximumInitialBalance.asKnown() == null) 0 else 1) + (if (perUnitCostBasis.asKnown() == null) 0 else 1) + (status.asKnown()?.validity() ?: 0) + /** A PriceFilter that only allows item_id field for block filters. */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price the block applies to. Only item_id is supported. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price the block applies to. Only item_id is supported. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price the block applies to. Only item_id is supported. */ + class Field @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 { + + val ITEM_ID = of("item_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + ITEM_ID + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + ITEM_ID, + /** + * An enum member indicating that [Field] 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) { + ITEM_ID -> Value.ITEM_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ITEM_ID -> Known.ITEM_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + class Status @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -511,7 +1069,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -524,15 +1082,34 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditListResponse && id == other.id && balance == other.balance && effectiveDate == other.effectiveDate && expiryDate == other.expiryDate && maximumInitialBalance == other.maximumInitialBalance && perUnitCostBasis == other.perUnitCostBasis && status == other.status && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCreditListResponse && + id == other.id && + balance == other.balance && + effectiveDate == other.effectiveDate && + expiryDate == other.expiryDate && + filters == other.filters && + maximumInitialBalance == other.maximumInitialBalance && + perUnitCostBasis == other.perUnitCostBasis && + status == other.status && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, balance, effectiveDate, expiryDate, maximumInitialBalance, perUnitCostBasis, status, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + balance, + effectiveDate, + expiryDate, + filters, + maximumInitialBalance, + perUnitCostBasis, + status, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "CustomerCreditListResponse{id=$id, balance=$balance, effectiveDate=$effectiveDate, expiryDate=$expiryDate, maximumInitialBalance=$maximumInitialBalance, perUnitCostBasis=$perUnitCostBasis, status=$status, additionalProperties=$additionalProperties}" + "CustomerCreditListResponse{id=$id, balance=$balance, effectiveDate=$effectiveDate, expiryDate=$expiryDate, filters=$filters, maximumInitialBalance=$maximumInitialBalance, perUnitCostBasis=$perUnitCostBasis, status=$status, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateByExternalIdParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateByExternalIdParams.kt index 1d7a68302..cd3048b14 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateByExternalIdParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateByExternalIdParams.kt @@ -511,6 +511,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val currency: JsonField, @@ -977,12 +978,31 @@ private constructor( return true } - return /* spotless:off */ other is Body && amount == other.amount && currency == other.currency && invoiceSettings == other.invoiceSettings && perUnitCostBasis == other.perUnitCostBasis && threshold == other.threshold && activeFrom == other.activeFrom && expiresAfter == other.expiresAfter && expiresAfterUnit == other.expiresAfterUnit && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + amount == other.amount && + currency == other.currency && + invoiceSettings == other.invoiceSettings && + perUnitCostBasis == other.perUnitCostBasis && + threshold == other.threshold && + activeFrom == other.activeFrom && + expiresAfter == other.expiresAfter && + expiresAfterUnit == other.expiresAfterUnit && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, currency, invoiceSettings, perUnitCostBasis, threshold, activeFrom, expiresAfter, expiresAfterUnit, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amount, + currency, + invoiceSettings, + perUnitCostBasis, + threshold, + activeFrom, + expiresAfter, + expiresAfterUnit, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -992,6 +1012,7 @@ private constructor( /** Settings for invoices generated by triggered top-ups. */ class InvoiceSettings + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val autoCollection: JsonField, private val netTerms: JsonField, @@ -1272,12 +1293,23 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceSettings && autoCollection == other.autoCollection && netTerms == other.netTerms && memo == other.memo && requireSuccessfulPayment == other.requireSuccessfulPayment && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InvoiceSettings && + autoCollection == other.autoCollection && + netTerms == other.netTerms && + memo == other.memo && + requireSuccessfulPayment == other.requireSuccessfulPayment && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(autoCollection, netTerms, memo, requireSuccessfulPayment, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + autoCollection, + netTerms, + memo, + requireSuccessfulPayment, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1406,7 +1438,7 @@ private constructor( return true } - return /* spotless:off */ other is ExpiresAfterUnit && value == other.value /* spotless:on */ + return other is ExpiresAfterUnit && value == other.value } override fun hashCode() = value.hashCode() @@ -1419,10 +1451,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpCreateByExternalIdParams && externalCustomerId == other.externalCustomerId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerCreditTopUpCreateByExternalIdParams && + externalCustomerId == other.externalCustomerId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalCustomerId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(externalCustomerId, body, additionalHeaders, additionalQueryParams) override fun toString() = "CustomerCreditTopUpCreateByExternalIdParams{externalCustomerId=$externalCustomerId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateByExternalIdResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateByExternalIdResponse.kt index 9ef08c81f..8859a6e07 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateByExternalIdResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateByExternalIdResponse.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class CustomerCreditTopUpCreateByExternalIdResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, @@ -579,7 +580,7 @@ private constructor( return true } - return /* spotless:off */ other is ExpiresAfterUnit && value == other.value /* spotless:on */ + return other is ExpiresAfterUnit && value == other.value } override fun hashCode() = value.hashCode() @@ -592,12 +593,31 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpCreateByExternalIdResponse && id == other.id && amount == other.amount && currency == other.currency && invoiceSettings == other.invoiceSettings && perUnitCostBasis == other.perUnitCostBasis && threshold == other.threshold && expiresAfter == other.expiresAfter && expiresAfterUnit == other.expiresAfterUnit && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCreditTopUpCreateByExternalIdResponse && + id == other.id && + amount == other.amount && + currency == other.currency && + invoiceSettings == other.invoiceSettings && + perUnitCostBasis == other.perUnitCostBasis && + threshold == other.threshold && + expiresAfter == other.expiresAfter && + expiresAfterUnit == other.expiresAfterUnit && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, currency, invoiceSettings, perUnitCostBasis, threshold, expiresAfter, expiresAfterUnit, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + currency, + invoiceSettings, + perUnitCostBasis, + threshold, + expiresAfter, + expiresAfterUnit, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateParams.kt index 511102afe..c01272718 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateParams.kt @@ -507,6 +507,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val currency: JsonField, @@ -973,12 +974,31 @@ private constructor( return true } - return /* spotless:off */ other is Body && amount == other.amount && currency == other.currency && invoiceSettings == other.invoiceSettings && perUnitCostBasis == other.perUnitCostBasis && threshold == other.threshold && activeFrom == other.activeFrom && expiresAfter == other.expiresAfter && expiresAfterUnit == other.expiresAfterUnit && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + amount == other.amount && + currency == other.currency && + invoiceSettings == other.invoiceSettings && + perUnitCostBasis == other.perUnitCostBasis && + threshold == other.threshold && + activeFrom == other.activeFrom && + expiresAfter == other.expiresAfter && + expiresAfterUnit == other.expiresAfterUnit && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, currency, invoiceSettings, perUnitCostBasis, threshold, activeFrom, expiresAfter, expiresAfterUnit, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amount, + currency, + invoiceSettings, + perUnitCostBasis, + threshold, + activeFrom, + expiresAfter, + expiresAfterUnit, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -988,6 +1008,7 @@ private constructor( /** Settings for invoices generated by triggered top-ups. */ class InvoiceSettings + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val autoCollection: JsonField, private val netTerms: JsonField, @@ -1268,12 +1289,23 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceSettings && autoCollection == other.autoCollection && netTerms == other.netTerms && memo == other.memo && requireSuccessfulPayment == other.requireSuccessfulPayment && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InvoiceSettings && + autoCollection == other.autoCollection && + netTerms == other.netTerms && + memo == other.memo && + requireSuccessfulPayment == other.requireSuccessfulPayment && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(autoCollection, netTerms, memo, requireSuccessfulPayment, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + autoCollection, + netTerms, + memo, + requireSuccessfulPayment, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1402,7 +1434,7 @@ private constructor( return true } - return /* spotless:off */ other is ExpiresAfterUnit && value == other.value /* spotless:on */ + return other is ExpiresAfterUnit && value == other.value } override fun hashCode() = value.hashCode() @@ -1415,10 +1447,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpCreateParams && customerId == other.customerId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerCreditTopUpCreateParams && + customerId == other.customerId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(customerId, body, additionalHeaders, additionalQueryParams) override fun toString() = "CustomerCreditTopUpCreateParams{customerId=$customerId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateResponse.kt index ad517a80a..51e385def 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpCreateResponse.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class CustomerCreditTopUpCreateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, @@ -577,7 +578,7 @@ private constructor( return true } - return /* spotless:off */ other is ExpiresAfterUnit && value == other.value /* spotless:on */ + return other is ExpiresAfterUnit && value == other.value } override fun hashCode() = value.hashCode() @@ -590,12 +591,31 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpCreateResponse && id == other.id && amount == other.amount && currency == other.currency && invoiceSettings == other.invoiceSettings && perUnitCostBasis == other.perUnitCostBasis && threshold == other.threshold && expiresAfter == other.expiresAfter && expiresAfterUnit == other.expiresAfterUnit && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCreditTopUpCreateResponse && + id == other.id && + amount == other.amount && + currency == other.currency && + invoiceSettings == other.invoiceSettings && + perUnitCostBasis == other.perUnitCostBasis && + threshold == other.threshold && + expiresAfter == other.expiresAfter && + expiresAfterUnit == other.expiresAfterUnit && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, currency, invoiceSettings, perUnitCostBasis, threshold, expiresAfter, expiresAfterUnit, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + currency, + invoiceSettings, + perUnitCostBasis, + threshold, + expiresAfter, + expiresAfterUnit, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpDeleteByExternalIdParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpDeleteByExternalIdParams.kt index 3e1522016..ae27c66c7 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpDeleteByExternalIdParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpDeleteByExternalIdParams.kt @@ -240,10 +240,22 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpDeleteByExternalIdParams && externalCustomerId == other.externalCustomerId && topUpId == other.topUpId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is CustomerCreditTopUpDeleteByExternalIdParams && + externalCustomerId == other.externalCustomerId && + topUpId == other.topUpId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalCustomerId, topUpId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + externalCustomerId, + topUpId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) override fun toString() = "CustomerCreditTopUpDeleteByExternalIdParams{externalCustomerId=$externalCustomerId, topUpId=$topUpId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpDeleteParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpDeleteParams.kt index 28ad8d205..63196684b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpDeleteParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpDeleteParams.kt @@ -236,10 +236,22 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpDeleteParams && customerId == other.customerId && topUpId == other.topUpId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is CustomerCreditTopUpDeleteParams && + customerId == other.customerId && + topUpId == other.topUpId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, topUpId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + customerId, + topUpId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) override fun toString() = "CustomerCreditTopUpDeleteParams{customerId=$customerId, topUpId=$topUpId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPage.kt index d489a15aa..194e98bf7 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPage.kt @@ -130,10 +130,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpListByExternalIdPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerCreditTopUpListByExternalIdPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerCreditTopUpListByExternalIdPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageAsync.kt index 283a6192e..8d6ba039b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageAsync.kt @@ -132,10 +132,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpListByExternalIdPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerCreditTopUpListByExternalIdPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerCreditTopUpListByExternalIdPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageResponse.kt index ef7def9e6..2ddf634ad 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CustomerCreditTopUpListByExternalIdPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -224,12 +225,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpListByExternalIdPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCreditTopUpListByExternalIdPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdParams.kt index 91ece0dc1..87e7b7aaa 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdParams.kt @@ -223,10 +223,16 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpListByExternalIdParams && externalCustomerId == other.externalCustomerId && cursor == other.cursor && limit == other.limit && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerCreditTopUpListByExternalIdParams && + externalCustomerId == other.externalCustomerId && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalCustomerId, cursor, limit, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(externalCustomerId, cursor, limit, additionalHeaders, additionalQueryParams) override fun toString() = "CustomerCreditTopUpListByExternalIdParams{externalCustomerId=$externalCustomerId, cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdResponse.kt index 38917df56..f88cb1588 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdResponse.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class CustomerCreditTopUpListByExternalIdResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, @@ -578,7 +579,7 @@ private constructor( return true } - return /* spotless:off */ other is ExpiresAfterUnit && value == other.value /* spotless:on */ + return other is ExpiresAfterUnit && value == other.value } override fun hashCode() = value.hashCode() @@ -591,12 +592,31 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpListByExternalIdResponse && id == other.id && amount == other.amount && currency == other.currency && invoiceSettings == other.invoiceSettings && perUnitCostBasis == other.perUnitCostBasis && threshold == other.threshold && expiresAfter == other.expiresAfter && expiresAfterUnit == other.expiresAfterUnit && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCreditTopUpListByExternalIdResponse && + id == other.id && + amount == other.amount && + currency == other.currency && + invoiceSettings == other.invoiceSettings && + perUnitCostBasis == other.perUnitCostBasis && + threshold == other.threshold && + expiresAfter == other.expiresAfter && + expiresAfterUnit == other.expiresAfterUnit && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, currency, invoiceSettings, perUnitCostBasis, threshold, expiresAfter, expiresAfterUnit, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + currency, + invoiceSettings, + perUnitCostBasis, + threshold, + expiresAfter, + expiresAfterUnit, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPage.kt index db9b2978e..fd626521a 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPage.kt @@ -122,10 +122,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerCreditTopUpListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerCreditTopUpListPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageAsync.kt index 06908ff0a..f0f0163cf 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageAsync.kt @@ -125,10 +125,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerCreditTopUpListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerCreditTopUpListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageResponse.kt index ff5436023..91a2363cf 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CustomerCreditTopUpListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -222,12 +223,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCreditTopUpListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListParams.kt index 6a4506d4b..070e21d87 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListParams.kt @@ -217,10 +217,16 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpListParams && customerId == other.customerId && cursor == other.cursor && limit == other.limit && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerCreditTopUpListParams && + customerId == other.customerId && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, cursor, limit, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(customerId, cursor, limit, additionalHeaders, additionalQueryParams) override fun toString() = "CustomerCreditTopUpListParams{customerId=$customerId, cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListResponse.kt index 9e04ca9a4..e69eeaafd 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListResponse.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class CustomerCreditTopUpListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, @@ -577,7 +578,7 @@ private constructor( return true } - return /* spotless:off */ other is ExpiresAfterUnit && value == other.value /* spotless:on */ + return other is ExpiresAfterUnit && value == other.value } override fun hashCode() = value.hashCode() @@ -590,12 +591,31 @@ private constructor( return true } - return /* spotless:off */ other is CustomerCreditTopUpListResponse && id == other.id && amount == other.amount && currency == other.currency && invoiceSettings == other.invoiceSettings && perUnitCostBasis == other.perUnitCostBasis && threshold == other.threshold && expiresAfter == other.expiresAfter && expiresAfterUnit == other.expiresAfterUnit && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerCreditTopUpListResponse && + id == other.id && + amount == other.amount && + currency == other.currency && + invoiceSettings == other.invoiceSettings && + perUnitCostBasis == other.perUnitCostBasis && + threshold == other.threshold && + expiresAfter == other.expiresAfter && + expiresAfterUnit == other.expiresAfterUnit && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, currency, invoiceSettings, perUnitCostBasis, threshold, expiresAfter, expiresAfterUnit, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + currency, + invoiceSettings, + perUnitCostBasis, + threshold, + expiresAfter, + expiresAfterUnit, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerDeleteParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerDeleteParams.kt index 167cac20f..2641e0913 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerDeleteParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerDeleteParams.kt @@ -218,10 +218,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerDeleteParams && customerId == other.customerId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is CustomerDeleteParams && + customerId == other.customerId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(customerId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "CustomerDeleteParams{customerId=$customerId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerFetchByExternalIdParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerFetchByExternalIdParams.kt index 42b0d7acc..ab49748ce 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerFetchByExternalIdParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerFetchByExternalIdParams.kt @@ -187,10 +187,14 @@ private constructor( return true } - return /* spotless:off */ other is CustomerFetchByExternalIdParams && externalCustomerId == other.externalCustomerId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerFetchByExternalIdParams && + externalCustomerId == other.externalCustomerId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalCustomerId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(externalCustomerId, additionalHeaders, additionalQueryParams) override fun toString() = "CustomerFetchByExternalIdParams{externalCustomerId=$externalCustomerId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerFetchParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerFetchParams.kt index 1762f05fa..fb3900bf2 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerFetchParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerFetchParams.kt @@ -179,10 +179,14 @@ private constructor( return true } - return /* spotless:off */ other is CustomerFetchParams && customerId == other.customerId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerFetchParams && + customerId == other.customerId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(customerId, additionalHeaders, additionalQueryParams) override fun toString() = "CustomerFetchParams{customerId=$customerId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerHierarchyConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerHierarchyConfig.kt index b26ee4da3..97156aa30 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerHierarchyConfig.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerHierarchyConfig.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class CustomerHierarchyConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val childCustomerIds: JsonField>, private val parentCustomerId: JsonField, @@ -215,12 +216,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerHierarchyConfig && childCustomerIds == other.childCustomerIds && parentCustomerId == other.parentCustomerId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerHierarchyConfig && + childCustomerIds == other.childCustomerIds && + parentCustomerId == other.parentCustomerId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(childCustomerIds, parentCustomerId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(childCustomerIds, parentCustomerId, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListPage.kt index 389df12cc..9420603cc 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListPage.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerListPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListPageAsync.kt index 671a631b4..e26b9fe5c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListPageAsync.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is CustomerListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "CustomerListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListPageResponse.kt index d6adc698a..61c03dc7a 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class CustomerListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -214,12 +215,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListParams.kt index b3766665a..3578309e5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerListParams.kt @@ -252,10 +252,28 @@ private constructor( return true } - return /* spotless:off */ other is CustomerListParams && createdAtGt == other.createdAtGt && createdAtGte == other.createdAtGte && createdAtLt == other.createdAtLt && createdAtLte == other.createdAtLte && cursor == other.cursor && limit == other.limit && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerListParams && + createdAtGt == other.createdAtGt && + createdAtGte == other.createdAtGte && + createdAtLt == other.createdAtLt && + createdAtLte == other.createdAtLte && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(createdAtGt, createdAtGte, createdAtLt, createdAtLte, cursor, limit, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + createdAtGt, + createdAtGte, + createdAtLt, + createdAtLte, + cursor, + limit, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "CustomerListParams{createdAtGt=$createdAtGt, createdAtGte=$createdAtGte, createdAtLt=$createdAtLt, createdAtLte=$createdAtLte, cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerMinified.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerMinified.kt index b73a05d52..ad20e3643 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerMinified.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerMinified.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class CustomerMinified +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val externalCustomerId: JsonField, @@ -195,12 +196,13 @@ private constructor( return true } - return /* spotless:off */ other is CustomerMinified && id == other.id && externalCustomerId == other.externalCustomerId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerMinified && + id == other.id && + externalCustomerId == other.externalCustomerId && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, externalCustomerId, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerSyncPaymentMethodsFromGatewayByExternalCustomerIdParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerSyncPaymentMethodsFromGatewayByExternalCustomerIdParams.kt index 2bf8e319b..0ae98d514 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerSyncPaymentMethodsFromGatewayByExternalCustomerIdParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerSyncPaymentMethodsFromGatewayByExternalCustomerIdParams.kt @@ -233,10 +233,20 @@ private constructor( return true } - return /* spotless:off */ other is CustomerSyncPaymentMethodsFromGatewayByExternalCustomerIdParams && externalCustomerId == other.externalCustomerId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is CustomerSyncPaymentMethodsFromGatewayByExternalCustomerIdParams && + externalCustomerId == other.externalCustomerId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalCustomerId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + externalCustomerId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) override fun toString() = "CustomerSyncPaymentMethodsFromGatewayByExternalCustomerIdParams{externalCustomerId=$externalCustomerId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerSyncPaymentMethodsFromGatewayParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerSyncPaymentMethodsFromGatewayParams.kt index e5e741654..b805d0740 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerSyncPaymentMethodsFromGatewayParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerSyncPaymentMethodsFromGatewayParams.kt @@ -222,10 +222,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerSyncPaymentMethodsFromGatewayParams && customerId == other.customerId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is CustomerSyncPaymentMethodsFromGatewayParams && + customerId == other.customerId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(customerId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "CustomerSyncPaymentMethodsFromGatewayParams{customerId=$customerId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerTaxId.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerTaxId.kt index 567bcf539..789be664d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerTaxId.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerTaxId.kt @@ -89,9 +89,9 @@ import java.util.Objects * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -162,6 +162,7 @@ import java.util.Objects * |Zimbabwe |`zw_tin` |Zimbabwe Tax Identification Number | */ class CustomerTaxId +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val country: JsonField, private val type: JsonField, @@ -1136,7 +1137,7 @@ private constructor( return true } - return /* spotless:off */ other is Country && value == other.value /* spotless:on */ + return other is Country && value == other.value } override fun hashCode() = value.hashCode() @@ -1908,7 +1909,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -1921,12 +1922,14 @@ private constructor( return true } - return /* spotless:off */ other is CustomerTaxId && country == other.country && type == other.type && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerTaxId && + country == other.country && + type == other.type && + value == other.value && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(country, type, value, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerUpdateByExternalIdParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerUpdateByExternalIdParams.kt index 92b67ef6c..068cf3bf2 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerUpdateByExternalIdParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerUpdateByExternalIdParams.kt @@ -22,6 +22,7 @@ import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.Params import com.withorb.api.core.checkKnown +import com.withorb.api.core.checkRequired import com.withorb.api.core.getOrThrow import com.withorb.api.core.http.Headers import com.withorb.api.core.http.QueryParams @@ -54,7 +55,8 @@ private constructor( /** * Additional email addresses for this customer. If populated, these email addresses will be - * CC'd for customer communications. + * CC'd for customer communications. The total number of email addresses (including the primary + * email) cannot exceed 50. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -71,6 +73,17 @@ private constructor( */ fun autoCollection(): Boolean? = body.autoCollection() + /** + * Used to determine if invoices for this customer will be automatically issued. If true, + * invoices will be automatically issued. If false, invoices will require manual approval.If + * `null` is specified, the customer's auto issuance setting will be inherited from the + * account-level setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun autoIssuance(): Boolean? = body.autoIssuance() + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -137,6 +150,15 @@ private constructor( */ fun name(): String? = body.name() + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a supported + * payment provider such as Stripe. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun paymentConfiguration(): PaymentConfiguration? = body.paymentConfiguration() + /** * This is used for creating charges or invoices in an external system via Orb. When not in test * mode: @@ -249,9 +271,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -350,6 +372,13 @@ private constructor( */ fun _autoCollection(): JsonField = body._autoCollection() + /** + * Returns the raw JSON value of [autoIssuance]. + * + * Unlike [autoIssuance], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _autoIssuance(): JsonField = body._autoIssuance() + /** * Returns the raw JSON value of [billingAddress]. * @@ -407,6 +436,14 @@ private constructor( */ fun _name(): JsonField = body._name() + /** + * Returns the raw JSON value of [paymentConfiguration]. + * + * Unlike [paymentConfiguration], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _paymentConfiguration(): JsonField = body._paymentConfiguration() + /** * Returns the raw JSON value of [paymentProvider]. * @@ -501,8 +538,8 @@ private constructor( * - [accountingSyncConfiguration] * - [additionalEmails] * - [autoCollection] + * - [autoIssuance] * - [billingAddress] - * - [currency] * - etc. */ fun body(body: Body) = apply { this.body = body.toBuilder() } @@ -524,7 +561,8 @@ private constructor( /** * Additional email addresses for this customer. If populated, these email addresses will be - * CC'd for customer communications. + * CC'd for customer communications. The total number of email addresses (including the + * primary email) cannot exceed 50. */ fun additionalEmails(additionalEmails: List?) = apply { body.additionalEmails(additionalEmails) @@ -575,6 +613,32 @@ private constructor( body.autoCollection(autoCollection) } + /** + * Used to determine if invoices for this customer will be automatically issued. If true, + * invoices will be automatically issued. If false, invoices will require manual approval.If + * `null` is specified, the customer's auto issuance setting will be inherited from the + * account-level setting. + */ + fun autoIssuance(autoIssuance: Boolean?) = apply { body.autoIssuance(autoIssuance) } + + /** + * Alias for [Builder.autoIssuance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun autoIssuance(autoIssuance: Boolean) = autoIssuance(autoIssuance as Boolean?) + + /** + * Sets [Builder.autoIssuance] to an arbitrary JSON value. + * + * You should usually call [Builder.autoIssuance] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun autoIssuance(autoIssuance: JsonField) = apply { + body.autoIssuance(autoIssuance) + } + fun billingAddress(billingAddress: AddressInput?) = apply { body.billingAddress(billingAddress) } @@ -697,6 +761,25 @@ private constructor( */ fun name(name: JsonField) = apply { body.name(name) } + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a + * supported payment provider such as Stripe. + */ + fun paymentConfiguration(paymentConfiguration: PaymentConfiguration?) = apply { + body.paymentConfiguration(paymentConfiguration) + } + + /** + * Sets [Builder.paymentConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentConfiguration] with a well-typed + * [PaymentConfiguration] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun paymentConfiguration(paymentConfiguration: JsonField) = apply { + body.paymentConfiguration(paymentConfiguration) + } + /** * This is used for creating charges or invoices in an external system via Orb. When not in * test mode: @@ -838,6 +921,55 @@ private constructor( body.sphereTaxConfiguration(taxExempt) } + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofNumeral(numeral)`. */ + fun taxConfiguration(numeral: TaxConfiguration.Numeral) = apply { + body.taxConfiguration(numeral) + } + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Numeral.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun numeralTaxConfiguration(taxExempt: Boolean) = apply { + body.numeralTaxConfiguration(taxExempt) + } + + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofAnrok(anrok)`. */ + fun taxConfiguration(anrok: TaxConfiguration.Anrok) = apply { body.taxConfiguration(anrok) } + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Anrok.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun anrokTaxConfiguration(taxExempt: Boolean) = apply { + body.anrokTaxConfiguration(taxExempt) + } + + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofStripe(stripe)`. */ + fun taxConfiguration(stripe: TaxConfiguration.Stripe) = apply { + body.taxConfiguration(stripe) + } + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Stripe.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun stripeTaxConfiguration(taxExempt: Boolean) = apply { + body.stripeTaxConfiguration(taxExempt) + } + /** * Tax IDs are commonly required to be displayed on customer invoices, which are added to * the headers of invoices. @@ -911,9 +1043,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -1138,10 +1270,12 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val accountingSyncConfiguration: JsonField, private val additionalEmails: JsonField>, private val autoCollection: JsonField, + private val autoIssuance: JsonField, private val billingAddress: JsonField, private val currency: JsonField, private val email: JsonField, @@ -1150,6 +1284,7 @@ private constructor( private val hierarchy: JsonField, private val metadata: JsonField, private val name: JsonField, + private val paymentConfiguration: JsonField, private val paymentProvider: JsonField, private val paymentProviderId: JsonField, private val reportingConfiguration: JsonField, @@ -1171,6 +1306,9 @@ private constructor( @JsonProperty("auto_collection") @ExcludeMissing autoCollection: JsonField = JsonMissing.of(), + @JsonProperty("auto_issuance") + @ExcludeMissing + autoIssuance: JsonField = JsonMissing.of(), @JsonProperty("billing_address") @ExcludeMissing billingAddress: JsonField = JsonMissing.of(), @@ -1191,6 +1329,9 @@ private constructor( @ExcludeMissing metadata: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("payment_configuration") + @ExcludeMissing + paymentConfiguration: JsonField = JsonMissing.of(), @JsonProperty("payment_provider") @ExcludeMissing paymentProvider: JsonField = JsonMissing.of(), @@ -1213,6 +1354,7 @@ private constructor( accountingSyncConfiguration, additionalEmails, autoCollection, + autoIssuance, billingAddress, currency, email, @@ -1221,6 +1363,7 @@ private constructor( hierarchy, metadata, name, + paymentConfiguration, paymentProvider, paymentProviderId, reportingConfiguration, @@ -1239,7 +1382,8 @@ private constructor( /** * Additional email addresses for this customer. If populated, these email addresses will be - * CC'd for customer communications. + * CC'd for customer communications. The total number of email addresses (including the + * primary email) cannot exceed 50. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1256,6 +1400,17 @@ private constructor( */ fun autoCollection(): Boolean? = autoCollection.getNullable("auto_collection") + /** + * Used to determine if invoices for this customer will be automatically issued. If true, + * invoices will be automatically issued. If false, invoices will require manual approval.If + * `null` is specified, the customer's auto issuance setting will be inherited from the + * account-level setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun autoIssuance(): Boolean? = autoIssuance.getNullable("auto_issuance") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1322,6 +1477,16 @@ private constructor( */ fun name(): String? = name.getNullable("name") + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a + * supported payment provider such as Stripe. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun paymentConfiguration(): PaymentConfiguration? = + paymentConfiguration.getNullable("payment_configuration") + /** * This is used for creating charges or invoices in an external system via Orb. When not in * test mode: @@ -1436,9 +1601,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -1544,6 +1709,16 @@ private constructor( @ExcludeMissing fun _autoCollection(): JsonField = autoCollection + /** + * Returns the raw JSON value of [autoIssuance]. + * + * Unlike [autoIssuance], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("auto_issuance") + @ExcludeMissing + fun _autoIssuance(): JsonField = autoIssuance + /** * Returns the raw JSON value of [billingAddress]. * @@ -1611,6 +1786,16 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + /** + * Returns the raw JSON value of [paymentConfiguration]. + * + * Unlike [paymentConfiguration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("payment_configuration") + @ExcludeMissing + fun _paymentConfiguration(): JsonField = paymentConfiguration + /** * Returns the raw JSON value of [paymentProvider]. * @@ -1693,6 +1878,7 @@ private constructor( JsonMissing.of() private var additionalEmails: JsonField>? = null private var autoCollection: JsonField = JsonMissing.of() + private var autoIssuance: JsonField = JsonMissing.of() private var billingAddress: JsonField = JsonMissing.of() private var currency: JsonField = JsonMissing.of() private var email: JsonField = JsonMissing.of() @@ -1701,6 +1887,7 @@ private constructor( private var hierarchy: JsonField = JsonMissing.of() private var metadata: JsonField = JsonMissing.of() private var name: JsonField = JsonMissing.of() + private var paymentConfiguration: JsonField = JsonMissing.of() private var paymentProvider: JsonField = JsonMissing.of() private var paymentProviderId: JsonField = JsonMissing.of() private var reportingConfiguration: JsonField = @@ -1714,6 +1901,7 @@ private constructor( accountingSyncConfiguration = body.accountingSyncConfiguration additionalEmails = body.additionalEmails.map { it.toMutableList() } autoCollection = body.autoCollection + autoIssuance = body.autoIssuance billingAddress = body.billingAddress currency = body.currency email = body.email @@ -1722,6 +1910,7 @@ private constructor( hierarchy = body.hierarchy metadata = body.metadata name = body.name + paymentConfiguration = body.paymentConfiguration paymentProvider = body.paymentProvider paymentProviderId = body.paymentProviderId reportingConfiguration = body.reportingConfiguration @@ -1748,7 +1937,8 @@ private constructor( /** * Additional email addresses for this customer. If populated, these email addresses - * will be CC'd for customer communications. + * will be CC'd for customer communications. The total number of email addresses + * (including the primary email) cannot exceed 50. */ fun additionalEmails(additionalEmails: List?) = additionalEmails(JsonField.ofNullable(additionalEmails)) @@ -1802,6 +1992,33 @@ private constructor( this.autoCollection = autoCollection } + /** + * Used to determine if invoices for this customer will be automatically issued. If + * true, invoices will be automatically issued. If false, invoices will require manual + * approval.If `null` is specified, the customer's auto issuance setting will be + * inherited from the account-level setting. + */ + fun autoIssuance(autoIssuance: Boolean?) = + autoIssuance(JsonField.ofNullable(autoIssuance)) + + /** + * Alias for [Builder.autoIssuance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun autoIssuance(autoIssuance: Boolean) = autoIssuance(autoIssuance as Boolean?) + + /** + * Sets [Builder.autoIssuance] to an arbitrary JSON value. + * + * You should usually call [Builder.autoIssuance] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun autoIssuance(autoIssuance: JsonField) = apply { + this.autoIssuance = autoIssuance + } + fun billingAddress(billingAddress: AddressInput?) = billingAddress(JsonField.ofNullable(billingAddress)) @@ -1927,6 +2144,25 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a + * supported payment provider such as Stripe. + */ + fun paymentConfiguration(paymentConfiguration: PaymentConfiguration?) = + paymentConfiguration(JsonField.ofNullable(paymentConfiguration)) + + /** + * Sets [Builder.paymentConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentConfiguration] with a well-typed + * [PaymentConfiguration] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun paymentConfiguration(paymentConfiguration: JsonField) = + apply { + this.paymentConfiguration = paymentConfiguration + } + /** * This is used for creating charges or invoices in an external system via Orb. When not * in test mode: @@ -2072,6 +2308,51 @@ private constructor( .build() ) + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofNumeral(numeral)`. */ + fun taxConfiguration(numeral: TaxConfiguration.Numeral) = + taxConfiguration(TaxConfiguration.ofNumeral(numeral)) + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Numeral.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun numeralTaxConfiguration(taxExempt: Boolean) = + taxConfiguration(TaxConfiguration.Numeral.builder().taxExempt(taxExempt).build()) + + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofAnrok(anrok)`. */ + fun taxConfiguration(anrok: TaxConfiguration.Anrok) = + taxConfiguration(TaxConfiguration.ofAnrok(anrok)) + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Anrok.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun anrokTaxConfiguration(taxExempt: Boolean) = + taxConfiguration(TaxConfiguration.Anrok.builder().taxExempt(taxExempt).build()) + + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofStripe(stripe)`. */ + fun taxConfiguration(stripe: TaxConfiguration.Stripe) = + taxConfiguration(TaxConfiguration.ofStripe(stripe)) + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Stripe.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun stripeTaxConfiguration(taxExempt: Boolean) = + taxConfiguration(TaxConfiguration.Stripe.builder().taxExempt(taxExempt).build()) + /** * Tax IDs are commonly required to be displayed on customer invoices, which are added * to the headers of invoices. @@ -2145,9 +2426,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -2257,6 +2538,7 @@ private constructor( accountingSyncConfiguration, (additionalEmails ?: JsonMissing.of()).map { it.toImmutable() }, autoCollection, + autoIssuance, billingAddress, currency, email, @@ -2265,6 +2547,7 @@ private constructor( hierarchy, metadata, name, + paymentConfiguration, paymentProvider, paymentProviderId, reportingConfiguration, @@ -2285,6 +2568,7 @@ private constructor( accountingSyncConfiguration()?.validate() additionalEmails() autoCollection() + autoIssuance() billingAddress()?.validate() currency() email() @@ -2293,6 +2577,7 @@ private constructor( hierarchy()?.validate() metadata()?.validate() name() + paymentConfiguration()?.validate() paymentProvider()?.validate() paymentProviderId() reportingConfiguration()?.validate() @@ -2320,6 +2605,7 @@ private constructor( (accountingSyncConfiguration.asKnown()?.validity() ?: 0) + (additionalEmails.asKnown()?.size ?: 0) + (if (autoCollection.asKnown() == null) 0 else 1) + + (if (autoIssuance.asKnown() == null) 0 else 1) + (billingAddress.asKnown()?.validity() ?: 0) + (if (currency.asKnown() == null) 0 else 1) + (if (email.asKnown() == null) 0 else 1) + @@ -2328,6 +2614,7 @@ private constructor( (hierarchy.asKnown()?.validity() ?: 0) + (metadata.asKnown()?.validity() ?: 0) + (if (name.asKnown() == null) 0 else 1) + + (paymentConfiguration.asKnown()?.validity() ?: 0) + (paymentProvider.asKnown()?.validity() ?: 0) + (if (paymentProviderId.asKnown() == null) 0 else 1) + (reportingConfiguration.asKnown()?.validity() ?: 0) + @@ -2340,17 +2627,58 @@ private constructor( return true } - return /* spotless:off */ other is Body && accountingSyncConfiguration == other.accountingSyncConfiguration && additionalEmails == other.additionalEmails && autoCollection == other.autoCollection && billingAddress == other.billingAddress && currency == other.currency && email == other.email && emailDelivery == other.emailDelivery && externalCustomerId == other.externalCustomerId && hierarchy == other.hierarchy && metadata == other.metadata && name == other.name && paymentProvider == other.paymentProvider && paymentProviderId == other.paymentProviderId && reportingConfiguration == other.reportingConfiguration && shippingAddress == other.shippingAddress && taxConfiguration == other.taxConfiguration && taxId == other.taxId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + accountingSyncConfiguration == other.accountingSyncConfiguration && + additionalEmails == other.additionalEmails && + autoCollection == other.autoCollection && + autoIssuance == other.autoIssuance && + billingAddress == other.billingAddress && + currency == other.currency && + email == other.email && + emailDelivery == other.emailDelivery && + externalCustomerId == other.externalCustomerId && + hierarchy == other.hierarchy && + metadata == other.metadata && + name == other.name && + paymentConfiguration == other.paymentConfiguration && + paymentProvider == other.paymentProvider && + paymentProviderId == other.paymentProviderId && + reportingConfiguration == other.reportingConfiguration && + shippingAddress == other.shippingAddress && + taxConfiguration == other.taxConfiguration && + taxId == other.taxId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(accountingSyncConfiguration, additionalEmails, autoCollection, billingAddress, currency, email, emailDelivery, externalCustomerId, hierarchy, metadata, name, paymentProvider, paymentProviderId, reportingConfiguration, shippingAddress, taxConfiguration, taxId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + accountingSyncConfiguration, + additionalEmails, + autoCollection, + autoIssuance, + billingAddress, + currency, + email, + emailDelivery, + externalCustomerId, + hierarchy, + metadata, + name, + paymentConfiguration, + paymentProvider, + paymentProviderId, + reportingConfiguration, + shippingAddress, + taxConfiguration, + taxId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Body{accountingSyncConfiguration=$accountingSyncConfiguration, additionalEmails=$additionalEmails, autoCollection=$autoCollection, billingAddress=$billingAddress, currency=$currency, email=$email, emailDelivery=$emailDelivery, externalCustomerId=$externalCustomerId, hierarchy=$hierarchy, metadata=$metadata, name=$name, paymentProvider=$paymentProvider, paymentProviderId=$paymentProviderId, reportingConfiguration=$reportingConfiguration, shippingAddress=$shippingAddress, taxConfiguration=$taxConfiguration, taxId=$taxId, additionalProperties=$additionalProperties}" + "Body{accountingSyncConfiguration=$accountingSyncConfiguration, additionalEmails=$additionalEmails, autoCollection=$autoCollection, autoIssuance=$autoIssuance, billingAddress=$billingAddress, currency=$currency, email=$email, emailDelivery=$emailDelivery, externalCustomerId=$externalCustomerId, hierarchy=$hierarchy, metadata=$metadata, name=$name, paymentConfiguration=$paymentConfiguration, paymentProvider=$paymentProvider, paymentProviderId=$paymentProviderId, reportingConfiguration=$reportingConfiguration, shippingAddress=$shippingAddress, taxConfiguration=$taxConfiguration, taxId=$taxId, additionalProperties=$additionalProperties}" } /** @@ -2445,12 +2773,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2458,86 +2784,626 @@ private constructor( } /** - * This is used for creating charges or invoices in an external system via Orb. When not in test - * mode: - * - the connection must first be configured in the Orb webapp. - * - if the provider is an invoicing provider (`stripe_invoice`, `quickbooks`, `bill.com`, - * `netsuite`), any product mappings must first be configured with the Orb team. + * Payment configuration for the customer, applicable when using Orb Invoicing with a supported + * payment provider such as Stripe. */ - class PaymentProvider @JsonCreator private constructor(private val value: JsonField) : - Enum { + class PaymentConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val paymentProviders: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("payment_providers") + @ExcludeMissing + paymentProviders: JsonField> = JsonMissing.of() + ) : this(paymentProviders, mutableMapOf()) /** - * Returns this class instance's raw value. + * Provider-specific payment configuration. * - * 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 OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { + fun paymentProviders(): List? = + paymentProviders.getNullable("payment_providers") - val QUICKBOOKS = of("quickbooks") + /** + * Returns the raw JSON value of [paymentProviders]. + * + * Unlike [paymentProviders], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("payment_providers") + @ExcludeMissing + fun _paymentProviders(): JsonField> = paymentProviders - val BILL_COM = of("bill.com") + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - val STRIPE_CHARGE = of("stripe_charge") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - val STRIPE_INVOICE = of("stripe_invoice") + fun toBuilder() = Builder().from(this) - val NETSUITE = of("netsuite") + companion object { - fun of(value: String) = PaymentProvider(JsonField.of(value)) + /** Returns a mutable builder for constructing an instance of [PaymentConfiguration]. */ + fun builder() = Builder() } - /** An enum containing [PaymentProvider]'s known values. */ - enum class Known { - QUICKBOOKS, - BILL_COM, - STRIPE_CHARGE, - STRIPE_INVOICE, - NETSUITE, - } + /** A builder for [PaymentConfiguration]. */ + class Builder internal constructor() { + + private var paymentProviders: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(paymentConfiguration: PaymentConfiguration) = apply { + paymentProviders = paymentConfiguration.paymentProviders.map { it.toMutableList() } + additionalProperties = paymentConfiguration.additionalProperties.toMutableMap() + } + + /** Provider-specific payment configuration. */ + fun paymentProviders(paymentProviders: List) = + paymentProviders(JsonField.of(paymentProviders)) - /** - * An enum containing [PaymentProvider]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [PaymentProvider] 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 { - QUICKBOOKS, - BILL_COM, - STRIPE_CHARGE, - STRIPE_INVOICE, - NETSUITE, /** - * An enum member indicating that [PaymentProvider] was instantiated with an unknown - * value. + * Sets [Builder.paymentProviders] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentProviders] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. */ - _UNKNOWN, - } + fun paymentProviders(paymentProviders: JsonField>) = apply { + this.paymentProviders = paymentProviders.map { it.toMutableList() } + } - /** - * 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) { - QUICKBOOKS -> Value.QUICKBOOKS - BILL_COM -> Value.BILL_COM - STRIPE_CHARGE -> Value.STRIPE_CHARGE - STRIPE_INVOICE -> Value.STRIPE_INVOICE - NETSUITE -> Value.NETSUITE - else -> Value._UNKNOWN + /** + * Adds a single [PaymentProvider] to [paymentProviders]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPaymentProvider(paymentProvider: PaymentProvider) = apply { + paymentProviders = + (paymentProviders ?: JsonField.of(mutableListOf())).also { + checkKnown("paymentProviders", it).add(paymentProvider) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PaymentConfiguration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): PaymentConfiguration = + PaymentConfiguration( + (paymentProviders ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PaymentConfiguration = apply { + if (validated) { + return@apply + } + + paymentProviders()?.forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (paymentProviders.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + class PaymentProvider + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val providerType: JsonField, + private val excludedPaymentMethodTypes: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("provider_type") + @ExcludeMissing + providerType: JsonField = JsonMissing.of(), + @JsonProperty("excluded_payment_method_types") + @ExcludeMissing + excludedPaymentMethodTypes: JsonField> = JsonMissing.of(), + ) : this(providerType, excludedPaymentMethodTypes, mutableMapOf()) + + /** + * The payment provider to configure. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun providerType(): ProviderType = providerType.getRequired("provider_type") + + /** + * List of Stripe payment method types to exclude for this customer. Excluded payment + * methods will not be available for the customer to select during payment, and will not + * be used for auto-collection. If a customer's default payment method becomes excluded, + * Orb will attempt to use the next available compatible payment method for + * auto-collection. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun excludedPaymentMethodTypes(): List? = + excludedPaymentMethodTypes.getNullable("excluded_payment_method_types") + + /** + * Returns the raw JSON value of [providerType]. + * + * Unlike [providerType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("provider_type") + @ExcludeMissing + fun _providerType(): JsonField = providerType + + /** + * Returns the raw JSON value of [excludedPaymentMethodTypes]. + * + * Unlike [excludedPaymentMethodTypes], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("excluded_payment_method_types") + @ExcludeMissing + fun _excludedPaymentMethodTypes(): JsonField> = excludedPaymentMethodTypes + + @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 [PaymentProvider]. + * + * The following fields are required: + * ```kotlin + * .providerType() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PaymentProvider]. */ + class Builder internal constructor() { + + private var providerType: JsonField? = null + private var excludedPaymentMethodTypes: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(paymentProvider: PaymentProvider) = apply { + providerType = paymentProvider.providerType + excludedPaymentMethodTypes = + paymentProvider.excludedPaymentMethodTypes.map { it.toMutableList() } + additionalProperties = paymentProvider.additionalProperties.toMutableMap() + } + + /** The payment provider to configure. */ + fun providerType(providerType: ProviderType) = + providerType(JsonField.of(providerType)) + + /** + * Sets [Builder.providerType] to an arbitrary JSON value. + * + * You should usually call [Builder.providerType] with a well-typed [ProviderType] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun providerType(providerType: JsonField) = apply { + this.providerType = providerType + } + + /** + * List of Stripe payment method types to exclude for this customer. Excluded + * payment methods will not be available for the customer to select during payment, + * and will not be used for auto-collection. If a customer's default payment method + * becomes excluded, Orb will attempt to use the next available compatible payment + * method for auto-collection. + */ + fun excludedPaymentMethodTypes(excludedPaymentMethodTypes: List) = + excludedPaymentMethodTypes(JsonField.of(excludedPaymentMethodTypes)) + + /** + * Sets [Builder.excludedPaymentMethodTypes] to an arbitrary JSON value. + * + * You should usually call [Builder.excludedPaymentMethodTypes] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun excludedPaymentMethodTypes( + excludedPaymentMethodTypes: JsonField> + ) = apply { + this.excludedPaymentMethodTypes = + excludedPaymentMethodTypes.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [excludedPaymentMethodTypes]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExcludedPaymentMethodType(excludedPaymentMethodType: String) = apply { + excludedPaymentMethodTypes = + (excludedPaymentMethodTypes ?: JsonField.of(mutableListOf())).also { + checkKnown("excludedPaymentMethodTypes", it) + .add(excludedPaymentMethodType) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PaymentProvider]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .providerType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PaymentProvider = + PaymentProvider( + checkRequired("providerType", providerType), + (excludedPaymentMethodTypes ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PaymentProvider = apply { + if (validated) { + return@apply + } + + providerType().validate() + excludedPaymentMethodTypes() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (providerType.asKnown()?.validity() ?: 0) + + (excludedPaymentMethodTypes.asKnown()?.size ?: 0) + + /** The payment provider to configure. */ + class ProviderType + @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 { + + val STRIPE = of("stripe") + + fun of(value: String) = ProviderType(JsonField.of(value)) + } + + /** An enum containing [ProviderType]'s known values. */ + enum class Known { + STRIPE + } + + /** + * An enum containing [ProviderType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [ProviderType] 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 [ProviderType] 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + STRIPE -> Known.STRIPE + else -> throw OrbInvalidDataException("Unknown ProviderType: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): ProviderType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 ProviderType && 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 PaymentProvider && + providerType == other.providerType && + excludedPaymentMethodTypes == other.excludedPaymentMethodTypes && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(providerType, excludedPaymentMethodTypes, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PaymentProvider{providerType=$providerType, excludedPaymentMethodTypes=$excludedPaymentMethodTypes, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PaymentConfiguration && + paymentProviders == other.paymentProviders && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(paymentProviders, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PaymentConfiguration{paymentProviders=$paymentProviders, additionalProperties=$additionalProperties}" + } + + /** + * This is used for creating charges or invoices in an external system via Orb. When not in test + * mode: + * - the connection must first be configured in the Orb webapp. + * - if the provider is an invoicing provider (`stripe_invoice`, `quickbooks`, `bill.com`, + * `netsuite`), any product mappings must first be configured with the Orb team. + */ + class PaymentProvider @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 { + + val QUICKBOOKS = of("quickbooks") + + val BILL_COM = of("bill.com") + + val STRIPE_CHARGE = of("stripe_charge") + + val STRIPE_INVOICE = of("stripe_invoice") + + val NETSUITE = of("netsuite") + + fun of(value: String) = PaymentProvider(JsonField.of(value)) + } + + /** An enum containing [PaymentProvider]'s known values. */ + enum class Known { + QUICKBOOKS, + BILL_COM, + STRIPE_CHARGE, + STRIPE_INVOICE, + NETSUITE, + } + + /** + * An enum containing [PaymentProvider]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [PaymentProvider] 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 { + QUICKBOOKS, + BILL_COM, + STRIPE_CHARGE, + STRIPE_INVOICE, + NETSUITE, + /** + * An enum member indicating that [PaymentProvider] 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) { + QUICKBOOKS -> Value.QUICKBOOKS + BILL_COM -> Value.BILL_COM + STRIPE_CHARGE -> Value.STRIPE_CHARGE + STRIPE_INVOICE -> Value.STRIPE_INVOICE + NETSUITE -> Value.NETSUITE + else -> Value._UNKNOWN } /** @@ -2602,7 +3468,7 @@ private constructor( return true } - return /* spotless:off */ other is PaymentProvider && value == other.value /* spotless:on */ + return other is PaymentProvider && value == other.value } override fun hashCode() = value.hashCode() @@ -2617,6 +3483,9 @@ private constructor( private val avalara: NewAvalaraTaxConfiguration? = null, private val taxjar: NewTaxJarConfiguration? = null, private val sphere: NewSphereConfiguration? = null, + private val numeral: Numeral? = null, + private val anrok: Anrok? = null, + private val stripe: Stripe? = null, private val _json: JsonValue? = null, ) { @@ -2626,18 +3495,36 @@ private constructor( fun sphere(): NewSphereConfiguration? = sphere + fun numeral(): Numeral? = numeral + + fun anrok(): Anrok? = anrok + + fun stripe(): Stripe? = stripe + fun isAvalara(): Boolean = avalara != null fun isTaxjar(): Boolean = taxjar != null fun isSphere(): Boolean = sphere != null + fun isNumeral(): Boolean = numeral != null + + fun isAnrok(): Boolean = anrok != null + + fun isStripe(): Boolean = stripe != null + fun asAvalara(): NewAvalaraTaxConfiguration = avalara.getOrThrow("avalara") fun asTaxjar(): NewTaxJarConfiguration = taxjar.getOrThrow("taxjar") fun asSphere(): NewSphereConfiguration = sphere.getOrThrow("sphere") + fun asNumeral(): Numeral = numeral.getOrThrow("numeral") + + fun asAnrok(): Anrok = anrok.getOrThrow("anrok") + + fun asStripe(): Stripe = stripe.getOrThrow("stripe") + fun _json(): JsonValue? = _json fun accept(visitor: Visitor): T = @@ -2645,6 +3532,9 @@ private constructor( avalara != null -> visitor.visitAvalara(avalara) taxjar != null -> visitor.visitTaxjar(taxjar) sphere != null -> visitor.visitSphere(sphere) + numeral != null -> visitor.visitNumeral(numeral) + anrok != null -> visitor.visitAnrok(anrok) + stripe != null -> visitor.visitStripe(stripe) else -> visitor.unknown(_json) } @@ -2668,6 +3558,18 @@ private constructor( override fun visitSphere(sphere: NewSphereConfiguration) { sphere.validate() } + + override fun visitNumeral(numeral: Numeral) { + numeral.validate() + } + + override fun visitAnrok(anrok: Anrok) { + anrok.validate() + } + + override fun visitStripe(stripe: Stripe) { + stripe.validate() + } } ) validated = true @@ -2697,6 +3599,12 @@ private constructor( override fun visitSphere(sphere: NewSphereConfiguration) = sphere.validity() + override fun visitNumeral(numeral: Numeral) = numeral.validity() + + override fun visitAnrok(anrok: Anrok) = anrok.validity() + + override fun visitStripe(stripe: Stripe) = stripe.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -2706,16 +3614,25 @@ private constructor( return true } - return /* spotless:off */ other is TaxConfiguration && avalara == other.avalara && taxjar == other.taxjar && sphere == other.sphere /* spotless:on */ + return other is TaxConfiguration && + avalara == other.avalara && + taxjar == other.taxjar && + sphere == other.sphere && + numeral == other.numeral && + anrok == other.anrok && + stripe == other.stripe } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(avalara, taxjar, sphere) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(avalara, taxjar, sphere, numeral, anrok, stripe) override fun toString(): String = when { avalara != null -> "TaxConfiguration{avalara=$avalara}" taxjar != null -> "TaxConfiguration{taxjar=$taxjar}" sphere != null -> "TaxConfiguration{sphere=$sphere}" + numeral != null -> "TaxConfiguration{numeral=$numeral}" + anrok != null -> "TaxConfiguration{anrok=$anrok}" + stripe != null -> "TaxConfiguration{stripe=$stripe}" _json != null -> "TaxConfiguration{_unknown=$_json}" else -> throw IllegalStateException("Invalid TaxConfiguration") } @@ -2727,6 +3644,12 @@ private constructor( fun ofTaxjar(taxjar: NewTaxJarConfiguration) = TaxConfiguration(taxjar = taxjar) fun ofSphere(sphere: NewSphereConfiguration) = TaxConfiguration(sphere = sphere) + + fun ofNumeral(numeral: Numeral) = TaxConfiguration(numeral = numeral) + + fun ofAnrok(anrok: Anrok) = TaxConfiguration(anrok = anrok) + + fun ofStripe(stripe: Stripe) = TaxConfiguration(stripe = stripe) } /** @@ -2741,6 +3664,12 @@ private constructor( fun visitSphere(sphere: NewSphereConfiguration): T + fun visitNumeral(numeral: Numeral): T + + fun visitAnrok(anrok: Anrok): T + + fun visitStripe(stripe: Stripe): T + /** * Maps an unknown variant of [TaxConfiguration] to a value of type [T]. * @@ -2778,6 +3707,21 @@ private constructor( TaxConfiguration(sphere = it, _json = json) } ?: TaxConfiguration(_json = json) } + "numeral" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TaxConfiguration(numeral = it, _json = json) + } ?: TaxConfiguration(_json = json) + } + "anrok" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TaxConfiguration(anrok = it, _json = json) + } ?: TaxConfiguration(_json = json) + } + "stripe" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TaxConfiguration(stripe = it, _json = json) + } ?: TaxConfiguration(_json = json) + } } return TaxConfiguration(_json = json) @@ -2795,11 +3739,806 @@ private constructor( value.avalara != null -> generator.writeObject(value.avalara) value.taxjar != null -> generator.writeObject(value.taxjar) value.sphere != null -> generator.writeObject(value.sphere) + value.numeral != null -> generator.writeObject(value.numeral) + value.anrok != null -> generator.writeObject(value.anrok) + value.stripe != null -> generator.writeObject(value.stripe) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid TaxConfiguration") } } } + + class Numeral + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val taxExempt: JsonField, + private val taxProvider: JsonValue, + private val automaticTaxEnabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tax_exempt") + @ExcludeMissing + taxExempt: JsonField = JsonMissing.of(), + @JsonProperty("tax_provider") + @ExcludeMissing + taxProvider: JsonValue = JsonMissing.of(), + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + automaticTaxEnabled: JsonField = JsonMissing.of(), + ) : this(taxExempt, taxProvider, automaticTaxEnabled, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun taxExempt(): Boolean = taxExempt.getRequired("tax_exempt") + + /** + * Expected to always return the following: + * ```kotlin + * JsonValue.from("numeral") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("tax_provider") + @ExcludeMissing + fun _taxProvider(): JsonValue = taxProvider + + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun automaticTaxEnabled(): Boolean? = + automaticTaxEnabled.getNullable("automatic_tax_enabled") + + /** + * Returns the raw JSON value of [taxExempt]. + * + * Unlike [taxExempt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tax_exempt") + @ExcludeMissing + fun _taxExempt(): JsonField = taxExempt + + /** + * Returns the raw JSON value of [automaticTaxEnabled]. + * + * Unlike [automaticTaxEnabled], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + fun _automaticTaxEnabled(): JsonField = automaticTaxEnabled + + @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 [Numeral]. + * + * The following fields are required: + * ```kotlin + * .taxExempt() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Numeral]. */ + class Builder internal constructor() { + + private var taxExempt: JsonField? = null + private var taxProvider: JsonValue = JsonValue.from("numeral") + private var automaticTaxEnabled: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(numeral: Numeral) = apply { + taxExempt = numeral.taxExempt + taxProvider = numeral.taxProvider + automaticTaxEnabled = numeral.automaticTaxEnabled + additionalProperties = numeral.additionalProperties.toMutableMap() + } + + fun taxExempt(taxExempt: Boolean) = taxExempt(JsonField.of(taxExempt)) + + /** + * Sets [Builder.taxExempt] to an arbitrary JSON value. + * + * You should usually call [Builder.taxExempt] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun taxExempt(taxExempt: JsonField) = apply { this.taxExempt = taxExempt } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("numeral") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun taxProvider(taxProvider: JsonValue) = apply { this.taxProvider = taxProvider } + + /** + * Whether to automatically calculate tax for this customer. When null, inherits + * from account-level setting. When true or false, overrides the account setting. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean?) = + automaticTaxEnabled(JsonField.ofNullable(automaticTaxEnabled)) + + /** + * Alias for [Builder.automaticTaxEnabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean) = + automaticTaxEnabled(automaticTaxEnabled as Boolean?) + + /** + * Sets [Builder.automaticTaxEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticTaxEnabled] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: JsonField) = apply { + this.automaticTaxEnabled = automaticTaxEnabled + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Numeral]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .taxExempt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Numeral = + Numeral( + checkRequired("taxExempt", taxExempt), + taxProvider, + automaticTaxEnabled, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Numeral = apply { + if (validated) { + return@apply + } + + taxExempt() + _taxProvider().let { + if (it != JsonValue.from("numeral")) { + throw OrbInvalidDataException("'taxProvider' is invalid, received $it") + } + } + automaticTaxEnabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (taxExempt.asKnown() == null) 0 else 1) + + taxProvider.let { if (it == JsonValue.from("numeral")) 1 else 0 } + + (if (automaticTaxEnabled.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Numeral && + taxExempt == other.taxExempt && + taxProvider == other.taxProvider && + automaticTaxEnabled == other.automaticTaxEnabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(taxExempt, taxProvider, automaticTaxEnabled, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Numeral{taxExempt=$taxExempt, taxProvider=$taxProvider, automaticTaxEnabled=$automaticTaxEnabled, additionalProperties=$additionalProperties}" + } + + class Anrok + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val taxExempt: JsonField, + private val taxProvider: JsonValue, + private val automaticTaxEnabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tax_exempt") + @ExcludeMissing + taxExempt: JsonField = JsonMissing.of(), + @JsonProperty("tax_provider") + @ExcludeMissing + taxProvider: JsonValue = JsonMissing.of(), + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + automaticTaxEnabled: JsonField = JsonMissing.of(), + ) : this(taxExempt, taxProvider, automaticTaxEnabled, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun taxExempt(): Boolean = taxExempt.getRequired("tax_exempt") + + /** + * Expected to always return the following: + * ```kotlin + * JsonValue.from("anrok") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("tax_provider") + @ExcludeMissing + fun _taxProvider(): JsonValue = taxProvider + + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun automaticTaxEnabled(): Boolean? = + automaticTaxEnabled.getNullable("automatic_tax_enabled") + + /** + * Returns the raw JSON value of [taxExempt]. + * + * Unlike [taxExempt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tax_exempt") + @ExcludeMissing + fun _taxExempt(): JsonField = taxExempt + + /** + * Returns the raw JSON value of [automaticTaxEnabled]. + * + * Unlike [automaticTaxEnabled], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + fun _automaticTaxEnabled(): JsonField = automaticTaxEnabled + + @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 [Anrok]. + * + * The following fields are required: + * ```kotlin + * .taxExempt() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Anrok]. */ + class Builder internal constructor() { + + private var taxExempt: JsonField? = null + private var taxProvider: JsonValue = JsonValue.from("anrok") + private var automaticTaxEnabled: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(anrok: Anrok) = apply { + taxExempt = anrok.taxExempt + taxProvider = anrok.taxProvider + automaticTaxEnabled = anrok.automaticTaxEnabled + additionalProperties = anrok.additionalProperties.toMutableMap() + } + + fun taxExempt(taxExempt: Boolean) = taxExempt(JsonField.of(taxExempt)) + + /** + * Sets [Builder.taxExempt] to an arbitrary JSON value. + * + * You should usually call [Builder.taxExempt] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun taxExempt(taxExempt: JsonField) = apply { this.taxExempt = taxExempt } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("anrok") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun taxProvider(taxProvider: JsonValue) = apply { this.taxProvider = taxProvider } + + /** + * Whether to automatically calculate tax for this customer. When null, inherits + * from account-level setting. When true or false, overrides the account setting. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean?) = + automaticTaxEnabled(JsonField.ofNullable(automaticTaxEnabled)) + + /** + * Alias for [Builder.automaticTaxEnabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean) = + automaticTaxEnabled(automaticTaxEnabled as Boolean?) + + /** + * Sets [Builder.automaticTaxEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticTaxEnabled] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: JsonField) = apply { + this.automaticTaxEnabled = automaticTaxEnabled + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Anrok]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .taxExempt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Anrok = + Anrok( + checkRequired("taxExempt", taxExempt), + taxProvider, + automaticTaxEnabled, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Anrok = apply { + if (validated) { + return@apply + } + + taxExempt() + _taxProvider().let { + if (it != JsonValue.from("anrok")) { + throw OrbInvalidDataException("'taxProvider' is invalid, received $it") + } + } + automaticTaxEnabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (taxExempt.asKnown() == null) 0 else 1) + + taxProvider.let { if (it == JsonValue.from("anrok")) 1 else 0 } + + (if (automaticTaxEnabled.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Anrok && + taxExempt == other.taxExempt && + taxProvider == other.taxProvider && + automaticTaxEnabled == other.automaticTaxEnabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(taxExempt, taxProvider, automaticTaxEnabled, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Anrok{taxExempt=$taxExempt, taxProvider=$taxProvider, automaticTaxEnabled=$automaticTaxEnabled, additionalProperties=$additionalProperties}" + } + + class Stripe + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val taxExempt: JsonField, + private val taxProvider: JsonValue, + private val automaticTaxEnabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tax_exempt") + @ExcludeMissing + taxExempt: JsonField = JsonMissing.of(), + @JsonProperty("tax_provider") + @ExcludeMissing + taxProvider: JsonValue = JsonMissing.of(), + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + automaticTaxEnabled: JsonField = JsonMissing.of(), + ) : this(taxExempt, taxProvider, automaticTaxEnabled, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun taxExempt(): Boolean = taxExempt.getRequired("tax_exempt") + + /** + * Expected to always return the following: + * ```kotlin + * JsonValue.from("stripe") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("tax_provider") + @ExcludeMissing + fun _taxProvider(): JsonValue = taxProvider + + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun automaticTaxEnabled(): Boolean? = + automaticTaxEnabled.getNullable("automatic_tax_enabled") + + /** + * Returns the raw JSON value of [taxExempt]. + * + * Unlike [taxExempt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tax_exempt") + @ExcludeMissing + fun _taxExempt(): JsonField = taxExempt + + /** + * Returns the raw JSON value of [automaticTaxEnabled]. + * + * Unlike [automaticTaxEnabled], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + fun _automaticTaxEnabled(): JsonField = automaticTaxEnabled + + @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: + * ```kotlin + * .taxExempt() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Stripe]. */ + class Builder internal constructor() { + + private var taxExempt: JsonField? = null + private var taxProvider: JsonValue = JsonValue.from("stripe") + private var automaticTaxEnabled: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(stripe: Stripe) = apply { + taxExempt = stripe.taxExempt + taxProvider = stripe.taxProvider + automaticTaxEnabled = stripe.automaticTaxEnabled + additionalProperties = stripe.additionalProperties.toMutableMap() + } + + fun taxExempt(taxExempt: Boolean) = taxExempt(JsonField.of(taxExempt)) + + /** + * Sets [Builder.taxExempt] to an arbitrary JSON value. + * + * You should usually call [Builder.taxExempt] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun taxExempt(taxExempt: JsonField) = apply { this.taxExempt = taxExempt } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("stripe") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun taxProvider(taxProvider: JsonValue) = apply { this.taxProvider = taxProvider } + + /** + * Whether to automatically calculate tax for this customer. When null, inherits + * from account-level setting. When true or false, overrides the account setting. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean?) = + automaticTaxEnabled(JsonField.ofNullable(automaticTaxEnabled)) + + /** + * Alias for [Builder.automaticTaxEnabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean) = + automaticTaxEnabled(automaticTaxEnabled as Boolean?) + + /** + * Sets [Builder.automaticTaxEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticTaxEnabled] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: JsonField) = apply { + this.automaticTaxEnabled = automaticTaxEnabled + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .taxExempt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Stripe = + Stripe( + checkRequired("taxExempt", taxExempt), + taxProvider, + automaticTaxEnabled, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Stripe = apply { + if (validated) { + return@apply + } + + taxExempt() + _taxProvider().let { + if (it != JsonValue.from("stripe")) { + throw OrbInvalidDataException("'taxProvider' is invalid, received $it") + } + } + automaticTaxEnabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (taxExempt.asKnown() == null) 0 else 1) + + taxProvider.let { if (it == JsonValue.from("stripe")) 1 else 0 } + + (if (automaticTaxEnabled.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Stripe && + taxExempt == other.taxExempt && + taxProvider == other.taxProvider && + automaticTaxEnabled == other.automaticTaxEnabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(taxExempt, taxProvider, automaticTaxEnabled, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Stripe{taxExempt=$taxExempt, taxProvider=$taxProvider, automaticTaxEnabled=$automaticTaxEnabled, additionalProperties=$additionalProperties}" + } } override fun equals(other: Any?): Boolean { @@ -2807,10 +4546,14 @@ private constructor( return true } - return /* spotless:off */ other is CustomerUpdateByExternalIdParams && id == other.id && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerUpdateByExternalIdParams && + id == other.id && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(id, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(id, body, additionalHeaders, additionalQueryParams) override fun toString() = "CustomerUpdateByExternalIdParams{id=$id, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerUpdateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerUpdateParams.kt index 971c8ffec..cedbbdcc2 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerUpdateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/CustomerUpdateParams.kt @@ -22,6 +22,7 @@ import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.Params import com.withorb.api.core.checkKnown +import com.withorb.api.core.checkRequired import com.withorb.api.core.getOrThrow import com.withorb.api.core.http.Headers import com.withorb.api.core.http.QueryParams @@ -55,7 +56,8 @@ private constructor( /** * Additional email addresses for this customer. If populated, these email addresses will be - * CC'd for customer communications. + * CC'd for customer communications. The total number of email addresses (including the primary + * email) cannot exceed 50. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -72,6 +74,17 @@ private constructor( */ fun autoCollection(): Boolean? = body.autoCollection() + /** + * Used to determine if invoices for this customer will be automatically issued. If true, + * invoices will be automatically issued. If false, invoices will require manual approval.If + * `null` is specified, the customer's auto issuance setting will be inherited from the + * account-level setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun autoIssuance(): Boolean? = body.autoIssuance() + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -138,6 +151,15 @@ private constructor( */ fun name(): String? = body.name() + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a supported + * payment provider such as Stripe. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun paymentConfiguration(): PaymentConfiguration? = body.paymentConfiguration() + /** * This is used for creating charges or invoices in an external system via Orb. When not in test * mode: @@ -250,9 +272,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -351,6 +373,13 @@ private constructor( */ fun _autoCollection(): JsonField = body._autoCollection() + /** + * Returns the raw JSON value of [autoIssuance]. + * + * Unlike [autoIssuance], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _autoIssuance(): JsonField = body._autoIssuance() + /** * Returns the raw JSON value of [billingAddress]. * @@ -408,6 +437,14 @@ private constructor( */ fun _name(): JsonField = body._name() + /** + * Returns the raw JSON value of [paymentConfiguration]. + * + * Unlike [paymentConfiguration], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _paymentConfiguration(): JsonField = body._paymentConfiguration() + /** * Returns the raw JSON value of [paymentProvider]. * @@ -497,8 +534,8 @@ private constructor( * - [accountingSyncConfiguration] * - [additionalEmails] * - [autoCollection] + * - [autoIssuance] * - [billingAddress] - * - [currency] * - etc. */ fun body(body: Body) = apply { this.body = body.toBuilder() } @@ -520,7 +557,8 @@ private constructor( /** * Additional email addresses for this customer. If populated, these email addresses will be - * CC'd for customer communications. + * CC'd for customer communications. The total number of email addresses (including the + * primary email) cannot exceed 50. */ fun additionalEmails(additionalEmails: List?) = apply { body.additionalEmails(additionalEmails) @@ -571,6 +609,32 @@ private constructor( body.autoCollection(autoCollection) } + /** + * Used to determine if invoices for this customer will be automatically issued. If true, + * invoices will be automatically issued. If false, invoices will require manual approval.If + * `null` is specified, the customer's auto issuance setting will be inherited from the + * account-level setting. + */ + fun autoIssuance(autoIssuance: Boolean?) = apply { body.autoIssuance(autoIssuance) } + + /** + * Alias for [Builder.autoIssuance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun autoIssuance(autoIssuance: Boolean) = autoIssuance(autoIssuance as Boolean?) + + /** + * Sets [Builder.autoIssuance] to an arbitrary JSON value. + * + * You should usually call [Builder.autoIssuance] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun autoIssuance(autoIssuance: JsonField) = apply { + body.autoIssuance(autoIssuance) + } + fun billingAddress(billingAddress: AddressInput?) = apply { body.billingAddress(billingAddress) } @@ -693,6 +757,25 @@ private constructor( */ fun name(name: JsonField) = apply { body.name(name) } + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a + * supported payment provider such as Stripe. + */ + fun paymentConfiguration(paymentConfiguration: PaymentConfiguration?) = apply { + body.paymentConfiguration(paymentConfiguration) + } + + /** + * Sets [Builder.paymentConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentConfiguration] with a well-typed + * [PaymentConfiguration] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun paymentConfiguration(paymentConfiguration: JsonField) = apply { + body.paymentConfiguration(paymentConfiguration) + } + /** * This is used for creating charges or invoices in an external system via Orb. When not in * test mode: @@ -834,6 +917,55 @@ private constructor( body.sphereTaxConfiguration(taxExempt) } + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofNumeral(numeral)`. */ + fun taxConfiguration(numeral: TaxConfiguration.Numeral) = apply { + body.taxConfiguration(numeral) + } + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Numeral.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun numeralTaxConfiguration(taxExempt: Boolean) = apply { + body.numeralTaxConfiguration(taxExempt) + } + + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofAnrok(anrok)`. */ + fun taxConfiguration(anrok: TaxConfiguration.Anrok) = apply { body.taxConfiguration(anrok) } + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Anrok.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun anrokTaxConfiguration(taxExempt: Boolean) = apply { + body.anrokTaxConfiguration(taxExempt) + } + + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofStripe(stripe)`. */ + fun taxConfiguration(stripe: TaxConfiguration.Stripe) = apply { + body.taxConfiguration(stripe) + } + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Stripe.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun stripeTaxConfiguration(taxExempt: Boolean) = apply { + body.stripeTaxConfiguration(taxExempt) + } + /** * Tax IDs are commonly required to be displayed on customer invoices, which are added to * the headers of invoices. @@ -907,9 +1039,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -1134,10 +1266,12 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val accountingSyncConfiguration: JsonField, private val additionalEmails: JsonField>, private val autoCollection: JsonField, + private val autoIssuance: JsonField, private val billingAddress: JsonField, private val currency: JsonField, private val email: JsonField, @@ -1146,6 +1280,7 @@ private constructor( private val hierarchy: JsonField, private val metadata: JsonField, private val name: JsonField, + private val paymentConfiguration: JsonField, private val paymentProvider: JsonField, private val paymentProviderId: JsonField, private val reportingConfiguration: JsonField, @@ -1167,6 +1302,9 @@ private constructor( @JsonProperty("auto_collection") @ExcludeMissing autoCollection: JsonField = JsonMissing.of(), + @JsonProperty("auto_issuance") + @ExcludeMissing + autoIssuance: JsonField = JsonMissing.of(), @JsonProperty("billing_address") @ExcludeMissing billingAddress: JsonField = JsonMissing.of(), @@ -1187,6 +1325,9 @@ private constructor( @ExcludeMissing metadata: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("payment_configuration") + @ExcludeMissing + paymentConfiguration: JsonField = JsonMissing.of(), @JsonProperty("payment_provider") @ExcludeMissing paymentProvider: JsonField = JsonMissing.of(), @@ -1209,6 +1350,7 @@ private constructor( accountingSyncConfiguration, additionalEmails, autoCollection, + autoIssuance, billingAddress, currency, email, @@ -1217,6 +1359,7 @@ private constructor( hierarchy, metadata, name, + paymentConfiguration, paymentProvider, paymentProviderId, reportingConfiguration, @@ -1235,7 +1378,8 @@ private constructor( /** * Additional email addresses for this customer. If populated, these email addresses will be - * CC'd for customer communications. + * CC'd for customer communications. The total number of email addresses (including the + * primary email) cannot exceed 50. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1252,6 +1396,17 @@ private constructor( */ fun autoCollection(): Boolean? = autoCollection.getNullable("auto_collection") + /** + * Used to determine if invoices for this customer will be automatically issued. If true, + * invoices will be automatically issued. If false, invoices will require manual approval.If + * `null` is specified, the customer's auto issuance setting will be inherited from the + * account-level setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun autoIssuance(): Boolean? = autoIssuance.getNullable("auto_issuance") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1318,6 +1473,16 @@ private constructor( */ fun name(): String? = name.getNullable("name") + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a + * supported payment provider such as Stripe. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun paymentConfiguration(): PaymentConfiguration? = + paymentConfiguration.getNullable("payment_configuration") + /** * This is used for creating charges or invoices in an external system via Orb. When not in * test mode: @@ -1432,9 +1597,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -1540,6 +1705,16 @@ private constructor( @ExcludeMissing fun _autoCollection(): JsonField = autoCollection + /** + * Returns the raw JSON value of [autoIssuance]. + * + * Unlike [autoIssuance], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("auto_issuance") + @ExcludeMissing + fun _autoIssuance(): JsonField = autoIssuance + /** * Returns the raw JSON value of [billingAddress]. * @@ -1607,6 +1782,16 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + /** + * Returns the raw JSON value of [paymentConfiguration]. + * + * Unlike [paymentConfiguration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("payment_configuration") + @ExcludeMissing + fun _paymentConfiguration(): JsonField = paymentConfiguration + /** * Returns the raw JSON value of [paymentProvider]. * @@ -1689,6 +1874,7 @@ private constructor( JsonMissing.of() private var additionalEmails: JsonField>? = null private var autoCollection: JsonField = JsonMissing.of() + private var autoIssuance: JsonField = JsonMissing.of() private var billingAddress: JsonField = JsonMissing.of() private var currency: JsonField = JsonMissing.of() private var email: JsonField = JsonMissing.of() @@ -1697,6 +1883,7 @@ private constructor( private var hierarchy: JsonField = JsonMissing.of() private var metadata: JsonField = JsonMissing.of() private var name: JsonField = JsonMissing.of() + private var paymentConfiguration: JsonField = JsonMissing.of() private var paymentProvider: JsonField = JsonMissing.of() private var paymentProviderId: JsonField = JsonMissing.of() private var reportingConfiguration: JsonField = @@ -1710,6 +1897,7 @@ private constructor( accountingSyncConfiguration = body.accountingSyncConfiguration additionalEmails = body.additionalEmails.map { it.toMutableList() } autoCollection = body.autoCollection + autoIssuance = body.autoIssuance billingAddress = body.billingAddress currency = body.currency email = body.email @@ -1718,6 +1906,7 @@ private constructor( hierarchy = body.hierarchy metadata = body.metadata name = body.name + paymentConfiguration = body.paymentConfiguration paymentProvider = body.paymentProvider paymentProviderId = body.paymentProviderId reportingConfiguration = body.reportingConfiguration @@ -1744,7 +1933,8 @@ private constructor( /** * Additional email addresses for this customer. If populated, these email addresses - * will be CC'd for customer communications. + * will be CC'd for customer communications. The total number of email addresses + * (including the primary email) cannot exceed 50. */ fun additionalEmails(additionalEmails: List?) = additionalEmails(JsonField.ofNullable(additionalEmails)) @@ -1798,6 +1988,33 @@ private constructor( this.autoCollection = autoCollection } + /** + * Used to determine if invoices for this customer will be automatically issued. If + * true, invoices will be automatically issued. If false, invoices will require manual + * approval.If `null` is specified, the customer's auto issuance setting will be + * inherited from the account-level setting. + */ + fun autoIssuance(autoIssuance: Boolean?) = + autoIssuance(JsonField.ofNullable(autoIssuance)) + + /** + * Alias for [Builder.autoIssuance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun autoIssuance(autoIssuance: Boolean) = autoIssuance(autoIssuance as Boolean?) + + /** + * Sets [Builder.autoIssuance] to an arbitrary JSON value. + * + * You should usually call [Builder.autoIssuance] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun autoIssuance(autoIssuance: JsonField) = apply { + this.autoIssuance = autoIssuance + } + fun billingAddress(billingAddress: AddressInput?) = billingAddress(JsonField.ofNullable(billingAddress)) @@ -1923,6 +2140,25 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** + * Payment configuration for the customer, applicable when using Orb Invoicing with a + * supported payment provider such as Stripe. + */ + fun paymentConfiguration(paymentConfiguration: PaymentConfiguration?) = + paymentConfiguration(JsonField.ofNullable(paymentConfiguration)) + + /** + * Sets [Builder.paymentConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentConfiguration] with a well-typed + * [PaymentConfiguration] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun paymentConfiguration(paymentConfiguration: JsonField) = + apply { + this.paymentConfiguration = paymentConfiguration + } + /** * This is used for creating charges or invoices in an external system via Orb. When not * in test mode: @@ -2068,6 +2304,51 @@ private constructor( .build() ) + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofNumeral(numeral)`. */ + fun taxConfiguration(numeral: TaxConfiguration.Numeral) = + taxConfiguration(TaxConfiguration.ofNumeral(numeral)) + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Numeral.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun numeralTaxConfiguration(taxExempt: Boolean) = + taxConfiguration(TaxConfiguration.Numeral.builder().taxExempt(taxExempt).build()) + + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofAnrok(anrok)`. */ + fun taxConfiguration(anrok: TaxConfiguration.Anrok) = + taxConfiguration(TaxConfiguration.ofAnrok(anrok)) + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Anrok.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun anrokTaxConfiguration(taxExempt: Boolean) = + taxConfiguration(TaxConfiguration.Anrok.builder().taxExempt(taxExempt).build()) + + /** Alias for calling [taxConfiguration] with `TaxConfiguration.ofStripe(stripe)`. */ + fun taxConfiguration(stripe: TaxConfiguration.Stripe) = + taxConfiguration(TaxConfiguration.ofStripe(stripe)) + + /** + * Alias for calling [taxConfiguration] with the following: + * ```kotlin + * TaxConfiguration.Stripe.builder() + * .taxExempt(taxExempt) + * .build() + * ``` + */ + fun stripeTaxConfiguration(taxExempt: Boolean) = + taxConfiguration(TaxConfiguration.Stripe.builder().taxExempt(taxExempt).build()) + /** * Tax IDs are commonly required to be displayed on customer invoices, which are added * to the headers of invoices. @@ -2141,9 +2422,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -2253,6 +2534,7 @@ private constructor( accountingSyncConfiguration, (additionalEmails ?: JsonMissing.of()).map { it.toImmutable() }, autoCollection, + autoIssuance, billingAddress, currency, email, @@ -2261,6 +2543,7 @@ private constructor( hierarchy, metadata, name, + paymentConfiguration, paymentProvider, paymentProviderId, reportingConfiguration, @@ -2281,6 +2564,7 @@ private constructor( accountingSyncConfiguration()?.validate() additionalEmails() autoCollection() + autoIssuance() billingAddress()?.validate() currency() email() @@ -2289,6 +2573,7 @@ private constructor( hierarchy()?.validate() metadata()?.validate() name() + paymentConfiguration()?.validate() paymentProvider()?.validate() paymentProviderId() reportingConfiguration()?.validate() @@ -2316,6 +2601,7 @@ private constructor( (accountingSyncConfiguration.asKnown()?.validity() ?: 0) + (additionalEmails.asKnown()?.size ?: 0) + (if (autoCollection.asKnown() == null) 0 else 1) + + (if (autoIssuance.asKnown() == null) 0 else 1) + (billingAddress.asKnown()?.validity() ?: 0) + (if (currency.asKnown() == null) 0 else 1) + (if (email.asKnown() == null) 0 else 1) + @@ -2324,6 +2610,7 @@ private constructor( (hierarchy.asKnown()?.validity() ?: 0) + (metadata.asKnown()?.validity() ?: 0) + (if (name.asKnown() == null) 0 else 1) + + (paymentConfiguration.asKnown()?.validity() ?: 0) + (paymentProvider.asKnown()?.validity() ?: 0) + (if (paymentProviderId.asKnown() == null) 0 else 1) + (reportingConfiguration.asKnown()?.validity() ?: 0) + @@ -2336,17 +2623,58 @@ private constructor( return true } - return /* spotless:off */ other is Body && accountingSyncConfiguration == other.accountingSyncConfiguration && additionalEmails == other.additionalEmails && autoCollection == other.autoCollection && billingAddress == other.billingAddress && currency == other.currency && email == other.email && emailDelivery == other.emailDelivery && externalCustomerId == other.externalCustomerId && hierarchy == other.hierarchy && metadata == other.metadata && name == other.name && paymentProvider == other.paymentProvider && paymentProviderId == other.paymentProviderId && reportingConfiguration == other.reportingConfiguration && shippingAddress == other.shippingAddress && taxConfiguration == other.taxConfiguration && taxId == other.taxId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + accountingSyncConfiguration == other.accountingSyncConfiguration && + additionalEmails == other.additionalEmails && + autoCollection == other.autoCollection && + autoIssuance == other.autoIssuance && + billingAddress == other.billingAddress && + currency == other.currency && + email == other.email && + emailDelivery == other.emailDelivery && + externalCustomerId == other.externalCustomerId && + hierarchy == other.hierarchy && + metadata == other.metadata && + name == other.name && + paymentConfiguration == other.paymentConfiguration && + paymentProvider == other.paymentProvider && + paymentProviderId == other.paymentProviderId && + reportingConfiguration == other.reportingConfiguration && + shippingAddress == other.shippingAddress && + taxConfiguration == other.taxConfiguration && + taxId == other.taxId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(accountingSyncConfiguration, additionalEmails, autoCollection, billingAddress, currency, email, emailDelivery, externalCustomerId, hierarchy, metadata, name, paymentProvider, paymentProviderId, reportingConfiguration, shippingAddress, taxConfiguration, taxId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + accountingSyncConfiguration, + additionalEmails, + autoCollection, + autoIssuance, + billingAddress, + currency, + email, + emailDelivery, + externalCustomerId, + hierarchy, + metadata, + name, + paymentConfiguration, + paymentProvider, + paymentProviderId, + reportingConfiguration, + shippingAddress, + taxConfiguration, + taxId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Body{accountingSyncConfiguration=$accountingSyncConfiguration, additionalEmails=$additionalEmails, autoCollection=$autoCollection, billingAddress=$billingAddress, currency=$currency, email=$email, emailDelivery=$emailDelivery, externalCustomerId=$externalCustomerId, hierarchy=$hierarchy, metadata=$metadata, name=$name, paymentProvider=$paymentProvider, paymentProviderId=$paymentProviderId, reportingConfiguration=$reportingConfiguration, shippingAddress=$shippingAddress, taxConfiguration=$taxConfiguration, taxId=$taxId, additionalProperties=$additionalProperties}" + "Body{accountingSyncConfiguration=$accountingSyncConfiguration, additionalEmails=$additionalEmails, autoCollection=$autoCollection, autoIssuance=$autoIssuance, billingAddress=$billingAddress, currency=$currency, email=$email, emailDelivery=$emailDelivery, externalCustomerId=$externalCustomerId, hierarchy=$hierarchy, metadata=$metadata, name=$name, paymentConfiguration=$paymentConfiguration, paymentProvider=$paymentProvider, paymentProviderId=$paymentProviderId, reportingConfiguration=$reportingConfiguration, shippingAddress=$shippingAddress, taxConfiguration=$taxConfiguration, taxId=$taxId, additionalProperties=$additionalProperties}" } /** @@ -2441,12 +2769,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2454,86 +2780,626 @@ private constructor( } /** - * This is used for creating charges or invoices in an external system via Orb. When not in test - * mode: - * - the connection must first be configured in the Orb webapp. - * - if the provider is an invoicing provider (`stripe_invoice`, `quickbooks`, `bill.com`, - * `netsuite`), any product mappings must first be configured with the Orb team. + * Payment configuration for the customer, applicable when using Orb Invoicing with a supported + * payment provider such as Stripe. */ - class PaymentProvider @JsonCreator private constructor(private val value: JsonField) : - Enum { + class PaymentConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val paymentProviders: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("payment_providers") + @ExcludeMissing + paymentProviders: JsonField> = JsonMissing.of() + ) : this(paymentProviders, mutableMapOf()) /** - * Returns this class instance's raw value. + * Provider-specific payment configuration. * - * 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 OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { + fun paymentProviders(): List? = + paymentProviders.getNullable("payment_providers") - val QUICKBOOKS = of("quickbooks") + /** + * Returns the raw JSON value of [paymentProviders]. + * + * Unlike [paymentProviders], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("payment_providers") + @ExcludeMissing + fun _paymentProviders(): JsonField> = paymentProviders - val BILL_COM = of("bill.com") + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - val STRIPE_CHARGE = of("stripe_charge") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - val STRIPE_INVOICE = of("stripe_invoice") + fun toBuilder() = Builder().from(this) - val NETSUITE = of("netsuite") + companion object { - fun of(value: String) = PaymentProvider(JsonField.of(value)) + /** Returns a mutable builder for constructing an instance of [PaymentConfiguration]. */ + fun builder() = Builder() } - /** An enum containing [PaymentProvider]'s known values. */ - enum class Known { - QUICKBOOKS, - BILL_COM, - STRIPE_CHARGE, - STRIPE_INVOICE, - NETSUITE, - } + /** A builder for [PaymentConfiguration]. */ + class Builder internal constructor() { + + private var paymentProviders: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(paymentConfiguration: PaymentConfiguration) = apply { + paymentProviders = paymentConfiguration.paymentProviders.map { it.toMutableList() } + additionalProperties = paymentConfiguration.additionalProperties.toMutableMap() + } + + /** Provider-specific payment configuration. */ + fun paymentProviders(paymentProviders: List) = + paymentProviders(JsonField.of(paymentProviders)) - /** - * An enum containing [PaymentProvider]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [PaymentProvider] 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 { - QUICKBOOKS, - BILL_COM, - STRIPE_CHARGE, - STRIPE_INVOICE, - NETSUITE, /** - * An enum member indicating that [PaymentProvider] was instantiated with an unknown - * value. + * Sets [Builder.paymentProviders] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentProviders] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. */ - _UNKNOWN, - } + fun paymentProviders(paymentProviders: JsonField>) = apply { + this.paymentProviders = paymentProviders.map { it.toMutableList() } + } - /** - * 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) { - QUICKBOOKS -> Value.QUICKBOOKS - BILL_COM -> Value.BILL_COM - STRIPE_CHARGE -> Value.STRIPE_CHARGE - STRIPE_INVOICE -> Value.STRIPE_INVOICE - NETSUITE -> Value.NETSUITE - else -> Value._UNKNOWN + /** + * Adds a single [PaymentProvider] to [paymentProviders]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPaymentProvider(paymentProvider: PaymentProvider) = apply { + paymentProviders = + (paymentProviders ?: JsonField.of(mutableListOf())).also { + checkKnown("paymentProviders", it).add(paymentProvider) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PaymentConfiguration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): PaymentConfiguration = + PaymentConfiguration( + (paymentProviders ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PaymentConfiguration = apply { + if (validated) { + return@apply + } + + paymentProviders()?.forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (paymentProviders.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + class PaymentProvider + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val providerType: JsonField, + private val excludedPaymentMethodTypes: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("provider_type") + @ExcludeMissing + providerType: JsonField = JsonMissing.of(), + @JsonProperty("excluded_payment_method_types") + @ExcludeMissing + excludedPaymentMethodTypes: JsonField> = JsonMissing.of(), + ) : this(providerType, excludedPaymentMethodTypes, mutableMapOf()) + + /** + * The payment provider to configure. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun providerType(): ProviderType = providerType.getRequired("provider_type") + + /** + * List of Stripe payment method types to exclude for this customer. Excluded payment + * methods will not be available for the customer to select during payment, and will not + * be used for auto-collection. If a customer's default payment method becomes excluded, + * Orb will attempt to use the next available compatible payment method for + * auto-collection. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun excludedPaymentMethodTypes(): List? = + excludedPaymentMethodTypes.getNullable("excluded_payment_method_types") + + /** + * Returns the raw JSON value of [providerType]. + * + * Unlike [providerType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("provider_type") + @ExcludeMissing + fun _providerType(): JsonField = providerType + + /** + * Returns the raw JSON value of [excludedPaymentMethodTypes]. + * + * Unlike [excludedPaymentMethodTypes], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("excluded_payment_method_types") + @ExcludeMissing + fun _excludedPaymentMethodTypes(): JsonField> = excludedPaymentMethodTypes + + @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 [PaymentProvider]. + * + * The following fields are required: + * ```kotlin + * .providerType() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PaymentProvider]. */ + class Builder internal constructor() { + + private var providerType: JsonField? = null + private var excludedPaymentMethodTypes: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(paymentProvider: PaymentProvider) = apply { + providerType = paymentProvider.providerType + excludedPaymentMethodTypes = + paymentProvider.excludedPaymentMethodTypes.map { it.toMutableList() } + additionalProperties = paymentProvider.additionalProperties.toMutableMap() + } + + /** The payment provider to configure. */ + fun providerType(providerType: ProviderType) = + providerType(JsonField.of(providerType)) + + /** + * Sets [Builder.providerType] to an arbitrary JSON value. + * + * You should usually call [Builder.providerType] with a well-typed [ProviderType] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun providerType(providerType: JsonField) = apply { + this.providerType = providerType + } + + /** + * List of Stripe payment method types to exclude for this customer. Excluded + * payment methods will not be available for the customer to select during payment, + * and will not be used for auto-collection. If a customer's default payment method + * becomes excluded, Orb will attempt to use the next available compatible payment + * method for auto-collection. + */ + fun excludedPaymentMethodTypes(excludedPaymentMethodTypes: List) = + excludedPaymentMethodTypes(JsonField.of(excludedPaymentMethodTypes)) + + /** + * Sets [Builder.excludedPaymentMethodTypes] to an arbitrary JSON value. + * + * You should usually call [Builder.excludedPaymentMethodTypes] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun excludedPaymentMethodTypes( + excludedPaymentMethodTypes: JsonField> + ) = apply { + this.excludedPaymentMethodTypes = + excludedPaymentMethodTypes.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [excludedPaymentMethodTypes]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExcludedPaymentMethodType(excludedPaymentMethodType: String) = apply { + excludedPaymentMethodTypes = + (excludedPaymentMethodTypes ?: JsonField.of(mutableListOf())).also { + checkKnown("excludedPaymentMethodTypes", it) + .add(excludedPaymentMethodType) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PaymentProvider]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .providerType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PaymentProvider = + PaymentProvider( + checkRequired("providerType", providerType), + (excludedPaymentMethodTypes ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PaymentProvider = apply { + if (validated) { + return@apply + } + + providerType().validate() + excludedPaymentMethodTypes() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (providerType.asKnown()?.validity() ?: 0) + + (excludedPaymentMethodTypes.asKnown()?.size ?: 0) + + /** The payment provider to configure. */ + class ProviderType + @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 { + + val STRIPE = of("stripe") + + fun of(value: String) = ProviderType(JsonField.of(value)) + } + + /** An enum containing [ProviderType]'s known values. */ + enum class Known { + STRIPE + } + + /** + * An enum containing [ProviderType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [ProviderType] 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 [ProviderType] 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + STRIPE -> Known.STRIPE + else -> throw OrbInvalidDataException("Unknown ProviderType: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): ProviderType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 ProviderType && 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 PaymentProvider && + providerType == other.providerType && + excludedPaymentMethodTypes == other.excludedPaymentMethodTypes && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(providerType, excludedPaymentMethodTypes, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PaymentProvider{providerType=$providerType, excludedPaymentMethodTypes=$excludedPaymentMethodTypes, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PaymentConfiguration && + paymentProviders == other.paymentProviders && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(paymentProviders, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PaymentConfiguration{paymentProviders=$paymentProviders, additionalProperties=$additionalProperties}" + } + + /** + * This is used for creating charges or invoices in an external system via Orb. When not in test + * mode: + * - the connection must first be configured in the Orb webapp. + * - if the provider is an invoicing provider (`stripe_invoice`, `quickbooks`, `bill.com`, + * `netsuite`), any product mappings must first be configured with the Orb team. + */ + class PaymentProvider @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 { + + val QUICKBOOKS = of("quickbooks") + + val BILL_COM = of("bill.com") + + val STRIPE_CHARGE = of("stripe_charge") + + val STRIPE_INVOICE = of("stripe_invoice") + + val NETSUITE = of("netsuite") + + fun of(value: String) = PaymentProvider(JsonField.of(value)) + } + + /** An enum containing [PaymentProvider]'s known values. */ + enum class Known { + QUICKBOOKS, + BILL_COM, + STRIPE_CHARGE, + STRIPE_INVOICE, + NETSUITE, + } + + /** + * An enum containing [PaymentProvider]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [PaymentProvider] 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 { + QUICKBOOKS, + BILL_COM, + STRIPE_CHARGE, + STRIPE_INVOICE, + NETSUITE, + /** + * An enum member indicating that [PaymentProvider] 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) { + QUICKBOOKS -> Value.QUICKBOOKS + BILL_COM -> Value.BILL_COM + STRIPE_CHARGE -> Value.STRIPE_CHARGE + STRIPE_INVOICE -> Value.STRIPE_INVOICE + NETSUITE -> Value.NETSUITE + else -> Value._UNKNOWN } /** @@ -2598,7 +3464,7 @@ private constructor( return true } - return /* spotless:off */ other is PaymentProvider && value == other.value /* spotless:on */ + return other is PaymentProvider && value == other.value } override fun hashCode() = value.hashCode() @@ -2613,6 +3479,9 @@ private constructor( private val avalara: NewAvalaraTaxConfiguration? = null, private val taxjar: NewTaxJarConfiguration? = null, private val sphere: NewSphereConfiguration? = null, + private val numeral: Numeral? = null, + private val anrok: Anrok? = null, + private val stripe: Stripe? = null, private val _json: JsonValue? = null, ) { @@ -2622,18 +3491,36 @@ private constructor( fun sphere(): NewSphereConfiguration? = sphere + fun numeral(): Numeral? = numeral + + fun anrok(): Anrok? = anrok + + fun stripe(): Stripe? = stripe + fun isAvalara(): Boolean = avalara != null fun isTaxjar(): Boolean = taxjar != null fun isSphere(): Boolean = sphere != null + fun isNumeral(): Boolean = numeral != null + + fun isAnrok(): Boolean = anrok != null + + fun isStripe(): Boolean = stripe != null + fun asAvalara(): NewAvalaraTaxConfiguration = avalara.getOrThrow("avalara") fun asTaxjar(): NewTaxJarConfiguration = taxjar.getOrThrow("taxjar") fun asSphere(): NewSphereConfiguration = sphere.getOrThrow("sphere") + fun asNumeral(): Numeral = numeral.getOrThrow("numeral") + + fun asAnrok(): Anrok = anrok.getOrThrow("anrok") + + fun asStripe(): Stripe = stripe.getOrThrow("stripe") + fun _json(): JsonValue? = _json fun accept(visitor: Visitor): T = @@ -2641,6 +3528,9 @@ private constructor( avalara != null -> visitor.visitAvalara(avalara) taxjar != null -> visitor.visitTaxjar(taxjar) sphere != null -> visitor.visitSphere(sphere) + numeral != null -> visitor.visitNumeral(numeral) + anrok != null -> visitor.visitAnrok(anrok) + stripe != null -> visitor.visitStripe(stripe) else -> visitor.unknown(_json) } @@ -2664,6 +3554,18 @@ private constructor( override fun visitSphere(sphere: NewSphereConfiguration) { sphere.validate() } + + override fun visitNumeral(numeral: Numeral) { + numeral.validate() + } + + override fun visitAnrok(anrok: Anrok) { + anrok.validate() + } + + override fun visitStripe(stripe: Stripe) { + stripe.validate() + } } ) validated = true @@ -2693,6 +3595,12 @@ private constructor( override fun visitSphere(sphere: NewSphereConfiguration) = sphere.validity() + override fun visitNumeral(numeral: Numeral) = numeral.validity() + + override fun visitAnrok(anrok: Anrok) = anrok.validity() + + override fun visitStripe(stripe: Stripe) = stripe.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -2702,16 +3610,25 @@ private constructor( return true } - return /* spotless:off */ other is TaxConfiguration && avalara == other.avalara && taxjar == other.taxjar && sphere == other.sphere /* spotless:on */ + return other is TaxConfiguration && + avalara == other.avalara && + taxjar == other.taxjar && + sphere == other.sphere && + numeral == other.numeral && + anrok == other.anrok && + stripe == other.stripe } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(avalara, taxjar, sphere) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(avalara, taxjar, sphere, numeral, anrok, stripe) override fun toString(): String = when { avalara != null -> "TaxConfiguration{avalara=$avalara}" taxjar != null -> "TaxConfiguration{taxjar=$taxjar}" sphere != null -> "TaxConfiguration{sphere=$sphere}" + numeral != null -> "TaxConfiguration{numeral=$numeral}" + anrok != null -> "TaxConfiguration{anrok=$anrok}" + stripe != null -> "TaxConfiguration{stripe=$stripe}" _json != null -> "TaxConfiguration{_unknown=$_json}" else -> throw IllegalStateException("Invalid TaxConfiguration") } @@ -2723,6 +3640,12 @@ private constructor( fun ofTaxjar(taxjar: NewTaxJarConfiguration) = TaxConfiguration(taxjar = taxjar) fun ofSphere(sphere: NewSphereConfiguration) = TaxConfiguration(sphere = sphere) + + fun ofNumeral(numeral: Numeral) = TaxConfiguration(numeral = numeral) + + fun ofAnrok(anrok: Anrok) = TaxConfiguration(anrok = anrok) + + fun ofStripe(stripe: Stripe) = TaxConfiguration(stripe = stripe) } /** @@ -2737,6 +3660,12 @@ private constructor( fun visitSphere(sphere: NewSphereConfiguration): T + fun visitNumeral(numeral: Numeral): T + + fun visitAnrok(anrok: Anrok): T + + fun visitStripe(stripe: Stripe): T + /** * Maps an unknown variant of [TaxConfiguration] to a value of type [T]. * @@ -2774,6 +3703,21 @@ private constructor( TaxConfiguration(sphere = it, _json = json) } ?: TaxConfiguration(_json = json) } + "numeral" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TaxConfiguration(numeral = it, _json = json) + } ?: TaxConfiguration(_json = json) + } + "anrok" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TaxConfiguration(anrok = it, _json = json) + } ?: TaxConfiguration(_json = json) + } + "stripe" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TaxConfiguration(stripe = it, _json = json) + } ?: TaxConfiguration(_json = json) + } } return TaxConfiguration(_json = json) @@ -2791,11 +3735,806 @@ private constructor( value.avalara != null -> generator.writeObject(value.avalara) value.taxjar != null -> generator.writeObject(value.taxjar) value.sphere != null -> generator.writeObject(value.sphere) + value.numeral != null -> generator.writeObject(value.numeral) + value.anrok != null -> generator.writeObject(value.anrok) + value.stripe != null -> generator.writeObject(value.stripe) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid TaxConfiguration") } } } + + class Numeral + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val taxExempt: JsonField, + private val taxProvider: JsonValue, + private val automaticTaxEnabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tax_exempt") + @ExcludeMissing + taxExempt: JsonField = JsonMissing.of(), + @JsonProperty("tax_provider") + @ExcludeMissing + taxProvider: JsonValue = JsonMissing.of(), + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + automaticTaxEnabled: JsonField = JsonMissing.of(), + ) : this(taxExempt, taxProvider, automaticTaxEnabled, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun taxExempt(): Boolean = taxExempt.getRequired("tax_exempt") + + /** + * Expected to always return the following: + * ```kotlin + * JsonValue.from("numeral") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("tax_provider") + @ExcludeMissing + fun _taxProvider(): JsonValue = taxProvider + + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun automaticTaxEnabled(): Boolean? = + automaticTaxEnabled.getNullable("automatic_tax_enabled") + + /** + * Returns the raw JSON value of [taxExempt]. + * + * Unlike [taxExempt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tax_exempt") + @ExcludeMissing + fun _taxExempt(): JsonField = taxExempt + + /** + * Returns the raw JSON value of [automaticTaxEnabled]. + * + * Unlike [automaticTaxEnabled], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + fun _automaticTaxEnabled(): JsonField = automaticTaxEnabled + + @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 [Numeral]. + * + * The following fields are required: + * ```kotlin + * .taxExempt() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Numeral]. */ + class Builder internal constructor() { + + private var taxExempt: JsonField? = null + private var taxProvider: JsonValue = JsonValue.from("numeral") + private var automaticTaxEnabled: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(numeral: Numeral) = apply { + taxExempt = numeral.taxExempt + taxProvider = numeral.taxProvider + automaticTaxEnabled = numeral.automaticTaxEnabled + additionalProperties = numeral.additionalProperties.toMutableMap() + } + + fun taxExempt(taxExempt: Boolean) = taxExempt(JsonField.of(taxExempt)) + + /** + * Sets [Builder.taxExempt] to an arbitrary JSON value. + * + * You should usually call [Builder.taxExempt] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun taxExempt(taxExempt: JsonField) = apply { this.taxExempt = taxExempt } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("numeral") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun taxProvider(taxProvider: JsonValue) = apply { this.taxProvider = taxProvider } + + /** + * Whether to automatically calculate tax for this customer. When null, inherits + * from account-level setting. When true or false, overrides the account setting. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean?) = + automaticTaxEnabled(JsonField.ofNullable(automaticTaxEnabled)) + + /** + * Alias for [Builder.automaticTaxEnabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean) = + automaticTaxEnabled(automaticTaxEnabled as Boolean?) + + /** + * Sets [Builder.automaticTaxEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticTaxEnabled] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: JsonField) = apply { + this.automaticTaxEnabled = automaticTaxEnabled + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Numeral]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .taxExempt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Numeral = + Numeral( + checkRequired("taxExempt", taxExempt), + taxProvider, + automaticTaxEnabled, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Numeral = apply { + if (validated) { + return@apply + } + + taxExempt() + _taxProvider().let { + if (it != JsonValue.from("numeral")) { + throw OrbInvalidDataException("'taxProvider' is invalid, received $it") + } + } + automaticTaxEnabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (taxExempt.asKnown() == null) 0 else 1) + + taxProvider.let { if (it == JsonValue.from("numeral")) 1 else 0 } + + (if (automaticTaxEnabled.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Numeral && + taxExempt == other.taxExempt && + taxProvider == other.taxProvider && + automaticTaxEnabled == other.automaticTaxEnabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(taxExempt, taxProvider, automaticTaxEnabled, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Numeral{taxExempt=$taxExempt, taxProvider=$taxProvider, automaticTaxEnabled=$automaticTaxEnabled, additionalProperties=$additionalProperties}" + } + + class Anrok + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val taxExempt: JsonField, + private val taxProvider: JsonValue, + private val automaticTaxEnabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tax_exempt") + @ExcludeMissing + taxExempt: JsonField = JsonMissing.of(), + @JsonProperty("tax_provider") + @ExcludeMissing + taxProvider: JsonValue = JsonMissing.of(), + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + automaticTaxEnabled: JsonField = JsonMissing.of(), + ) : this(taxExempt, taxProvider, automaticTaxEnabled, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun taxExempt(): Boolean = taxExempt.getRequired("tax_exempt") + + /** + * Expected to always return the following: + * ```kotlin + * JsonValue.from("anrok") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("tax_provider") + @ExcludeMissing + fun _taxProvider(): JsonValue = taxProvider + + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun automaticTaxEnabled(): Boolean? = + automaticTaxEnabled.getNullable("automatic_tax_enabled") + + /** + * Returns the raw JSON value of [taxExempt]. + * + * Unlike [taxExempt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tax_exempt") + @ExcludeMissing + fun _taxExempt(): JsonField = taxExempt + + /** + * Returns the raw JSON value of [automaticTaxEnabled]. + * + * Unlike [automaticTaxEnabled], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + fun _automaticTaxEnabled(): JsonField = automaticTaxEnabled + + @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 [Anrok]. + * + * The following fields are required: + * ```kotlin + * .taxExempt() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Anrok]. */ + class Builder internal constructor() { + + private var taxExempt: JsonField? = null + private var taxProvider: JsonValue = JsonValue.from("anrok") + private var automaticTaxEnabled: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(anrok: Anrok) = apply { + taxExempt = anrok.taxExempt + taxProvider = anrok.taxProvider + automaticTaxEnabled = anrok.automaticTaxEnabled + additionalProperties = anrok.additionalProperties.toMutableMap() + } + + fun taxExempt(taxExempt: Boolean) = taxExempt(JsonField.of(taxExempt)) + + /** + * Sets [Builder.taxExempt] to an arbitrary JSON value. + * + * You should usually call [Builder.taxExempt] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun taxExempt(taxExempt: JsonField) = apply { this.taxExempt = taxExempt } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("anrok") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun taxProvider(taxProvider: JsonValue) = apply { this.taxProvider = taxProvider } + + /** + * Whether to automatically calculate tax for this customer. When null, inherits + * from account-level setting. When true or false, overrides the account setting. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean?) = + automaticTaxEnabled(JsonField.ofNullable(automaticTaxEnabled)) + + /** + * Alias for [Builder.automaticTaxEnabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean) = + automaticTaxEnabled(automaticTaxEnabled as Boolean?) + + /** + * Sets [Builder.automaticTaxEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticTaxEnabled] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: JsonField) = apply { + this.automaticTaxEnabled = automaticTaxEnabled + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Anrok]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .taxExempt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Anrok = + Anrok( + checkRequired("taxExempt", taxExempt), + taxProvider, + automaticTaxEnabled, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Anrok = apply { + if (validated) { + return@apply + } + + taxExempt() + _taxProvider().let { + if (it != JsonValue.from("anrok")) { + throw OrbInvalidDataException("'taxProvider' is invalid, received $it") + } + } + automaticTaxEnabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (taxExempt.asKnown() == null) 0 else 1) + + taxProvider.let { if (it == JsonValue.from("anrok")) 1 else 0 } + + (if (automaticTaxEnabled.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Anrok && + taxExempt == other.taxExempt && + taxProvider == other.taxProvider && + automaticTaxEnabled == other.automaticTaxEnabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(taxExempt, taxProvider, automaticTaxEnabled, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Anrok{taxExempt=$taxExempt, taxProvider=$taxProvider, automaticTaxEnabled=$automaticTaxEnabled, additionalProperties=$additionalProperties}" + } + + class Stripe + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val taxExempt: JsonField, + private val taxProvider: JsonValue, + private val automaticTaxEnabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tax_exempt") + @ExcludeMissing + taxExempt: JsonField = JsonMissing.of(), + @JsonProperty("tax_provider") + @ExcludeMissing + taxProvider: JsonValue = JsonMissing.of(), + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + automaticTaxEnabled: JsonField = JsonMissing.of(), + ) : this(taxExempt, taxProvider, automaticTaxEnabled, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun taxExempt(): Boolean = taxExempt.getRequired("tax_exempt") + + /** + * Expected to always return the following: + * ```kotlin + * JsonValue.from("stripe") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("tax_provider") + @ExcludeMissing + fun _taxProvider(): JsonValue = taxProvider + + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun automaticTaxEnabled(): Boolean? = + automaticTaxEnabled.getNullable("automatic_tax_enabled") + + /** + * Returns the raw JSON value of [taxExempt]. + * + * Unlike [taxExempt], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tax_exempt") + @ExcludeMissing + fun _taxExempt(): JsonField = taxExempt + + /** + * Returns the raw JSON value of [automaticTaxEnabled]. + * + * Unlike [automaticTaxEnabled], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + fun _automaticTaxEnabled(): JsonField = automaticTaxEnabled + + @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: + * ```kotlin + * .taxExempt() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Stripe]. */ + class Builder internal constructor() { + + private var taxExempt: JsonField? = null + private var taxProvider: JsonValue = JsonValue.from("stripe") + private var automaticTaxEnabled: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(stripe: Stripe) = apply { + taxExempt = stripe.taxExempt + taxProvider = stripe.taxProvider + automaticTaxEnabled = stripe.automaticTaxEnabled + additionalProperties = stripe.additionalProperties.toMutableMap() + } + + fun taxExempt(taxExempt: Boolean) = taxExempt(JsonField.of(taxExempt)) + + /** + * Sets [Builder.taxExempt] to an arbitrary JSON value. + * + * You should usually call [Builder.taxExempt] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun taxExempt(taxExempt: JsonField) = apply { this.taxExempt = taxExempt } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("stripe") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun taxProvider(taxProvider: JsonValue) = apply { this.taxProvider = taxProvider } + + /** + * Whether to automatically calculate tax for this customer. When null, inherits + * from account-level setting. When true or false, overrides the account setting. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean?) = + automaticTaxEnabled(JsonField.ofNullable(automaticTaxEnabled)) + + /** + * Alias for [Builder.automaticTaxEnabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean) = + automaticTaxEnabled(automaticTaxEnabled as Boolean?) + + /** + * Sets [Builder.automaticTaxEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticTaxEnabled] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: JsonField) = apply { + this.automaticTaxEnabled = automaticTaxEnabled + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .taxExempt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Stripe = + Stripe( + checkRequired("taxExempt", taxExempt), + taxProvider, + automaticTaxEnabled, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Stripe = apply { + if (validated) { + return@apply + } + + taxExempt() + _taxProvider().let { + if (it != JsonValue.from("stripe")) { + throw OrbInvalidDataException("'taxProvider' is invalid, received $it") + } + } + automaticTaxEnabled() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (taxExempt.asKnown() == null) 0 else 1) + + taxProvider.let { if (it == JsonValue.from("stripe")) 1 else 0 } + + (if (automaticTaxEnabled.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Stripe && + taxExempt == other.taxExempt && + taxProvider == other.taxProvider && + automaticTaxEnabled == other.automaticTaxEnabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(taxExempt, taxProvider, automaticTaxEnabled, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Stripe{taxExempt=$taxExempt, taxProvider=$taxProvider, automaticTaxEnabled=$automaticTaxEnabled, additionalProperties=$additionalProperties}" + } } override fun equals(other: Any?): Boolean { @@ -2803,10 +4542,15 @@ private constructor( return true } - return /* spotless:off */ other is CustomerUpdateParams && customerId == other.customerId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is CustomerUpdateParams && + customerId == other.customerId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customerId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(customerId, body, additionalHeaders, additionalQueryParams) override fun toString() = "CustomerUpdateParams{customerId=$customerId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DecrementLedgerEntry.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DecrementLedgerEntry.kt index f91c0c80f..6d0b26325 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DecrementLedgerEntry.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DecrementLedgerEntry.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class DecrementLedgerEntry +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, @@ -829,7 +830,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryStatus && value == other.value /* spotless:on */ + return other is EntryStatus && value == other.value } override fun hashCode() = value.hashCode() @@ -949,7 +950,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryType && value == other.value /* spotless:on */ + return other is EntryType && value == other.value } override fun hashCode() = value.hashCode() @@ -1049,12 +1050,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1066,12 +1065,47 @@ private constructor( return true } - return /* spotless:off */ other is DecrementLedgerEntry && id == other.id && amount == other.amount && createdAt == other.createdAt && creditBlock == other.creditBlock && currency == other.currency && customer == other.customer && description == other.description && endingBalance == other.endingBalance && entryStatus == other.entryStatus && entryType == other.entryType && ledgerSequenceNumber == other.ledgerSequenceNumber && metadata == other.metadata && startingBalance == other.startingBalance && eventId == other.eventId && invoiceId == other.invoiceId && priceId == other.priceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is DecrementLedgerEntry && + id == other.id && + amount == other.amount && + createdAt == other.createdAt && + creditBlock == other.creditBlock && + currency == other.currency && + customer == other.customer && + description == other.description && + endingBalance == other.endingBalance && + entryStatus == other.entryStatus && + entryType == other.entryType && + ledgerSequenceNumber == other.ledgerSequenceNumber && + metadata == other.metadata && + startingBalance == other.startingBalance && + eventId == other.eventId && + invoiceId == other.invoiceId && + priceId == other.priceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, createdAt, creditBlock, currency, customer, description, endingBalance, entryStatus, entryType, ledgerSequenceNumber, metadata, startingBalance, eventId, invoiceId, priceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + createdAt, + creditBlock, + currency, + customer, + description, + endingBalance, + entryStatus, + entryType, + ledgerSequenceNumber, + metadata, + startingBalance, + eventId, + invoiceId, + priceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceConfiguration.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceConfiguration.kt index 592151d5a..bdebb97b8 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceConfiguration.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceConfiguration.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class DimensionalPriceConfiguration +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val dimensionValues: JsonField>, private val dimensionalPriceGroupId: JsonField, @@ -221,12 +222,15 @@ private constructor( return true } - return /* spotless:off */ other is DimensionalPriceConfiguration && dimensionValues == other.dimensionValues && dimensionalPriceGroupId == other.dimensionalPriceGroupId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is DimensionalPriceConfiguration && + dimensionValues == other.dimensionValues && + dimensionalPriceGroupId == other.dimensionalPriceGroupId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(dimensionValues, dimensionalPriceGroupId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(dimensionValues, dimensionalPriceGroupId, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroup.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroup.kt index 7cb9c7e5a..7f20c1500 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroup.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroup.kt @@ -22,6 +22,7 @@ import java.util.Objects * dimensions. Prices in a price group must specify the parition used to derive their usage. */ class DimensionalPriceGroup +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetricId: JsonField, @@ -481,12 +482,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -498,12 +497,27 @@ private constructor( return true } - return /* spotless:off */ other is DimensionalPriceGroup && id == other.id && billableMetricId == other.billableMetricId && dimensions == other.dimensions && externalDimensionalPriceGroupId == other.externalDimensionalPriceGroupId && metadata == other.metadata && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is DimensionalPriceGroup && + id == other.id && + billableMetricId == other.billableMetricId && + dimensions == other.dimensions && + externalDimensionalPriceGroupId == other.externalDimensionalPriceGroupId && + metadata == other.metadata && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetricId, dimensions, externalDimensionalPriceGroupId, metadata, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetricId, + dimensions, + externalDimensionalPriceGroupId, + metadata, + name, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupCreateParams.kt index ba42ad8ba..192835cad 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupCreateParams.kt @@ -22,7 +22,7 @@ import java.util.Objects /** * A dimensional price group is used to partition the result of a billable metric by a set of - * dimensions. Prices in a price group must specify the parition used to derive their usage. + * dimensions. Prices in a price group must specify the partition used to derive their usage. * * For example, suppose we have a billable metric that measures the number of widgets used and we * want to charge differently depending on the color of the widget. We can create a price group with @@ -387,6 +387,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val billableMetricId: JsonField, private val dimensions: JsonField>, @@ -714,13 +715,26 @@ private constructor( return true } - return /* spotless:off */ other is Body && billableMetricId == other.billableMetricId && dimensions == other.dimensions && name == other.name && externalDimensionalPriceGroupId == other.externalDimensionalPriceGroupId && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + billableMetricId == other.billableMetricId && + dimensions == other.dimensions && + name == other.name && + externalDimensionalPriceGroupId == other.externalDimensionalPriceGroupId && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + billableMetricId, + dimensions, + name, + externalDimensionalPriceGroupId, + metadata, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(billableMetricId, dimensions, name, externalDimensionalPriceGroupId, metadata, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = @@ -819,12 +833,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -836,10 +848,13 @@ private constructor( return true } - return /* spotless:off */ other is DimensionalPriceGroupCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DimensionalPriceGroupCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "DimensionalPriceGroupCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupExternalDimensionalPriceGroupIdRetrieveParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupExternalDimensionalPriceGroupIdRetrieveParams.kt index 8477f874c..e6db24899 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupExternalDimensionalPriceGroupIdRetrieveParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupExternalDimensionalPriceGroupIdRetrieveParams.kt @@ -191,10 +191,14 @@ private constructor( return true } - return /* spotless:off */ other is DimensionalPriceGroupExternalDimensionalPriceGroupIdRetrieveParams && externalDimensionalPriceGroupId == other.externalDimensionalPriceGroupId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DimensionalPriceGroupExternalDimensionalPriceGroupIdRetrieveParams && + externalDimensionalPriceGroupId == other.externalDimensionalPriceGroupId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalDimensionalPriceGroupId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(externalDimensionalPriceGroupId, additionalHeaders, additionalQueryParams) override fun toString() = "DimensionalPriceGroupExternalDimensionalPriceGroupIdRetrieveParams{externalDimensionalPriceGroupId=$externalDimensionalPriceGroupId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupExternalDimensionalPriceGroupIdUpdateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupExternalDimensionalPriceGroupIdUpdateParams.kt index c1170b681..681ece4ba 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupExternalDimensionalPriceGroupIdUpdateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupExternalDimensionalPriceGroupIdUpdateParams.kt @@ -313,6 +313,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val bodyExternalDimensionalPriceGroupId: JsonField, private val metadata: JsonField, @@ -505,12 +506,15 @@ private constructor( return true } - return /* spotless:off */ other is Body && bodyExternalDimensionalPriceGroupId == other.bodyExternalDimensionalPriceGroupId && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + bodyExternalDimensionalPriceGroupId == other.bodyExternalDimensionalPriceGroupId && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bodyExternalDimensionalPriceGroupId, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(bodyExternalDimensionalPriceGroupId, metadata, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -610,12 +614,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -627,10 +629,20 @@ private constructor( return true } - return /* spotless:off */ other is DimensionalPriceGroupExternalDimensionalPriceGroupIdUpdateParams && pathExternalDimensionalPriceGroupId == other.pathExternalDimensionalPriceGroupId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DimensionalPriceGroupExternalDimensionalPriceGroupIdUpdateParams && + pathExternalDimensionalPriceGroupId == other.pathExternalDimensionalPriceGroupId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(pathExternalDimensionalPriceGroupId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + pathExternalDimensionalPriceGroupId, + body, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "DimensionalPriceGroupExternalDimensionalPriceGroupIdUpdateParams{pathExternalDimensionalPriceGroupId=$pathExternalDimensionalPriceGroupId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPage.kt index 553b0012d..c4c1c79b2 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPage.kt @@ -120,10 +120,13 @@ private constructor( return true } - return /* spotless:off */ other is DimensionalPriceGroupListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is DimensionalPriceGroupListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "DimensionalPriceGroupListPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPageAsync.kt index 612c000a9..5eed83c49 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPageAsync.kt @@ -122,10 +122,13 @@ private constructor( return true } - return /* spotless:off */ other is DimensionalPriceGroupListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is DimensionalPriceGroupListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "DimensionalPriceGroupListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListParams.kt index effb098e0..1bd7e151f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListParams.kt @@ -205,10 +205,15 @@ private constructor( return true } - return /* spotless:off */ other is DimensionalPriceGroupListParams && cursor == other.cursor && limit == other.limit && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DimensionalPriceGroupListParams && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(cursor, limit, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(cursor, limit, additionalHeaders, additionalQueryParams) override fun toString() = "DimensionalPriceGroupListParams{cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupRetrieveParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupRetrieveParams.kt index b56f6a904..fb45e6a94 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupRetrieveParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupRetrieveParams.kt @@ -182,10 +182,14 @@ private constructor( return true } - return /* spotless:off */ other is DimensionalPriceGroupRetrieveParams && dimensionalPriceGroupId == other.dimensionalPriceGroupId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DimensionalPriceGroupRetrieveParams && + dimensionalPriceGroupId == other.dimensionalPriceGroupId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(dimensionalPriceGroupId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(dimensionalPriceGroupId, additionalHeaders, additionalQueryParams) override fun toString() = "DimensionalPriceGroupRetrieveParams{dimensionalPriceGroupId=$dimensionalPriceGroupId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupUpdateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupUpdateParams.kt index 4908fc88a..9ba8b805a 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupUpdateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupUpdateParams.kt @@ -302,6 +302,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val externalDimensionalPriceGroupId: JsonField, private val metadata: JsonField, @@ -487,12 +488,15 @@ private constructor( return true } - return /* spotless:off */ other is Body && externalDimensionalPriceGroupId == other.externalDimensionalPriceGroupId && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + externalDimensionalPriceGroupId == other.externalDimensionalPriceGroupId && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(externalDimensionalPriceGroupId, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(externalDimensionalPriceGroupId, metadata, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -592,12 +596,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -609,10 +611,15 @@ private constructor( return true } - return /* spotless:off */ other is DimensionalPriceGroupUpdateParams && dimensionalPriceGroupId == other.dimensionalPriceGroupId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DimensionalPriceGroupUpdateParams && + dimensionalPriceGroupId == other.dimensionalPriceGroupId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(dimensionalPriceGroupId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(dimensionalPriceGroupId, body, additionalHeaders, additionalQueryParams) override fun toString() = "DimensionalPriceGroupUpdateParams{dimensionalPriceGroupId=$dimensionalPriceGroupId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroups.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroups.kt index ceaad174d..82e9c1212 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroups.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroups.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class DimensionalPriceGroups +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -216,12 +217,15 @@ private constructor( return true } - return /* spotless:off */ other is DimensionalPriceGroups && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is DimensionalPriceGroups && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Discount.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Discount.kt index a80419648..7b5d6a307 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Discount.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Discount.kt @@ -124,10 +124,14 @@ private constructor( return true } - return /* spotless:off */ other is Discount && percentage == other.percentage && trial == other.trial && usage == other.usage && amount == other.amount /* spotless:on */ + return other is Discount && + percentage == other.percentage && + trial == other.trial && + usage == other.usage && + amount == other.amount } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentage, trial, usage, amount) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(percentage, trial, usage, amount) override fun toString(): String = when { diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DiscountOverride.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DiscountOverride.kt index d72ff9f70..6b7970b5d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DiscountOverride.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/DiscountOverride.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class DiscountOverride +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val discountType: JsonField, private val amountDiscount: JsonField, @@ -425,7 +426,7 @@ private constructor( return true } - return /* spotless:off */ other is DiscountType && value == other.value /* spotless:on */ + return other is DiscountType && value == other.value } override fun hashCode() = value.hashCode() @@ -438,12 +439,23 @@ private constructor( return true } - return /* spotless:off */ other is DiscountOverride && discountType == other.discountType && amountDiscount == other.amountDiscount && percentageDiscount == other.percentageDiscount && usageDiscount == other.usageDiscount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is DiscountOverride && + discountType == other.discountType && + amountDiscount == other.amountDiscount && + percentageDiscount == other.percentageDiscount && + usageDiscount == other.usageDiscount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(discountType, amountDiscount, percentageDiscount, usageDiscount, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + discountType, + amountDiscount, + percentageDiscount, + usageDiscount, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EvaluatePriceGroup.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EvaluatePriceGroup.kt index a489efb54..e89a6ce43 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EvaluatePriceGroup.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EvaluatePriceGroup.kt @@ -29,6 +29,7 @@ import java.util.Collections import java.util.Objects class EvaluatePriceGroup +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val groupingValues: JsonField>, @@ -354,10 +355,13 @@ private constructor( return true } - return /* spotless:off */ other is GroupingValue && string == other.string && double == other.double && boolean == other.boolean /* spotless:on */ + return other is GroupingValue && + string == other.string && + double == other.double && + boolean == other.boolean } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, double, boolean) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, double, boolean) override fun toString(): String = when { @@ -460,12 +464,16 @@ private constructor( return true } - return /* spotless:off */ other is EvaluatePriceGroup && amount == other.amount && groupingValues == other.groupingValues && quantity == other.quantity && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EvaluatePriceGroup && + amount == other.amount && + groupingValues == other.groupingValues && + quantity == other.quantity && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, groupingValues, quantity, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(amount, groupingValues, quantity, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCloseParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCloseParams.kt index bc6cfa91b..6422d31a3 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCloseParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCloseParams.kt @@ -212,10 +212,15 @@ private constructor( return true } - return /* spotless:off */ other is EventBackfillCloseParams && backfillId == other.backfillId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is EventBackfillCloseParams && + backfillId == other.backfillId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(backfillId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(backfillId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "EventBackfillCloseParams{backfillId=$backfillId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCloseResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCloseResponse.kt index 7a7bca5bc..50219ab9a 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCloseResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCloseResponse.kt @@ -22,6 +22,7 @@ import java.util.Objects * timeframe. */ class EventBackfillCloseResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val closeTime: JsonField, @@ -716,7 +717,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -729,12 +730,37 @@ private constructor( return true } - return /* spotless:off */ other is EventBackfillCloseResponse && id == other.id && closeTime == other.closeTime && createdAt == other.createdAt && customerId == other.customerId && eventsIngested == other.eventsIngested && replaceExistingEvents == other.replaceExistingEvents && revertedAt == other.revertedAt && status == other.status && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && deprecationFilter == other.deprecationFilter && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EventBackfillCloseResponse && + id == other.id && + closeTime == other.closeTime && + createdAt == other.createdAt && + customerId == other.customerId && + eventsIngested == other.eventsIngested && + replaceExistingEvents == other.replaceExistingEvents && + revertedAt == other.revertedAt && + status == other.status && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + deprecationFilter == other.deprecationFilter && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, closeTime, createdAt, customerId, eventsIngested, replaceExistingEvents, revertedAt, status, timeframeEnd, timeframeStart, deprecationFilter, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + closeTime, + createdAt, + customerId, + eventsIngested, + replaceExistingEvents, + revertedAt, + status, + timeframeEnd, + timeframeStart, + deprecationFilter, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCreateParams.kt index a479bcb58..aa0e14457 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCreateParams.kt @@ -43,11 +43,14 @@ import java.util.Objects * for that customer. If neither is specified, the backfill will affect all customers. * * When `replace_existing_events` is `true`, this indicates that existing events in the timeframe - * should no longer be counted towards invoiced usage. In this scenario, the parameter `filter` can - * be optionally added which enables filtering using + * should no longer be counted towards invoiced usage. In this scenario, the parameter + * `deprecation_filter` can be optionally added which enables filtering using * [computed properties](/extensibility/advanced-metrics#computed-properties). The expressiveness of * computed properties allows you to deprecate existing events based on both a period of time and * specific property values. + * + * You may not have multiple backfills in a pending or pending_revert state with overlapping + * timeframes. */ class EventBackfillCreateParams private constructor( @@ -496,6 +499,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val timeframeEnd: JsonField, private val timeframeStart: JsonField, @@ -940,13 +944,30 @@ private constructor( return true } - return /* spotless:off */ other is Body && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && closeTime == other.closeTime && customerId == other.customerId && deprecationFilter == other.deprecationFilter && externalCustomerId == other.externalCustomerId && replaceExistingEvents == other.replaceExistingEvents && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + closeTime == other.closeTime && + customerId == other.customerId && + deprecationFilter == other.deprecationFilter && + externalCustomerId == other.externalCustomerId && + replaceExistingEvents == other.replaceExistingEvents && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + timeframeEnd, + timeframeStart, + closeTime, + customerId, + deprecationFilter, + externalCustomerId, + replaceExistingEvents, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(timeframeEnd, timeframeStart, closeTime, customerId, deprecationFilter, externalCustomerId, replaceExistingEvents, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = @@ -958,10 +979,13 @@ private constructor( return true } - return /* spotless:off */ other is EventBackfillCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is EventBackfillCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "EventBackfillCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCreateResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCreateResponse.kt index 416fd2f0e..6c2b86ccd 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCreateResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillCreateResponse.kt @@ -22,6 +22,7 @@ import java.util.Objects * timeframe. */ class EventBackfillCreateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val closeTime: JsonField, @@ -716,7 +717,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -729,12 +730,37 @@ private constructor( return true } - return /* spotless:off */ other is EventBackfillCreateResponse && id == other.id && closeTime == other.closeTime && createdAt == other.createdAt && customerId == other.customerId && eventsIngested == other.eventsIngested && replaceExistingEvents == other.replaceExistingEvents && revertedAt == other.revertedAt && status == other.status && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && deprecationFilter == other.deprecationFilter && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EventBackfillCreateResponse && + id == other.id && + closeTime == other.closeTime && + createdAt == other.createdAt && + customerId == other.customerId && + eventsIngested == other.eventsIngested && + replaceExistingEvents == other.replaceExistingEvents && + revertedAt == other.revertedAt && + status == other.status && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + deprecationFilter == other.deprecationFilter && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, closeTime, createdAt, customerId, eventsIngested, replaceExistingEvents, revertedAt, status, timeframeEnd, timeframeStart, deprecationFilter, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + closeTime, + createdAt, + customerId, + eventsIngested, + replaceExistingEvents, + revertedAt, + status, + timeframeEnd, + timeframeStart, + deprecationFilter, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillFetchParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillFetchParams.kt index 7e249c345..b06db7b15 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillFetchParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillFetchParams.kt @@ -174,10 +174,14 @@ private constructor( return true } - return /* spotless:off */ other is EventBackfillFetchParams && backfillId == other.backfillId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is EventBackfillFetchParams && + backfillId == other.backfillId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(backfillId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(backfillId, additionalHeaders, additionalQueryParams) override fun toString() = "EventBackfillFetchParams{backfillId=$backfillId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillFetchResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillFetchResponse.kt index ae45dd763..46d1dfd4a 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillFetchResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillFetchResponse.kt @@ -22,6 +22,7 @@ import java.util.Objects * timeframe. */ class EventBackfillFetchResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val closeTime: JsonField, @@ -716,7 +717,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -729,12 +730,37 @@ private constructor( return true } - return /* spotless:off */ other is EventBackfillFetchResponse && id == other.id && closeTime == other.closeTime && createdAt == other.createdAt && customerId == other.customerId && eventsIngested == other.eventsIngested && replaceExistingEvents == other.replaceExistingEvents && revertedAt == other.revertedAt && status == other.status && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && deprecationFilter == other.deprecationFilter && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EventBackfillFetchResponse && + id == other.id && + closeTime == other.closeTime && + createdAt == other.createdAt && + customerId == other.customerId && + eventsIngested == other.eventsIngested && + replaceExistingEvents == other.replaceExistingEvents && + revertedAt == other.revertedAt && + status == other.status && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + deprecationFilter == other.deprecationFilter && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, closeTime, createdAt, customerId, eventsIngested, replaceExistingEvents, revertedAt, status, timeframeEnd, timeframeStart, deprecationFilter, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + closeTime, + createdAt, + customerId, + eventsIngested, + replaceExistingEvents, + revertedAt, + status, + timeframeEnd, + timeframeStart, + deprecationFilter, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPage.kt index a6cb91ee2..83a32431b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPage.kt @@ -120,10 +120,13 @@ private constructor( return true } - return /* spotless:off */ other is EventBackfillListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is EventBackfillListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "EventBackfillListPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageAsync.kt index 33df64f50..d959578fb 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageAsync.kt @@ -120,10 +120,13 @@ private constructor( return true } - return /* spotless:off */ other is EventBackfillListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is EventBackfillListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "EventBackfillListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageResponse.kt index 506edb374..5c6dddd35 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class EventBackfillListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -219,12 +220,15 @@ private constructor( return true } - return /* spotless:off */ other is EventBackfillListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EventBackfillListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListParams.kt index 67225c207..ed7ec4453 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListParams.kt @@ -207,10 +207,15 @@ private constructor( return true } - return /* spotless:off */ other is EventBackfillListParams && cursor == other.cursor && limit == other.limit && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is EventBackfillListParams && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(cursor, limit, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(cursor, limit, additionalHeaders, additionalQueryParams) override fun toString() = "EventBackfillListParams{cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListResponse.kt index 5114a2ed0..89a70c831 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillListResponse.kt @@ -22,6 +22,7 @@ import java.util.Objects * timeframe. */ class EventBackfillListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val closeTime: JsonField, @@ -716,7 +717,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -729,12 +730,37 @@ private constructor( return true } - return /* spotless:off */ other is EventBackfillListResponse && id == other.id && closeTime == other.closeTime && createdAt == other.createdAt && customerId == other.customerId && eventsIngested == other.eventsIngested && replaceExistingEvents == other.replaceExistingEvents && revertedAt == other.revertedAt && status == other.status && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && deprecationFilter == other.deprecationFilter && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EventBackfillListResponse && + id == other.id && + closeTime == other.closeTime && + createdAt == other.createdAt && + customerId == other.customerId && + eventsIngested == other.eventsIngested && + replaceExistingEvents == other.replaceExistingEvents && + revertedAt == other.revertedAt && + status == other.status && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + deprecationFilter == other.deprecationFilter && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, closeTime, createdAt, customerId, eventsIngested, replaceExistingEvents, revertedAt, status, timeframeEnd, timeframeStart, deprecationFilter, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + closeTime, + createdAt, + customerId, + eventsIngested, + replaceExistingEvents, + revertedAt, + status, + timeframeEnd, + timeframeStart, + deprecationFilter, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillRevertParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillRevertParams.kt index c68eb0043..3452518f5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillRevertParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillRevertParams.kt @@ -217,10 +217,15 @@ private constructor( return true } - return /* spotless:off */ other is EventBackfillRevertParams && backfillId == other.backfillId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is EventBackfillRevertParams && + backfillId == other.backfillId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(backfillId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(backfillId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "EventBackfillRevertParams{backfillId=$backfillId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillRevertResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillRevertResponse.kt index 7c0a2f451..ec2db19f7 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillRevertResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventBackfillRevertResponse.kt @@ -22,6 +22,7 @@ import java.util.Objects * timeframe. */ class EventBackfillRevertResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val closeTime: JsonField, @@ -716,7 +717,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -729,12 +730,37 @@ private constructor( return true } - return /* spotless:off */ other is EventBackfillRevertResponse && id == other.id && closeTime == other.closeTime && createdAt == other.createdAt && customerId == other.customerId && eventsIngested == other.eventsIngested && replaceExistingEvents == other.replaceExistingEvents && revertedAt == other.revertedAt && status == other.status && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && deprecationFilter == other.deprecationFilter && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EventBackfillRevertResponse && + id == other.id && + closeTime == other.closeTime && + createdAt == other.createdAt && + customerId == other.customerId && + eventsIngested == other.eventsIngested && + replaceExistingEvents == other.replaceExistingEvents && + revertedAt == other.revertedAt && + status == other.status && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + deprecationFilter == other.deprecationFilter && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, closeTime, createdAt, customerId, eventsIngested, replaceExistingEvents, revertedAt, status, timeframeEnd, timeframeStart, deprecationFilter, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + closeTime, + createdAt, + customerId, + eventsIngested, + replaceExistingEvents, + revertedAt, + status, + timeframeEnd, + timeframeStart, + deprecationFilter, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventDeprecateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventDeprecateParams.kt index cf6b8d855..fe99bc1a8 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventDeprecateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventDeprecateParams.kt @@ -18,8 +18,8 @@ import java.util.Objects * * This is a powerful and audit-safe mechanism to retroactively deprecate a single event in cases * where you need to: - * - no longer bill for an event that was improperly reported - * - no longer bill for an event based on the result of an external API call (e.g. call to a payment + * * no longer bill for an event that was improperly reported + * * no longer bill for an event based on the result of an external API call (e.g. call to a payment * gateway failed and the user should not be billed) * * If you want to only change specific properties of an event, but keep the event as part of the @@ -30,16 +30,16 @@ import java.util.Objects * overwrites or permanently deletes ingested usage data. * * ## Request validation - * - Orb does not accept an `idempotency_key` with the event in this endpoint, since this request is + * * Orb does not accept an `idempotency_key` with the event in this endpoint, since this request is * by design idempotent. On retryable errors, you should retry the request and assume the * deprecation operation has not succeeded until receipt of a 2xx. - * - The event's `timestamp` must fall within the customer's current subscription's billing period, + * * The event's `timestamp` must fall within the customer's current subscription's billing period, * or within the grace period of the customer's current subscription's previous billing period. * Orb does not allow deprecating events for billing periods that have already invoiced customers. - * - The `customer_id` or the `external_customer_id` of the original event ingestion request must + * * The `customer_id` or the `external_customer_id` of the original event ingestion request must * identify a Customer resource within Orb, even if this event was ingested during the initial * integration period. We do not allow deprecating events for customers not in the Orb system. - * - By default, no more than 100 events can be deprecated for a single customer in a 100 day + * * By default, no more than 100 events can be deprecated for a single customer in a 100 day * period. For higher volume updates, consider using the [event backfill](create-backfill) * endpoint. */ @@ -240,10 +240,15 @@ private constructor( return true } - return /* spotless:off */ other is EventDeprecateParams && eventId == other.eventId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is EventDeprecateParams && + eventId == other.eventId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(eventId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(eventId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "EventDeprecateParams{eventId=$eventId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventDeprecateResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventDeprecateResponse.kt index c4f29d91b..c786d6ed8 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventDeprecateResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventDeprecateResponse.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class EventDeprecateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val deprecated: JsonField, private val additionalProperties: MutableMap, @@ -158,12 +159,12 @@ private constructor( return true } - return /* spotless:off */ other is EventDeprecateResponse && deprecated == other.deprecated && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EventDeprecateResponse && + deprecated == other.deprecated && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(deprecated, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventIngestParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventIngestParams.kt index 6b006ad4c..c39062d41 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventIngestParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventIngestParams.kt @@ -78,7 +78,6 @@ import java.util.Objects * ``` * * ## Required fields - * * Because events streamed to Orb are meant to be as flexible as possible, there are only a few * required fields in every event. * - We recommend that `idempotency_key` are unique strings that you generated with V4 UUIDs, but @@ -108,7 +107,6 @@ import java.util.Objects * numeric type in the event. * * ## Determining event timestamp - * * For cases where usage is being reported in real time as it is occurring, timestamp should * correspond to the time that usage occurred. * @@ -162,7 +160,6 @@ import java.util.Objects * should be retried in their entirety. * * ## API usage and limits - * * The ingestion API is designed made for real-time streaming ingestion and architected for high * throughput. Even if events are later deemed unnecessary or filtered out, we encourage you to log * them to Orb if they may be relevant to billing calculations in the future. @@ -176,7 +173,6 @@ import java.util.Objects * from initial setup. * * ## Testing in debug mode - * * The ingestion API supports a debug mode, which returns additional verbose output to indicate * which event idempotency keys were newly ingested or duplicates from previous requests. To enable * this mode, mark `debug=true` as a query parameter. @@ -195,7 +191,11 @@ import java.util.Objects * { * "debug": { * "duplicate": [], - * "ingested": ["B7E83HDMfJPAunXW", "SJs5DQJ3TnwSqEZE", "8SivfDsNKwCeAXim"] + * "ingested": [ + * "B7E83HDMfJPAunXW", + * "SJs5DQJ3TnwSqEZE", + * "8SivfDsNKwCeAXim" + * ] * }, * "validation_failed": [] * } @@ -476,6 +476,7 @@ private constructor( .build() class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val events: JsonField>, private val additionalProperties: MutableMap, @@ -632,12 +633,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && events == other.events && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + events == other.events && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(events, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -645,6 +646,7 @@ private constructor( } class Event + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val eventName: JsonField, private val idempotencyKey: JsonField, @@ -1114,12 +1116,10 @@ private constructor( return true } - return /* spotless:off */ other is Properties && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Properties && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1131,12 +1131,27 @@ private constructor( return true } - return /* spotless:off */ other is Event && eventName == other.eventName && idempotencyKey == other.idempotencyKey && properties == other.properties && timestamp == other.timestamp && customerId == other.customerId && externalCustomerId == other.externalCustomerId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Event && + eventName == other.eventName && + idempotencyKey == other.idempotencyKey && + properties == other.properties && + timestamp == other.timestamp && + customerId == other.customerId && + externalCustomerId == other.externalCustomerId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(eventName, idempotencyKey, properties, timestamp, customerId, externalCustomerId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + eventName, + idempotencyKey, + properties, + timestamp, + customerId, + externalCustomerId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1149,10 +1164,16 @@ private constructor( return true } - return /* spotless:off */ other is EventIngestParams && backfillId == other.backfillId && debug == other.debug && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is EventIngestParams && + backfillId == other.backfillId && + debug == other.debug && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(backfillId, debug, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(backfillId, debug, body, additionalHeaders, additionalQueryParams) override fun toString() = "EventIngestParams{backfillId=$backfillId, debug=$debug, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventIngestResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventIngestResponse.kt index 7af6e9e95..c79fbc638 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventIngestResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventIngestResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class EventIngestResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val validationFailed: JsonField>, private val debug: JsonField, @@ -219,6 +220,7 @@ private constructor( (debug.asKnown()?.validity() ?: 0) class ValidationFailed + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val idempotencyKey: JsonField, private val validationErrors: JsonField>, @@ -429,12 +431,15 @@ private constructor( return true } - return /* spotless:off */ other is ValidationFailed && idempotencyKey == other.idempotencyKey && validationErrors == other.validationErrors && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ValidationFailed && + idempotencyKey == other.idempotencyKey && + validationErrors == other.validationErrors && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(idempotencyKey, validationErrors, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(idempotencyKey, validationErrors, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -447,6 +452,7 @@ private constructor( * ingested and duplicate event idempotency keys. */ class Debug + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val duplicate: JsonField>, private val ingested: JsonField>, @@ -656,12 +662,15 @@ private constructor( return true } - return /* spotless:off */ other is Debug && duplicate == other.duplicate && ingested == other.ingested && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Debug && + duplicate == other.duplicate && + ingested == other.ingested && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(duplicate, ingested, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(duplicate, ingested, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -674,12 +683,15 @@ private constructor( return true } - return /* spotless:off */ other is EventIngestResponse && validationFailed == other.validationFailed && debug == other.debug && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EventIngestResponse && + validationFailed == other.validationFailed && + debug == other.debug && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(validationFailed, debug, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(validationFailed, debug, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventSearchParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventSearchParams.kt index cb30d5f25..84d4db66f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventSearchParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventSearchParams.kt @@ -341,6 +341,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val eventIds: JsonField>, private val timeframeEnd: JsonField, @@ -601,12 +602,16 @@ private constructor( return true } - return /* spotless:off */ other is Body && eventIds == other.eventIds && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + eventIds == other.eventIds && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(eventIds, timeframeEnd, timeframeStart, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(eventIds, timeframeEnd, timeframeStart, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -619,10 +624,13 @@ private constructor( return true } - return /* spotless:off */ other is EventSearchParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is EventSearchParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "EventSearchParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventSearchResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventSearchResponse.kt index 345449896..6839236de 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventSearchResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventSearchResponse.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class EventSearchResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val additionalProperties: MutableMap, @@ -172,6 +173,7 @@ private constructor( * the usage charges for a given billing period. */ class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val customerId: JsonField, @@ -678,12 +680,10 @@ private constructor( return true } - return /* spotless:off */ other is Properties && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Properties && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -695,12 +695,29 @@ private constructor( return true } - return /* spotless:off */ other is Data && id == other.id && customerId == other.customerId && deprecated == other.deprecated && eventName == other.eventName && externalCustomerId == other.externalCustomerId && properties == other.properties && timestamp == other.timestamp && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Data && + id == other.id && + customerId == other.customerId && + deprecated == other.deprecated && + eventName == other.eventName && + externalCustomerId == other.externalCustomerId && + properties == other.properties && + timestamp == other.timestamp && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, customerId, deprecated, eventName, externalCustomerId, properties, timestamp, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + customerId, + deprecated, + eventName, + externalCustomerId, + properties, + timestamp, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -713,12 +730,12 @@ private constructor( return true } - return /* spotless:off */ other is EventSearchResponse && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EventSearchResponse && + data == other.data && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventUpdateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventUpdateParams.kt index c6d9a4cc4..507414c8d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventUpdateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventUpdateParams.kt @@ -33,8 +33,8 @@ import java.util.Objects * * This is a powerful and audit-safe mechanism to retroactively update a single event in cases where * you need to: - * - update an event with new metadata as you iterate on your pricing model - * - update an event based on the result of an external API call (e.g. call to a payment gateway + * * update an event with new metadata as you iterate on your pricing model + * * update an event based on the result of an external API call (e.g. call to a payment gateway * succeeded or failed) * * This amendment API is always audit-safe. The process will still retain the original event, though @@ -42,21 +42,21 @@ import java.util.Objects * overwrites or permanently deletes ingested usage data. * * ## Request validation - * - The `timestamp` of the new event must match the `timestamp` of the existing event already + * * The `timestamp` of the new event must match the `timestamp` of the existing event already * ingested. As with ingestion, all timestamps must be sent in ISO8601 format with UTC timezone * offset. - * - The `customer_id` or `external_customer_id` of the new event must match the `customer_id` or + * * The `customer_id` or `external_customer_id` of the new event must match the `customer_id` or * `external_customer_id` of the existing event already ingested. Exactly one of `customer_id` and * `external_customer_id` should be specified, and similar to ingestion, the ID must identify a * Customer resource within Orb. Unlike ingestion, for event amendment, we strictly enforce that * the Customer must be in the Orb system, even during the initial integration period. We do not * allow updating the `Customer` an event is associated with. - * - Orb does not accept an `idempotency_key` with the event in this endpoint, since this request is + * * Orb does not accept an `idempotency_key` with the event in this endpoint, since this request is * by design idempotent. On retryable errors, you should retry the request and assume the * amendment operation has not succeeded until receipt of a 2xx. - * - The event's `timestamp` must fall within the customer's current subscription's billing period, + * * The event's `timestamp` must fall within the customer's current subscription's billing period, * or within the grace period of the customer's current subscription's previous billing period. - * - By default, no more than 100 events can be amended for a single customer in a 100 day period. + * * By default, no more than 100 events can be amended for a single customer in a 100 day period. * For higher volume updates, consider using the [event backfill](create-backfill) endpoint. */ class EventUpdateParams @@ -428,6 +428,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val eventName: JsonField, private val properties: JsonField, @@ -750,13 +751,26 @@ private constructor( return true } - return /* spotless:off */ other is Body && eventName == other.eventName && properties == other.properties && timestamp == other.timestamp && customerId == other.customerId && externalCustomerId == other.externalCustomerId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + eventName == other.eventName && + properties == other.properties && + timestamp == other.timestamp && + customerId == other.customerId && + externalCustomerId == other.externalCustomerId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + eventName, + properties, + timestamp, + customerId, + externalCustomerId, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(eventName, properties, timestamp, customerId, externalCustomerId, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = @@ -854,12 +868,10 @@ private constructor( return true } - return /* spotless:off */ other is Properties && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Properties && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -871,10 +883,15 @@ private constructor( return true } - return /* spotless:off */ other is EventUpdateParams && eventId == other.eventId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is EventUpdateParams && + eventId == other.eventId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(eventId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(eventId, body, additionalHeaders, additionalQueryParams) override fun toString() = "EventUpdateParams{eventId=$eventId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventUpdateResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventUpdateResponse.kt index a52c6758c..5b55f1a5e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventUpdateResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventUpdateResponse.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class EventUpdateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amended: JsonField, private val additionalProperties: MutableMap, @@ -157,12 +158,12 @@ private constructor( return true } - return /* spotless:off */ other is EventUpdateResponse && amended == other.amended && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EventUpdateResponse && + amended == other.amended && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(amended, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventVolumeListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventVolumeListParams.kt index be3b48b47..2dd9ac120 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventVolumeListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventVolumeListParams.kt @@ -274,10 +274,24 @@ private constructor( return true } - return /* spotless:off */ other is EventVolumeListParams && timeframeStart == other.timeframeStart && cursor == other.cursor && limit == other.limit && timeframeEnd == other.timeframeEnd && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is EventVolumeListParams && + timeframeStart == other.timeframeStart && + cursor == other.cursor && + limit == other.limit && + timeframeEnd == other.timeframeEnd && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(timeframeStart, cursor, limit, timeframeEnd, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + timeframeStart, + cursor, + limit, + timeframeEnd, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "EventVolumeListParams{timeframeStart=$timeframeStart, cursor=$cursor, limit=$limit, timeframeEnd=$timeframeEnd, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventVolumes.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventVolumes.kt index df99171a2..cab0c8cbd 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventVolumes.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/EventVolumes.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class EventVolumes +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val additionalProperties: MutableMap, @@ -171,6 +172,7 @@ private constructor( * the aggregation is the `timestamp` datetime field on events. */ class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val count: JsonField, private val timeframeEnd: JsonField, @@ -397,12 +399,16 @@ private constructor( return true } - return /* spotless:off */ other is Data && count == other.count && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Data && + count == other.count && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(count, timeframeEnd, timeframeStart, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(count, timeframeEnd, timeframeStart, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -415,12 +421,12 @@ private constructor( return true } - return /* spotless:off */ other is EventVolumes && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EventVolumes && + data == other.data && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ExpirationChangeLedgerEntry.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ExpirationChangeLedgerEntry.kt index 13fd30d5a..c2f47fc30 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ExpirationChangeLedgerEntry.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ExpirationChangeLedgerEntry.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class ExpirationChangeLedgerEntry +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, @@ -778,7 +779,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryStatus && value == other.value /* spotless:on */ + return other is EntryStatus && value == other.value } override fun hashCode() = value.hashCode() @@ -898,7 +899,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryType && value == other.value /* spotless:on */ + return other is EntryType && value == other.value } override fun hashCode() = value.hashCode() @@ -998,12 +999,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1015,12 +1014,43 @@ private constructor( return true } - return /* spotless:off */ other is ExpirationChangeLedgerEntry && id == other.id && amount == other.amount && createdAt == other.createdAt && creditBlock == other.creditBlock && currency == other.currency && customer == other.customer && description == other.description && endingBalance == other.endingBalance && entryStatus == other.entryStatus && entryType == other.entryType && ledgerSequenceNumber == other.ledgerSequenceNumber && metadata == other.metadata && newBlockExpiryDate == other.newBlockExpiryDate && startingBalance == other.startingBalance && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ExpirationChangeLedgerEntry && + id == other.id && + amount == other.amount && + createdAt == other.createdAt && + creditBlock == other.creditBlock && + currency == other.currency && + customer == other.customer && + description == other.description && + endingBalance == other.endingBalance && + entryStatus == other.entryStatus && + entryType == other.entryType && + ledgerSequenceNumber == other.ledgerSequenceNumber && + metadata == other.metadata && + newBlockExpiryDate == other.newBlockExpiryDate && + startingBalance == other.startingBalance && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, createdAt, creditBlock, currency, customer, description, endingBalance, entryStatus, entryType, ledgerSequenceNumber, metadata, newBlockExpiryDate, startingBalance, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + createdAt, + creditBlock, + currency, + customer, + description, + endingBalance, + entryStatus, + entryType, + ledgerSequenceNumber, + metadata, + newBlockExpiryDate, + startingBalance, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/FixedFeeQuantityScheduleEntry.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/FixedFeeQuantityScheduleEntry.kt index b43e4800f..fcedfc94e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/FixedFeeQuantityScheduleEntry.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/FixedFeeQuantityScheduleEntry.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class FixedFeeQuantityScheduleEntry +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val endDate: JsonField, private val priceId: JsonField, @@ -261,12 +262,17 @@ private constructor( return true } - return /* spotless:off */ other is FixedFeeQuantityScheduleEntry && endDate == other.endDate && priceId == other.priceId && quantity == other.quantity && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FixedFeeQuantityScheduleEntry && + endDate == other.endDate && + priceId == other.priceId && + quantity == other.quantity && + startDate == other.startDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(endDate, priceId, quantity, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(endDate, priceId, quantity, startDate, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/FixedFeeQuantityTransition.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/FixedFeeQuantityTransition.kt index f747d988f..37a3f6c98 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/FixedFeeQuantityTransition.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/FixedFeeQuantityTransition.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class FixedFeeQuantityTransition +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val effectiveDate: JsonField, private val priceId: JsonField, @@ -228,12 +229,16 @@ private constructor( return true } - return /* spotless:off */ other is FixedFeeQuantityTransition && effectiveDate == other.effectiveDate && priceId == other.priceId && quantity == other.quantity && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FixedFeeQuantityTransition && + effectiveDate == other.effectiveDate && + priceId == other.priceId && + quantity == other.quantity && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(effectiveDate, priceId, quantity, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(effectiveDate, priceId, quantity, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/IncrementLedgerEntry.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/IncrementLedgerEntry.kt index 53e6f762f..a6eb27650 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/IncrementLedgerEntry.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/IncrementLedgerEntry.kt @@ -20,6 +20,7 @@ import java.util.Collections import java.util.Objects class IncrementLedgerEntry +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, @@ -790,7 +791,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryStatus && value == other.value /* spotless:on */ + return other is EntryStatus && value == other.value } override fun hashCode() = value.hashCode() @@ -910,7 +911,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryType && value == other.value /* spotless:on */ + return other is EntryType && value == other.value } override fun hashCode() = value.hashCode() @@ -1010,12 +1011,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1027,12 +1026,43 @@ private constructor( return true } - return /* spotless:off */ other is IncrementLedgerEntry && id == other.id && amount == other.amount && createdAt == other.createdAt && creditBlock == other.creditBlock && currency == other.currency && customer == other.customer && description == other.description && endingBalance == other.endingBalance && entryStatus == other.entryStatus && entryType == other.entryType && ledgerSequenceNumber == other.ledgerSequenceNumber && metadata == other.metadata && startingBalance == other.startingBalance && createdInvoices == other.createdInvoices && additionalProperties == other.additionalProperties /* spotless:on */ + return other is IncrementLedgerEntry && + id == other.id && + amount == other.amount && + createdAt == other.createdAt && + creditBlock == other.creditBlock && + currency == other.currency && + customer == other.customer && + description == other.description && + endingBalance == other.endingBalance && + entryStatus == other.entryStatus && + entryType == other.entryType && + ledgerSequenceNumber == other.ledgerSequenceNumber && + metadata == other.metadata && + startingBalance == other.startingBalance && + createdInvoices == other.createdInvoices && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, createdAt, creditBlock, currency, customer, description, endingBalance, entryStatus, entryType, ledgerSequenceNumber, metadata, startingBalance, createdInvoices, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + createdAt, + creditBlock, + currency, + customer, + description, + endingBalance, + entryStatus, + entryType, + ledgerSequenceNumber, + metadata, + startingBalance, + createdInvoices, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Invoice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Invoice.kt index 6ae5a30b2..d5799d974 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Invoice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Invoice.kt @@ -37,6 +37,7 @@ import java.util.Objects * cancellation. */ class Invoice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amountDue: JsonField, @@ -367,9 +368,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -1401,9 +1402,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -2238,6 +2239,7 @@ private constructor( (if (willAutoIssue.asKnown() == null) 0 else 1) class AutoCollection + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val enabled: JsonField, private val nextAttemptAt: JsonField, @@ -2543,12 +2545,23 @@ private constructor( return true } - return /* spotless:off */ other is AutoCollection && enabled == other.enabled && nextAttemptAt == other.nextAttemptAt && numAttempts == other.numAttempts && previouslyAttemptedAt == other.previouslyAttemptedAt && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AutoCollection && + enabled == other.enabled && + nextAttemptAt == other.nextAttemptAt && + numAttempts == other.numAttempts && + previouslyAttemptedAt == other.previouslyAttemptedAt && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(enabled, nextAttemptAt, numAttempts, previouslyAttemptedAt, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + enabled, + nextAttemptAt, + numAttempts, + previouslyAttemptedAt, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2557,6 +2570,7 @@ private constructor( } class CreditNote + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val creditNoteNumber: JsonField, @@ -2918,12 +2932,29 @@ private constructor( return true } - return /* spotless:off */ other is CreditNote && id == other.id && creditNoteNumber == other.creditNoteNumber && memo == other.memo && reason == other.reason && total == other.total && type == other.type && voidedAt == other.voidedAt && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CreditNote && + id == other.id && + creditNoteNumber == other.creditNoteNumber && + memo == other.memo && + reason == other.reason && + total == other.total && + type == other.type && + voidedAt == other.voidedAt && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, creditNoteNumber, memo, reason, total, type, voidedAt, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + creditNoteNumber, + memo, + reason, + total, + type, + voidedAt, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2932,6 +2963,7 @@ private constructor( } class CustomerBalanceTransaction + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val action: JsonField, @@ -3473,6 +3505,8 @@ private constructor( val EXTERNAL_PAYMENT = of("external_payment") + val SMALL_INVOICE_CARRYOVER = of("small_invoice_carryover") + fun of(value: String) = Action(JsonField.of(value)) } @@ -3487,6 +3521,7 @@ private constructor( CREDIT_NOTE_VOIDED, OVERPAYMENT_REFUND, EXTERNAL_PAYMENT, + SMALL_INVOICE_CARRYOVER, } /** @@ -3508,6 +3543,7 @@ private constructor( CREDIT_NOTE_VOIDED, OVERPAYMENT_REFUND, EXTERNAL_PAYMENT, + SMALL_INVOICE_CARRYOVER, /** * An enum member indicating that [Action] was instantiated with an unknown value. */ @@ -3532,6 +3568,7 @@ private constructor( CREDIT_NOTE_VOIDED -> Value.CREDIT_NOTE_VOIDED OVERPAYMENT_REFUND -> Value.OVERPAYMENT_REFUND EXTERNAL_PAYMENT -> Value.EXTERNAL_PAYMENT + SMALL_INVOICE_CARRYOVER -> Value.SMALL_INVOICE_CARRYOVER else -> Value._UNKNOWN } @@ -3555,6 +3592,7 @@ private constructor( CREDIT_NOTE_VOIDED -> Known.CREDIT_NOTE_VOIDED OVERPAYMENT_REFUND -> Known.OVERPAYMENT_REFUND EXTERNAL_PAYMENT -> Known.EXTERNAL_PAYMENT + SMALL_INVOICE_CARRYOVER -> Known.SMALL_INVOICE_CARRYOVER else -> throw OrbInvalidDataException("Unknown Action: $value") } @@ -3602,7 +3640,7 @@ private constructor( return true } - return /* spotless:off */ other is Action && value == other.value /* spotless:on */ + return other is Action && value == other.value } override fun hashCode() = value.hashCode() @@ -3727,7 +3765,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -3740,12 +3778,35 @@ private constructor( return true } - return /* spotless:off */ other is CustomerBalanceTransaction && id == other.id && action == other.action && amount == other.amount && createdAt == other.createdAt && creditNote == other.creditNote && description == other.description && endingBalance == other.endingBalance && invoice == other.invoice && startingBalance == other.startingBalance && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerBalanceTransaction && + id == other.id && + action == other.action && + amount == other.amount && + createdAt == other.createdAt && + creditNote == other.creditNote && + description == other.description && + endingBalance == other.endingBalance && + invoice == other.invoice && + startingBalance == other.startingBalance && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, action, amount, createdAt, creditNote, description, endingBalance, invoice, startingBalance, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + action, + amount, + createdAt, + creditNote, + description, + endingBalance, + invoice, + startingBalance, + type, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -3879,7 +3940,7 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceSource && value == other.value /* spotless:on */ + return other is InvoiceSource && value == other.value } override fun hashCode() = value.hashCode() @@ -3888,20 +3949,16 @@ private constructor( } class LineItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustedSubtotal: JsonField, private val adjustments: JsonField>, private val amount: JsonField, private val creditsApplied: JsonField, - private val discount: JsonField, private val endDate: JsonField, private val filter: JsonField, private val grouping: JsonField, - private val maximum: JsonField, - private val maximumAmount: JsonField, - private val minimum: JsonField, - private val minimumAmount: JsonField, private val name: JsonField, private val partiallyInvoicedAmount: JsonField, private val price: JsonField, @@ -3927,9 +3984,6 @@ private constructor( @JsonProperty("credits_applied") @ExcludeMissing creditsApplied: JsonField = JsonMissing.of(), - @JsonProperty("discount") - @ExcludeMissing - discount: JsonField = JsonMissing.of(), @JsonProperty("end_date") @ExcludeMissing endDate: JsonField = JsonMissing.of(), @@ -3937,14 +3991,6 @@ private constructor( @JsonProperty("grouping") @ExcludeMissing grouping: JsonField = JsonMissing.of(), - @JsonProperty("maximum") @ExcludeMissing maximum: JsonField = JsonMissing.of(), - @JsonProperty("maximum_amount") - @ExcludeMissing - maximumAmount: JsonField = JsonMissing.of(), - @JsonProperty("minimum") @ExcludeMissing minimum: JsonField = JsonMissing.of(), - @JsonProperty("minimum_amount") - @ExcludeMissing - minimumAmount: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("partially_invoiced_amount") @ExcludeMissing @@ -3974,14 +4020,9 @@ private constructor( adjustments, amount, creditsApplied, - discount, endDate, filter, grouping, - maximum, - maximumAmount, - minimum, - minimumAmount, name, partiallyInvoicedAmount, price, @@ -4038,14 +4079,6 @@ private constructor( */ fun creditsApplied(): String = creditsApplied.getRequired("credits_applied") - /** - * This field is deprecated in favor of `adjustments` - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") fun discount(): Discount? = discount.getNullable("discount") - /** * The end date of the range of time applied for this line item's price. * @@ -4072,40 +4105,6 @@ private constructor( */ fun grouping(): String? = grouping.getNullable("grouping") - /** - * This field is deprecated in favor of `adjustments`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") fun maximum(): Maximum? = maximum.getNullable("maximum") - - /** - * This field is deprecated in favor of `adjustments`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") - fun maximumAmount(): String? = maximumAmount.getNullable("maximum_amount") - - /** - * This field is deprecated in favor of `adjustments`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") fun minimum(): Minimum? = minimum.getNullable("minimum") - - /** - * This field is deprecated in favor of `adjustments`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") - fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") - /** * The name of the price associated with this line item. * @@ -4166,7 +4165,7 @@ private constructor( fun subLineItems(): List = subLineItems.getRequired("sub_line_items") /** - * The line amount before before any adjustments. + * The line amount before any adjustments. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -4233,16 +4232,6 @@ private constructor( @ExcludeMissing fun _creditsApplied(): JsonField = creditsApplied - /** - * Returns the raw JSON value of [discount]. - * - * Unlike [discount], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("discount") - @ExcludeMissing - fun _discount(): JsonField = discount - /** * Returns the raw JSON value of [endDate]. * @@ -4266,48 +4255,6 @@ private constructor( */ @JsonProperty("grouping") @ExcludeMissing fun _grouping(): JsonField = grouping - /** - * Returns the raw JSON value of [maximum]. - * - * Unlike [maximum], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("maximum") - @ExcludeMissing - fun _maximum(): JsonField = maximum - - /** - * Returns the raw JSON value of [maximumAmount]. - * - * Unlike [maximumAmount], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @Deprecated("deprecated") - @JsonProperty("maximum_amount") - @ExcludeMissing - fun _maximumAmount(): JsonField = maximumAmount - - /** - * Returns the raw JSON value of [minimum]. - * - * Unlike [minimum], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("minimum") - @ExcludeMissing - fun _minimum(): JsonField = minimum - - /** - * Returns the raw JSON value of [minimumAmount]. - * - * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @Deprecated("deprecated") - @JsonProperty("minimum_amount") - @ExcludeMissing - fun _minimumAmount(): JsonField = minimumAmount - /** * Returns the raw JSON value of [name]. * @@ -4408,14 +4355,9 @@ private constructor( * .adjustments() * .amount() * .creditsApplied() - * .discount() * .endDate() * .filter() * .grouping() - * .maximum() - * .maximumAmount() - * .minimum() - * .minimumAmount() * .name() * .partiallyInvoicedAmount() * .price() @@ -4438,14 +4380,9 @@ private constructor( private var adjustments: JsonField>? = null private var amount: JsonField? = null private var creditsApplied: JsonField? = null - private var discount: JsonField? = null private var endDate: JsonField? = null private var filter: JsonField? = null private var grouping: JsonField? = null - private var maximum: JsonField? = null - private var maximumAmount: JsonField? = null - private var minimum: JsonField? = null - private var minimumAmount: JsonField? = null private var name: JsonField? = null private var partiallyInvoicedAmount: JsonField? = null private var price: JsonField? = null @@ -4463,14 +4400,9 @@ private constructor( adjustments = lineItem.adjustments.map { it.toMutableList() } amount = lineItem.amount creditsApplied = lineItem.creditsApplied - discount = lineItem.discount endDate = lineItem.endDate filter = lineItem.filter grouping = lineItem.grouping - maximum = lineItem.maximum - maximumAmount = lineItem.maximumAmount - minimum = lineItem.minimum - minimumAmount = lineItem.minimumAmount name = lineItem.name partiallyInvoicedAmount = lineItem.partiallyInvoicedAmount price = lineItem.price @@ -4600,91 +4532,6 @@ private constructor( this.creditsApplied = creditsApplied } - /** This field is deprecated in favor of `adjustments` */ - @Deprecated("deprecated") - fun discount(discount: Discount?) = discount(JsonField.ofNullable(discount)) - - /** - * Sets [Builder.discount] to an arbitrary JSON value. - * - * You should usually call [Builder.discount] with a well-typed [Discount] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun discount(discount: JsonField) = apply { this.discount = discount } - - /** Alias for calling [discount] with `Discount.ofPercentage(percentage)`. */ - @Deprecated("deprecated") - fun discount(percentage: PercentageDiscount) = - discount(Discount.ofPercentage(percentage)) - - /** - * Alias for calling [discount] with the following: - * ```kotlin - * PercentageDiscount.builder() - * .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - * .percentageDiscount(percentageDiscount) - * .build() - * ``` - */ - @Deprecated("deprecated") - fun percentageDiscount(percentageDiscount: Double) = - discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(percentageDiscount) - .build() - ) - - /** Alias for calling [discount] with `Discount.ofTrial(trial)`. */ - @Deprecated("deprecated") - fun discount(trial: TrialDiscount) = discount(Discount.ofTrial(trial)) - - /** Alias for calling [discount] with `Discount.ofUsage(usage)`. */ - @Deprecated("deprecated") - fun discount(usage: UsageDiscount) = discount(Discount.ofUsage(usage)) - - /** - * Alias for calling [discount] with the following: - * ```kotlin - * UsageDiscount.builder() - * .discountType(UsageDiscount.DiscountType.USAGE) - * .usageDiscount(usageDiscount) - * .build() - * ``` - */ - @Deprecated("deprecated") - fun usageDiscount(usageDiscount: Double) = - discount( - UsageDiscount.builder() - .discountType(UsageDiscount.DiscountType.USAGE) - .usageDiscount(usageDiscount) - .build() - ) - - /** Alias for calling [discount] with `Discount.ofAmount(amount)`. */ - @Deprecated("deprecated") - fun discount(amount: AmountDiscount) = discount(Discount.ofAmount(amount)) - - /** - * Alias for calling [discount] with the following: - * ```kotlin - * AmountDiscount.builder() - * .discountType(AmountDiscount.DiscountType.AMOUNT) - * .amountDiscount(amountDiscount) - * .build() - * ``` - */ - @Deprecated("deprecated") - fun amountDiscount(amountDiscount: String) = - discount( - AmountDiscount.builder() - .discountType(AmountDiscount.DiscountType.AMOUNT) - .amountDiscount(amountDiscount) - .build() - ) - /** The end date of the range of time applied for this line item's price. */ fun endDate(endDate: OffsetDateTime) = endDate(JsonField.of(endDate)) @@ -4725,68 +4572,6 @@ private constructor( */ fun grouping(grouping: JsonField) = apply { this.grouping = grouping } - /** This field is deprecated in favor of `adjustments`. */ - @Deprecated("deprecated") - fun maximum(maximum: Maximum?) = maximum(JsonField.ofNullable(maximum)) - - /** - * Sets [Builder.maximum] to an arbitrary JSON value. - * - * You should usually call [Builder.maximum] with a well-typed [Maximum] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun maximum(maximum: JsonField) = apply { this.maximum = maximum } - - /** This field is deprecated in favor of `adjustments`. */ - @Deprecated("deprecated") - fun maximumAmount(maximumAmount: String?) = - maximumAmount(JsonField.ofNullable(maximumAmount)) - - /** - * Sets [Builder.maximumAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.maximumAmount] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun maximumAmount(maximumAmount: JsonField) = apply { - this.maximumAmount = maximumAmount - } - - /** This field is deprecated in favor of `adjustments`. */ - @Deprecated("deprecated") - fun minimum(minimum: Minimum?) = minimum(JsonField.ofNullable(minimum)) - - /** - * Sets [Builder.minimum] to an arbitrary JSON value. - * - * You should usually call [Builder.minimum] with a well-typed [Minimum] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun minimum(minimum: JsonField) = apply { this.minimum = minimum } - - /** This field is deprecated in favor of `adjustments`. */ - @Deprecated("deprecated") - fun minimumAmount(minimumAmount: String?) = - minimumAmount(JsonField.ofNullable(minimumAmount)) - - /** - * Sets [Builder.minimumAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.minimumAmount] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun minimumAmount(minimumAmount: JsonField) = apply { - this.minimumAmount = minimumAmount - } - /** The name of the price associated with this line item. */ fun name(name: String) = name(JsonField.of(name)) @@ -4838,28 +4623,23 @@ private constructor( fun price(price: JsonField) = apply { this.price = price } /** Alias for calling [price] with `Price.ofUnit(unit)`. */ - fun price(unit: Price.Unit) = price(Price.ofUnit(unit)) - - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: Price.Package) = price(Price.ofPackage(package_)) - - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: Price.Matrix) = price(Price.ofMatrix(matrix)) + fun price(unit: Price.UnitPrice) = price(Price.ofUnit(unit)) /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ fun price(tiered: Price.Tiered) = price(Price.ofTiered(tiered)) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: Price.TieredBps) = price(Price.ofTieredBps(tieredBps)) + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: Price.Bulk) = price(Price.ofBulk(bulk)) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: Price.Bps) = price(Price.ofBps(bps)) + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: Price.BulkBps) = price(Price.ofBulkBps(bulkBps)) + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: Price.Package) = price(Price.ofPackage(package_)) - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: Price.Bulk) = price(Price.ofBulk(bulk)) + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: Price.Matrix) = price(Price.ofMatrix(matrix)) /** * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. @@ -4871,14 +4651,14 @@ private constructor( fun price(tieredPackage: Price.TieredPackage) = price(Price.ofTieredPackage(tieredPackage)) - /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: Price.GroupedTiered) = - price(Price.ofGroupedTiered(groupedTiered)) - /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ fun price(tieredWithMinimum: Price.TieredWithMinimum) = price(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: Price.GroupedTiered) = + price(Price.ofGroupedTiered(groupedTiered)) + /** * Alias for calling [price] with * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. @@ -4917,6 +4697,10 @@ private constructor( fun price(groupedAllocation: Price.GroupedAllocation) = price(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: Price.BulkWithProration) = + price(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [price] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -4931,6 +4715,13 @@ private constructor( fun price(groupedWithMeteredMinimum: Price.GroupedWithMeteredMinimum) = price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** * Alias for calling [price] with * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. @@ -4938,10 +4729,6 @@ private constructor( fun price(matrixWithDisplayName: Price.MatrixWithDisplayName) = price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: Price.BulkWithProration) = - price(Price.ofBulkWithProration(bulkWithProration)) - /** * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. */ @@ -4978,10 +4765,19 @@ private constructor( /** * Alias for calling [price] with - * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. */ - fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = - price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: Price.Minimum) = price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) /** Either the fixed fee quantity or the usage during the service period. */ fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) @@ -5049,7 +4845,7 @@ private constructor( /** Alias for calling [addSubLineItem] with `SubLineItem.ofNull(null_)`. */ fun addSubLineItem(null_: OtherSubLineItem) = addSubLineItem(SubLineItem.ofNull(null_)) - /** The line amount before before any adjustments. */ + /** The line amount before any adjustments. */ fun subtotal(subtotal: String) = subtotal(JsonField.of(subtotal)) /** @@ -5148,14 +4944,9 @@ private constructor( * .adjustments() * .amount() * .creditsApplied() - * .discount() * .endDate() * .filter() * .grouping() - * .maximum() - * .maximumAmount() - * .minimum() - * .minimumAmount() * .name() * .partiallyInvoicedAmount() * .price() @@ -5176,14 +4967,9 @@ private constructor( checkRequired("adjustments", adjustments).map { it.toImmutable() }, checkRequired("amount", amount), checkRequired("creditsApplied", creditsApplied), - checkRequired("discount", discount), checkRequired("endDate", endDate), checkRequired("filter", filter), checkRequired("grouping", grouping), - checkRequired("maximum", maximum), - checkRequired("maximumAmount", maximumAmount), - checkRequired("minimum", minimum), - checkRequired("minimumAmount", minimumAmount), checkRequired("name", name), checkRequired("partiallyInvoicedAmount", partiallyInvoicedAmount), checkRequired("price", price), @@ -5209,14 +4995,9 @@ private constructor( adjustments().forEach { it.validate() } amount() creditsApplied() - discount()?.validate() endDate() filter() grouping() - maximum()?.validate() - maximumAmount() - minimum()?.validate() - minimumAmount() name() partiallyInvoicedAmount() price().validate() @@ -5249,14 +5030,9 @@ private constructor( (adjustments.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (amount.asKnown() == null) 0 else 1) + (if (creditsApplied.asKnown() == null) 0 else 1) + - (discount.asKnown()?.validity() ?: 0) + (if (endDate.asKnown() == null) 0 else 1) + (if (filter.asKnown() == null) 0 else 1) + (if (grouping.asKnown() == null) 0 else 1) + - (maximum.asKnown()?.validity() ?: 0) + - (if (maximumAmount.asKnown() == null) 0 else 1) + - (minimum.asKnown()?.validity() ?: 0) + - (if (minimumAmount.asKnown() == null) 0 else 1) + (if (name.asKnown() == null) 0 else 1) + (if (partiallyInvoicedAmount.asKnown() == null) 0 else 1) + (price.asKnown()?.validity() ?: 0) + @@ -5408,10 +5184,16 @@ private constructor( return true } - return /* spotless:off */ other is Adjustment && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && percentageDiscount == other.percentageDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ + return other is Adjustment && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + percentageDiscount == other.percentageDiscount && + minimum == other.minimum && + maximum == other.maximum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(usageDiscount, amountDiscount, percentageDiscount, minimum, maximum) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(usageDiscount, amountDiscount, percentageDiscount, minimum, maximum) override fun toString(): String = when { @@ -5637,10 +5419,13 @@ private constructor( return true } - return /* spotless:off */ other is SubLineItem && matrix == other.matrix && tier == other.tier && null_ == other.null_ /* spotless:on */ + return other is SubLineItem && + matrix == other.matrix && + tier == other.tier && + null_ == other.null_ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(matrix, tier, null_) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(matrix, tier, null_) override fun toString(): String = when { @@ -5738,17 +5523,54 @@ private constructor( return true } - return /* spotless:off */ other is LineItem && id == other.id && adjustedSubtotal == other.adjustedSubtotal && adjustments == other.adjustments && amount == other.amount && creditsApplied == other.creditsApplied && discount == other.discount && endDate == other.endDate && filter == other.filter && grouping == other.grouping && maximum == other.maximum && maximumAmount == other.maximumAmount && minimum == other.minimum && minimumAmount == other.minimumAmount && name == other.name && partiallyInvoicedAmount == other.partiallyInvoicedAmount && price == other.price && quantity == other.quantity && startDate == other.startDate && subLineItems == other.subLineItems && subtotal == other.subtotal && taxAmounts == other.taxAmounts && usageCustomerIds == other.usageCustomerIds && additionalProperties == other.additionalProperties /* spotless:on */ + return other is LineItem && + id == other.id && + adjustedSubtotal == other.adjustedSubtotal && + adjustments == other.adjustments && + amount == other.amount && + creditsApplied == other.creditsApplied && + endDate == other.endDate && + filter == other.filter && + grouping == other.grouping && + name == other.name && + partiallyInvoicedAmount == other.partiallyInvoicedAmount && + price == other.price && + quantity == other.quantity && + startDate == other.startDate && + subLineItems == other.subLineItems && + subtotal == other.subtotal && + taxAmounts == other.taxAmounts && + usageCustomerIds == other.usageCustomerIds && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustedSubtotal, adjustments, amount, creditsApplied, discount, endDate, filter, grouping, maximum, maximumAmount, minimum, minimumAmount, name, partiallyInvoicedAmount, price, quantity, startDate, subLineItems, subtotal, taxAmounts, usageCustomerIds, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustedSubtotal, + adjustments, + amount, + creditsApplied, + endDate, + filter, + grouping, + name, + partiallyInvoicedAmount, + price, + quantity, + startDate, + subLineItems, + subtotal, + taxAmounts, + usageCustomerIds, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "LineItem{id=$id, adjustedSubtotal=$adjustedSubtotal, adjustments=$adjustments, amount=$amount, creditsApplied=$creditsApplied, discount=$discount, endDate=$endDate, filter=$filter, grouping=$grouping, maximum=$maximum, maximumAmount=$maximumAmount, minimum=$minimum, minimumAmount=$minimumAmount, name=$name, partiallyInvoicedAmount=$partiallyInvoicedAmount, price=$price, quantity=$quantity, startDate=$startDate, subLineItems=$subLineItems, subtotal=$subtotal, taxAmounts=$taxAmounts, usageCustomerIds=$usageCustomerIds, additionalProperties=$additionalProperties}" + "LineItem{id=$id, adjustedSubtotal=$adjustedSubtotal, adjustments=$adjustments, amount=$amount, creditsApplied=$creditsApplied, endDate=$endDate, filter=$filter, grouping=$grouping, name=$name, partiallyInvoicedAmount=$partiallyInvoicedAmount, price=$price, quantity=$quantity, startDate=$startDate, subLineItems=$subLineItems, subtotal=$subtotal, taxAmounts=$taxAmounts, usageCustomerIds=$usageCustomerIds, additionalProperties=$additionalProperties}" } /** @@ -5843,12 +5665,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -5856,12 +5676,14 @@ private constructor( } class PaymentAttempt + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, private val createdAt: JsonField, private val paymentProvider: JsonField, private val paymentProviderId: JsonField, + private val receiptPdf: JsonField, private val succeeded: JsonField, private val additionalProperties: MutableMap, ) { @@ -5879,6 +5701,9 @@ private constructor( @JsonProperty("payment_provider_id") @ExcludeMissing paymentProviderId: JsonField = JsonMissing.of(), + @JsonProperty("receipt_pdf") + @ExcludeMissing + receiptPdf: JsonField = JsonMissing.of(), @JsonProperty("succeeded") @ExcludeMissing succeeded: JsonField = JsonMissing.of(), @@ -5888,6 +5713,7 @@ private constructor( createdAt, paymentProvider, paymentProviderId, + receiptPdf, succeeded, mutableMapOf(), ) @@ -5932,6 +5758,15 @@ private constructor( */ fun paymentProviderId(): String? = paymentProviderId.getNullable("payment_provider_id") + /** + * URL to the downloadable PDF version of the receipt. This field will be `null` for payment + * attempts that did not succeed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun receiptPdf(): String? = receiptPdf.getNullable("receipt_pdf") + /** * Whether the payment attempt succeeded. * @@ -5983,6 +5818,15 @@ private constructor( @ExcludeMissing fun _paymentProviderId(): JsonField = paymentProviderId + /** + * Returns the raw JSON value of [receiptPdf]. + * + * Unlike [receiptPdf], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("receipt_pdf") + @ExcludeMissing + fun _receiptPdf(): JsonField = receiptPdf + /** * Returns the raw JSON value of [succeeded]. * @@ -6014,6 +5858,7 @@ private constructor( * .createdAt() * .paymentProvider() * .paymentProviderId() + * .receiptPdf() * .succeeded() * ``` */ @@ -6028,6 +5873,7 @@ private constructor( private var createdAt: JsonField? = null private var paymentProvider: JsonField? = null private var paymentProviderId: JsonField? = null + private var receiptPdf: JsonField? = null private var succeeded: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -6037,6 +5883,7 @@ private constructor( createdAt = paymentAttempt.createdAt paymentProvider = paymentAttempt.paymentProvider paymentProviderId = paymentAttempt.paymentProviderId + receiptPdf = paymentAttempt.receiptPdf succeeded = paymentAttempt.succeeded additionalProperties = paymentAttempt.additionalProperties.toMutableMap() } @@ -6109,6 +5956,21 @@ private constructor( this.paymentProviderId = paymentProviderId } + /** + * URL to the downloadable PDF version of the receipt. This field will be `null` for + * payment attempts that did not succeed. + */ + fun receiptPdf(receiptPdf: String?) = receiptPdf(JsonField.ofNullable(receiptPdf)) + + /** + * Sets [Builder.receiptPdf] to an arbitrary JSON value. + * + * You should usually call [Builder.receiptPdf] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun receiptPdf(receiptPdf: JsonField) = apply { this.receiptPdf = receiptPdf } + /** Whether the payment attempt succeeded. */ fun succeeded(succeeded: Boolean) = succeeded(JsonField.of(succeeded)) @@ -6152,6 +6014,7 @@ private constructor( * .createdAt() * .paymentProvider() * .paymentProviderId() + * .receiptPdf() * .succeeded() * ``` * @@ -6164,6 +6027,7 @@ private constructor( checkRequired("createdAt", createdAt), checkRequired("paymentProvider", paymentProvider), checkRequired("paymentProviderId", paymentProviderId), + checkRequired("receiptPdf", receiptPdf), checkRequired("succeeded", succeeded), additionalProperties.toMutableMap(), ) @@ -6181,6 +6045,7 @@ private constructor( createdAt() paymentProvider()?.validate() paymentProviderId() + receiptPdf() succeeded() validated = true } @@ -6205,6 +6070,7 @@ private constructor( (if (createdAt.asKnown() == null) 0 else 1) + (paymentProvider.asKnown()?.validity() ?: 0) + (if (paymentProviderId.asKnown() == null) 0 else 1) + + (if (receiptPdf.asKnown() == null) 0 else 1) + (if (succeeded.asKnown() == null) 0 else 1) /** The payment provider that attempted to collect the payment. */ @@ -6324,7 +6190,7 @@ private constructor( return true } - return /* spotless:off */ other is PaymentProvider && value == other.value /* spotless:on */ + return other is PaymentProvider && value == other.value } override fun hashCode() = value.hashCode() @@ -6337,17 +6203,34 @@ private constructor( return true } - return /* spotless:off */ other is PaymentAttempt && id == other.id && amount == other.amount && createdAt == other.createdAt && paymentProvider == other.paymentProvider && paymentProviderId == other.paymentProviderId && succeeded == other.succeeded && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PaymentAttempt && + id == other.id && + amount == other.amount && + createdAt == other.createdAt && + paymentProvider == other.paymentProvider && + paymentProviderId == other.paymentProviderId && + receiptPdf == other.receiptPdf && + succeeded == other.succeeded && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, createdAt, paymentProvider, paymentProviderId, succeeded, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + createdAt, + paymentProvider, + paymentProviderId, + receiptPdf, + succeeded, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "PaymentAttempt{id=$id, amount=$amount, createdAt=$createdAt, paymentProvider=$paymentProvider, paymentProviderId=$paymentProviderId, succeeded=$succeeded, additionalProperties=$additionalProperties}" + "PaymentAttempt{id=$id, amount=$amount, createdAt=$createdAt, paymentProvider=$paymentProvider, paymentProviderId=$paymentProviderId, receiptPdf=$receiptPdf, succeeded=$succeeded, additionalProperties=$additionalProperties}" } class Status @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -6484,7 +6367,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -6497,12 +6380,97 @@ private constructor( return true } - return /* spotless:off */ other is Invoice && id == other.id && amountDue == other.amountDue && autoCollection == other.autoCollection && billingAddress == other.billingAddress && createdAt == other.createdAt && creditNotes == other.creditNotes && currency == other.currency && customer == other.customer && customerBalanceTransactions == other.customerBalanceTransactions && customerTaxId == other.customerTaxId && discount == other.discount && discounts == other.discounts && dueDate == other.dueDate && eligibleToIssueAt == other.eligibleToIssueAt && hostedInvoiceUrl == other.hostedInvoiceUrl && invoiceDate == other.invoiceDate && invoiceNumber == other.invoiceNumber && invoicePdf == other.invoicePdf && invoiceSource == other.invoiceSource && issueFailedAt == other.issueFailedAt && issuedAt == other.issuedAt && lineItems == other.lineItems && maximum == other.maximum && maximumAmount == other.maximumAmount && memo == other.memo && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && paidAt == other.paidAt && paymentAttempts == other.paymentAttempts && paymentFailedAt == other.paymentFailedAt && paymentStartedAt == other.paymentStartedAt && scheduledIssueAt == other.scheduledIssueAt && shippingAddress == other.shippingAddress && status == other.status && subscription == other.subscription && subtotal == other.subtotal && syncFailedAt == other.syncFailedAt && total == other.total && voidedAt == other.voidedAt && willAutoIssue == other.willAutoIssue && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Invoice && + id == other.id && + amountDue == other.amountDue && + autoCollection == other.autoCollection && + billingAddress == other.billingAddress && + createdAt == other.createdAt && + creditNotes == other.creditNotes && + currency == other.currency && + customer == other.customer && + customerBalanceTransactions == other.customerBalanceTransactions && + customerTaxId == other.customerTaxId && + discount == other.discount && + discounts == other.discounts && + dueDate == other.dueDate && + eligibleToIssueAt == other.eligibleToIssueAt && + hostedInvoiceUrl == other.hostedInvoiceUrl && + invoiceDate == other.invoiceDate && + invoiceNumber == other.invoiceNumber && + invoicePdf == other.invoicePdf && + invoiceSource == other.invoiceSource && + issueFailedAt == other.issueFailedAt && + issuedAt == other.issuedAt && + lineItems == other.lineItems && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + memo == other.memo && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + paidAt == other.paidAt && + paymentAttempts == other.paymentAttempts && + paymentFailedAt == other.paymentFailedAt && + paymentStartedAt == other.paymentStartedAt && + scheduledIssueAt == other.scheduledIssueAt && + shippingAddress == other.shippingAddress && + status == other.status && + subscription == other.subscription && + subtotal == other.subtotal && + syncFailedAt == other.syncFailedAt && + total == other.total && + voidedAt == other.voidedAt && + willAutoIssue == other.willAutoIssue && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amountDue, autoCollection, billingAddress, createdAt, creditNotes, currency, customer, customerBalanceTransactions, customerTaxId, discount, discounts, dueDate, eligibleToIssueAt, hostedInvoiceUrl, invoiceDate, invoiceNumber, invoicePdf, invoiceSource, issueFailedAt, issuedAt, lineItems, maximum, maximumAmount, memo, metadata, minimum, minimumAmount, paidAt, paymentAttempts, paymentFailedAt, paymentStartedAt, scheduledIssueAt, shippingAddress, status, subscription, subtotal, syncFailedAt, total, voidedAt, willAutoIssue, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amountDue, + autoCollection, + billingAddress, + createdAt, + creditNotes, + currency, + customer, + customerBalanceTransactions, + customerTaxId, + discount, + discounts, + dueDate, + eligibleToIssueAt, + hostedInvoiceUrl, + invoiceDate, + invoiceNumber, + invoicePdf, + invoiceSource, + issueFailedAt, + issuedAt, + lineItems, + maximum, + maximumAmount, + memo, + metadata, + minimum, + minimumAmount, + paidAt, + paymentAttempts, + paymentFailedAt, + paymentStartedAt, + scheduledIssueAt, + shippingAddress, + status, + subscription, + subtotal, + syncFailedAt, + total, + voidedAt, + willAutoIssue, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceCreateParams.kt index 92db04fc8..613a3f96b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceCreateParams.kt @@ -6,14 +6,25 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.BaseDeserializer +import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.Params +import com.withorb.api.core.allMaxBy import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired +import com.withorb.api.core.getOrThrow import com.withorb.api.core.http.Headers import com.withorb.api.core.http.QueryParams import com.withorb.api.core.toImmutable @@ -71,6 +82,15 @@ private constructor( */ fun discount(): Discount? = body.discount() + /** + * An optional custom due date for the invoice. If not set, the due date will be calculated + * based on the `net_terms` value. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun dueDate(): DueDate? = body.dueDate() + /** * The `external_customer_id` of the `Customer` to create this invoice for. One of `customer_id` * and `external_customer_id` are required. @@ -81,7 +101,8 @@ private constructor( fun externalCustomerId(): String? = body.externalCustomerId() /** - * An optional memo to attach to the invoice. + * An optional memo to attach to the invoice. If no memo is provided, we will attach the default + * memo * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -99,9 +120,11 @@ private constructor( fun metadata(): Metadata? = body.metadata() /** - * Determines the difference between the invoice issue date for subscription invoices as the - * date that they are due. A value of '0' here represents that the invoice is due on issue, - * whereas a value of 30 represents that the customer has 30 days to pay the invoice. + * The net terms determines the due date of the invoice. Due date is calculated based on the + * invoice or issuance date, depending on the account's configured due date calculation method. + * A value of '0' here represents that the invoice is due on issue, whereas a value of '30' + * represents that the customer has 30 days to pay the invoice. Do not set this field if you + * want to set a custom due date. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -152,6 +175,13 @@ private constructor( */ fun _discount(): JsonField = body._discount() + /** + * Returns the raw JSON value of [dueDate]. + * + * Unlike [dueDate], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _dueDate(): JsonField = body._dueDate() + /** * Returns the raw JSON value of [externalCustomerId]. * @@ -362,6 +392,26 @@ private constructor( */ fun amountDiscount(amountDiscount: String) = apply { body.amountDiscount(amountDiscount) } + /** + * An optional custom due date for the invoice. If not set, the due date will be calculated + * based on the `net_terms` value. + */ + fun dueDate(dueDate: DueDate?) = apply { body.dueDate(dueDate) } + + /** + * Sets [Builder.dueDate] to an arbitrary JSON value. + * + * You should usually call [Builder.dueDate] with a well-typed [DueDate] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun dueDate(dueDate: JsonField) = apply { body.dueDate(dueDate) } + + /** Alias for calling [dueDate] with `DueDate.ofDate(date)`. */ + fun dueDate(date: LocalDate) = apply { body.dueDate(date) } + + /** Alias for calling [dueDate] with `DueDate.ofDateTime(dateTime)`. */ + fun dueDate(dateTime: OffsetDateTime) = apply { body.dueDate(dateTime) } + /** * The `external_customer_id` of the `Customer` to create this invoice for. One of * `customer_id` and `external_customer_id` are required. @@ -381,7 +431,10 @@ private constructor( body.externalCustomerId(externalCustomerId) } - /** An optional memo to attach to the invoice. */ + /** + * An optional memo to attach to the invoice. If no memo is provided, we will attach the + * default memo + */ fun memo(memo: String?) = apply { body.memo(memo) } /** @@ -409,9 +462,11 @@ private constructor( fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } /** - * Determines the difference between the invoice issue date for subscription invoices as the - * date that they are due. A value of '0' here represents that the invoice is due on issue, - * whereas a value of 30 represents that the customer has 30 days to pay the invoice. + * The net terms determines the due date of the invoice. Due date is calculated based on the + * invoice or issuance date, depending on the account's configured due date calculation + * method. A value of '0' here represents that the invoice is due on issue, whereas a value + * of '30' represents that the customer has 30 days to pay the invoice. Do not set this + * field if you want to set a custom due date. */ fun netTerms(netTerms: Long?) = apply { body.netTerms(netTerms) } @@ -593,12 +648,14 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val currency: JsonField, private val invoiceDate: JsonField, private val lineItems: JsonField>, private val customerId: JsonField, private val discount: JsonField, + private val dueDate: JsonField, private val externalCustomerId: JsonField, private val memo: JsonField, private val metadata: JsonField, @@ -624,6 +681,9 @@ private constructor( @JsonProperty("discount") @ExcludeMissing discount: JsonField = JsonMissing.of(), + @JsonProperty("due_date") + @ExcludeMissing + dueDate: JsonField = JsonMissing.of(), @JsonProperty("external_customer_id") @ExcludeMissing externalCustomerId: JsonField = JsonMissing.of(), @@ -641,6 +701,7 @@ private constructor( lineItems, customerId, discount, + dueDate, externalCustomerId, memo, metadata, @@ -689,6 +750,15 @@ private constructor( */ fun discount(): Discount? = discount.getNullable("discount") + /** + * An optional custom due date for the invoice. If not set, the due date will be calculated + * based on the `net_terms` value. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dueDate(): DueDate? = dueDate.getNullable("due_date") + /** * The `external_customer_id` of the `Customer` to create this invoice for. One of * `customer_id` and `external_customer_id` are required. @@ -699,7 +769,8 @@ private constructor( fun externalCustomerId(): String? = externalCustomerId.getNullable("external_customer_id") /** - * An optional memo to attach to the invoice. + * An optional memo to attach to the invoice. If no memo is provided, we will attach the + * default memo * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -717,9 +788,11 @@ private constructor( fun metadata(): Metadata? = metadata.getNullable("metadata") /** - * Determines the difference between the invoice issue date for subscription invoices as the - * date that they are due. A value of '0' here represents that the invoice is due on issue, - * whereas a value of 30 represents that the customer has 30 days to pay the invoice. + * The net terms determines the due date of the invoice. Due date is calculated based on the + * invoice or issuance date, depending on the account's configured due date calculation + * method. A value of '0' here represents that the invoice is due on issue, whereas a value + * of '30' represents that the customer has 30 days to pay the invoice. Do not set this + * field if you want to set a custom due date. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -776,6 +849,13 @@ private constructor( */ @JsonProperty("discount") @ExcludeMissing fun _discount(): JsonField = discount + /** + * Returns the raw JSON value of [dueDate]. + * + * Unlike [dueDate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("due_date") @ExcludeMissing fun _dueDate(): JsonField = dueDate + /** * Returns the raw JSON value of [externalCustomerId]. * @@ -852,6 +932,7 @@ private constructor( private var lineItems: JsonField>? = null private var customerId: JsonField = JsonMissing.of() private var discount: JsonField = JsonMissing.of() + private var dueDate: JsonField = JsonMissing.of() private var externalCustomerId: JsonField = JsonMissing.of() private var memo: JsonField = JsonMissing.of() private var metadata: JsonField = JsonMissing.of() @@ -865,6 +946,7 @@ private constructor( lineItems = body.lineItems.map { it.toMutableList() } customerId = body.customerId discount = body.discount + dueDate = body.dueDate externalCustomerId = body.externalCustomerId memo = body.memo metadata = body.metadata @@ -1021,6 +1103,27 @@ private constructor( .build() ) + /** + * An optional custom due date for the invoice. If not set, the due date will be + * calculated based on the `net_terms` value. + */ + fun dueDate(dueDate: DueDate?) = dueDate(JsonField.ofNullable(dueDate)) + + /** + * Sets [Builder.dueDate] to an arbitrary JSON value. + * + * You should usually call [Builder.dueDate] with a well-typed [DueDate] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun dueDate(dueDate: JsonField) = apply { this.dueDate = dueDate } + + /** Alias for calling [dueDate] with `DueDate.ofDate(date)`. */ + fun dueDate(date: LocalDate) = dueDate(DueDate.ofDate(date)) + + /** Alias for calling [dueDate] with `DueDate.ofDateTime(dateTime)`. */ + fun dueDate(dateTime: OffsetDateTime) = dueDate(DueDate.ofDateTime(dateTime)) + /** * The `external_customer_id` of the `Customer` to create this invoice for. One of * `customer_id` and `external_customer_id` are required. @@ -1039,7 +1142,10 @@ private constructor( this.externalCustomerId = externalCustomerId } - /** An optional memo to attach to the invoice. */ + /** + * An optional memo to attach to the invoice. If no memo is provided, we will attach the + * default memo + */ fun memo(memo: String?) = memo(JsonField.ofNullable(memo)) /** @@ -1068,10 +1174,11 @@ private constructor( fun metadata(metadata: JsonField) = apply { this.metadata = metadata } /** - * Determines the difference between the invoice issue date for subscription invoices as - * the date that they are due. A value of '0' here represents that the invoice is due on - * issue, whereas a value of 30 represents that the customer has 30 days to pay the - * invoice. + * The net terms determines the due date of the invoice. Due date is calculated based on + * the invoice or issuance date, depending on the account's configured due date + * calculation method. A value of '0' here represents that the invoice is due on issue, + * whereas a value of '30' represents that the customer has 30 days to pay the invoice. + * Do not set this field if you want to set a custom due date. */ fun netTerms(netTerms: Long?) = netTerms(JsonField.ofNullable(netTerms)) @@ -1148,6 +1255,7 @@ private constructor( checkRequired("lineItems", lineItems).map { it.toImmutable() }, customerId, discount, + dueDate, externalCustomerId, memo, metadata, @@ -1169,6 +1277,7 @@ private constructor( lineItems().forEach { it.validate() } customerId() discount()?.validate() + dueDate()?.validate() externalCustomerId() memo() metadata()?.validate() @@ -1197,6 +1306,7 @@ private constructor( (lineItems.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (customerId.asKnown() == null) 0 else 1) + (discount.asKnown()?.validity() ?: 0) + + (dueDate.asKnown()?.validity() ?: 0) + (if (externalCustomerId.asKnown() == null) 0 else 1) + (if (memo.asKnown() == null) 0 else 1) + (metadata.asKnown()?.validity() ?: 0) + @@ -1208,20 +1318,46 @@ private constructor( return true } - return /* spotless:off */ other is Body && currency == other.currency && invoiceDate == other.invoiceDate && lineItems == other.lineItems && customerId == other.customerId && discount == other.discount && externalCustomerId == other.externalCustomerId && memo == other.memo && metadata == other.metadata && netTerms == other.netTerms && willAutoIssue == other.willAutoIssue && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + currency == other.currency && + invoiceDate == other.invoiceDate && + lineItems == other.lineItems && + customerId == other.customerId && + discount == other.discount && + dueDate == other.dueDate && + externalCustomerId == other.externalCustomerId && + memo == other.memo && + metadata == other.metadata && + netTerms == other.netTerms && + willAutoIssue == other.willAutoIssue && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(currency, invoiceDate, lineItems, customerId, discount, externalCustomerId, memo, metadata, netTerms, willAutoIssue, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + currency, + invoiceDate, + lineItems, + customerId, + discount, + dueDate, + externalCustomerId, + memo, + metadata, + netTerms, + willAutoIssue, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Body{currency=$currency, invoiceDate=$invoiceDate, lineItems=$lineItems, customerId=$customerId, discount=$discount, externalCustomerId=$externalCustomerId, memo=$memo, metadata=$metadata, netTerms=$netTerms, willAutoIssue=$willAutoIssue, additionalProperties=$additionalProperties}" + "Body{currency=$currency, invoiceDate=$invoiceDate, lineItems=$lineItems, customerId=$customerId, discount=$discount, dueDate=$dueDate, externalCustomerId=$externalCustomerId, memo=$memo, metadata=$metadata, netTerms=$netTerms, willAutoIssue=$willAutoIssue, additionalProperties=$additionalProperties}" } class LineItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val endDate: JsonField, private val itemId: JsonField, @@ -1299,6 +1435,8 @@ private constructor( fun startDate(): LocalDate = startDate.getRequired("start_date") /** + * Configuration for unit pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -1483,6 +1621,7 @@ private constructor( */ fun startDate(startDate: JsonField) = apply { this.startDate = startDate } + /** Configuration for unit pricing */ fun unitConfig(unitConfig: UnitConfig) = unitConfig(JsonField.of(unitConfig)) /** @@ -1701,7 +1840,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1714,12 +1853,29 @@ private constructor( return true } - return /* spotless:off */ other is LineItem && endDate == other.endDate && itemId == other.itemId && modelType == other.modelType && name == other.name && quantity == other.quantity && startDate == other.startDate && unitConfig == other.unitConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is LineItem && + endDate == other.endDate && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + quantity == other.quantity && + startDate == other.startDate && + unitConfig == other.unitConfig && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(endDate, itemId, modelType, name, quantity, startDate, unitConfig, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + endDate, + itemId, + modelType, + name, + quantity, + startDate, + unitConfig, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1727,6 +1883,178 @@ private constructor( "LineItem{endDate=$endDate, itemId=$itemId, modelType=$modelType, name=$name, quantity=$quantity, startDate=$startDate, unitConfig=$unitConfig, additionalProperties=$additionalProperties}" } + /** + * An optional custom due date for the invoice. If not set, the due date will be calculated + * based on the `net_terms` value. + */ + @JsonDeserialize(using = DueDate.Deserializer::class) + @JsonSerialize(using = DueDate.Serializer::class) + class DueDate + private constructor( + private val date: LocalDate? = null, + private val dateTime: OffsetDateTime? = null, + private val _json: JsonValue? = null, + ) { + + fun date(): LocalDate? = date + + fun dateTime(): OffsetDateTime? = dateTime + + fun isDate(): Boolean = date != null + + fun isDateTime(): Boolean = dateTime != null + + fun asDate(): LocalDate = date.getOrThrow("date") + + fun asDateTime(): OffsetDateTime = dateTime.getOrThrow("dateTime") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + date != null -> visitor.visitDate(date) + dateTime != null -> visitor.visitDateTime(dateTime) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): DueDate = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitDate(date: LocalDate) {} + + override fun visitDateTime(dateTime: OffsetDateTime) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitDate(date: LocalDate) = 1 + + override fun visitDateTime(dateTime: OffsetDateTime) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DueDate && date == other.date && dateTime == other.dateTime + } + + override fun hashCode(): Int = Objects.hash(date, dateTime) + + override fun toString(): String = + when { + date != null -> "DueDate{date=$date}" + dateTime != null -> "DueDate{dateTime=$dateTime}" + _json != null -> "DueDate{_unknown=$_json}" + else -> throw IllegalStateException("Invalid DueDate") + } + + companion object { + + fun ofDate(date: LocalDate) = DueDate(date = date) + + fun ofDateTime(dateTime: OffsetDateTime) = DueDate(dateTime = dateTime) + } + + /** + * An interface that defines how to map each variant of [DueDate] to a value of type [T]. + */ + interface Visitor { + + fun visitDate(date: LocalDate): T + + fun visitDateTime(dateTime: OffsetDateTime): T + + /** + * Maps an unknown variant of [DueDate] to a value of type [T]. + * + * An instance of [DueDate] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown DueDate: $json") + } + } + + internal class Deserializer : BaseDeserializer(DueDate::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): DueDate { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + DueDate(date = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + DueDate(dateTime = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from object). + 0 -> DueDate(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(DueDate::class) { + + override fun serialize( + value: DueDate, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.date != null -> generator.writeObject(value.date) + value.dateTime != null -> generator.writeObject(value.dateTime) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid DueDate") + } + } + } + } + /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1819,12 +2147,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1836,10 +2162,13 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is InvoiceCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "InvoiceCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceFetchParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceFetchParams.kt index cd4aa98ec..4cbff9b06 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceFetchParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceFetchParams.kt @@ -170,10 +170,13 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceFetchParams && invoiceId == other.invoiceId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is InvoiceFetchParams && + invoiceId == other.invoiceId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(invoiceId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(invoiceId, additionalHeaders, additionalQueryParams) override fun toString() = "InvoiceFetchParams{invoiceId=$invoiceId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceFetchUpcomingParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceFetchUpcomingParams.kt index 84ef1e721..943c0f66d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceFetchUpcomingParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceFetchUpcomingParams.kt @@ -190,10 +190,14 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceFetchUpcomingParams && subscriptionId == other.subscriptionId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is InvoiceFetchUpcomingParams && + subscriptionId == other.subscriptionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionId, additionalHeaders, additionalQueryParams) override fun toString() = "InvoiceFetchUpcomingParams{subscriptionId=$subscriptionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceFetchUpcomingResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceFetchUpcomingResponse.kt index 6a4a0e2b2..ed4908c15 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceFetchUpcomingResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceFetchUpcomingResponse.kt @@ -30,6 +30,7 @@ import java.util.Collections import java.util.Objects class InvoiceFetchUpcomingResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amountDue: JsonField, @@ -360,9 +361,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -1395,9 +1396,9 @@ private constructor( * |Ireland |`eu_vat` |European VAT Number | * |Israel |`il_vat` |Israel VAT | * |Italy |`eu_vat` |European VAT Number | - * |Japan |`jp_cn` |Japanese Corporate Number (_Hōjin Bangō_) | - * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_)| - * |Japan |`jp_trn` |Japanese Tax Registration Number (_Tōroku Bangō_) | + * |Japan |`jp_cn` |Japanese Corporate Number (*Hōjin Bangō*) | + * |Japan |`jp_rn` |Japanese Registered Foreign Businesses' Registration Number (*Tōroku Kokugai Jigyōsha no Tōroku Bangō*)| + * |Japan |`jp_trn` |Japanese Tax Registration Number (*Tōroku Bangō*) | * |Kazakhstan |`kz_bin` |Kazakhstani Business Identification Number | * |Kenya |`ke_pin` |Kenya Revenue Authority Personal Identification Number | * |Kyrgyzstan |`kg_tin` |Kyrgyzstan Tax Identification Number | @@ -2232,6 +2233,7 @@ private constructor( (if (willAutoIssue.asKnown() == null) 0 else 1) class AutoCollection + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val enabled: JsonField, private val nextAttemptAt: JsonField, @@ -2537,12 +2539,23 @@ private constructor( return true } - return /* spotless:off */ other is AutoCollection && enabled == other.enabled && nextAttemptAt == other.nextAttemptAt && numAttempts == other.numAttempts && previouslyAttemptedAt == other.previouslyAttemptedAt && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AutoCollection && + enabled == other.enabled && + nextAttemptAt == other.nextAttemptAt && + numAttempts == other.numAttempts && + previouslyAttemptedAt == other.previouslyAttemptedAt && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(enabled, nextAttemptAt, numAttempts, previouslyAttemptedAt, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + enabled, + nextAttemptAt, + numAttempts, + previouslyAttemptedAt, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2551,6 +2564,7 @@ private constructor( } class CreditNote + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val creditNoteNumber: JsonField, @@ -2912,12 +2926,29 @@ private constructor( return true } - return /* spotless:off */ other is CreditNote && id == other.id && creditNoteNumber == other.creditNoteNumber && memo == other.memo && reason == other.reason && total == other.total && type == other.type && voidedAt == other.voidedAt && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CreditNote && + id == other.id && + creditNoteNumber == other.creditNoteNumber && + memo == other.memo && + reason == other.reason && + total == other.total && + type == other.type && + voidedAt == other.voidedAt && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, creditNoteNumber, memo, reason, total, type, voidedAt, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + creditNoteNumber, + memo, + reason, + total, + type, + voidedAt, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2926,6 +2957,7 @@ private constructor( } class CustomerBalanceTransaction + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val action: JsonField, @@ -3467,6 +3499,8 @@ private constructor( val EXTERNAL_PAYMENT = of("external_payment") + val SMALL_INVOICE_CARRYOVER = of("small_invoice_carryover") + fun of(value: String) = Action(JsonField.of(value)) } @@ -3481,6 +3515,7 @@ private constructor( CREDIT_NOTE_VOIDED, OVERPAYMENT_REFUND, EXTERNAL_PAYMENT, + SMALL_INVOICE_CARRYOVER, } /** @@ -3502,6 +3537,7 @@ private constructor( CREDIT_NOTE_VOIDED, OVERPAYMENT_REFUND, EXTERNAL_PAYMENT, + SMALL_INVOICE_CARRYOVER, /** * An enum member indicating that [Action] was instantiated with an unknown value. */ @@ -3526,6 +3562,7 @@ private constructor( CREDIT_NOTE_VOIDED -> Value.CREDIT_NOTE_VOIDED OVERPAYMENT_REFUND -> Value.OVERPAYMENT_REFUND EXTERNAL_PAYMENT -> Value.EXTERNAL_PAYMENT + SMALL_INVOICE_CARRYOVER -> Value.SMALL_INVOICE_CARRYOVER else -> Value._UNKNOWN } @@ -3549,6 +3586,7 @@ private constructor( CREDIT_NOTE_VOIDED -> Known.CREDIT_NOTE_VOIDED OVERPAYMENT_REFUND -> Known.OVERPAYMENT_REFUND EXTERNAL_PAYMENT -> Known.EXTERNAL_PAYMENT + SMALL_INVOICE_CARRYOVER -> Known.SMALL_INVOICE_CARRYOVER else -> throw OrbInvalidDataException("Unknown Action: $value") } @@ -3596,7 +3634,7 @@ private constructor( return true } - return /* spotless:off */ other is Action && value == other.value /* spotless:on */ + return other is Action && value == other.value } override fun hashCode() = value.hashCode() @@ -3721,7 +3759,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -3734,12 +3772,35 @@ private constructor( return true } - return /* spotless:off */ other is CustomerBalanceTransaction && id == other.id && action == other.action && amount == other.amount && createdAt == other.createdAt && creditNote == other.creditNote && description == other.description && endingBalance == other.endingBalance && invoice == other.invoice && startingBalance == other.startingBalance && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CustomerBalanceTransaction && + id == other.id && + action == other.action && + amount == other.amount && + createdAt == other.createdAt && + creditNote == other.creditNote && + description == other.description && + endingBalance == other.endingBalance && + invoice == other.invoice && + startingBalance == other.startingBalance && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, action, amount, createdAt, creditNote, description, endingBalance, invoice, startingBalance, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + action, + amount, + createdAt, + creditNote, + description, + endingBalance, + invoice, + startingBalance, + type, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -3873,7 +3934,7 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceSource && value == other.value /* spotless:on */ + return other is InvoiceSource && value == other.value } override fun hashCode() = value.hashCode() @@ -3882,20 +3943,16 @@ private constructor( } class LineItem + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustedSubtotal: JsonField, private val adjustments: JsonField>, private val amount: JsonField, private val creditsApplied: JsonField, - private val discount: JsonField, private val endDate: JsonField, private val filter: JsonField, private val grouping: JsonField, - private val maximum: JsonField, - private val maximumAmount: JsonField, - private val minimum: JsonField, - private val minimumAmount: JsonField, private val name: JsonField, private val partiallyInvoicedAmount: JsonField, private val price: JsonField, @@ -3921,9 +3978,6 @@ private constructor( @JsonProperty("credits_applied") @ExcludeMissing creditsApplied: JsonField = JsonMissing.of(), - @JsonProperty("discount") - @ExcludeMissing - discount: JsonField = JsonMissing.of(), @JsonProperty("end_date") @ExcludeMissing endDate: JsonField = JsonMissing.of(), @@ -3931,14 +3985,6 @@ private constructor( @JsonProperty("grouping") @ExcludeMissing grouping: JsonField = JsonMissing.of(), - @JsonProperty("maximum") @ExcludeMissing maximum: JsonField = JsonMissing.of(), - @JsonProperty("maximum_amount") - @ExcludeMissing - maximumAmount: JsonField = JsonMissing.of(), - @JsonProperty("minimum") @ExcludeMissing minimum: JsonField = JsonMissing.of(), - @JsonProperty("minimum_amount") - @ExcludeMissing - minimumAmount: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("partially_invoiced_amount") @ExcludeMissing @@ -3968,14 +4014,9 @@ private constructor( adjustments, amount, creditsApplied, - discount, endDate, filter, grouping, - maximum, - maximumAmount, - minimum, - minimumAmount, name, partiallyInvoicedAmount, price, @@ -4032,14 +4073,6 @@ private constructor( */ fun creditsApplied(): String = creditsApplied.getRequired("credits_applied") - /** - * This field is deprecated in favor of `adjustments` - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") fun discount(): Discount? = discount.getNullable("discount") - /** * The end date of the range of time applied for this line item's price. * @@ -4066,40 +4099,6 @@ private constructor( */ fun grouping(): String? = grouping.getNullable("grouping") - /** - * This field is deprecated in favor of `adjustments`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") fun maximum(): Maximum? = maximum.getNullable("maximum") - - /** - * This field is deprecated in favor of `adjustments`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") - fun maximumAmount(): String? = maximumAmount.getNullable("maximum_amount") - - /** - * This field is deprecated in favor of `adjustments`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") fun minimum(): Minimum? = minimum.getNullable("minimum") - - /** - * This field is deprecated in favor of `adjustments`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") - fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") - /** * The name of the price associated with this line item. * @@ -4160,7 +4159,7 @@ private constructor( fun subLineItems(): List = subLineItems.getRequired("sub_line_items") /** - * The line amount before before any adjustments. + * The line amount before any adjustments. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -4227,16 +4226,6 @@ private constructor( @ExcludeMissing fun _creditsApplied(): JsonField = creditsApplied - /** - * Returns the raw JSON value of [discount]. - * - * Unlike [discount], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("discount") - @ExcludeMissing - fun _discount(): JsonField = discount - /** * Returns the raw JSON value of [endDate]. * @@ -4260,48 +4249,6 @@ private constructor( */ @JsonProperty("grouping") @ExcludeMissing fun _grouping(): JsonField = grouping - /** - * Returns the raw JSON value of [maximum]. - * - * Unlike [maximum], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("maximum") - @ExcludeMissing - fun _maximum(): JsonField = maximum - - /** - * Returns the raw JSON value of [maximumAmount]. - * - * Unlike [maximumAmount], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @Deprecated("deprecated") - @JsonProperty("maximum_amount") - @ExcludeMissing - fun _maximumAmount(): JsonField = maximumAmount - - /** - * Returns the raw JSON value of [minimum]. - * - * Unlike [minimum], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("minimum") - @ExcludeMissing - fun _minimum(): JsonField = minimum - - /** - * Returns the raw JSON value of [minimumAmount]. - * - * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @Deprecated("deprecated") - @JsonProperty("minimum_amount") - @ExcludeMissing - fun _minimumAmount(): JsonField = minimumAmount - /** * Returns the raw JSON value of [name]. * @@ -4402,14 +4349,9 @@ private constructor( * .adjustments() * .amount() * .creditsApplied() - * .discount() * .endDate() * .filter() * .grouping() - * .maximum() - * .maximumAmount() - * .minimum() - * .minimumAmount() * .name() * .partiallyInvoicedAmount() * .price() @@ -4432,14 +4374,9 @@ private constructor( private var adjustments: JsonField>? = null private var amount: JsonField? = null private var creditsApplied: JsonField? = null - private var discount: JsonField? = null private var endDate: JsonField? = null private var filter: JsonField? = null private var grouping: JsonField? = null - private var maximum: JsonField? = null - private var maximumAmount: JsonField? = null - private var minimum: JsonField? = null - private var minimumAmount: JsonField? = null private var name: JsonField? = null private var partiallyInvoicedAmount: JsonField? = null private var price: JsonField? = null @@ -4457,14 +4394,9 @@ private constructor( adjustments = lineItem.adjustments.map { it.toMutableList() } amount = lineItem.amount creditsApplied = lineItem.creditsApplied - discount = lineItem.discount endDate = lineItem.endDate filter = lineItem.filter grouping = lineItem.grouping - maximum = lineItem.maximum - maximumAmount = lineItem.maximumAmount - minimum = lineItem.minimum - minimumAmount = lineItem.minimumAmount name = lineItem.name partiallyInvoicedAmount = lineItem.partiallyInvoicedAmount price = lineItem.price @@ -4594,91 +4526,6 @@ private constructor( this.creditsApplied = creditsApplied } - /** This field is deprecated in favor of `adjustments` */ - @Deprecated("deprecated") - fun discount(discount: Discount?) = discount(JsonField.ofNullable(discount)) - - /** - * Sets [Builder.discount] to an arbitrary JSON value. - * - * You should usually call [Builder.discount] with a well-typed [Discount] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun discount(discount: JsonField) = apply { this.discount = discount } - - /** Alias for calling [discount] with `Discount.ofPercentage(percentage)`. */ - @Deprecated("deprecated") - fun discount(percentage: PercentageDiscount) = - discount(Discount.ofPercentage(percentage)) - - /** - * Alias for calling [discount] with the following: - * ```kotlin - * PercentageDiscount.builder() - * .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - * .percentageDiscount(percentageDiscount) - * .build() - * ``` - */ - @Deprecated("deprecated") - fun percentageDiscount(percentageDiscount: Double) = - discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(percentageDiscount) - .build() - ) - - /** Alias for calling [discount] with `Discount.ofTrial(trial)`. */ - @Deprecated("deprecated") - fun discount(trial: TrialDiscount) = discount(Discount.ofTrial(trial)) - - /** Alias for calling [discount] with `Discount.ofUsage(usage)`. */ - @Deprecated("deprecated") - fun discount(usage: UsageDiscount) = discount(Discount.ofUsage(usage)) - - /** - * Alias for calling [discount] with the following: - * ```kotlin - * UsageDiscount.builder() - * .discountType(UsageDiscount.DiscountType.USAGE) - * .usageDiscount(usageDiscount) - * .build() - * ``` - */ - @Deprecated("deprecated") - fun usageDiscount(usageDiscount: Double) = - discount( - UsageDiscount.builder() - .discountType(UsageDiscount.DiscountType.USAGE) - .usageDiscount(usageDiscount) - .build() - ) - - /** Alias for calling [discount] with `Discount.ofAmount(amount)`. */ - @Deprecated("deprecated") - fun discount(amount: AmountDiscount) = discount(Discount.ofAmount(amount)) - - /** - * Alias for calling [discount] with the following: - * ```kotlin - * AmountDiscount.builder() - * .discountType(AmountDiscount.DiscountType.AMOUNT) - * .amountDiscount(amountDiscount) - * .build() - * ``` - */ - @Deprecated("deprecated") - fun amountDiscount(amountDiscount: String) = - discount( - AmountDiscount.builder() - .discountType(AmountDiscount.DiscountType.AMOUNT) - .amountDiscount(amountDiscount) - .build() - ) - /** The end date of the range of time applied for this line item's price. */ fun endDate(endDate: OffsetDateTime) = endDate(JsonField.of(endDate)) @@ -4719,68 +4566,6 @@ private constructor( */ fun grouping(grouping: JsonField) = apply { this.grouping = grouping } - /** This field is deprecated in favor of `adjustments`. */ - @Deprecated("deprecated") - fun maximum(maximum: Maximum?) = maximum(JsonField.ofNullable(maximum)) - - /** - * Sets [Builder.maximum] to an arbitrary JSON value. - * - * You should usually call [Builder.maximum] with a well-typed [Maximum] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun maximum(maximum: JsonField) = apply { this.maximum = maximum } - - /** This field is deprecated in favor of `adjustments`. */ - @Deprecated("deprecated") - fun maximumAmount(maximumAmount: String?) = - maximumAmount(JsonField.ofNullable(maximumAmount)) - - /** - * Sets [Builder.maximumAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.maximumAmount] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun maximumAmount(maximumAmount: JsonField) = apply { - this.maximumAmount = maximumAmount - } - - /** This field is deprecated in favor of `adjustments`. */ - @Deprecated("deprecated") - fun minimum(minimum: Minimum?) = minimum(JsonField.ofNullable(minimum)) - - /** - * Sets [Builder.minimum] to an arbitrary JSON value. - * - * You should usually call [Builder.minimum] with a well-typed [Minimum] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun minimum(minimum: JsonField) = apply { this.minimum = minimum } - - /** This field is deprecated in favor of `adjustments`. */ - @Deprecated("deprecated") - fun minimumAmount(minimumAmount: String?) = - minimumAmount(JsonField.ofNullable(minimumAmount)) - - /** - * Sets [Builder.minimumAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.minimumAmount] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun minimumAmount(minimumAmount: JsonField) = apply { - this.minimumAmount = minimumAmount - } - /** The name of the price associated with this line item. */ fun name(name: String) = name(JsonField.of(name)) @@ -4832,28 +4617,23 @@ private constructor( fun price(price: JsonField) = apply { this.price = price } /** Alias for calling [price] with `Price.ofUnit(unit)`. */ - fun price(unit: Price.Unit) = price(Price.ofUnit(unit)) - - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: Price.Package) = price(Price.ofPackage(package_)) - - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: Price.Matrix) = price(Price.ofMatrix(matrix)) + fun price(unit: Price.UnitPrice) = price(Price.ofUnit(unit)) /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ fun price(tiered: Price.Tiered) = price(Price.ofTiered(tiered)) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: Price.TieredBps) = price(Price.ofTieredBps(tieredBps)) + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: Price.Bulk) = price(Price.ofBulk(bulk)) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: Price.Bps) = price(Price.ofBps(bps)) + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: Price.BulkBps) = price(Price.ofBulkBps(bulkBps)) + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: Price.Package) = price(Price.ofPackage(package_)) - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: Price.Bulk) = price(Price.ofBulk(bulk)) + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: Price.Matrix) = price(Price.ofMatrix(matrix)) /** * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. @@ -4865,14 +4645,14 @@ private constructor( fun price(tieredPackage: Price.TieredPackage) = price(Price.ofTieredPackage(tieredPackage)) - /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: Price.GroupedTiered) = - price(Price.ofGroupedTiered(groupedTiered)) - /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ fun price(tieredWithMinimum: Price.TieredWithMinimum) = price(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: Price.GroupedTiered) = + price(Price.ofGroupedTiered(groupedTiered)) + /** * Alias for calling [price] with * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. @@ -4911,6 +4691,10 @@ private constructor( fun price(groupedAllocation: Price.GroupedAllocation) = price(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: Price.BulkWithProration) = + price(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [price] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -4925,6 +4709,13 @@ private constructor( fun price(groupedWithMeteredMinimum: Price.GroupedWithMeteredMinimum) = price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** * Alias for calling [price] with * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. @@ -4932,10 +4723,6 @@ private constructor( fun price(matrixWithDisplayName: Price.MatrixWithDisplayName) = price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: Price.BulkWithProration) = - price(Price.ofBulkWithProration(bulkWithProration)) - /** * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. */ @@ -4972,10 +4759,19 @@ private constructor( /** * Alias for calling [price] with - * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. */ - fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = - price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: Price.Minimum) = price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) /** Either the fixed fee quantity or the usage during the service period. */ fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) @@ -5043,7 +4839,7 @@ private constructor( /** Alias for calling [addSubLineItem] with `SubLineItem.ofNull(null_)`. */ fun addSubLineItem(null_: OtherSubLineItem) = addSubLineItem(SubLineItem.ofNull(null_)) - /** The line amount before before any adjustments. */ + /** The line amount before any adjustments. */ fun subtotal(subtotal: String) = subtotal(JsonField.of(subtotal)) /** @@ -5142,14 +4938,9 @@ private constructor( * .adjustments() * .amount() * .creditsApplied() - * .discount() * .endDate() * .filter() * .grouping() - * .maximum() - * .maximumAmount() - * .minimum() - * .minimumAmount() * .name() * .partiallyInvoicedAmount() * .price() @@ -5170,14 +4961,9 @@ private constructor( checkRequired("adjustments", adjustments).map { it.toImmutable() }, checkRequired("amount", amount), checkRequired("creditsApplied", creditsApplied), - checkRequired("discount", discount), checkRequired("endDate", endDate), checkRequired("filter", filter), checkRequired("grouping", grouping), - checkRequired("maximum", maximum), - checkRequired("maximumAmount", maximumAmount), - checkRequired("minimum", minimum), - checkRequired("minimumAmount", minimumAmount), checkRequired("name", name), checkRequired("partiallyInvoicedAmount", partiallyInvoicedAmount), checkRequired("price", price), @@ -5203,14 +4989,9 @@ private constructor( adjustments().forEach { it.validate() } amount() creditsApplied() - discount()?.validate() endDate() filter() grouping() - maximum()?.validate() - maximumAmount() - minimum()?.validate() - minimumAmount() name() partiallyInvoicedAmount() price().validate() @@ -5243,14 +5024,9 @@ private constructor( (adjustments.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (amount.asKnown() == null) 0 else 1) + (if (creditsApplied.asKnown() == null) 0 else 1) + - (discount.asKnown()?.validity() ?: 0) + (if (endDate.asKnown() == null) 0 else 1) + (if (filter.asKnown() == null) 0 else 1) + (if (grouping.asKnown() == null) 0 else 1) + - (maximum.asKnown()?.validity() ?: 0) + - (if (maximumAmount.asKnown() == null) 0 else 1) + - (minimum.asKnown()?.validity() ?: 0) + - (if (minimumAmount.asKnown() == null) 0 else 1) + (if (name.asKnown() == null) 0 else 1) + (if (partiallyInvoicedAmount.asKnown() == null) 0 else 1) + (price.asKnown()?.validity() ?: 0) + @@ -5402,10 +5178,16 @@ private constructor( return true } - return /* spotless:off */ other is Adjustment && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && percentageDiscount == other.percentageDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ + return other is Adjustment && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + percentageDiscount == other.percentageDiscount && + minimum == other.minimum && + maximum == other.maximum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(usageDiscount, amountDiscount, percentageDiscount, minimum, maximum) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(usageDiscount, amountDiscount, percentageDiscount, minimum, maximum) override fun toString(): String = when { @@ -5631,10 +5413,13 @@ private constructor( return true } - return /* spotless:off */ other is SubLineItem && matrix == other.matrix && tier == other.tier && null_ == other.null_ /* spotless:on */ + return other is SubLineItem && + matrix == other.matrix && + tier == other.tier && + null_ == other.null_ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(matrix, tier, null_) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(matrix, tier, null_) override fun toString(): String = when { @@ -5732,17 +5517,54 @@ private constructor( return true } - return /* spotless:off */ other is LineItem && id == other.id && adjustedSubtotal == other.adjustedSubtotal && adjustments == other.adjustments && amount == other.amount && creditsApplied == other.creditsApplied && discount == other.discount && endDate == other.endDate && filter == other.filter && grouping == other.grouping && maximum == other.maximum && maximumAmount == other.maximumAmount && minimum == other.minimum && minimumAmount == other.minimumAmount && name == other.name && partiallyInvoicedAmount == other.partiallyInvoicedAmount && price == other.price && quantity == other.quantity && startDate == other.startDate && subLineItems == other.subLineItems && subtotal == other.subtotal && taxAmounts == other.taxAmounts && usageCustomerIds == other.usageCustomerIds && additionalProperties == other.additionalProperties /* spotless:on */ + return other is LineItem && + id == other.id && + adjustedSubtotal == other.adjustedSubtotal && + adjustments == other.adjustments && + amount == other.amount && + creditsApplied == other.creditsApplied && + endDate == other.endDate && + filter == other.filter && + grouping == other.grouping && + name == other.name && + partiallyInvoicedAmount == other.partiallyInvoicedAmount && + price == other.price && + quantity == other.quantity && + startDate == other.startDate && + subLineItems == other.subLineItems && + subtotal == other.subtotal && + taxAmounts == other.taxAmounts && + usageCustomerIds == other.usageCustomerIds && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustedSubtotal, adjustments, amount, creditsApplied, discount, endDate, filter, grouping, maximum, maximumAmount, minimum, minimumAmount, name, partiallyInvoicedAmount, price, quantity, startDate, subLineItems, subtotal, taxAmounts, usageCustomerIds, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustedSubtotal, + adjustments, + amount, + creditsApplied, + endDate, + filter, + grouping, + name, + partiallyInvoicedAmount, + price, + quantity, + startDate, + subLineItems, + subtotal, + taxAmounts, + usageCustomerIds, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "LineItem{id=$id, adjustedSubtotal=$adjustedSubtotal, adjustments=$adjustments, amount=$amount, creditsApplied=$creditsApplied, discount=$discount, endDate=$endDate, filter=$filter, grouping=$grouping, maximum=$maximum, maximumAmount=$maximumAmount, minimum=$minimum, minimumAmount=$minimumAmount, name=$name, partiallyInvoicedAmount=$partiallyInvoicedAmount, price=$price, quantity=$quantity, startDate=$startDate, subLineItems=$subLineItems, subtotal=$subtotal, taxAmounts=$taxAmounts, usageCustomerIds=$usageCustomerIds, additionalProperties=$additionalProperties}" + "LineItem{id=$id, adjustedSubtotal=$adjustedSubtotal, adjustments=$adjustments, amount=$amount, creditsApplied=$creditsApplied, endDate=$endDate, filter=$filter, grouping=$grouping, name=$name, partiallyInvoicedAmount=$partiallyInvoicedAmount, price=$price, quantity=$quantity, startDate=$startDate, subLineItems=$subLineItems, subtotal=$subtotal, taxAmounts=$taxAmounts, usageCustomerIds=$usageCustomerIds, additionalProperties=$additionalProperties}" } /** @@ -5837,12 +5659,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -5850,12 +5670,14 @@ private constructor( } class PaymentAttempt + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, private val createdAt: JsonField, private val paymentProvider: JsonField, private val paymentProviderId: JsonField, + private val receiptPdf: JsonField, private val succeeded: JsonField, private val additionalProperties: MutableMap, ) { @@ -5873,6 +5695,9 @@ private constructor( @JsonProperty("payment_provider_id") @ExcludeMissing paymentProviderId: JsonField = JsonMissing.of(), + @JsonProperty("receipt_pdf") + @ExcludeMissing + receiptPdf: JsonField = JsonMissing.of(), @JsonProperty("succeeded") @ExcludeMissing succeeded: JsonField = JsonMissing.of(), @@ -5882,6 +5707,7 @@ private constructor( createdAt, paymentProvider, paymentProviderId, + receiptPdf, succeeded, mutableMapOf(), ) @@ -5926,6 +5752,15 @@ private constructor( */ fun paymentProviderId(): String? = paymentProviderId.getNullable("payment_provider_id") + /** + * URL to the downloadable PDF version of the receipt. This field will be `null` for payment + * attempts that did not succeed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun receiptPdf(): String? = receiptPdf.getNullable("receipt_pdf") + /** * Whether the payment attempt succeeded. * @@ -5977,6 +5812,15 @@ private constructor( @ExcludeMissing fun _paymentProviderId(): JsonField = paymentProviderId + /** + * Returns the raw JSON value of [receiptPdf]. + * + * Unlike [receiptPdf], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("receipt_pdf") + @ExcludeMissing + fun _receiptPdf(): JsonField = receiptPdf + /** * Returns the raw JSON value of [succeeded]. * @@ -6008,6 +5852,7 @@ private constructor( * .createdAt() * .paymentProvider() * .paymentProviderId() + * .receiptPdf() * .succeeded() * ``` */ @@ -6022,6 +5867,7 @@ private constructor( private var createdAt: JsonField? = null private var paymentProvider: JsonField? = null private var paymentProviderId: JsonField? = null + private var receiptPdf: JsonField? = null private var succeeded: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -6031,6 +5877,7 @@ private constructor( createdAt = paymentAttempt.createdAt paymentProvider = paymentAttempt.paymentProvider paymentProviderId = paymentAttempt.paymentProviderId + receiptPdf = paymentAttempt.receiptPdf succeeded = paymentAttempt.succeeded additionalProperties = paymentAttempt.additionalProperties.toMutableMap() } @@ -6103,6 +5950,21 @@ private constructor( this.paymentProviderId = paymentProviderId } + /** + * URL to the downloadable PDF version of the receipt. This field will be `null` for + * payment attempts that did not succeed. + */ + fun receiptPdf(receiptPdf: String?) = receiptPdf(JsonField.ofNullable(receiptPdf)) + + /** + * Sets [Builder.receiptPdf] to an arbitrary JSON value. + * + * You should usually call [Builder.receiptPdf] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun receiptPdf(receiptPdf: JsonField) = apply { this.receiptPdf = receiptPdf } + /** Whether the payment attempt succeeded. */ fun succeeded(succeeded: Boolean) = succeeded(JsonField.of(succeeded)) @@ -6146,6 +6008,7 @@ private constructor( * .createdAt() * .paymentProvider() * .paymentProviderId() + * .receiptPdf() * .succeeded() * ``` * @@ -6158,6 +6021,7 @@ private constructor( checkRequired("createdAt", createdAt), checkRequired("paymentProvider", paymentProvider), checkRequired("paymentProviderId", paymentProviderId), + checkRequired("receiptPdf", receiptPdf), checkRequired("succeeded", succeeded), additionalProperties.toMutableMap(), ) @@ -6175,6 +6039,7 @@ private constructor( createdAt() paymentProvider()?.validate() paymentProviderId() + receiptPdf() succeeded() validated = true } @@ -6199,6 +6064,7 @@ private constructor( (if (createdAt.asKnown() == null) 0 else 1) + (paymentProvider.asKnown()?.validity() ?: 0) + (if (paymentProviderId.asKnown() == null) 0 else 1) + + (if (receiptPdf.asKnown() == null) 0 else 1) + (if (succeeded.asKnown() == null) 0 else 1) /** The payment provider that attempted to collect the payment. */ @@ -6318,7 +6184,7 @@ private constructor( return true } - return /* spotless:off */ other is PaymentProvider && value == other.value /* spotless:on */ + return other is PaymentProvider && value == other.value } override fun hashCode() = value.hashCode() @@ -6331,17 +6197,34 @@ private constructor( return true } - return /* spotless:off */ other is PaymentAttempt && id == other.id && amount == other.amount && createdAt == other.createdAt && paymentProvider == other.paymentProvider && paymentProviderId == other.paymentProviderId && succeeded == other.succeeded && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PaymentAttempt && + id == other.id && + amount == other.amount && + createdAt == other.createdAt && + paymentProvider == other.paymentProvider && + paymentProviderId == other.paymentProviderId && + receiptPdf == other.receiptPdf && + succeeded == other.succeeded && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, createdAt, paymentProvider, paymentProviderId, succeeded, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + createdAt, + paymentProvider, + paymentProviderId, + receiptPdf, + succeeded, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "PaymentAttempt{id=$id, amount=$amount, createdAt=$createdAt, paymentProvider=$paymentProvider, paymentProviderId=$paymentProviderId, succeeded=$succeeded, additionalProperties=$additionalProperties}" + "PaymentAttempt{id=$id, amount=$amount, createdAt=$createdAt, paymentProvider=$paymentProvider, paymentProviderId=$paymentProviderId, receiptPdf=$receiptPdf, succeeded=$succeeded, additionalProperties=$additionalProperties}" } class Status @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -6478,7 +6361,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -6491,12 +6374,97 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceFetchUpcomingResponse && id == other.id && amountDue == other.amountDue && autoCollection == other.autoCollection && billingAddress == other.billingAddress && createdAt == other.createdAt && creditNotes == other.creditNotes && currency == other.currency && customer == other.customer && customerBalanceTransactions == other.customerBalanceTransactions && customerTaxId == other.customerTaxId && discount == other.discount && discounts == other.discounts && dueDate == other.dueDate && eligibleToIssueAt == other.eligibleToIssueAt && hostedInvoiceUrl == other.hostedInvoiceUrl && invoiceNumber == other.invoiceNumber && invoicePdf == other.invoicePdf && invoiceSource == other.invoiceSource && issueFailedAt == other.issueFailedAt && issuedAt == other.issuedAt && lineItems == other.lineItems && maximum == other.maximum && maximumAmount == other.maximumAmount && memo == other.memo && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && paidAt == other.paidAt && paymentAttempts == other.paymentAttempts && paymentFailedAt == other.paymentFailedAt && paymentStartedAt == other.paymentStartedAt && scheduledIssueAt == other.scheduledIssueAt && shippingAddress == other.shippingAddress && status == other.status && subscription == other.subscription && subtotal == other.subtotal && syncFailedAt == other.syncFailedAt && targetDate == other.targetDate && total == other.total && voidedAt == other.voidedAt && willAutoIssue == other.willAutoIssue && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InvoiceFetchUpcomingResponse && + id == other.id && + amountDue == other.amountDue && + autoCollection == other.autoCollection && + billingAddress == other.billingAddress && + createdAt == other.createdAt && + creditNotes == other.creditNotes && + currency == other.currency && + customer == other.customer && + customerBalanceTransactions == other.customerBalanceTransactions && + customerTaxId == other.customerTaxId && + discount == other.discount && + discounts == other.discounts && + dueDate == other.dueDate && + eligibleToIssueAt == other.eligibleToIssueAt && + hostedInvoiceUrl == other.hostedInvoiceUrl && + invoiceNumber == other.invoiceNumber && + invoicePdf == other.invoicePdf && + invoiceSource == other.invoiceSource && + issueFailedAt == other.issueFailedAt && + issuedAt == other.issuedAt && + lineItems == other.lineItems && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + memo == other.memo && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + paidAt == other.paidAt && + paymentAttempts == other.paymentAttempts && + paymentFailedAt == other.paymentFailedAt && + paymentStartedAt == other.paymentStartedAt && + scheduledIssueAt == other.scheduledIssueAt && + shippingAddress == other.shippingAddress && + status == other.status && + subscription == other.subscription && + subtotal == other.subtotal && + syncFailedAt == other.syncFailedAt && + targetDate == other.targetDate && + total == other.total && + voidedAt == other.voidedAt && + willAutoIssue == other.willAutoIssue && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amountDue, autoCollection, billingAddress, createdAt, creditNotes, currency, customer, customerBalanceTransactions, customerTaxId, discount, discounts, dueDate, eligibleToIssueAt, hostedInvoiceUrl, invoiceNumber, invoicePdf, invoiceSource, issueFailedAt, issuedAt, lineItems, maximum, maximumAmount, memo, metadata, minimum, minimumAmount, paidAt, paymentAttempts, paymentFailedAt, paymentStartedAt, scheduledIssueAt, shippingAddress, status, subscription, subtotal, syncFailedAt, targetDate, total, voidedAt, willAutoIssue, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amountDue, + autoCollection, + billingAddress, + createdAt, + creditNotes, + currency, + customer, + customerBalanceTransactions, + customerTaxId, + discount, + discounts, + dueDate, + eligibleToIssueAt, + hostedInvoiceUrl, + invoiceNumber, + invoicePdf, + invoiceSource, + issueFailedAt, + issuedAt, + lineItems, + maximum, + maximumAmount, + memo, + metadata, + minimum, + minimumAmount, + paidAt, + paymentAttempts, + paymentFailedAt, + paymentStartedAt, + scheduledIssueAt, + shippingAddress, + status, + subscription, + subtotal, + syncFailedAt, + targetDate, + total, + voidedAt, + willAutoIssue, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceIssueParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceIssueParams.kt index 268bc23fc..efc0c2aee 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceIssueParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceIssueParams.kt @@ -257,6 +257,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val synchronous: JsonField, private val additionalProperties: MutableMap, @@ -397,12 +398,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && synchronous == other.synchronous && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + synchronous == other.synchronous && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(synchronous, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -415,10 +416,15 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceIssueParams && invoiceId == other.invoiceId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is InvoiceIssueParams && + invoiceId == other.invoiceId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(invoiceId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(invoiceId, body, additionalHeaders, additionalQueryParams) override fun toString() = "InvoiceIssueParams{invoiceId=$invoiceId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceLevelDiscount.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceLevelDiscount.kt index be57db54f..239c2a8ba 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceLevelDiscount.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceLevelDiscount.kt @@ -110,10 +110,13 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceLevelDiscount && percentage == other.percentage && amount == other.amount && trial == other.trial /* spotless:on */ + return other is InvoiceLevelDiscount && + percentage == other.percentage && + amount == other.amount && + trial == other.trial } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentage, amount, trial) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(percentage, amount, trial) override fun toString(): String = when { diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceLineItemCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceLineItemCreateParams.kt index 354721a8a..4005dc59e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceLineItemCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceLineItemCreateParams.kt @@ -22,6 +22,15 @@ import java.util.Objects /** * This creates a one-off fixed fee invoice line item on an Invoice. This can only be done for * invoices that are in a `draft` status. + * + * The behavior depends on which parameters are provided: + * - If `item_id` is provided without `name`: The item is looked up by ID, and the item's name is + * used for the line item. + * - If `name` is provided without `item_id`: An item with the given name is searched for in the + * account. If found, that item is used. If not found, a new item is created with that name. The + * new item's name is used for the line item. + * - If both `item_id` and `name` are provided: The item is looked up by ID for association, but the + * provided `name` is used for the line item (not the item's name). */ class InvoiceLineItemCreateParams private constructor( @@ -54,15 +63,6 @@ private constructor( */ fun invoiceId(): String = body.invoiceId() - /** - * The item name associated with this line item. If an item with the same name exists in Orb, - * that item will be associated with the line item. - * - * @throws OrbInvalidDataException if 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 = body.name() - /** * The number of units on the line item * @@ -79,6 +79,29 @@ private constructor( */ fun startDate(): LocalDate = body.startDate() + /** + * The id of the item to associate with this line item. If provided without `name`, the item's + * name will be used for the price/line item. If provided with `name`, the item will be + * associated but `name` will be used for the line item. At least one of `name` or `item_id` + * must be provided. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun itemId(): String? = body.itemId() + + /** + * The name to use for the line item. If `item_id` is not provided, Orb will search for an item + * with this name. If found, that item will be associated with the line item. If not found, a + * new item will be created with this name. If `item_id` is provided, this name will be used for + * the line item, but the item association will be based on `item_id`. At least one of `name` or + * `item_id` must be provided. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun name(): String? = body.name() + /** * Returns the raw JSON value of [amount]. * @@ -100,13 +123,6 @@ private constructor( */ fun _invoiceId(): JsonField = body._invoiceId() - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _name(): JsonField = body._name() - /** * Returns the raw JSON value of [quantity]. * @@ -121,6 +137,20 @@ private constructor( */ fun _startDate(): JsonField = body._startDate() + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _itemId(): JsonField = body._itemId() + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _name(): JsonField = body._name() + fun _additionalBodyProperties(): Map = body._additionalProperties() /** Additional headers to send with the request. */ @@ -141,7 +171,6 @@ private constructor( * .amount() * .endDate() * .invoiceId() - * .name() * .quantity() * .startDate() * ``` @@ -170,8 +199,8 @@ private constructor( * - [amount] * - [endDate] * - [invoiceId] - * - [name] * - [quantity] + * - [startDate] * - etc. */ fun body(body: Body) = apply { this.body = body.toBuilder() } @@ -211,20 +240,6 @@ private constructor( */ fun invoiceId(invoiceId: JsonField) = apply { body.invoiceId(invoiceId) } - /** - * The item name associated with this line item. If an item with the same name exists in - * Orb, that item will be associated with the line item. - */ - fun name(name: String) = apply { body.name(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 { body.name(name) } - /** The number of units on the line item */ fun quantity(quantity: Double) = apply { body.quantity(quantity) } @@ -248,6 +263,39 @@ private constructor( */ fun startDate(startDate: JsonField) = apply { body.startDate(startDate) } + /** + * The id of the item to associate with this line item. If provided without `name`, the + * item's name will be used for the price/line item. If provided with `name`, the item will + * be associated but `name` will be used for the line item. At least one of `name` or + * `item_id` must be provided. + */ + fun itemId(itemId: String?) = apply { body.itemId(itemId) } + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { body.itemId(itemId) } + + /** + * The name to use for the line item. If `item_id` is not provided, Orb will search for an + * item with this name. If found, that item will be associated with the line item. If not + * found, a new item will be created with this name. If `item_id` is provided, this name + * will be used for the line item, but the item association will be based on `item_id`. At + * least one of `name` or `item_id` must be provided. + */ + fun name(name: String?) = apply { body.name(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 { body.name(name) } + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { body.additionalProperties(additionalBodyProperties) } @@ -375,7 +423,6 @@ private constructor( * .amount() * .endDate() * .invoiceId() - * .name() * .quantity() * .startDate() * ``` @@ -397,13 +444,15 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val endDate: JsonField, private val invoiceId: JsonField, - private val name: JsonField, private val quantity: JsonField, private val startDate: JsonField, + private val itemId: JsonField, + private val name: JsonField, private val additionalProperties: MutableMap, ) { @@ -416,14 +465,15 @@ private constructor( @JsonProperty("invoice_id") @ExcludeMissing invoiceId: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("quantity") @ExcludeMissing quantity: JsonField = JsonMissing.of(), @JsonProperty("start_date") @ExcludeMissing startDate: JsonField = JsonMissing.of(), - ) : this(amount, endDate, invoiceId, name, quantity, startDate, mutableMapOf()) + @JsonProperty("item_id") @ExcludeMissing itemId: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(amount, endDate, invoiceId, quantity, startDate, itemId, name, mutableMapOf()) /** * The total amount in the invoice's currency to add to the line item. @@ -449,15 +499,6 @@ private constructor( */ fun invoiceId(): String = invoiceId.getRequired("invoice_id") - /** - * The item name associated with this line item. If an item with the same name exists in - * Orb, that item will be associated with the line item. - * - * @throws OrbInvalidDataException if 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") - /** * The number of units on the line item * @@ -474,6 +515,29 @@ private constructor( */ fun startDate(): LocalDate = startDate.getRequired("start_date") + /** + * The id of the item to associate with this line item. If provided without `name`, the + * item's name will be used for the price/line item. If provided with `name`, the item will + * be associated but `name` will be used for the line item. At least one of `name` or + * `item_id` must be provided. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun itemId(): String? = itemId.getNullable("item_id") + + /** + * The name to use for the line item. If `item_id` is not provided, Orb will search for an + * item with this name. If found, that item will be associated with the line item. If not + * found, a new item will be created with this name. If `item_id` is provided, this name + * will be used for the line item, but the item association will be based on `item_id`. At + * least one of `name` or `item_id` must be provided. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): String? = name.getNullable("name") + /** * Returns the raw JSON value of [amount]. * @@ -495,13 +559,6 @@ private constructor( */ @JsonProperty("invoice_id") @ExcludeMissing fun _invoiceId(): JsonField = invoiceId - /** - * 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 [quantity]. * @@ -518,6 +575,20 @@ private constructor( @ExcludeMissing fun _startDate(): JsonField = startDate + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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) @@ -540,7 +611,6 @@ private constructor( * .amount() * .endDate() * .invoiceId() - * .name() * .quantity() * .startDate() * ``` @@ -554,18 +624,20 @@ private constructor( private var amount: JsonField? = null private var endDate: JsonField? = null private var invoiceId: JsonField? = null - private var name: JsonField? = null private var quantity: JsonField? = null private var startDate: JsonField? = null + private var itemId: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(body: Body) = apply { amount = body.amount endDate = body.endDate invoiceId = body.invoiceId - name = body.name quantity = body.quantity startDate = body.startDate + itemId = body.itemId + name = body.name additionalProperties = body.additionalProperties.toMutableMap() } @@ -605,21 +677,6 @@ private constructor( */ fun invoiceId(invoiceId: JsonField) = apply { this.invoiceId = invoiceId } - /** - * The item name associated with this line item. If an item with the same name exists in - * Orb, that item will be associated with the line item. - */ - 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 number of units on the line item */ fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) @@ -644,6 +701,41 @@ private constructor( */ fun startDate(startDate: JsonField) = apply { this.startDate = startDate } + /** + * The id of the item to associate with this line item. If provided without `name`, the + * item's name will be used for the price/line item. If provided with `name`, the item + * will be associated but `name` will be used for the line item. At least one of `name` + * or `item_id` must be provided. + */ + fun itemId(itemId: String?) = itemId(JsonField.ofNullable(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * The name to use for the line item. If `item_id` is not provided, Orb will search for + * an item with this name. If found, that item will be associated with the line item. If + * not found, a new item will be created with this name. If `item_id` is provided, this + * name will be used for the line item, but the item association will be based on + * `item_id`. At least one of `name` or `item_id` must be provided. + */ + fun name(name: String?) = name(JsonField.ofNullable(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) @@ -673,7 +765,6 @@ private constructor( * .amount() * .endDate() * .invoiceId() - * .name() * .quantity() * .startDate() * ``` @@ -685,9 +776,10 @@ private constructor( checkRequired("amount", amount), checkRequired("endDate", endDate), checkRequired("invoiceId", invoiceId), - checkRequired("name", name), checkRequired("quantity", quantity), checkRequired("startDate", startDate), + itemId, + name, additionalProperties.toMutableMap(), ) } @@ -702,9 +794,10 @@ private constructor( amount() endDate() invoiceId() - name() quantity() startDate() + itemId() + name() validated = true } @@ -726,26 +819,44 @@ private constructor( (if (amount.asKnown() == null) 0 else 1) + (if (endDate.asKnown() == null) 0 else 1) + (if (invoiceId.asKnown() == null) 0 else 1) + - (if (name.asKnown() == null) 0 else 1) + (if (quantity.asKnown() == null) 0 else 1) + - (if (startDate.asKnown() == null) 0 else 1) + (if (startDate.asKnown() == null) 0 else 1) + + (if (itemId.asKnown() == null) 0 else 1) + + (if (name.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is Body && amount == other.amount && endDate == other.endDate && invoiceId == other.invoiceId && name == other.name && quantity == other.quantity && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + amount == other.amount && + endDate == other.endDate && + invoiceId == other.invoiceId && + quantity == other.quantity && + startDate == other.startDate && + itemId == other.itemId && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, endDate, invoiceId, name, quantity, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amount, + endDate, + invoiceId, + quantity, + startDate, + itemId, + name, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Body{amount=$amount, endDate=$endDate, invoiceId=$invoiceId, name=$name, quantity=$quantity, startDate=$startDate, additionalProperties=$additionalProperties}" + "Body{amount=$amount, endDate=$endDate, invoiceId=$invoiceId, quantity=$quantity, startDate=$startDate, itemId=$itemId, name=$name, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -753,10 +864,13 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceLineItemCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is InvoiceLineItemCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "InvoiceLineItemCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceLineItemCreateResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceLineItemCreateResponse.kt index e5923615c..de451d952 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceLineItemCreateResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceLineItemCreateResponse.kt @@ -29,20 +29,16 @@ import java.util.Collections import java.util.Objects class InvoiceLineItemCreateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustedSubtotal: JsonField, private val adjustments: JsonField>, private val amount: JsonField, private val creditsApplied: JsonField, - private val discount: JsonField, private val endDate: JsonField, private val filter: JsonField, private val grouping: JsonField, - private val maximum: JsonField, - private val maximumAmount: JsonField, - private val minimum: JsonField, - private val minimumAmount: JsonField, private val name: JsonField, private val partiallyInvoicedAmount: JsonField, private val price: JsonField, @@ -68,20 +64,11 @@ private constructor( @JsonProperty("credits_applied") @ExcludeMissing creditsApplied: JsonField = JsonMissing.of(), - @JsonProperty("discount") @ExcludeMissing discount: JsonField = JsonMissing.of(), @JsonProperty("end_date") @ExcludeMissing endDate: JsonField = JsonMissing.of(), @JsonProperty("filter") @ExcludeMissing filter: JsonField = JsonMissing.of(), @JsonProperty("grouping") @ExcludeMissing grouping: JsonField = JsonMissing.of(), - @JsonProperty("maximum") @ExcludeMissing maximum: JsonField = JsonMissing.of(), - @JsonProperty("maximum_amount") - @ExcludeMissing - maximumAmount: JsonField = JsonMissing.of(), - @JsonProperty("minimum") @ExcludeMissing minimum: JsonField = JsonMissing.of(), - @JsonProperty("minimum_amount") - @ExcludeMissing - minimumAmount: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("partially_invoiced_amount") @ExcludeMissing @@ -107,14 +94,9 @@ private constructor( adjustments, amount, creditsApplied, - discount, endDate, filter, grouping, - maximum, - maximumAmount, - minimum, - minimumAmount, name, partiallyInvoicedAmount, price, @@ -171,14 +153,6 @@ private constructor( */ fun creditsApplied(): String = creditsApplied.getRequired("credits_applied") - /** - * This field is deprecated in favor of `adjustments` - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - @Deprecated("deprecated") fun discount(): Discount? = discount.getNullable("discount") - /** * The end date of the range of time applied for this line item's price. * @@ -205,40 +179,6 @@ private constructor( */ fun grouping(): String? = grouping.getNullable("grouping") - /** - * This field is deprecated in favor of `adjustments`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - @Deprecated("deprecated") fun maximum(): Maximum? = maximum.getNullable("maximum") - - /** - * This field is deprecated in favor of `adjustments`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - @Deprecated("deprecated") - fun maximumAmount(): String? = maximumAmount.getNullable("maximum_amount") - - /** - * This field is deprecated in favor of `adjustments`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - @Deprecated("deprecated") fun minimum(): Minimum? = minimum.getNullable("minimum") - - /** - * This field is deprecated in favor of `adjustments`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - @Deprecated("deprecated") - fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") - /** * The name of the price associated with this line item. * @@ -298,7 +238,7 @@ private constructor( fun subLineItems(): List = subLineItems.getRequired("sub_line_items") /** - * The line amount before before any adjustments. + * The line amount before any adjustments. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). @@ -364,16 +304,6 @@ private constructor( @ExcludeMissing fun _creditsApplied(): JsonField = creditsApplied - /** - * Returns the raw JSON value of [discount]. - * - * Unlike [discount], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("discount") - @ExcludeMissing - fun _discount(): JsonField = discount - /** * Returns the raw JSON value of [endDate]. * @@ -395,46 +325,6 @@ private constructor( */ @JsonProperty("grouping") @ExcludeMissing fun _grouping(): JsonField = grouping - /** - * Returns the raw JSON value of [maximum]. - * - * Unlike [maximum], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("maximum") - @ExcludeMissing - fun _maximum(): JsonField = maximum - - /** - * Returns the raw JSON value of [maximumAmount]. - * - * Unlike [maximumAmount], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("maximum_amount") - @ExcludeMissing - fun _maximumAmount(): JsonField = maximumAmount - - /** - * Returns the raw JSON value of [minimum]. - * - * Unlike [minimum], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("minimum") - @ExcludeMissing - fun _minimum(): JsonField = minimum - - /** - * Returns the raw JSON value of [minimumAmount]. - * - * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("minimum_amount") - @ExcludeMissing - fun _minimumAmount(): JsonField = minimumAmount - /** * Returns the raw JSON value of [name]. * @@ -535,14 +425,9 @@ private constructor( * .adjustments() * .amount() * .creditsApplied() - * .discount() * .endDate() * .filter() * .grouping() - * .maximum() - * .maximumAmount() - * .minimum() - * .minimumAmount() * .name() * .partiallyInvoicedAmount() * .price() @@ -565,14 +450,9 @@ private constructor( private var adjustments: JsonField>? = null private var amount: JsonField? = null private var creditsApplied: JsonField? = null - private var discount: JsonField? = null private var endDate: JsonField? = null private var filter: JsonField? = null private var grouping: JsonField? = null - private var maximum: JsonField? = null - private var maximumAmount: JsonField? = null - private var minimum: JsonField? = null - private var minimumAmount: JsonField? = null private var name: JsonField? = null private var partiallyInvoicedAmount: JsonField? = null private var price: JsonField? = null @@ -590,14 +470,9 @@ private constructor( adjustments = invoiceLineItemCreateResponse.adjustments.map { it.toMutableList() } amount = invoiceLineItemCreateResponse.amount creditsApplied = invoiceLineItemCreateResponse.creditsApplied - discount = invoiceLineItemCreateResponse.discount endDate = invoiceLineItemCreateResponse.endDate filter = invoiceLineItemCreateResponse.filter grouping = invoiceLineItemCreateResponse.grouping - maximum = invoiceLineItemCreateResponse.maximum - maximumAmount = invoiceLineItemCreateResponse.maximumAmount - minimum = invoiceLineItemCreateResponse.minimum - minimumAmount = invoiceLineItemCreateResponse.minimumAmount name = invoiceLineItemCreateResponse.name partiallyInvoicedAmount = invoiceLineItemCreateResponse.partiallyInvoicedAmount price = invoiceLineItemCreateResponse.price @@ -721,90 +596,6 @@ private constructor( this.creditsApplied = creditsApplied } - /** This field is deprecated in favor of `adjustments` */ - @Deprecated("deprecated") - fun discount(discount: Discount?) = discount(JsonField.ofNullable(discount)) - - /** - * Sets [Builder.discount] to an arbitrary JSON value. - * - * You should usually call [Builder.discount] with a well-typed [Discount] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - @Deprecated("deprecated") - fun discount(discount: JsonField) = apply { this.discount = discount } - - /** Alias for calling [discount] with `Discount.ofPercentage(percentage)`. */ - @Deprecated("deprecated") - fun discount(percentage: PercentageDiscount) = discount(Discount.ofPercentage(percentage)) - - /** - * Alias for calling [discount] with the following: - * ```kotlin - * PercentageDiscount.builder() - * .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - * .percentageDiscount(percentageDiscount) - * .build() - * ``` - */ - @Deprecated("deprecated") - fun percentageDiscount(percentageDiscount: Double) = - discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(percentageDiscount) - .build() - ) - - /** Alias for calling [discount] with `Discount.ofTrial(trial)`. */ - @Deprecated("deprecated") - fun discount(trial: TrialDiscount) = discount(Discount.ofTrial(trial)) - - /** Alias for calling [discount] with `Discount.ofUsage(usage)`. */ - @Deprecated("deprecated") - fun discount(usage: UsageDiscount) = discount(Discount.ofUsage(usage)) - - /** - * Alias for calling [discount] with the following: - * ```kotlin - * UsageDiscount.builder() - * .discountType(UsageDiscount.DiscountType.USAGE) - * .usageDiscount(usageDiscount) - * .build() - * ``` - */ - @Deprecated("deprecated") - fun usageDiscount(usageDiscount: Double) = - discount( - UsageDiscount.builder() - .discountType(UsageDiscount.DiscountType.USAGE) - .usageDiscount(usageDiscount) - .build() - ) - - /** Alias for calling [discount] with `Discount.ofAmount(amount)`. */ - @Deprecated("deprecated") - fun discount(amount: AmountDiscount) = discount(Discount.ofAmount(amount)) - - /** - * Alias for calling [discount] with the following: - * ```kotlin - * AmountDiscount.builder() - * .discountType(AmountDiscount.DiscountType.AMOUNT) - * .amountDiscount(amountDiscount) - * .build() - * ``` - */ - @Deprecated("deprecated") - fun amountDiscount(amountDiscount: String) = - discount( - AmountDiscount.builder() - .discountType(AmountDiscount.DiscountType.AMOUNT) - .amountDiscount(amountDiscount) - .build() - ) - /** The end date of the range of time applied for this line item's price. */ fun endDate(endDate: OffsetDateTime) = endDate(JsonField.of(endDate)) @@ -843,66 +634,6 @@ private constructor( */ fun grouping(grouping: JsonField) = apply { this.grouping = grouping } - /** This field is deprecated in favor of `adjustments`. */ - @Deprecated("deprecated") - fun maximum(maximum: Maximum?) = maximum(JsonField.ofNullable(maximum)) - - /** - * Sets [Builder.maximum] to an arbitrary JSON value. - * - * You should usually call [Builder.maximum] with a well-typed [Maximum] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - @Deprecated("deprecated") - fun maximum(maximum: JsonField) = apply { this.maximum = maximum } - - /** This field is deprecated in favor of `adjustments`. */ - @Deprecated("deprecated") - fun maximumAmount(maximumAmount: String?) = - maximumAmount(JsonField.ofNullable(maximumAmount)) - - /** - * Sets [Builder.maximumAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.maximumAmount] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - @Deprecated("deprecated") - fun maximumAmount(maximumAmount: JsonField) = apply { - this.maximumAmount = maximumAmount - } - - /** This field is deprecated in favor of `adjustments`. */ - @Deprecated("deprecated") - fun minimum(minimum: Minimum?) = minimum(JsonField.ofNullable(minimum)) - - /** - * Sets [Builder.minimum] to an arbitrary JSON value. - * - * You should usually call [Builder.minimum] with a well-typed [Minimum] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - @Deprecated("deprecated") - fun minimum(minimum: JsonField) = apply { this.minimum = minimum } - - /** This field is deprecated in favor of `adjustments`. */ - @Deprecated("deprecated") - fun minimumAmount(minimumAmount: String?) = - minimumAmount(JsonField.ofNullable(minimumAmount)) - - /** - * Sets [Builder.minimumAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.minimumAmount] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - @Deprecated("deprecated") - fun minimumAmount(minimumAmount: JsonField) = apply { - this.minimumAmount = minimumAmount - } - /** The name of the price associated with this line item. */ fun name(name: String) = name(JsonField.of(name)) @@ -952,28 +683,23 @@ private constructor( fun price(price: JsonField) = apply { this.price = price } /** Alias for calling [price] with `Price.ofUnit(unit)`. */ - fun price(unit: Price.Unit) = price(Price.ofUnit(unit)) - - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: Price.Package) = price(Price.ofPackage(package_)) - - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: Price.Matrix) = price(Price.ofMatrix(matrix)) + fun price(unit: Price.UnitPrice) = price(Price.ofUnit(unit)) /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ fun price(tiered: Price.Tiered) = price(Price.ofTiered(tiered)) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: Price.TieredBps) = price(Price.ofTieredBps(tieredBps)) + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: Price.Bulk) = price(Price.ofBulk(bulk)) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: Price.Bps) = price(Price.ofBps(bps)) + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: Price.BulkBps) = price(Price.ofBulkBps(bulkBps)) + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: Price.Package) = price(Price.ofPackage(package_)) - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: Price.Bulk) = price(Price.ofBulk(bulk)) + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: Price.Matrix) = price(Price.ofMatrix(matrix)) /** Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. */ fun price(thresholdTotalAmount: Price.ThresholdTotalAmount) = @@ -982,13 +708,13 @@ private constructor( /** Alias for calling [price] with `Price.ofTieredPackage(tieredPackage)`. */ fun price(tieredPackage: Price.TieredPackage) = price(Price.ofTieredPackage(tieredPackage)) - /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: Price.GroupedTiered) = price(Price.ofGroupedTiered(groupedTiered)) - /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ fun price(tieredWithMinimum: Price.TieredWithMinimum) = price(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: Price.GroupedTiered) = price(Price.ofGroupedTiered(groupedTiered)) + /** * Alias for calling [price] with * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. @@ -1022,6 +748,10 @@ private constructor( fun price(groupedAllocation: Price.GroupedAllocation) = price(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: Price.BulkWithProration) = + price(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [price] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -1036,16 +766,19 @@ private constructor( fun price(groupedWithMeteredMinimum: Price.GroupedWithMeteredMinimum) = price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** * Alias for calling [price] with `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. */ fun price(matrixWithDisplayName: Price.MatrixWithDisplayName) = price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: Price.BulkWithProration) = - price(Price.ofBulkWithProration(bulkWithProration)) - /** Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. */ fun price(groupedTieredPackage: Price.GroupedTieredPackage) = price(Price.ofGroupedTieredPackage(groupedTieredPackage)) @@ -1078,10 +811,19 @@ private constructor( /** * Alias for calling [price] with - * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. */ - fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = - price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: Price.Minimum) = price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) /** Either the fixed fee quantity or the usage during the service period. */ fun quantity(quantity: Double) = quantity(JsonField.of(quantity)) @@ -1144,7 +886,7 @@ private constructor( /** Alias for calling [addSubLineItem] with `SubLineItem.ofNull(null_)`. */ fun addSubLineItem(null_: OtherSubLineItem) = addSubLineItem(SubLineItem.ofNull(null_)) - /** The line amount before before any adjustments. */ + /** The line amount before any adjustments. */ fun subtotal(subtotal: String) = subtotal(JsonField.of(subtotal)) /** @@ -1242,14 +984,9 @@ private constructor( * .adjustments() * .amount() * .creditsApplied() - * .discount() * .endDate() * .filter() * .grouping() - * .maximum() - * .maximumAmount() - * .minimum() - * .minimumAmount() * .name() * .partiallyInvoicedAmount() * .price() @@ -1270,14 +1007,9 @@ private constructor( checkRequired("adjustments", adjustments).map { it.toImmutable() }, checkRequired("amount", amount), checkRequired("creditsApplied", creditsApplied), - checkRequired("discount", discount), checkRequired("endDate", endDate), checkRequired("filter", filter), checkRequired("grouping", grouping), - checkRequired("maximum", maximum), - checkRequired("maximumAmount", maximumAmount), - checkRequired("minimum", minimum), - checkRequired("minimumAmount", minimumAmount), checkRequired("name", name), checkRequired("partiallyInvoicedAmount", partiallyInvoicedAmount), checkRequired("price", price), @@ -1303,14 +1035,9 @@ private constructor( adjustments().forEach { it.validate() } amount() creditsApplied() - discount()?.validate() endDate() filter() grouping() - maximum()?.validate() - maximumAmount() - minimum()?.validate() - minimumAmount() name() partiallyInvoicedAmount() price().validate() @@ -1342,14 +1069,9 @@ private constructor( (adjustments.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (amount.asKnown() == null) 0 else 1) + (if (creditsApplied.asKnown() == null) 0 else 1) + - (discount.asKnown()?.validity() ?: 0) + (if (endDate.asKnown() == null) 0 else 1) + (if (filter.asKnown() == null) 0 else 1) + (if (grouping.asKnown() == null) 0 else 1) + - (maximum.asKnown()?.validity() ?: 0) + - (if (maximumAmount.asKnown() == null) 0 else 1) + - (minimum.asKnown()?.validity() ?: 0) + - (if (minimumAmount.asKnown() == null) 0 else 1) + (if (name.asKnown() == null) 0 else 1) + (if (partiallyInvoicedAmount.asKnown() == null) 0 else 1) + (price.asKnown()?.validity() ?: 0) + @@ -1500,10 +1222,16 @@ private constructor( return true } - return /* spotless:off */ other is Adjustment && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && percentageDiscount == other.percentageDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ + return other is Adjustment && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + percentageDiscount == other.percentageDiscount && + minimum == other.minimum && + maximum == other.maximum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(usageDiscount, amountDiscount, percentageDiscount, minimum, maximum) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(usageDiscount, amountDiscount, percentageDiscount, minimum, maximum) override fun toString(): String = when { @@ -1725,10 +1453,13 @@ private constructor( return true } - return /* spotless:off */ other is SubLineItem && matrix == other.matrix && tier == other.tier && null_ == other.null_ /* spotless:on */ + return other is SubLineItem && + matrix == other.matrix && + tier == other.tier && + null_ == other.null_ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(matrix, tier, null_) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(matrix, tier, null_) override fun toString(): String = when { @@ -1826,15 +1557,52 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceLineItemCreateResponse && id == other.id && adjustedSubtotal == other.adjustedSubtotal && adjustments == other.adjustments && amount == other.amount && creditsApplied == other.creditsApplied && discount == other.discount && endDate == other.endDate && filter == other.filter && grouping == other.grouping && maximum == other.maximum && maximumAmount == other.maximumAmount && minimum == other.minimum && minimumAmount == other.minimumAmount && name == other.name && partiallyInvoicedAmount == other.partiallyInvoicedAmount && price == other.price && quantity == other.quantity && startDate == other.startDate && subLineItems == other.subLineItems && subtotal == other.subtotal && taxAmounts == other.taxAmounts && usageCustomerIds == other.usageCustomerIds && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InvoiceLineItemCreateResponse && + id == other.id && + adjustedSubtotal == other.adjustedSubtotal && + adjustments == other.adjustments && + amount == other.amount && + creditsApplied == other.creditsApplied && + endDate == other.endDate && + filter == other.filter && + grouping == other.grouping && + name == other.name && + partiallyInvoicedAmount == other.partiallyInvoicedAmount && + price == other.price && + quantity == other.quantity && + startDate == other.startDate && + subLineItems == other.subLineItems && + subtotal == other.subtotal && + taxAmounts == other.taxAmounts && + usageCustomerIds == other.usageCustomerIds && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustedSubtotal, adjustments, amount, creditsApplied, discount, endDate, filter, grouping, maximum, maximumAmount, minimum, minimumAmount, name, partiallyInvoicedAmount, price, quantity, startDate, subLineItems, subtotal, taxAmounts, usageCustomerIds, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustedSubtotal, + adjustments, + amount, + creditsApplied, + endDate, + filter, + grouping, + name, + partiallyInvoicedAmount, + price, + quantity, + startDate, + subLineItems, + subtotal, + taxAmounts, + usageCustomerIds, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "InvoiceLineItemCreateResponse{id=$id, adjustedSubtotal=$adjustedSubtotal, adjustments=$adjustments, amount=$amount, creditsApplied=$creditsApplied, discount=$discount, endDate=$endDate, filter=$filter, grouping=$grouping, maximum=$maximum, maximumAmount=$maximumAmount, minimum=$minimum, minimumAmount=$minimumAmount, name=$name, partiallyInvoicedAmount=$partiallyInvoicedAmount, price=$price, quantity=$quantity, startDate=$startDate, subLineItems=$subLineItems, subtotal=$subtotal, taxAmounts=$taxAmounts, usageCustomerIds=$usageCustomerIds, additionalProperties=$additionalProperties}" + "InvoiceLineItemCreateResponse{id=$id, adjustedSubtotal=$adjustedSubtotal, adjustments=$adjustments, amount=$amount, creditsApplied=$creditsApplied, endDate=$endDate, filter=$filter, grouping=$grouping, name=$name, partiallyInvoicedAmount=$partiallyInvoicedAmount, price=$price, quantity=$quantity, startDate=$startDate, subLineItems=$subLineItems, subtotal=$subtotal, taxAmounts=$taxAmounts, usageCustomerIds=$usageCustomerIds, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListPage.kt index 062cc6fcc..6f5e36bb2 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListPage.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is InvoiceListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "InvoiceListPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageAsync.kt index 9ce9fa8fe..6eb0c571f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageAsync.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is InvoiceListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "InvoiceListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageResponse.kt index 85152dbab..14455bd37 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class InvoiceListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -214,12 +215,15 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InvoiceListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListParams.kt index d37d6701b..eee133137 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceListParams.kt @@ -529,7 +529,7 @@ private constructor( return true } - return /* spotless:off */ other is DateType && value == other.value /* spotless:on */ + return other is DateType && value == other.value } override fun hashCode() = value.hashCode() @@ -671,7 +671,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -684,10 +684,54 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceListParams && amount == other.amount && amountGt == other.amountGt && amountLt == other.amountLt && cursor == other.cursor && customerId == other.customerId && dateType == other.dateType && dueDate == other.dueDate && dueDateWindow == other.dueDateWindow && dueDateGt == other.dueDateGt && dueDateLt == other.dueDateLt && externalCustomerId == other.externalCustomerId && invoiceDateGt == other.invoiceDateGt && invoiceDateGte == other.invoiceDateGte && invoiceDateLt == other.invoiceDateLt && invoiceDateLte == other.invoiceDateLte && isRecurring == other.isRecurring && limit == other.limit && status == other.status && subscriptionId == other.subscriptionId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is InvoiceListParams && + amount == other.amount && + amountGt == other.amountGt && + amountLt == other.amountLt && + cursor == other.cursor && + customerId == other.customerId && + dateType == other.dateType && + dueDate == other.dueDate && + dueDateWindow == other.dueDateWindow && + dueDateGt == other.dueDateGt && + dueDateLt == other.dueDateLt && + externalCustomerId == other.externalCustomerId && + invoiceDateGt == other.invoiceDateGt && + invoiceDateGte == other.invoiceDateGte && + invoiceDateLt == other.invoiceDateLt && + invoiceDateLte == other.invoiceDateLte && + isRecurring == other.isRecurring && + limit == other.limit && + status == other.status && + subscriptionId == other.subscriptionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(amount, amountGt, amountLt, cursor, customerId, dateType, dueDate, dueDateWindow, dueDateGt, dueDateLt, externalCustomerId, invoiceDateGt, invoiceDateGte, invoiceDateLt, invoiceDateLte, isRecurring, limit, status, subscriptionId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + amount, + amountGt, + amountLt, + cursor, + customerId, + dateType, + dueDate, + dueDateWindow, + dueDateGt, + dueDateLt, + externalCustomerId, + invoiceDateGt, + invoiceDateGte, + invoiceDateLt, + invoiceDateLte, + isRecurring, + limit, + status, + subscriptionId, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "InvoiceListParams{amount=$amount, amountGt=$amountGt, amountLt=$amountLt, cursor=$cursor, customerId=$customerId, dateType=$dateType, dueDate=$dueDate, dueDateWindow=$dueDateWindow, dueDateGt=$dueDateGt, dueDateLt=$dueDateLt, externalCustomerId=$externalCustomerId, invoiceDateGt=$invoiceDateGt, invoiceDateGte=$invoiceDateGte, invoiceDateLt=$invoiceDateLt, invoiceDateLte=$invoiceDateLte, isRecurring=$isRecurring, limit=$limit, status=$status, subscriptionId=$subscriptionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceMarkPaidParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceMarkPaidParams.kt index 510fbd2bf..ea39f03c7 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceMarkPaidParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceMarkPaidParams.kt @@ -20,8 +20,8 @@ import java.util.Collections import java.util.Objects /** - * This endpoint allows an invoice's status to be set the `paid` status. This can only be done to - * invoices that are in the `issued` status. + * This endpoint allows an invoice's status to be set to the `paid` status. This can only be done to + * invoices that are in the `issued` or `synced` status. */ class InvoiceMarkPaidParams private constructor( @@ -320,6 +320,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val paymentReceivedDate: JsonField, private val externalId: JsonField, @@ -545,12 +546,16 @@ private constructor( return true } - return /* spotless:off */ other is Body && paymentReceivedDate == other.paymentReceivedDate && externalId == other.externalId && notes == other.notes && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + paymentReceivedDate == other.paymentReceivedDate && + externalId == other.externalId && + notes == other.notes && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(paymentReceivedDate, externalId, notes, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(paymentReceivedDate, externalId, notes, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -563,10 +568,15 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceMarkPaidParams && invoiceId == other.invoiceId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is InvoiceMarkPaidParams && + invoiceId == other.invoiceId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(invoiceId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(invoiceId, body, additionalHeaders, additionalQueryParams) override fun toString() = "InvoiceMarkPaidParams{invoiceId=$invoiceId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoicePayParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoicePayParams.kt index a2829e29a..f5a43a3c0 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoicePayParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoicePayParams.kt @@ -210,10 +210,15 @@ private constructor( return true } - return /* spotless:off */ other is InvoicePayParams && invoiceId == other.invoiceId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is InvoicePayParams && + invoiceId == other.invoiceId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(invoiceId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(invoiceId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "InvoicePayParams{invoiceId=$invoiceId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceTiny.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceTiny.kt index fe9aca2eb..aed6adb9e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceTiny.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceTiny.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class InvoiceTiny +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val additionalProperties: MutableMap, @@ -154,12 +155,12 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceTiny && id == other.id && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InvoiceTiny && + id == other.id && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceUpdateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceUpdateParams.kt index 922ff203b..9406557a7 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceUpdateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceUpdateParams.kt @@ -6,25 +6,39 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.BaseDeserializer +import com.withorb.api.core.BaseSerializer import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.Params +import com.withorb.api.core.allMaxBy +import com.withorb.api.core.getOrThrow import com.withorb.api.core.http.Headers import com.withorb.api.core.http.QueryParams import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException +import java.time.LocalDate +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects /** - * This endpoint allows you to update the `metadata`, `net_terms`, and `due_date` properties on an - * invoice. If you pass null for the metadata value, it will clear any existing metadata for that - * invoice. + * This endpoint allows you to update the `metadata`, `net_terms`, `due_date`, and `invoice_date` + * properties on an invoice. If you pass null for the metadata value, it will clear any existing + * metadata for that invoice. * - * `metadata` can be modified regardless of invoice state. `net_terms` and `due_date` can only be - * modified if the invoice is in a `draft` state. + * `metadata` can be modified regardless of invoice state. `net_terms`, `due_date`, and + * `invoice_date` can only be modified if the invoice is in a `draft` state. `invoice_date` can only + * be modified for non-subscription invoices. */ class InvoiceUpdateParams private constructor( @@ -36,6 +50,23 @@ private constructor( fun invoiceId(): String? = invoiceId + /** + * An optional custom due date for the invoice. If not set, the due date will be calculated + * based on the `net_terms` value. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun dueDate(): DueDate? = body.dueDate() + + /** + * The date of the invoice. Can only be modified for one-off draft invoices. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun invoiceDate(): InvoiceDate? = body.invoiceDate() + /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -46,6 +77,32 @@ private constructor( */ fun metadata(): Metadata? = body.metadata() + /** + * The net terms determines the due date of the invoice. Due date is calculated based on the + * invoice or issuance date, depending on the account's configured due date calculation method. + * A value of '0' here represents that the invoice is due on issue, whereas a value of '30' + * represents that the customer has 30 days to pay the invoice. Do not set this field if you + * want to set a custom due date. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun netTerms(): Long? = body.netTerms() + + /** + * Returns the raw JSON value of [dueDate]. + * + * Unlike [dueDate], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _dueDate(): JsonField = body._dueDate() + + /** + * Returns the raw JSON value of [invoiceDate]. + * + * Unlike [invoiceDate], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _invoiceDate(): JsonField = body._invoiceDate() + /** * Returns the raw JSON value of [metadata]. * @@ -53,6 +110,13 @@ private constructor( */ fun _metadata(): JsonField = body._metadata() + /** + * Returns the raw JSON value of [netTerms]. + * + * Unlike [netTerms], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _netTerms(): JsonField = body._netTerms() + fun _additionalBodyProperties(): Map = body._additionalProperties() /** Additional headers to send with the request. */ @@ -93,10 +157,53 @@ private constructor( * * 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: + * - [dueDate] + * - [invoiceDate] * - [metadata] + * - [netTerms] */ fun body(body: Body) = apply { this.body = body.toBuilder() } + /** + * An optional custom due date for the invoice. If not set, the due date will be calculated + * based on the `net_terms` value. + */ + fun dueDate(dueDate: DueDate?) = apply { body.dueDate(dueDate) } + + /** + * Sets [Builder.dueDate] to an arbitrary JSON value. + * + * You should usually call [Builder.dueDate] with a well-typed [DueDate] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun dueDate(dueDate: JsonField) = apply { body.dueDate(dueDate) } + + /** Alias for calling [dueDate] with `DueDate.ofDate(date)`. */ + fun dueDate(date: LocalDate) = apply { body.dueDate(date) } + + /** Alias for calling [dueDate] with `DueDate.ofDateTime(dateTime)`. */ + fun dueDate(dateTime: OffsetDateTime) = apply { body.dueDate(dateTime) } + + /** The date of the invoice. Can only be modified for one-off draft invoices. */ + fun invoiceDate(invoiceDate: InvoiceDate?) = apply { body.invoiceDate(invoiceDate) } + + /** + * Sets [Builder.invoiceDate] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceDate] with a well-typed [InvoiceDate] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun invoiceDate(invoiceDate: JsonField) = apply { + body.invoiceDate(invoiceDate) + } + + /** Alias for calling [invoiceDate] with `InvoiceDate.ofDate(date)`. */ + fun invoiceDate(date: LocalDate) = apply { body.invoiceDate(date) } + + /** Alias for calling [invoiceDate] with `InvoiceDate.ofDateTime(dateTime)`. */ + fun invoiceDate(dateTime: OffsetDateTime) = apply { body.invoiceDate(dateTime) } + /** * User-specified key/value pairs for the resource. Individual keys can be removed by * setting the value to `null`, and the entire metadata mapping can be cleared by setting @@ -113,6 +220,30 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + /** + * The net terms determines the due date of the invoice. Due date is calculated based on the + * invoice or issuance date, depending on the account's configured due date calculation + * method. A value of '0' here represents that the invoice is due on issue, whereas a value + * of '30' represents that the customer has 30 days to pay the invoice. Do not set this + * field if you want to set a custom due date. + */ + fun netTerms(netTerms: Long?) = apply { body.netTerms(netTerms) } + + /** + * Alias for [Builder.netTerms]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun netTerms(netTerms: Long) = netTerms(netTerms as Long?) + + /** + * Sets [Builder.netTerms] to an arbitrary JSON value. + * + * You should usually call [Builder.netTerms] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun netTerms(netTerms: JsonField) = apply { body.netTerms(netTerms) } + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { body.additionalProperties(additionalBodyProperties) } @@ -257,17 +388,45 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( + private val dueDate: JsonField, + private val invoiceDate: JsonField, private val metadata: JsonField, + private val netTerms: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( + @JsonProperty("due_date") + @ExcludeMissing + dueDate: JsonField = JsonMissing.of(), + @JsonProperty("invoice_date") + @ExcludeMissing + invoiceDate: JsonField = JsonMissing.of(), @JsonProperty("metadata") @ExcludeMissing - metadata: JsonField = JsonMissing.of() - ) : this(metadata, mutableMapOf()) + metadata: JsonField = JsonMissing.of(), + @JsonProperty("net_terms") @ExcludeMissing netTerms: JsonField = JsonMissing.of(), + ) : this(dueDate, invoiceDate, metadata, netTerms, mutableMapOf()) + + /** + * An optional custom due date for the invoice. If not set, the due date will be calculated + * based on the `net_terms` value. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dueDate(): DueDate? = dueDate.getNullable("due_date") + + /** + * The date of the invoice. Can only be modified for one-off draft invoices. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoiceDate(): InvoiceDate? = invoiceDate.getNullable("invoice_date") /** * User-specified key/value pairs for the resource. Individual keys can be removed by @@ -279,6 +438,34 @@ private constructor( */ fun metadata(): Metadata? = metadata.getNullable("metadata") + /** + * The net terms determines the due date of the invoice. Due date is calculated based on the + * invoice or issuance date, depending on the account's configured due date calculation + * method. A value of '0' here represents that the invoice is due on issue, whereas a value + * of '30' represents that the customer has 30 days to pay the invoice. Do not set this + * field if you want to set a custom due date. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun netTerms(): Long? = netTerms.getNullable("net_terms") + + /** + * Returns the raw JSON value of [dueDate]. + * + * Unlike [dueDate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("due_date") @ExcludeMissing fun _dueDate(): JsonField = dueDate + + /** + * Returns the raw JSON value of [invoiceDate]. + * + * Unlike [invoiceDate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("invoice_date") + @ExcludeMissing + fun _invoiceDate(): JsonField = invoiceDate + /** * Returns the raw JSON value of [metadata]. * @@ -286,6 +473,13 @@ private constructor( */ @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + /** + * Returns the raw JSON value of [netTerms]. + * + * Unlike [netTerms], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("net_terms") @ExcludeMissing fun _netTerms(): JsonField = netTerms + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -307,14 +501,63 @@ private constructor( /** A builder for [Body]. */ class Builder internal constructor() { + private var dueDate: JsonField = JsonMissing.of() + private var invoiceDate: JsonField = JsonMissing.of() private var metadata: JsonField = JsonMissing.of() + private var netTerms: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(body: Body) = apply { + dueDate = body.dueDate + invoiceDate = body.invoiceDate metadata = body.metadata + netTerms = body.netTerms additionalProperties = body.additionalProperties.toMutableMap() } + /** + * An optional custom due date for the invoice. If not set, the due date will be + * calculated based on the `net_terms` value. + */ + fun dueDate(dueDate: DueDate?) = dueDate(JsonField.ofNullable(dueDate)) + + /** + * Sets [Builder.dueDate] to an arbitrary JSON value. + * + * You should usually call [Builder.dueDate] with a well-typed [DueDate] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun dueDate(dueDate: JsonField) = apply { this.dueDate = dueDate } + + /** Alias for calling [dueDate] with `DueDate.ofDate(date)`. */ + fun dueDate(date: LocalDate) = dueDate(DueDate.ofDate(date)) + + /** Alias for calling [dueDate] with `DueDate.ofDateTime(dateTime)`. */ + fun dueDate(dateTime: OffsetDateTime) = dueDate(DueDate.ofDateTime(dateTime)) + + /** The date of the invoice. Can only be modified for one-off draft invoices. */ + fun invoiceDate(invoiceDate: InvoiceDate?) = + invoiceDate(JsonField.ofNullable(invoiceDate)) + + /** + * Sets [Builder.invoiceDate] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceDate] with a well-typed [InvoiceDate] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun invoiceDate(invoiceDate: JsonField) = apply { + this.invoiceDate = invoiceDate + } + + /** Alias for calling [invoiceDate] with `InvoiceDate.ofDate(date)`. */ + fun invoiceDate(date: LocalDate) = invoiceDate(InvoiceDate.ofDate(date)) + + /** Alias for calling [invoiceDate] with `InvoiceDate.ofDateTime(dateTime)`. */ + fun invoiceDate(dateTime: OffsetDateTime) = + invoiceDate(InvoiceDate.ofDateTime(dateTime)) + /** * User-specified key/value pairs for the resource. Individual keys can be removed by * setting the value to `null`, and the entire metadata mapping can be cleared by @@ -331,6 +574,31 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + /** + * The net terms determines the due date of the invoice. Due date is calculated based on + * the invoice or issuance date, depending on the account's configured due date + * calculation method. A value of '0' here represents that the invoice is due on issue, + * whereas a value of '30' represents that the customer has 30 days to pay the invoice. + * Do not set this field if you want to set a custom due date. + */ + fun netTerms(netTerms: Long?) = netTerms(JsonField.ofNullable(netTerms)) + + /** + * Alias for [Builder.netTerms]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun netTerms(netTerms: Long) = netTerms(netTerms as Long?) + + /** + * Sets [Builder.netTerms] to an arbitrary JSON value. + * + * You should usually call [Builder.netTerms] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun netTerms(netTerms: JsonField) = apply { this.netTerms = netTerms } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -355,7 +623,8 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Body = Body(metadata, additionalProperties.toMutableMap()) + fun build(): Body = + Body(dueDate, invoiceDate, metadata, netTerms, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -365,7 +634,10 @@ private constructor( return@apply } + dueDate()?.validate() + invoiceDate()?.validate() metadata()?.validate() + netTerms() validated = true } @@ -383,24 +655,375 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = (metadata.asKnown()?.validity() ?: 0) + internal fun validity(): Int = + (dueDate.asKnown()?.validity() ?: 0) + + (invoiceDate.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (netTerms.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is Body && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + dueDate == other.dueDate && + invoiceDate == other.invoiceDate && + metadata == other.metadata && + netTerms == other.netTerms && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(dueDate, invoiceDate, metadata, netTerms, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "Body{metadata=$metadata, additionalProperties=$additionalProperties}" + "Body{dueDate=$dueDate, invoiceDate=$invoiceDate, metadata=$metadata, netTerms=$netTerms, additionalProperties=$additionalProperties}" + } + + /** + * An optional custom due date for the invoice. If not set, the due date will be calculated + * based on the `net_terms` value. + */ + @JsonDeserialize(using = DueDate.Deserializer::class) + @JsonSerialize(using = DueDate.Serializer::class) + class DueDate + private constructor( + private val date: LocalDate? = null, + private val dateTime: OffsetDateTime? = null, + private val _json: JsonValue? = null, + ) { + + fun date(): LocalDate? = date + + fun dateTime(): OffsetDateTime? = dateTime + + fun isDate(): Boolean = date != null + + fun isDateTime(): Boolean = dateTime != null + + fun asDate(): LocalDate = date.getOrThrow("date") + + fun asDateTime(): OffsetDateTime = dateTime.getOrThrow("dateTime") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + date != null -> visitor.visitDate(date) + dateTime != null -> visitor.visitDateTime(dateTime) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): DueDate = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitDate(date: LocalDate) {} + + override fun visitDateTime(dateTime: OffsetDateTime) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitDate(date: LocalDate) = 1 + + override fun visitDateTime(dateTime: OffsetDateTime) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DueDate && date == other.date && dateTime == other.dateTime + } + + override fun hashCode(): Int = Objects.hash(date, dateTime) + + override fun toString(): String = + when { + date != null -> "DueDate{date=$date}" + dateTime != null -> "DueDate{dateTime=$dateTime}" + _json != null -> "DueDate{_unknown=$_json}" + else -> throw IllegalStateException("Invalid DueDate") + } + + companion object { + + fun ofDate(date: LocalDate) = DueDate(date = date) + + fun ofDateTime(dateTime: OffsetDateTime) = DueDate(dateTime = dateTime) + } + + /** + * An interface that defines how to map each variant of [DueDate] to a value of type [T]. + */ + interface Visitor { + + fun visitDate(date: LocalDate): T + + fun visitDateTime(dateTime: OffsetDateTime): T + + /** + * Maps an unknown variant of [DueDate] to a value of type [T]. + * + * An instance of [DueDate] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown DueDate: $json") + } + } + + internal class Deserializer : BaseDeserializer(DueDate::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): DueDate { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + DueDate(date = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + DueDate(dateTime = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from object). + 0 -> DueDate(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(DueDate::class) { + + override fun serialize( + value: DueDate, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.date != null -> generator.writeObject(value.date) + value.dateTime != null -> generator.writeObject(value.dateTime) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid DueDate") + } + } + } + } + + /** The date of the invoice. Can only be modified for one-off draft invoices. */ + @JsonDeserialize(using = InvoiceDate.Deserializer::class) + @JsonSerialize(using = InvoiceDate.Serializer::class) + class InvoiceDate + private constructor( + private val date: LocalDate? = null, + private val dateTime: OffsetDateTime? = null, + private val _json: JsonValue? = null, + ) { + + fun date(): LocalDate? = date + + fun dateTime(): OffsetDateTime? = dateTime + + fun isDate(): Boolean = date != null + + fun isDateTime(): Boolean = dateTime != null + + fun asDate(): LocalDate = date.getOrThrow("date") + + fun asDateTime(): OffsetDateTime = dateTime.getOrThrow("dateTime") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + date != null -> visitor.visitDate(date) + dateTime != null -> visitor.visitDateTime(dateTime) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): InvoiceDate = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitDate(date: LocalDate) {} + + override fun visitDateTime(dateTime: OffsetDateTime) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitDate(date: LocalDate) = 1 + + override fun visitDateTime(dateTime: OffsetDateTime) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InvoiceDate && date == other.date && dateTime == other.dateTime + } + + override fun hashCode(): Int = Objects.hash(date, dateTime) + + override fun toString(): String = + when { + date != null -> "InvoiceDate{date=$date}" + dateTime != null -> "InvoiceDate{dateTime=$dateTime}" + _json != null -> "InvoiceDate{_unknown=$_json}" + else -> throw IllegalStateException("Invalid InvoiceDate") + } + + companion object { + + fun ofDate(date: LocalDate) = InvoiceDate(date = date) + + fun ofDateTime(dateTime: OffsetDateTime) = InvoiceDate(dateTime = dateTime) + } + + /** + * An interface that defines how to map each variant of [InvoiceDate] to a value of type + * [T]. + */ + interface Visitor { + + fun visitDate(date: LocalDate): T + + fun visitDateTime(dateTime: OffsetDateTime): T + + /** + * Maps an unknown variant of [InvoiceDate] to a value of type [T]. + * + * An instance of [InvoiceDate] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on an + * older version than the API, then the API may respond with new variants that the SDK + * is unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown InvoiceDate: $json") + } + } + + internal class Deserializer : BaseDeserializer(InvoiceDate::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): InvoiceDate { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + InvoiceDate(date = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + InvoiceDate(dateTime = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with + // all the possible variants (e.g. deserializing from object). + 0 -> InvoiceDate(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely + // valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(InvoiceDate::class) { + + override fun serialize( + value: InvoiceDate, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.date != null -> generator.writeObject(value.date) + value.dateTime != null -> generator.writeObject(value.dateTime) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid InvoiceDate") + } + } + } } /** @@ -495,12 +1118,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -512,10 +1133,15 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceUpdateParams && invoiceId == other.invoiceId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is InvoiceUpdateParams && + invoiceId == other.invoiceId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(invoiceId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(invoiceId, body, additionalHeaders, additionalQueryParams) override fun toString() = "InvoiceUpdateParams{invoiceId=$invoiceId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceVoidParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceVoidParams.kt index 698e19ff8..45f8a7d15 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceVoidParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/InvoiceVoidParams.kt @@ -10,7 +10,7 @@ import com.withorb.api.core.toImmutable import java.util.Objects /** - * This endpoint allows an invoice's status to be set the `void` status. This can only be done to + * This endpoint allows an invoice's status to be set to the `void` status. This can only be done to * invoices that are in the `issued` status. * * If the associated invoice has used the customer balance to change the amount due, the customer @@ -217,10 +217,15 @@ private constructor( return true } - return /* spotless:off */ other is InvoiceVoidParams && invoiceId == other.invoiceId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is InvoiceVoidParams && + invoiceId == other.invoiceId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(invoiceId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(invoiceId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "InvoiceVoidParams{invoiceId=$invoiceId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Item.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Item.kt index 42f2b8103..92c529fe8 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Item.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Item.kt @@ -25,12 +25,14 @@ import java.util.Objects * and tax calculation purposes. */ class Item +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val createdAt: JsonField, private val externalConnections: JsonField>, private val metadata: JsonField, private val name: JsonField, + private val archivedAt: JsonField, private val additionalProperties: MutableMap, ) { @@ -45,21 +47,31 @@ private constructor( externalConnections: JsonField> = JsonMissing.of(), @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - ) : this(id, createdAt, externalConnections, metadata, name, mutableMapOf()) + @JsonProperty("archived_at") + @ExcludeMissing + archivedAt: JsonField = JsonMissing.of(), + ) : this(id, createdAt, externalConnections, metadata, name, archivedAt, mutableMapOf()) /** + * The Orb-assigned unique identifier for the item. + * * @throws OrbInvalidDataException if 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 time at which the item was created. + * * @throws OrbInvalidDataException if 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") /** + * A list of external connections for this item, used to sync with external invoicing and tax + * systems. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -77,11 +89,21 @@ private constructor( fun metadata(): Metadata = metadata.getRequired("metadata") /** + * The name of the item. + * * @throws OrbInvalidDataException if 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") + /** + * The time at which the item was archived. If null, the item is not archived. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun archivedAt(): OffsetDateTime? = archivedAt.getNullable("archived_at") + /** * Returns the raw JSON value of [id]. * @@ -122,6 +144,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + /** + * Returns the raw JSON value of [archivedAt]. + * + * Unlike [archivedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("archived_at") + @ExcludeMissing + fun _archivedAt(): JsonField = archivedAt + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -159,6 +190,7 @@ private constructor( private var externalConnections: JsonField>? = null private var metadata: JsonField? = null private var name: JsonField? = null + private var archivedAt: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(item: Item) = apply { @@ -167,9 +199,11 @@ private constructor( externalConnections = item.externalConnections.map { it.toMutableList() } metadata = item.metadata name = item.name + archivedAt = item.archivedAt additionalProperties = item.additionalProperties.toMutableMap() } + /** The Orb-assigned unique identifier for the item. */ fun id(id: String) = id(JsonField.of(id)) /** @@ -180,6 +214,7 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } + /** The time at which the item was created. */ fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) /** @@ -191,6 +226,10 @@ private constructor( */ fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + /** + * A list of external connections for this item, used to sync with external invoicing and + * tax systems. + */ fun externalConnections(externalConnections: List) = externalConnections(JsonField.of(externalConnections)) @@ -233,6 +272,7 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + /** The name of the item. */ fun name(name: String) = name(JsonField.of(name)) /** @@ -243,6 +283,20 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** The time at which the item was archived. If null, the item is not archived. */ + fun archivedAt(archivedAt: OffsetDateTime?) = archivedAt(JsonField.ofNullable(archivedAt)) + + /** + * Sets [Builder.archivedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.archivedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun archivedAt(archivedAt: JsonField) = apply { + this.archivedAt = archivedAt + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -285,6 +339,7 @@ private constructor( checkRequired("externalConnections", externalConnections).map { it.toImmutable() }, checkRequired("metadata", metadata), checkRequired("name", name), + archivedAt, additionalProperties.toMutableMap(), ) } @@ -301,6 +356,7 @@ private constructor( externalConnections().forEach { it.validate() } metadata().validate() name() + archivedAt() validated = true } @@ -322,9 +378,15 @@ private constructor( (if (createdAt.asKnown() == null) 0 else 1) + (externalConnections.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (metadata.asKnown()?.validity() ?: 0) + - (if (name.asKnown() == null) 0 else 1) + (if (name.asKnown() == null) 0 else 1) + + (if (archivedAt.asKnown() == null) 0 else 1) + /** + * Represents a connection between an Item and an external system for invoicing or tax + * calculation purposes. + */ class ExternalConnection + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val externalConnectionName: JsonField, private val externalEntityId: JsonField, @@ -342,6 +404,8 @@ private constructor( ) : this(externalConnectionName, externalEntityId, mutableMapOf()) /** + * The name of the external system this item is connected to. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -349,6 +413,8 @@ private constructor( externalConnectionName.getRequired("external_connection_name") /** + * The identifier of this item in the external system. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -413,6 +479,7 @@ private constructor( additionalProperties = externalConnection.additionalProperties.toMutableMap() } + /** The name of the external system this item is connected to. */ fun externalConnectionName(externalConnectionName: ExternalConnectionName) = externalConnectionName(JsonField.of(externalConnectionName)) @@ -428,6 +495,7 @@ private constructor( this.externalConnectionName = externalConnectionName } + /** The identifier of this item in the external system. */ fun externalEntityId(externalEntityId: String) = externalEntityId(JsonField.of(externalEntityId)) @@ -512,6 +580,7 @@ private constructor( (externalConnectionName.asKnown()?.validity() ?: 0) + (if (externalEntityId.asKnown() == null) 0 else 1) + /** The name of the external system this item is connected to. */ class ExternalConnectionName @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -542,6 +611,8 @@ private constructor( val ANROK = of("anrok") + val NUMERAL = of("numeral") + fun of(value: String) = ExternalConnectionName(JsonField.of(value)) } @@ -554,6 +625,7 @@ private constructor( TAXJAR, AVALARA, ANROK, + NUMERAL, } /** @@ -575,6 +647,7 @@ private constructor( TAXJAR, AVALARA, ANROK, + NUMERAL, /** * An enum member indicating that [ExternalConnectionName] was instantiated with an * unknown value. @@ -598,6 +671,7 @@ private constructor( TAXJAR -> Value.TAXJAR AVALARA -> Value.AVALARA ANROK -> Value.ANROK + NUMERAL -> Value.NUMERAL else -> Value._UNKNOWN } @@ -619,6 +693,7 @@ private constructor( TAXJAR -> Known.TAXJAR AVALARA -> Known.AVALARA ANROK -> Known.ANROK + NUMERAL -> Known.NUMERAL else -> throw OrbInvalidDataException("Unknown ExternalConnectionName: $value") } @@ -666,7 +741,7 @@ private constructor( return true } - return /* spotless:off */ other is ExternalConnectionName && value == other.value /* spotless:on */ + return other is ExternalConnectionName && value == other.value } override fun hashCode() = value.hashCode() @@ -679,12 +754,15 @@ private constructor( return true } - return /* spotless:off */ other is ExternalConnection && externalConnectionName == other.externalConnectionName && externalEntityId == other.externalEntityId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ExternalConnection && + externalConnectionName == other.externalConnectionName && + externalEntityId == other.externalEntityId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(externalConnectionName, externalEntityId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(externalConnectionName, externalEntityId, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -784,12 +862,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -801,15 +877,30 @@ private constructor( return true } - return /* spotless:off */ other is Item && id == other.id && createdAt == other.createdAt && externalConnections == other.externalConnections && metadata == other.metadata && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Item && + id == other.id && + createdAt == other.createdAt && + externalConnections == other.externalConnections && + metadata == other.metadata && + name == other.name && + archivedAt == other.archivedAt && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, createdAt, externalConnections, metadata, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + externalConnections, + metadata, + name, + archivedAt, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Item{id=$id, createdAt=$createdAt, externalConnections=$externalConnections, metadata=$metadata, name=$name, additionalProperties=$additionalProperties}" + "Item{id=$id, createdAt=$createdAt, externalConnections=$externalConnections, metadata=$metadata, name=$name, archivedAt=$archivedAt, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemArchiveParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemArchiveParams.kt index f86d8901e..b290bf41d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemArchiveParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemArchiveParams.kt @@ -207,10 +207,15 @@ private constructor( return true } - return /* spotless:off */ other is ItemArchiveParams && itemId == other.itemId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is ItemArchiveParams && + itemId == other.itemId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(itemId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(itemId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "ItemArchiveParams{itemId=$itemId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemCreateParams.kt index 910cccfbc..99a353fb6 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemCreateParams.kt @@ -272,6 +272,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val metadata: JsonField, @@ -453,12 +454,13 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, metadata, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -558,12 +560,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -575,10 +575,13 @@ private constructor( return true } - return /* spotless:off */ other is ItemCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ItemCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "ItemCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemFetchParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemFetchParams.kt index 5765f1056..0c82eb745 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemFetchParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemFetchParams.kt @@ -170,10 +170,13 @@ private constructor( return true } - return /* spotless:off */ other is ItemFetchParams && itemId == other.itemId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ItemFetchParams && + itemId == other.itemId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(itemId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(itemId, additionalHeaders, additionalQueryParams) override fun toString() = "ItemFetchParams{itemId=$itemId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListPage.kt index 9f427baae..a6f7625e2 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListPage.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is ItemListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ItemListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "ItemListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListPageAsync.kt index 1bdd94422..6e297d4dd 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListPageAsync.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is ItemListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ItemListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "ItemListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListPageResponse.kt index 35073a67d..aa627cf09 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class ItemListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -213,12 +214,15 @@ private constructor( return true } - return /* spotless:off */ other is ItemListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ItemListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListParams.kt index f01b923af..c6f2cd86b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemListParams.kt @@ -195,10 +195,15 @@ private constructor( return true } - return /* spotless:off */ other is ItemListParams && cursor == other.cursor && limit == other.limit && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ItemListParams && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(cursor, limit, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(cursor, limit, additionalHeaders, additionalQueryParams) override fun toString() = "ItemListParams{cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemSlim.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemSlim.kt index a4885ceec..5d9ad4ba2 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemSlim.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemSlim.kt @@ -15,7 +15,9 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects +/** A minimal representation of an Item containing only the essential identifying information. */ class ItemSlim +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -29,12 +31,16 @@ private constructor( ) : this(id, name, mutableMapOf()) /** + * The Orb-assigned unique identifier for the item. + * * @throws OrbInvalidDataException if 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 name of the item. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -93,6 +99,7 @@ private constructor( additionalProperties = itemSlim.additionalProperties.toMutableMap() } + /** The Orb-assigned unique identifier for the item. */ fun id(id: String) = id(JsonField.of(id)) /** @@ -103,6 +110,7 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } + /** The name of the item. */ fun name(name: String) = name(JsonField.of(name)) /** @@ -186,12 +194,13 @@ private constructor( return true } - return /* spotless:off */ other is ItemSlim && id == other.id && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ItemSlim && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, name, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemUpdateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemUpdateParams.kt index 696133f47..8a68183ae 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemUpdateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/ItemUpdateParams.kt @@ -321,6 +321,7 @@ private constructor( * replace the existing item mappings. */ class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val externalConnections: JsonField>, private val metadata: JsonField, @@ -543,12 +544,16 @@ private constructor( return true } - return /* spotless:off */ other is Body && externalConnections == other.externalConnections && metadata == other.metadata && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + externalConnections == other.externalConnections && + metadata == other.metadata && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(externalConnections, metadata, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(externalConnections, metadata, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -556,7 +561,12 @@ private constructor( "Body{externalConnections=$externalConnections, metadata=$metadata, name=$name, additionalProperties=$additionalProperties}" } + /** + * Represents a connection between an Item and an external system for invoicing or tax + * calculation purposes. + */ class ExternalConnection + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val externalConnectionName: JsonField, private val externalEntityId: JsonField, @@ -574,6 +584,8 @@ private constructor( ) : this(externalConnectionName, externalEntityId, mutableMapOf()) /** + * The name of the external system this item is connected to. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -581,6 +593,8 @@ private constructor( externalConnectionName.getRequired("external_connection_name") /** + * The identifier of this item in the external system. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -645,6 +659,7 @@ private constructor( additionalProperties = externalConnection.additionalProperties.toMutableMap() } + /** The name of the external system this item is connected to. */ fun externalConnectionName(externalConnectionName: ExternalConnectionName) = externalConnectionName(JsonField.of(externalConnectionName)) @@ -660,6 +675,7 @@ private constructor( this.externalConnectionName = externalConnectionName } + /** The identifier of this item in the external system. */ fun externalEntityId(externalEntityId: String) = externalEntityId(JsonField.of(externalEntityId)) @@ -744,6 +760,7 @@ private constructor( (externalConnectionName.asKnown()?.validity() ?: 0) + (if (externalEntityId.asKnown() == null) 0 else 1) + /** The name of the external system this item is connected to. */ class ExternalConnectionName @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -774,6 +791,8 @@ private constructor( val ANROK = of("anrok") + val NUMERAL = of("numeral") + fun of(value: String) = ExternalConnectionName(JsonField.of(value)) } @@ -786,6 +805,7 @@ private constructor( TAXJAR, AVALARA, ANROK, + NUMERAL, } /** @@ -807,6 +827,7 @@ private constructor( TAXJAR, AVALARA, ANROK, + NUMERAL, /** * An enum member indicating that [ExternalConnectionName] was instantiated with an * unknown value. @@ -830,6 +851,7 @@ private constructor( TAXJAR -> Value.TAXJAR AVALARA -> Value.AVALARA ANROK -> Value.ANROK + NUMERAL -> Value.NUMERAL else -> Value._UNKNOWN } @@ -851,6 +873,7 @@ private constructor( TAXJAR -> Known.TAXJAR AVALARA -> Known.AVALARA ANROK -> Known.ANROK + NUMERAL -> Known.NUMERAL else -> throw OrbInvalidDataException("Unknown ExternalConnectionName: $value") } @@ -898,7 +921,7 @@ private constructor( return true } - return /* spotless:off */ other is ExternalConnectionName && value == other.value /* spotless:on */ + return other is ExternalConnectionName && value == other.value } override fun hashCode() = value.hashCode() @@ -911,12 +934,15 @@ private constructor( return true } - return /* spotless:off */ other is ExternalConnection && externalConnectionName == other.externalConnectionName && externalEntityId == other.externalEntityId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ExternalConnection && + externalConnectionName == other.externalConnectionName && + externalEntityId == other.externalEntityId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(externalConnectionName, externalEntityId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(externalConnectionName, externalEntityId, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1016,12 +1042,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1033,10 +1057,15 @@ private constructor( return true } - return /* spotless:off */ other is ItemUpdateParams && itemId == other.itemId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ItemUpdateParams && + itemId == other.itemId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(itemId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(itemId, body, additionalHeaders, additionalQueryParams) override fun toString() = "ItemUpdateParams{itemId=$itemId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixConfig.kt index 932687735..2174f5b94 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixConfig.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixConfig.kt @@ -17,7 +17,9 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects +/** Configuration for matrix pricing */ class MatrixConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val defaultUnitAmount: JsonField, private val dimensions: JsonField>, @@ -55,7 +57,7 @@ private constructor( fun dimensions(): List = dimensions.getRequired("dimensions") /** - * Matrix values for specified matrix grouping keys + * Matrix values configuration * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). @@ -173,7 +175,7 @@ private constructor( } } - /** Matrix values for specified matrix grouping keys */ + /** Matrix values configuration */ fun matrixValues(matrixValues: List) = matrixValues(JsonField.of(matrixValues)) /** @@ -277,12 +279,16 @@ private constructor( return true } - return /* spotless:off */ other is MatrixConfig && defaultUnitAmount == other.defaultUnitAmount && dimensions == other.dimensions && matrixValues == other.matrixValues && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MatrixConfig && + defaultUnitAmount == other.defaultUnitAmount && + dimensions == other.dimensions && + matrixValues == other.matrixValues && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(defaultUnitAmount, dimensions, matrixValues, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(defaultUnitAmount, dimensions, matrixValues, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixSubLineItem.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixSubLineItem.kt index 286f3280f..ad71d156d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixSubLineItem.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixSubLineItem.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class MatrixSubLineItem +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val grouping: JsonField, @@ -24,6 +25,7 @@ private constructor( private val name: JsonField, private val quantity: JsonField, private val type: JsonField, + private val scaledQuantity: JsonField, private val additionalProperties: MutableMap, ) { @@ -39,7 +41,10 @@ private constructor( @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("quantity") @ExcludeMissing quantity: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(amount, grouping, matrixConfig, name, quantity, type, mutableMapOf()) + @JsonProperty("scaled_quantity") + @ExcludeMissing + scaledQuantity: JsonField = JsonMissing.of(), + ) : this(amount, grouping, matrixConfig, name, quantity, type, scaledQuantity, mutableMapOf()) /** * The total amount for this sub line item. @@ -79,6 +84,14 @@ private constructor( */ fun type(): Type = type.getRequired("type") + /** + * The scaled quantity for this line item for specific pricing structures + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun scaledQuantity(): Double? = scaledQuantity.getNullable("scaled_quantity") + /** * Returns the raw JSON value of [amount]. * @@ -125,6 +138,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + /** + * Returns the raw JSON value of [scaledQuantity]. + * + * Unlike [scaledQuantity], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("scaled_quantity") + @ExcludeMissing + fun _scaledQuantity(): JsonField = scaledQuantity + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -164,6 +186,7 @@ private constructor( private var name: JsonField? = null private var quantity: JsonField? = null private var type: JsonField? = null + private var scaledQuantity: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(matrixSubLineItem: MatrixSubLineItem) = apply { @@ -173,6 +196,7 @@ private constructor( name = matrixSubLineItem.name quantity = matrixSubLineItem.quantity type = matrixSubLineItem.type + scaledQuantity = matrixSubLineItem.scaledQuantity additionalProperties = matrixSubLineItem.additionalProperties.toMutableMap() } @@ -242,6 +266,28 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } + /** The scaled quantity for this line item for specific pricing structures */ + fun scaledQuantity(scaledQuantity: Double?) = + scaledQuantity(JsonField.ofNullable(scaledQuantity)) + + /** + * Alias for [Builder.scaledQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun scaledQuantity(scaledQuantity: Double) = scaledQuantity(scaledQuantity as Double?) + + /** + * Sets [Builder.scaledQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.scaledQuantity] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun scaledQuantity(scaledQuantity: JsonField) = apply { + this.scaledQuantity = scaledQuantity + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -286,6 +332,7 @@ private constructor( checkRequired("name", name), checkRequired("quantity", quantity), checkRequired("type", type), + scaledQuantity, additionalProperties.toMutableMap(), ) } @@ -303,6 +350,7 @@ private constructor( name() quantity() type().validate() + scaledQuantity() validated = true } @@ -325,7 +373,8 @@ private constructor( (matrixConfig.asKnown()?.validity() ?: 0) + (if (name.asKnown() == null) 0 else 1) + (if (quantity.asKnown() == null) 0 else 1) + - (type.asKnown()?.validity() ?: 0) + (type.asKnown()?.validity() ?: 0) + + (if (scaledQuantity.asKnown() == null) 0 else 1) class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -437,7 +486,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -450,15 +499,32 @@ private constructor( return true } - return /* spotless:off */ other is MatrixSubLineItem && amount == other.amount && grouping == other.grouping && matrixConfig == other.matrixConfig && name == other.name && quantity == other.quantity && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MatrixSubLineItem && + amount == other.amount && + grouping == other.grouping && + matrixConfig == other.matrixConfig && + name == other.name && + quantity == other.quantity && + type == other.type && + scaledQuantity == other.scaledQuantity && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, grouping, matrixConfig, name, quantity, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amount, + grouping, + matrixConfig, + name, + quantity, + type, + scaledQuantity, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "MatrixSubLineItem{amount=$amount, grouping=$grouping, matrixConfig=$matrixConfig, name=$name, quantity=$quantity, type=$type, additionalProperties=$additionalProperties}" + "MatrixSubLineItem{amount=$amount, grouping=$grouping, matrixConfig=$matrixConfig, name=$name, quantity=$quantity, type=$type, scaledQuantity=$scaledQuantity, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixValue.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixValue.kt index 19ebff2d4..acb4e7b98 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixValue.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixValue.kt @@ -17,7 +17,9 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects +/** Configuration for a single matrix value */ class MatrixValue +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val dimensionValues: JsonField>, private val unitAmount: JsonField, @@ -35,9 +37,7 @@ private constructor( ) : this(dimensionValues, unitAmount, mutableMapOf()) /** - * One or two matrix keys to filter usage to this Matrix value by. For example, - * ["region", "tier"] could be used to filter cloud usage by a cloud region and an instance - * tier. + * One or two matrix keys to filter usage to this Matrix value by * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). @@ -107,11 +107,7 @@ private constructor( additionalProperties = matrixValue.additionalProperties.toMutableMap() } - /** - * One or two matrix keys to filter usage to this Matrix value by. For example, - * ["region", "tier"] could be used to filter cloud usage by a cloud region and an instance - * tier. - */ + /** One or two matrix keys to filter usage to this Matrix value by */ fun dimensionValues(dimensionValues: List) = dimensionValues(JsonField.of(dimensionValues)) @@ -224,12 +220,15 @@ private constructor( return true } - return /* spotless:off */ other is MatrixValue && dimensionValues == other.dimensionValues && unitAmount == other.unitAmount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MatrixValue && + dimensionValues == other.dimensionValues && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(dimensionValues, unitAmount, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(dimensionValues, unitAmount, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixWithAllocationConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixWithAllocationConfig.kt index 303d93f9e..03e8c83d3 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixWithAllocationConfig.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MatrixWithAllocationConfig.kt @@ -17,9 +17,11 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects +/** Configuration for matrix pricing with usage allocation */ class MatrixWithAllocationConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val allocation: JsonField, + private val allocation: JsonField, private val defaultUnitAmount: JsonField, private val dimensions: JsonField>, private val matrixValues: JsonField>, @@ -30,7 +32,7 @@ private constructor( private constructor( @JsonProperty("allocation") @ExcludeMissing - allocation: JsonField = JsonMissing.of(), + allocation: JsonField = JsonMissing.of(), @JsonProperty("default_unit_amount") @ExcludeMissing defaultUnitAmount: JsonField = JsonMissing.of(), @@ -43,12 +45,12 @@ private constructor( ) : this(allocation, defaultUnitAmount, dimensions, matrixValues, mutableMapOf()) /** - * Allocation to be used to calculate the price + * Usage allocation * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun allocation(): Double = allocation.getRequired("allocation") + fun allocation(): String = allocation.getRequired("allocation") /** * Default per unit rate for any usage not bucketed into a specified matrix_value @@ -67,7 +69,7 @@ private constructor( fun dimensions(): List = dimensions.getRequired("dimensions") /** - * Matrix values for specified matrix grouping keys + * Matrix values configuration * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). @@ -79,7 +81,7 @@ private constructor( * * Unlike [allocation], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("allocation") @ExcludeMissing fun _allocation(): JsonField = allocation + @JsonProperty("allocation") @ExcludeMissing fun _allocation(): JsonField = allocation /** * Returns the raw JSON value of [defaultUnitAmount]. @@ -140,7 +142,7 @@ private constructor( /** A builder for [MatrixWithAllocationConfig]. */ class Builder internal constructor() { - private var allocation: JsonField? = null + private var allocation: JsonField? = null private var defaultUnitAmount: JsonField? = null private var dimensions: JsonField>? = null private var matrixValues: JsonField>? = null @@ -154,17 +156,17 @@ private constructor( additionalProperties = matrixWithAllocationConfig.additionalProperties.toMutableMap() } - /** Allocation to be used to calculate the price */ - fun allocation(allocation: Double) = allocation(JsonField.of(allocation)) + /** Usage allocation */ + fun allocation(allocation: String) = allocation(JsonField.of(allocation)) /** * Sets [Builder.allocation] to an arbitrary JSON value. * - * You should usually call [Builder.allocation] with a well-typed [Double] value instead. + * You should usually call [Builder.allocation] with a well-typed [String] value instead. * This method is primarily for setting the field to an undocumented or not yet supported * value. */ - fun allocation(allocation: JsonField) = apply { this.allocation = allocation } + fun allocation(allocation: JsonField) = apply { this.allocation = allocation } /** Default per unit rate for any usage not bucketed into a specified matrix_value */ fun defaultUnitAmount(defaultUnitAmount: String) = @@ -207,7 +209,7 @@ private constructor( } } - /** Matrix values for specified matrix grouping keys */ + /** Matrix values configuration */ fun matrixValues(matrixValues: List) = matrixValues(JsonField.of(matrixValues)) /** @@ -310,17 +312,251 @@ private constructor( (dimensions.asKnown()?.sumOf { (if (it == null) 0 else 1).toInt() } ?: 0) + (matrixValues.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + /** Configuration for a single matrix value */ + class MatrixValue + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val dimensionValues: JsonField>, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("dimension_values") + @ExcludeMissing + dimensionValues: JsonField> = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(dimensionValues, unitAmount, mutableMapOf()) + + /** + * One or two matrix keys to filter usage to this Matrix value by. For example, + * ["region", "tier"] could be used to filter cloud usage by a cloud region and an instance + * tier. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dimensionValues(): List = dimensionValues.getRequired("dimension_values") + + /** + * Unit price for the specified dimension_values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [dimensionValues]. + * + * Unlike [dimensionValues], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dimension_values") + @ExcludeMissing + fun _dimensionValues(): JsonField> = dimensionValues + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 [MatrixValue]. + * + * The following fields are required: + * ```kotlin + * .dimensionValues() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [MatrixValue]. */ + class Builder internal constructor() { + + private var dimensionValues: JsonField>? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(matrixValue: MatrixValue) = apply { + dimensionValues = matrixValue.dimensionValues.map { it.toMutableList() } + unitAmount = matrixValue.unitAmount + additionalProperties = matrixValue.additionalProperties.toMutableMap() + } + + /** + * One or two matrix keys to filter usage to this Matrix value by. For example, + * ["region", "tier"] could be used to filter cloud usage by a cloud region and an + * instance tier. + */ + fun dimensionValues(dimensionValues: List) = + dimensionValues(JsonField.of(dimensionValues)) + + /** + * Sets [Builder.dimensionValues] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionValues] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun dimensionValues(dimensionValues: JsonField>) = apply { + this.dimensionValues = dimensionValues.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [dimensionValues]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDimensionValue(dimensionValue: String) = apply { + dimensionValues = + (dimensionValues ?: JsonField.of(mutableListOf())).also { + checkKnown("dimensionValues", it).add(dimensionValue) + } + } + + /** Unit price for the specified dimension_values */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { this.unitAmount = unitAmount } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [MatrixValue]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .dimensionValues() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MatrixValue = + MatrixValue( + checkRequired("dimensionValues", dimensionValues).map { it.toImmutable() }, + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MatrixValue = apply { + if (validated) { + return@apply + } + + dimensionValues() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (dimensionValues.asKnown()?.sumOf { (if (it == null) 0 else 1).toInt() } ?: 0) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MatrixValue && + dimensionValues == other.dimensionValues && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(dimensionValues, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MatrixValue{dimensionValues=$dimensionValues, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MatrixWithAllocationConfig && allocation == other.allocation && defaultUnitAmount == other.defaultUnitAmount && dimensions == other.dimensions && matrixValues == other.matrixValues && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MatrixWithAllocationConfig && + allocation == other.allocation && + defaultUnitAmount == other.defaultUnitAmount && + dimensions == other.dimensions && + matrixValues == other.matrixValues && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(allocation, defaultUnitAmount, dimensions, matrixValues, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(allocation, defaultUnitAmount, dimensions, matrixValues, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Maximum.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Maximum.kt index 423b60087..8ba756ccc 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Maximum.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Maximum.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.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing @@ -18,9 +19,10 @@ import java.util.Collections import java.util.Objects class Maximum +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val maximumAmount: JsonField, private val additionalProperties: MutableMap, ) { @@ -32,7 +34,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("maximum_amount") @ExcludeMissing maximumAmount: JsonField = JsonMissing.of(), @@ -54,7 +56,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** * Maximum amount applied @@ -80,9 +82,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [maximumAmount]. @@ -124,7 +124,7 @@ private constructor( class Builder internal constructor() { private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var maximumAmount: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -169,25 +169,25 @@ private constructor( } /** The filters that determine which prices to apply this maximum to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -281,17 +281,549 @@ private constructor( (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (maximumAmount.asKnown() == null) 0 else 1) + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is Maximum && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && maximumAmount == other.maximumAmount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Maximum && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + maximumAmount == other.maximumAmount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(appliesToPriceIds, filters, maximumAmount, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(appliesToPriceIds, filters, maximumAmount, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MaximumInterval.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MaximumInterval.kt index c5c74cfff..89f26b163 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MaximumInterval.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MaximumInterval.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.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing @@ -19,10 +20,11 @@ import java.util.Collections import java.util.Objects class MaximumInterval +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val appliesToPriceIntervalIds: JsonField>, private val endDate: JsonField, - private val filters: JsonField>, + private val filters: JsonField>, private val maximumAmount: JsonField, private val startDate: JsonField, private val additionalProperties: MutableMap, @@ -38,7 +40,7 @@ private constructor( endDate: JsonField = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("maximum_amount") @ExcludeMissing maximumAmount: JsonField = JsonMissing.of(), @@ -70,7 +72,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** * The maximum amount to charge in a given billing period for the price intervals this transform @@ -111,9 +113,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [maximumAmount]. @@ -167,7 +167,7 @@ private constructor( private var appliesToPriceIntervalIds: JsonField>? = null private var endDate: JsonField? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var maximumAmount: JsonField? = null private var startDate: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -222,25 +222,25 @@ private constructor( fun endDate(endDate: JsonField) = apply { this.endDate = endDate } /** The filters that determine which prices this maximum interval applies to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -359,17 +359,558 @@ private constructor( (if (maximumAmount.asKnown() == null) 0 else 1) + (if (startDate.asKnown() == null) 0 else 1) + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MaximumInterval && appliesToPriceIntervalIds == other.appliesToPriceIntervalIds && endDate == other.endDate && filters == other.filters && maximumAmount == other.maximumAmount && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MaximumInterval && + appliesToPriceIntervalIds == other.appliesToPriceIntervalIds && + endDate == other.endDate && + filters == other.filters && + maximumAmount == other.maximumAmount && + startDate == other.startDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(appliesToPriceIntervalIds, endDate, filters, maximumAmount, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + appliesToPriceIntervalIds, + endDate, + filters, + maximumAmount, + startDate, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricCreateParams.kt index dab95c7e6..a6f20a939 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricCreateParams.kt @@ -369,6 +369,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val description: JsonField, private val itemId: JsonField, @@ -669,12 +670,18 @@ private constructor( return true } - return /* spotless:off */ other is Body && description == other.description && itemId == other.itemId && name == other.name && sql == other.sql && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + description == other.description && + itemId == other.itemId && + name == other.name && + sql == other.sql && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(description, itemId, name, sql, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(description, itemId, name, sql, metadata, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -774,12 +781,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -791,10 +796,13 @@ private constructor( return true } - return /* spotless:off */ other is MetricCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is MetricCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "MetricCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricFetchParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricFetchParams.kt index 697769d5d..8d7795d10 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricFetchParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricFetchParams.kt @@ -173,10 +173,13 @@ private constructor( return true } - return /* spotless:off */ other is MetricFetchParams && metricId == other.metricId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is MetricFetchParams && + metricId == other.metricId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(metricId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(metricId, additionalHeaders, additionalQueryParams) override fun toString() = "MetricFetchParams{metricId=$metricId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListPage.kt index 03d7a1a97..4131e61f0 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListPage.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is MetricListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is MetricListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "MetricListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListPageAsync.kt index b28125cfd..787683c1e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListPageAsync.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is MetricListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is MetricListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "MetricListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListPageResponse.kt index d1a1f0b53..0fc606b02 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class MetricListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -216,12 +217,15 @@ private constructor( return true } - return /* spotless:off */ other is MetricListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MetricListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListParams.kt index 64cc64834..67b5a9301 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricListParams.kt @@ -249,10 +249,28 @@ private constructor( return true } - return /* spotless:off */ other is MetricListParams && createdAtGt == other.createdAtGt && createdAtGte == other.createdAtGte && createdAtLt == other.createdAtLt && createdAtLte == other.createdAtLte && cursor == other.cursor && limit == other.limit && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is MetricListParams && + createdAtGt == other.createdAtGt && + createdAtGte == other.createdAtGte && + createdAtLt == other.createdAtLt && + createdAtLte == other.createdAtLte && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(createdAtGt, createdAtGte, createdAtLt, createdAtLte, cursor, limit, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + createdAtGt, + createdAtGte, + createdAtLt, + createdAtLte, + cursor, + limit, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "MetricListParams{createdAtGt=$createdAtGt, createdAtGte=$createdAtGte, createdAtLt=$createdAtLt, createdAtLte=$createdAtLte, cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricUpdateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricUpdateParams.kt index dc46caa59..f8d11b24f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricUpdateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MetricUpdateParams.kt @@ -253,6 +253,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val metadata: JsonField, private val additionalProperties: MutableMap, @@ -386,12 +387,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -491,12 +492,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -508,10 +507,15 @@ private constructor( return true } - return /* spotless:off */ other is MetricUpdateParams && metricId == other.metricId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is MetricUpdateParams && + metricId == other.metricId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(metricId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(metricId, body, additionalHeaders, additionalQueryParams) override fun toString() = "MetricUpdateParams{metricId=$metricId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Minimum.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Minimum.kt index a8b25ca5d..7c2da8175 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Minimum.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Minimum.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.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing @@ -18,9 +19,10 @@ import java.util.Collections import java.util.Objects class Minimum +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val minimumAmount: JsonField, private val additionalProperties: MutableMap, ) { @@ -32,7 +34,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("minimum_amount") @ExcludeMissing minimumAmount: JsonField = JsonMissing.of(), @@ -54,7 +56,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** * Minimum amount applied @@ -80,9 +82,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [minimumAmount]. @@ -124,7 +124,7 @@ private constructor( class Builder internal constructor() { private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var minimumAmount: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -169,25 +169,25 @@ private constructor( } /** The filters that determine which prices to apply this minimum to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -281,17 +281,549 @@ private constructor( (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is Minimum && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && minimumAmount == other.minimumAmount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Minimum && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + minimumAmount == other.minimumAmount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(appliesToPriceIds, filters, minimumAmount, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(appliesToPriceIds, filters, minimumAmount, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MinimumInterval.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MinimumInterval.kt index 41d3eba0b..6a4ea08b5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MinimumInterval.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MinimumInterval.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.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing @@ -19,10 +20,11 @@ import java.util.Collections import java.util.Objects class MinimumInterval +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val appliesToPriceIntervalIds: JsonField>, private val endDate: JsonField, - private val filters: JsonField>, + private val filters: JsonField>, private val minimumAmount: JsonField, private val startDate: JsonField, private val additionalProperties: MutableMap, @@ -38,7 +40,7 @@ private constructor( endDate: JsonField = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("minimum_amount") @ExcludeMissing minimumAmount: JsonField = JsonMissing.of(), @@ -70,7 +72,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** * The minimum amount to charge in a given billing period for the price intervals this minimum @@ -111,9 +113,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [minimumAmount]. @@ -167,7 +167,7 @@ private constructor( private var appliesToPriceIntervalIds: JsonField>? = null private var endDate: JsonField? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var minimumAmount: JsonField? = null private var startDate: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -222,25 +222,25 @@ private constructor( fun endDate(endDate: JsonField) = apply { this.endDate = endDate } /** The filters that determine which prices this minimum interval applies to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -359,17 +359,558 @@ private constructor( (if (minimumAmount.asKnown() == null) 0 else 1) + (if (startDate.asKnown() == null) 0 else 1) + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MinimumInterval && appliesToPriceIntervalIds == other.appliesToPriceIntervalIds && endDate == other.endDate && filters == other.filters && minimumAmount == other.minimumAmount && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MinimumInterval && + appliesToPriceIntervalIds == other.appliesToPriceIntervalIds && + endDate == other.endDate && + filters == other.filters && + minimumAmount == other.minimumAmount && + startDate == other.startDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(appliesToPriceIntervalIds, endDate, filters, minimumAmount, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + appliesToPriceIntervalIds, + endDate, + filters, + minimumAmount, + startDate, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryAmountDiscountAdjustment.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryAmountDiscountAdjustment.kt index 6a2a36ca6..b0f7331f8 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryAmountDiscountAdjustment.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryAmountDiscountAdjustment.kt @@ -19,13 +19,14 @@ import java.util.Collections import java.util.Objects class MonetaryAmountDiscountAdjustment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustmentType: JsonField, private val amount: JsonField, private val amountDiscount: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val reason: JsonField, private val replacesAdjustmentId: JsonField, @@ -47,7 +48,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -112,10 +113,10 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply to + * True for adjustments that apply to an entire invoice, false for adjustments that apply to * only one price. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -188,9 +189,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -260,7 +259,7 @@ private constructor( private var amount: JsonField? = null private var amountDiscount: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField? = null private var reason: JsonField? = null private var replacesAdjustmentId: JsonField? = null @@ -365,25 +364,25 @@ private constructor( } /** The filters that determine which prices to apply this adjustment to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -391,8 +390,8 @@ private constructor( } /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply - * to only one price. + * True for adjustments that apply to an entire invoice, false for adjustments that apply to + * only one price. */ fun isInvoiceLevel(isInvoiceLevel: Boolean) = isInvoiceLevel(JsonField.of(isInvoiceLevel)) @@ -647,7 +646,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -655,17 +654,566 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MonetaryAmountDiscountAdjustment && id == other.id && adjustmentType == other.adjustmentType && amount == other.amount && amountDiscount == other.amountDiscount && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && reason == other.reason && replacesAdjustmentId == other.replacesAdjustmentId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MonetaryAmountDiscountAdjustment && + id == other.id && + adjustmentType == other.adjustmentType && + amount == other.amount && + amountDiscount == other.amountDiscount && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + reason == other.reason && + replacesAdjustmentId == other.replacesAdjustmentId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustmentType, amount, amountDiscount, appliesToPriceIds, filters, isInvoiceLevel, reason, replacesAdjustmentId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustmentType, + amount, + amountDiscount, + appliesToPriceIds, + filters, + isInvoiceLevel, + reason, + replacesAdjustmentId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryMaximumAdjustment.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryMaximumAdjustment.kt index 40e9abcb9..438dacaad 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryMaximumAdjustment.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryMaximumAdjustment.kt @@ -19,12 +19,13 @@ import java.util.Collections import java.util.Objects class MonetaryMaximumAdjustment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustmentType: JsonField, private val amount: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val maximumAmount: JsonField, private val reason: JsonField, @@ -44,7 +45,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -103,10 +104,10 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply to + * True for adjustments that apply to an entire invoice, false for adjustments that apply to * only one price. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -179,9 +180,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -258,7 +257,7 @@ private constructor( private var adjustmentType: JsonField? = null private var amount: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField? = null private var maximumAmount: JsonField? = null private var reason: JsonField? = null @@ -345,25 +344,25 @@ private constructor( } /** The filters that determine which prices to apply this adjustment to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -371,8 +370,8 @@ private constructor( } /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply - * to only one price. + * True for adjustments that apply to an entire invoice, false for adjustments that apply to + * only one price. */ fun isInvoiceLevel(isInvoiceLevel: Boolean) = isInvoiceLevel(JsonField.of(isInvoiceLevel)) @@ -644,7 +643,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -652,17 +651,566 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MonetaryMaximumAdjustment && id == other.id && adjustmentType == other.adjustmentType && amount == other.amount && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && maximumAmount == other.maximumAmount && reason == other.reason && replacesAdjustmentId == other.replacesAdjustmentId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MonetaryMaximumAdjustment && + id == other.id && + adjustmentType == other.adjustmentType && + amount == other.amount && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + maximumAmount == other.maximumAmount && + reason == other.reason && + replacesAdjustmentId == other.replacesAdjustmentId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustmentType, amount, appliesToPriceIds, filters, isInvoiceLevel, maximumAmount, reason, replacesAdjustmentId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustmentType, + amount, + appliesToPriceIds, + filters, + isInvoiceLevel, + maximumAmount, + reason, + replacesAdjustmentId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryMinimumAdjustment.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryMinimumAdjustment.kt index aafbac05b..2e87bd2e7 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryMinimumAdjustment.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryMinimumAdjustment.kt @@ -19,12 +19,13 @@ import java.util.Collections import java.util.Objects class MonetaryMinimumAdjustment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustmentType: JsonField, private val amount: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val itemId: JsonField, private val minimumAmount: JsonField, @@ -45,7 +46,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -106,10 +107,10 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply to + * True for adjustments that apply to an entire invoice, false for adjustments that apply to * only one price. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -190,9 +191,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -277,7 +276,7 @@ private constructor( private var adjustmentType: JsonField? = null private var amount: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField? = null private var itemId: JsonField? = null private var minimumAmount: JsonField? = null @@ -366,25 +365,25 @@ private constructor( } /** The filters that determine which prices to apply this adjustment to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -392,8 +391,8 @@ private constructor( } /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply - * to only one price. + * True for adjustments that apply to an entire invoice, false for adjustments that apply to + * only one price. */ fun isInvoiceLevel(isInvoiceLevel: Boolean) = isInvoiceLevel(JsonField.of(isInvoiceLevel)) @@ -680,7 +679,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -688,17 +687,568 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MonetaryMinimumAdjustment && id == other.id && adjustmentType == other.adjustmentType && amount == other.amount && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && itemId == other.itemId && minimumAmount == other.minimumAmount && reason == other.reason && replacesAdjustmentId == other.replacesAdjustmentId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MonetaryMinimumAdjustment && + id == other.id && + adjustmentType == other.adjustmentType && + amount == other.amount && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + itemId == other.itemId && + minimumAmount == other.minimumAmount && + reason == other.reason && + replacesAdjustmentId == other.replacesAdjustmentId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustmentType, amount, appliesToPriceIds, filters, isInvoiceLevel, itemId, minimumAmount, reason, replacesAdjustmentId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustmentType, + amount, + appliesToPriceIds, + filters, + isInvoiceLevel, + itemId, + minimumAmount, + reason, + replacesAdjustmentId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryPercentageDiscountAdjustment.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryPercentageDiscountAdjustment.kt index 13afbfa84..65eb75503 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryPercentageDiscountAdjustment.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryPercentageDiscountAdjustment.kt @@ -19,12 +19,13 @@ import java.util.Collections import java.util.Objects class MonetaryPercentageDiscountAdjustment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustmentType: JsonField, private val amount: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val percentageDiscount: JsonField, private val reason: JsonField, @@ -44,7 +45,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -103,10 +104,10 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply to + * True for adjustments that apply to an entire invoice, false for adjustments that apply to * only one price. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -179,9 +180,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -260,7 +259,7 @@ private constructor( private var adjustmentType: JsonField? = null private var amount: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField? = null private var percentageDiscount: JsonField? = null private var reason: JsonField? = null @@ -350,25 +349,25 @@ private constructor( } /** The filters that determine which prices to apply this adjustment to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -376,8 +375,8 @@ private constructor( } /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply - * to only one price. + * True for adjustments that apply to an entire invoice, false for adjustments that apply to + * only one price. */ fun isInvoiceLevel(isInvoiceLevel: Boolean) = isInvoiceLevel(JsonField.of(isInvoiceLevel)) @@ -650,7 +649,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -658,17 +657,566 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MonetaryPercentageDiscountAdjustment && id == other.id && adjustmentType == other.adjustmentType && amount == other.amount && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && percentageDiscount == other.percentageDiscount && reason == other.reason && replacesAdjustmentId == other.replacesAdjustmentId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MonetaryPercentageDiscountAdjustment && + id == other.id && + adjustmentType == other.adjustmentType && + amount == other.amount && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + percentageDiscount == other.percentageDiscount && + reason == other.reason && + replacesAdjustmentId == other.replacesAdjustmentId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustmentType, amount, appliesToPriceIds, filters, isInvoiceLevel, percentageDiscount, reason, replacesAdjustmentId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustmentType, + amount, + appliesToPriceIds, + filters, + isInvoiceLevel, + percentageDiscount, + reason, + replacesAdjustmentId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryUsageDiscountAdjustment.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryUsageDiscountAdjustment.kt index c6aef48d8..e36a6926e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryUsageDiscountAdjustment.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MonetaryUsageDiscountAdjustment.kt @@ -19,12 +19,13 @@ import java.util.Collections import java.util.Objects class MonetaryUsageDiscountAdjustment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustmentType: JsonField, private val amount: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val reason: JsonField, private val replacesAdjustmentId: JsonField, @@ -44,7 +45,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -103,10 +104,10 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply to + * True for adjustments that apply to an entire invoice, false for adjustments that apply to * only one price. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -179,9 +180,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -259,7 +258,7 @@ private constructor( private var adjustmentType: JsonField? = null private var amount: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField? = null private var reason: JsonField? = null private var replacesAdjustmentId: JsonField? = null @@ -348,25 +347,25 @@ private constructor( } /** The filters that determine which prices to apply this adjustment to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -374,8 +373,8 @@ private constructor( } /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply - * to only one price. + * True for adjustments that apply to an entire invoice, false for adjustments that apply to + * only one price. */ fun isInvoiceLevel(isInvoiceLevel: Boolean) = isInvoiceLevel(JsonField.of(isInvoiceLevel)) @@ -647,7 +646,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -655,17 +654,566 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MonetaryUsageDiscountAdjustment && id == other.id && adjustmentType == other.adjustmentType && amount == other.amount && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && reason == other.reason && replacesAdjustmentId == other.replacesAdjustmentId && usageDiscount == other.usageDiscount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MonetaryUsageDiscountAdjustment && + id == other.id && + adjustmentType == other.adjustmentType && + amount == other.amount && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + reason == other.reason && + replacesAdjustmentId == other.replacesAdjustmentId && + usageDiscount == other.usageDiscount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustmentType, amount, appliesToPriceIds, filters, isInvoiceLevel, reason, replacesAdjustmentId, usageDiscount, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustmentType, + amount, + appliesToPriceIds, + filters, + isInvoiceLevel, + reason, + replacesAdjustmentId, + usageDiscount, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MutatedSubscription.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MutatedSubscription.kt index acc7e01f3..12aeeccd9 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MutatedSubscription.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/MutatedSubscription.kt @@ -30,6 +30,7 @@ import java.util.Collections import java.util.Objects class MutatedSubscription +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val activePlanPhaseOrder: JsonField, @@ -1628,10 +1629,13 @@ private constructor( return true } - return /* spotless:off */ other is DiscountInterval && amount == other.amount && percentage == other.percentage && usage == other.usage /* spotless:on */ + return other is DiscountInterval && + amount == other.amount && + percentage == other.percentage && + usage == other.usage } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(amount, percentage, usage) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(amount, percentage, usage) override fun toString(): String = when { @@ -1817,12 +1821,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1951,7 +1953,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -1964,12 +1966,71 @@ private constructor( return true } - return /* spotless:off */ other is MutatedSubscription && id == other.id && activePlanPhaseOrder == other.activePlanPhaseOrder && adjustmentIntervals == other.adjustmentIntervals && autoCollection == other.autoCollection && billingCycleAnchorConfiguration == other.billingCycleAnchorConfiguration && billingCycleDay == other.billingCycleDay && createdAt == other.createdAt && currentBillingPeriodEndDate == other.currentBillingPeriodEndDate && currentBillingPeriodStartDate == other.currentBillingPeriodStartDate && customer == other.customer && defaultInvoiceMemo == other.defaultInvoiceMemo && discountIntervals == other.discountIntervals && endDate == other.endDate && fixedFeeQuantitySchedule == other.fixedFeeQuantitySchedule && invoicingThreshold == other.invoicingThreshold && maximumIntervals == other.maximumIntervals && metadata == other.metadata && minimumIntervals == other.minimumIntervals && name == other.name && netTerms == other.netTerms && pendingSubscriptionChange == other.pendingSubscriptionChange && plan == other.plan && priceIntervals == other.priceIntervals && redeemedCoupon == other.redeemedCoupon && startDate == other.startDate && status == other.status && trialInfo == other.trialInfo && changedResources == other.changedResources && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MutatedSubscription && + id == other.id && + activePlanPhaseOrder == other.activePlanPhaseOrder && + adjustmentIntervals == other.adjustmentIntervals && + autoCollection == other.autoCollection && + billingCycleAnchorConfiguration == other.billingCycleAnchorConfiguration && + billingCycleDay == other.billingCycleDay && + createdAt == other.createdAt && + currentBillingPeriodEndDate == other.currentBillingPeriodEndDate && + currentBillingPeriodStartDate == other.currentBillingPeriodStartDate && + customer == other.customer && + defaultInvoiceMemo == other.defaultInvoiceMemo && + discountIntervals == other.discountIntervals && + endDate == other.endDate && + fixedFeeQuantitySchedule == other.fixedFeeQuantitySchedule && + invoicingThreshold == other.invoicingThreshold && + maximumIntervals == other.maximumIntervals && + metadata == other.metadata && + minimumIntervals == other.minimumIntervals && + name == other.name && + netTerms == other.netTerms && + pendingSubscriptionChange == other.pendingSubscriptionChange && + plan == other.plan && + priceIntervals == other.priceIntervals && + redeemedCoupon == other.redeemedCoupon && + startDate == other.startDate && + status == other.status && + trialInfo == other.trialInfo && + changedResources == other.changedResources && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, activePlanPhaseOrder, adjustmentIntervals, autoCollection, billingCycleAnchorConfiguration, billingCycleDay, createdAt, currentBillingPeriodEndDate, currentBillingPeriodStartDate, customer, defaultInvoiceMemo, discountIntervals, endDate, fixedFeeQuantitySchedule, invoicingThreshold, maximumIntervals, metadata, minimumIntervals, name, netTerms, pendingSubscriptionChange, plan, priceIntervals, redeemedCoupon, startDate, status, trialInfo, changedResources, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + activePlanPhaseOrder, + adjustmentIntervals, + autoCollection, + billingCycleAnchorConfiguration, + billingCycleDay, + createdAt, + currentBillingPeriodEndDate, + currentBillingPeriodStartDate, + customer, + defaultInvoiceMemo, + discountIntervals, + endDate, + fixedFeeQuantitySchedule, + invoicingThreshold, + maximumIntervals, + metadata, + minimumIntervals, + name, + netTerms, + pendingSubscriptionChange, + plan, + priceIntervals, + redeemedCoupon, + startDate, + status, + trialInfo, + changedResources, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAccountingSyncConfiguration.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAccountingSyncConfiguration.kt index 54752ed21..1674ea40f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAccountingSyncConfiguration.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAccountingSyncConfiguration.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class NewAccountingSyncConfiguration +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val accountingProviders: JsonField>, private val excluded: JsonField, @@ -208,12 +209,15 @@ private constructor( return true } - return /* spotless:off */ other is NewAccountingSyncConfiguration && accountingProviders == other.accountingProviders && excluded == other.excluded && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewAccountingSyncConfiguration && + accountingProviders == other.accountingProviders && + excluded == other.excluded && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(accountingProviders, excluded, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(accountingProviders, excluded, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAllocationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAllocationPrice.kt index d9c14a4bb..17669e69c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAllocationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAllocationPrice.kt @@ -11,18 +11,24 @@ import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewAllocationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val cadence: JsonField, private val currency: JsonField, private val customExpiration: JsonField, private val expiresAtEndOfCadence: JsonField, + private val filters: JsonField>, + private val itemId: JsonField, + private val perUnitCostBasis: JsonField, private val additionalProperties: MutableMap, ) { @@ -37,7 +43,24 @@ private constructor( @JsonProperty("expires_at_end_of_cadence") @ExcludeMissing expiresAtEndOfCadence: JsonField = JsonMissing.of(), - ) : this(amount, cadence, currency, customExpiration, expiresAtEndOfCadence, mutableMapOf()) + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("item_id") @ExcludeMissing itemId: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_cost_basis") + @ExcludeMissing + perUnitCostBasis: JsonField = JsonMissing.of(), + ) : this( + amount, + cadence, + currency, + customExpiration, + expiresAtEndOfCadence, + filters, + itemId, + perUnitCostBasis, + mutableMapOf(), + ) /** * An amount of the currency to allocate to the customer at the specified cadence. @@ -81,6 +104,33 @@ private constructor( fun expiresAtEndOfCadence(): Boolean? = expiresAtEndOfCadence.getNullable("expires_at_end_of_cadence") + /** + * The filters that determine which items the allocation applies to. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun filters(): List? = filters.getNullable("filters") + + /** + * The item ID that line items representing charges for this allocation will be associated with. + * If not provided, the default allocation item for the currency will be used (e.g. 'Included + * Allocation (USD)'). + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun itemId(): String? = itemId.getNullable("item_id") + + /** + * The (per-unit) cost basis of each created block. If non-zero, a customer will be invoiced + * according to the quantity and per unit cost basis specified for the allocation each cadence. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun perUnitCostBasis(): String? = perUnitCostBasis.getNullable("per_unit_cost_basis") + /** * Returns the raw JSON value of [amount]. * @@ -122,6 +172,30 @@ private constructor( @ExcludeMissing fun _expiresAtEndOfCadence(): JsonField = expiresAtEndOfCadence + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * Returns the raw JSON value of [perUnitCostBasis]. + * + * Unlike [perUnitCostBasis], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("per_unit_cost_basis") + @ExcludeMissing + fun _perUnitCostBasis(): JsonField = perUnitCostBasis + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -157,6 +231,9 @@ private constructor( private var currency: JsonField? = null private var customExpiration: JsonField = JsonMissing.of() private var expiresAtEndOfCadence: JsonField = JsonMissing.of() + private var filters: JsonField>? = null + private var itemId: JsonField = JsonMissing.of() + private var perUnitCostBasis: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(newAllocationPrice: NewAllocationPrice) = apply { @@ -165,6 +242,9 @@ private constructor( currency = newAllocationPrice.currency customExpiration = newAllocationPrice.customExpiration expiresAtEndOfCadence = newAllocationPrice.expiresAtEndOfCadence + filters = newAllocationPrice.filters.map { it.toMutableList() } + itemId = newAllocationPrice.itemId + perUnitCostBasis = newAllocationPrice.perUnitCostBasis additionalProperties = newAllocationPrice.additionalProperties.toMutableMap() } @@ -245,6 +325,66 @@ private constructor( this.expiresAtEndOfCadence = expiresAtEndOfCadence } + /** The filters that determine which items the allocation applies to. */ + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + + /** + * The item ID that line items representing charges for this allocation will be associated + * with. If not provided, the default allocation item for the currency will be used (e.g. + * 'Included Allocation (USD)'). + */ + fun itemId(itemId: String?) = itemId(JsonField.ofNullable(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * The (per-unit) cost basis of each created block. If non-zero, a customer will be invoiced + * according to the quantity and per unit cost basis specified for the allocation each + * cadence. + */ + fun perUnitCostBasis(perUnitCostBasis: String) = + perUnitCostBasis(JsonField.of(perUnitCostBasis)) + + /** + * Sets [Builder.perUnitCostBasis] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitCostBasis] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun perUnitCostBasis(perUnitCostBasis: JsonField) = apply { + this.perUnitCostBasis = perUnitCostBasis + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -285,6 +425,9 @@ private constructor( checkRequired("currency", currency), customExpiration, expiresAtEndOfCadence, + (filters ?: JsonMissing.of()).map { it.toImmutable() }, + itemId, + perUnitCostBasis, additionalProperties.toMutableMap(), ) } @@ -301,6 +444,9 @@ private constructor( currency() customExpiration()?.validate() expiresAtEndOfCadence() + filters()?.forEach { it.validate() } + itemId() + perUnitCostBasis() validated = true } @@ -322,7 +468,10 @@ private constructor( (cadence.asKnown()?.validity() ?: 0) + (if (currency.asKnown() == null) 0 else 1) + (customExpiration.asKnown()?.validity() ?: 0) + - (if (expiresAtEndOfCadence.asKnown() == null) 0 else 1) + (if (expiresAtEndOfCadence.asKnown() == null) 0 else 1) + + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + (if (perUnitCostBasis.asKnown() == null) 0 else 1) /** The cadence at which to allocate the amount to the customer. */ class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -459,7 +608,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -467,20 +616,544 @@ private constructor( override fun toString() = value.toString() } + /** A PriceFilter that only allows item_id field for block filters. */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price the block applies to. Only item_id is supported. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price the block applies to. Only item_id is supported. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price the block applies to. Only item_id is supported. */ + class Field @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 { + + val ITEM_ID = of("item_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + ITEM_ID + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + ITEM_ID, + /** + * An enum member indicating that [Field] 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) { + ITEM_ID -> Value.ITEM_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ITEM_ID -> Known.ITEM_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is NewAllocationPrice && amount == other.amount && cadence == other.cadence && currency == other.currency && customExpiration == other.customExpiration && expiresAtEndOfCadence == other.expiresAtEndOfCadence && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewAllocationPrice && + amount == other.amount && + cadence == other.cadence && + currency == other.currency && + customExpiration == other.customExpiration && + expiresAtEndOfCadence == other.expiresAtEndOfCadence && + filters == other.filters && + itemId == other.itemId && + perUnitCostBasis == other.perUnitCostBasis && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, cadence, currency, customExpiration, expiresAtEndOfCadence, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + amount, + cadence, + currency, + customExpiration, + expiresAtEndOfCadence, + filters, + itemId, + perUnitCostBasis, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "NewAllocationPrice{amount=$amount, cadence=$cadence, currency=$currency, customExpiration=$customExpiration, expiresAtEndOfCadence=$expiresAtEndOfCadence, additionalProperties=$additionalProperties}" + "NewAllocationPrice{amount=$amount, cadence=$cadence, currency=$currency, customExpiration=$customExpiration, expiresAtEndOfCadence=$expiresAtEndOfCadence, filters=$filters, itemId=$itemId, perUnitCostBasis=$perUnitCostBasis, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAmountDiscount.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAmountDiscount.kt index 8c31385b8..6b2295485 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAmountDiscount.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAmountDiscount.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class NewAmountDiscount +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val adjustmentType: JsonField, private val amountDiscount: JsonField, @@ -26,7 +27,7 @@ private constructor( private val appliesToItemIds: JsonField>, private val appliesToPriceIds: JsonField>, private val currency: JsonField, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val priceType: JsonField, private val additionalProperties: MutableMap, @@ -52,7 +53,7 @@ private constructor( @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -122,7 +123,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). */ - fun filters(): List? = filters.getNullable("filters") + fun filters(): List? = filters.getNullable("filters") /** * When false, this adjustment will be applied to a single price. Otherwise, it will be applied @@ -200,9 +201,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -255,7 +254,7 @@ private constructor( private var appliesToItemIds: JsonField>? = null private var appliesToPriceIds: JsonField>? = null private var currency: JsonField = JsonMissing.of() - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField = JsonMissing.of() private var priceType: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -381,25 +380,25 @@ private constructor( fun currency(currency: JsonField) = apply { this.currency = currency } /** A list of filters that determine which prices this adjustment will apply to. */ - fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -639,7 +638,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -758,7 +757,7 @@ private constructor( return true } - return /* spotless:off */ other is AppliesToAll && value == other.value /* spotless:on */ + return other is AppliesToAll && value == other.value } override fun hashCode() = value.hashCode() @@ -766,6 +765,534 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + /** If set, only prices of the specified type will have the adjustment applied. */ class PriceType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -903,7 +1430,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -916,12 +1443,33 @@ private constructor( return true } - return /* spotless:off */ other is NewAmountDiscount && adjustmentType == other.adjustmentType && amountDiscount == other.amountDiscount && appliesToAll == other.appliesToAll && appliesToItemIds == other.appliesToItemIds && appliesToPriceIds == other.appliesToPriceIds && currency == other.currency && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && priceType == other.priceType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewAmountDiscount && + adjustmentType == other.adjustmentType && + amountDiscount == other.amountDiscount && + appliesToAll == other.appliesToAll && + appliesToItemIds == other.appliesToItemIds && + appliesToPriceIds == other.appliesToPriceIds && + currency == other.currency && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + priceType == other.priceType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustmentType, amountDiscount, appliesToAll, appliesToItemIds, appliesToPriceIds, currency, filters, isInvoiceLevel, priceType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + adjustmentType, + amountDiscount, + appliesToAll, + appliesToItemIds, + appliesToPriceIds, + currency, + filters, + isInvoiceLevel, + priceType, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAvalaraTaxConfiguration.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAvalaraTaxConfiguration.kt index 624a24029..0397c6ff6 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAvalaraTaxConfiguration.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewAvalaraTaxConfiguration.kt @@ -17,9 +17,11 @@ import java.util.Collections import java.util.Objects class NewAvalaraTaxConfiguration +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val taxExempt: JsonField, private val taxProvider: JsonField, + private val automaticTaxEnabled: JsonField, private val taxExemptionCode: JsonField, private val additionalProperties: MutableMap, ) { @@ -32,10 +34,13 @@ private constructor( @JsonProperty("tax_provider") @ExcludeMissing taxProvider: JsonField = JsonMissing.of(), + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + automaticTaxEnabled: JsonField = JsonMissing.of(), @JsonProperty("tax_exemption_code") @ExcludeMissing taxExemptionCode: JsonField = JsonMissing.of(), - ) : this(taxExempt, taxProvider, taxExemptionCode, mutableMapOf()) + ) : this(taxExempt, taxProvider, automaticTaxEnabled, taxExemptionCode, mutableMapOf()) /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -49,6 +54,15 @@ private constructor( */ fun taxProvider(): TaxProvider = taxProvider.getRequired("tax_provider") + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun automaticTaxEnabled(): Boolean? = automaticTaxEnabled.getNullable("automatic_tax_enabled") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -71,6 +85,16 @@ private constructor( @ExcludeMissing fun _taxProvider(): JsonField = taxProvider + /** + * Returns the raw JSON value of [automaticTaxEnabled]. + * + * Unlike [automaticTaxEnabled], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + fun _automaticTaxEnabled(): JsonField = automaticTaxEnabled + /** * Returns the raw JSON value of [taxExemptionCode]. * @@ -112,12 +136,14 @@ private constructor( private var taxExempt: JsonField? = null private var taxProvider: JsonField? = null + private var automaticTaxEnabled: JsonField = JsonMissing.of() private var taxExemptionCode: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(newAvalaraTaxConfiguration: NewAvalaraTaxConfiguration) = apply { taxExempt = newAvalaraTaxConfiguration.taxExempt taxProvider = newAvalaraTaxConfiguration.taxProvider + automaticTaxEnabled = newAvalaraTaxConfiguration.automaticTaxEnabled taxExemptionCode = newAvalaraTaxConfiguration.taxExemptionCode additionalProperties = newAvalaraTaxConfiguration.additionalProperties.toMutableMap() } @@ -146,6 +172,32 @@ private constructor( this.taxProvider = taxProvider } + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean?) = + automaticTaxEnabled(JsonField.ofNullable(automaticTaxEnabled)) + + /** + * Alias for [Builder.automaticTaxEnabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean) = + automaticTaxEnabled(automaticTaxEnabled as Boolean?) + + /** + * Sets [Builder.automaticTaxEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticTaxEnabled] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: JsonField) = apply { + this.automaticTaxEnabled = automaticTaxEnabled + } + fun taxExemptionCode(taxExemptionCode: String?) = taxExemptionCode(JsonField.ofNullable(taxExemptionCode)) @@ -196,6 +248,7 @@ private constructor( NewAvalaraTaxConfiguration( checkRequired("taxExempt", taxExempt), checkRequired("taxProvider", taxProvider), + automaticTaxEnabled, taxExemptionCode, additionalProperties.toMutableMap(), ) @@ -210,6 +263,7 @@ private constructor( taxExempt() taxProvider().validate() + automaticTaxEnabled() taxExemptionCode() validated = true } @@ -230,6 +284,7 @@ private constructor( internal fun validity(): Int = (if (taxExempt.asKnown() == null) 0 else 1) + (taxProvider.asKnown()?.validity() ?: 0) + + (if (automaticTaxEnabled.asKnown() == null) 0 else 1) + (if (taxExemptionCode.asKnown() == null) 0 else 1) class TaxProvider @JsonCreator private constructor(private val value: JsonField) : @@ -345,7 +400,7 @@ private constructor( return true } - return /* spotless:off */ other is TaxProvider && value == other.value /* spotless:on */ + return other is TaxProvider && value == other.value } override fun hashCode() = value.hashCode() @@ -358,15 +413,26 @@ private constructor( return true } - return /* spotless:off */ other is NewAvalaraTaxConfiguration && taxExempt == other.taxExempt && taxProvider == other.taxProvider && taxExemptionCode == other.taxExemptionCode && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewAvalaraTaxConfiguration && + taxExempt == other.taxExempt && + taxProvider == other.taxProvider && + automaticTaxEnabled == other.automaticTaxEnabled && + taxExemptionCode == other.taxExemptionCode && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(taxExempt, taxProvider, taxExemptionCode, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + taxExempt, + taxProvider, + automaticTaxEnabled, + taxExemptionCode, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "NewAvalaraTaxConfiguration{taxExempt=$taxExempt, taxProvider=$taxProvider, taxExemptionCode=$taxExemptionCode, additionalProperties=$additionalProperties}" + "NewAvalaraTaxConfiguration{taxExempt=$taxExempt, taxProvider=$taxProvider, automaticTaxEnabled=$automaticTaxEnabled, taxExemptionCode=$taxExemptionCode, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewBillingCycleConfiguration.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewBillingCycleConfiguration.kt index ba9d80876..0070f7c1d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewBillingCycleConfiguration.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewBillingCycleConfiguration.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class NewBillingCycleConfiguration +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val duration: JsonField, private val durationUnit: JsonField, @@ -315,7 +316,7 @@ private constructor( return true } - return /* spotless:off */ other is DurationUnit && value == other.value /* spotless:on */ + return other is DurationUnit && value == other.value } override fun hashCode() = value.hashCode() @@ -328,12 +329,13 @@ private constructor( return true } - return /* spotless:off */ other is NewBillingCycleConfiguration && duration == other.duration && durationUnit == other.durationUnit && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewBillingCycleConfiguration && + duration == other.duration && + durationUnit == other.durationUnit && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(duration, durationUnit, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewDimensionalPriceConfiguration.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewDimensionalPriceConfiguration.kt index 8217d528d..463245414 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewDimensionalPriceConfiguration.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewDimensionalPriceConfiguration.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class NewDimensionalPriceConfiguration +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val dimensionValues: JsonField>, private val dimensionalPriceGroupId: JsonField, @@ -277,12 +278,21 @@ private constructor( return true } - return /* spotless:off */ other is NewDimensionalPriceConfiguration && dimensionValues == other.dimensionValues && dimensionalPriceGroupId == other.dimensionalPriceGroupId && externalDimensionalPriceGroupId == other.externalDimensionalPriceGroupId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewDimensionalPriceConfiguration && + dimensionValues == other.dimensionValues && + dimensionalPriceGroupId == other.dimensionalPriceGroupId && + externalDimensionalPriceGroupId == other.externalDimensionalPriceGroupId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(dimensionValues, dimensionalPriceGroupId, externalDimensionalPriceGroupId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + dimensionValues, + dimensionalPriceGroupId, + externalDimensionalPriceGroupId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBpsPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBpsPrice.kt deleted file mode 100644 index 28a6d0f00..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBpsPrice.kt +++ /dev/null @@ -1,1464 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer -import com.withorb.api.core.Enum -import com.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow -import com.withorb.api.core.toImmutable -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class NewFloatingBpsPrice -private constructor( - private val bpsConfig: JsonField, - private val cadence: JsonField, - private val currency: JsonField, - private val itemId: JsonField, - private val modelType: JsonField, - private val name: JsonField, - private val billableMetricId: JsonField, - private val billedInAdvance: JsonField, - private val billingCycleConfiguration: JsonField, - private val conversionRate: JsonField, - private val conversionRateConfig: JsonField, - private val dimensionalPriceConfiguration: JsonField, - private val externalPriceId: JsonField, - private val fixedPriceQuantity: JsonField, - private val invoiceGroupingKey: JsonField, - private val invoicingCycleConfiguration: JsonField, - private val metadata: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("bps_config") - @ExcludeMissing - bpsConfig: JsonField = JsonMissing.of(), - @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), - @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), - @JsonProperty("item_id") @ExcludeMissing itemId: JsonField = JsonMissing.of(), - @JsonProperty("model_type") - @ExcludeMissing - modelType: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("billable_metric_id") - @ExcludeMissing - billableMetricId: JsonField = JsonMissing.of(), - @JsonProperty("billed_in_advance") - @ExcludeMissing - billedInAdvance: JsonField = JsonMissing.of(), - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - billingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate") - @ExcludeMissing - conversionRate: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate_config") - @ExcludeMissing - conversionRateConfig: JsonField = JsonMissing.of(), - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - dimensionalPriceConfiguration: JsonField = - JsonMissing.of(), - @JsonProperty("external_price_id") - @ExcludeMissing - externalPriceId: JsonField = JsonMissing.of(), - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - invoiceGroupingKey: JsonField = JsonMissing.of(), - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - invoicingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), - ) : this( - bpsConfig, - cadence, - currency, - itemId, - modelType, - name, - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - mutableMapOf(), - ) - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun bpsConfig(): BpsConfig = bpsConfig.getRequired("bps_config") - - /** - * The cadence to bill for this price on. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun cadence(): Cadence = cadence.getRequired("cadence") - - /** - * An ISO 4217 currency string for which this price is billed in. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun currency(): String = currency.getRequired("currency") - - /** - * The id of the item the price will be associated with. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun itemId(): String = itemId.getRequired("item_id") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun modelType(): ModelType = modelType.getRequired("model_type") - - /** - * The name of the price. - * - * @throws OrbInvalidDataException if 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") - - /** - * The id of the billable metric for the price. Only needed if the price is usage-based. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is true, - * and in-arrears if this is false. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - - /** - * For custom cadence: specifies the duration of the billing period in days or months. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billingCycleConfiguration(): NewBillingCycleConfiguration? = - billingCycleConfiguration.getNullable("billing_cycle_configuration") - - /** - * The per unit conversion rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - - /** - * The configuration for the rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRateConfig(): ConversionRateConfig? = - conversionRateConfig.getNullable("conversion_rate_config") - - /** - * For dimensional price: specifies a price group and dimension values - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = - dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - - /** - * An alias for the price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - - /** - * If the Price represents a fixed cost, this represents the quantity of units applied. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") - - /** - * The property used to group this price on an invoice - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoiceGroupingKey(): String? = invoiceGroupingKey.getNullable("invoice_grouping_key") - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = - invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun metadata(): Metadata? = metadata.getNullable("metadata") - - /** - * Returns the raw JSON value of [bpsConfig]. - * - * Unlike [bpsConfig], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("bps_config") @ExcludeMissing fun _bpsConfig(): JsonField = bpsConfig - - /** - * Returns the raw JSON value of [cadence]. - * - * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence - - /** - * Returns the raw JSON value of [currency]. - * - * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency - - /** - * Returns the raw JSON value of [itemId]. - * - * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - - /** - * Returns the raw JSON value of [modelType]. - * - * Unlike [modelType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonField = modelType - - /** - * 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 [billableMetricId]. - * - * Unlike [billableMetricId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("billable_metric_id") - @ExcludeMissing - fun _billableMetricId(): JsonField = billableMetricId - - /** - * Returns the raw JSON value of [billedInAdvance]. - * - * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("billed_in_advance") - @ExcludeMissing - fun _billedInAdvance(): JsonField = billedInAdvance - - /** - * Returns the raw JSON value of [billingCycleConfiguration]. - * - * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - fun _billingCycleConfiguration(): JsonField = - billingCycleConfiguration - - /** - * Returns the raw JSON value of [conversionRate]. - * - * Unlike [conversionRate], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("conversion_rate") - @ExcludeMissing - fun _conversionRate(): JsonField = conversionRate - - /** - * Returns the raw JSON value of [conversionRateConfig]. - * - * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("conversion_rate_config") - @ExcludeMissing - fun _conversionRateConfig(): JsonField = conversionRateConfig - - /** - * Returns the raw JSON value of [dimensionalPriceConfiguration]. - * - * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - fun _dimensionalPriceConfiguration(): JsonField = - dimensionalPriceConfiguration - - /** - * Returns the raw JSON value of [externalPriceId]. - * - * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("external_price_id") - @ExcludeMissing - fun _externalPriceId(): JsonField = externalPriceId - - /** - * Returns the raw JSON value of [fixedPriceQuantity]. - * - * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - - /** - * Returns the raw JSON value of [invoiceGroupingKey]. - * - * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - - /** - * Returns the raw JSON value of [invoicingCycleConfiguration]. - * - * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - fun _invoicingCycleConfiguration(): JsonField = - invoicingCycleConfiguration - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - - @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 [NewFloatingBpsPrice]. - * - * The following fields are required: - * ```kotlin - * .bpsConfig() - * .cadence() - * .currency() - * .itemId() - * .modelType() - * .name() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [NewFloatingBpsPrice]. */ - class Builder internal constructor() { - - private var bpsConfig: JsonField? = null - private var cadence: JsonField? = null - private var currency: JsonField? = null - private var itemId: JsonField? = null - private var modelType: JsonField? = null - private var name: JsonField? = null - private var billableMetricId: JsonField = JsonMissing.of() - private var billedInAdvance: JsonField = JsonMissing.of() - private var billingCycleConfiguration: JsonField = - JsonMissing.of() - private var conversionRate: JsonField = JsonMissing.of() - private var conversionRateConfig: JsonField = JsonMissing.of() - private var dimensionalPriceConfiguration: JsonField = - JsonMissing.of() - private var externalPriceId: JsonField = JsonMissing.of() - private var fixedPriceQuantity: JsonField = JsonMissing.of() - private var invoiceGroupingKey: JsonField = JsonMissing.of() - private var invoicingCycleConfiguration: JsonField = - JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(newFloatingBpsPrice: NewFloatingBpsPrice) = apply { - bpsConfig = newFloatingBpsPrice.bpsConfig - cadence = newFloatingBpsPrice.cadence - currency = newFloatingBpsPrice.currency - itemId = newFloatingBpsPrice.itemId - modelType = newFloatingBpsPrice.modelType - name = newFloatingBpsPrice.name - billableMetricId = newFloatingBpsPrice.billableMetricId - billedInAdvance = newFloatingBpsPrice.billedInAdvance - billingCycleConfiguration = newFloatingBpsPrice.billingCycleConfiguration - conversionRate = newFloatingBpsPrice.conversionRate - conversionRateConfig = newFloatingBpsPrice.conversionRateConfig - dimensionalPriceConfiguration = newFloatingBpsPrice.dimensionalPriceConfiguration - externalPriceId = newFloatingBpsPrice.externalPriceId - fixedPriceQuantity = newFloatingBpsPrice.fixedPriceQuantity - invoiceGroupingKey = newFloatingBpsPrice.invoiceGroupingKey - invoicingCycleConfiguration = newFloatingBpsPrice.invoicingCycleConfiguration - metadata = newFloatingBpsPrice.metadata - additionalProperties = newFloatingBpsPrice.additionalProperties.toMutableMap() - } - - fun bpsConfig(bpsConfig: BpsConfig) = bpsConfig(JsonField.of(bpsConfig)) - - /** - * Sets [Builder.bpsConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.bpsConfig] with a well-typed [BpsConfig] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun bpsConfig(bpsConfig: JsonField) = apply { this.bpsConfig = bpsConfig } - - /** The cadence to bill for this price on. */ - fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) - - /** - * Sets [Builder.cadence] to an arbitrary JSON value. - * - * You should usually call [Builder.cadence] with a well-typed [Cadence] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun cadence(cadence: JsonField) = apply { this.cadence = cadence } - - /** An ISO 4217 currency string for which this price is billed in. */ - fun currency(currency: String) = currency(JsonField.of(currency)) - - /** - * Sets [Builder.currency] to an arbitrary JSON value. - * - * You should usually call [Builder.currency] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun currency(currency: JsonField) = apply { this.currency = currency } - - /** The id of the item the price will be associated with. */ - fun itemId(itemId: String) = itemId(JsonField.of(itemId)) - - /** - * Sets [Builder.itemId] to an arbitrary JSON value. - * - * You should usually call [Builder.itemId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun itemId(itemId: JsonField) = apply { this.itemId = itemId } - - fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) - - /** - * Sets [Builder.modelType] to an arbitrary JSON value. - * - * You should usually call [Builder.modelType] with a well-typed [ModelType] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun modelType(modelType: JsonField) = apply { this.modelType = modelType } - - /** The name of the price. */ - 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 id of the billable metric for the price. Only needed if the price is usage-based. */ - fun billableMetricId(billableMetricId: String?) = - billableMetricId(JsonField.ofNullable(billableMetricId)) - - /** - * Sets [Builder.billableMetricId] to an arbitrary JSON value. - * - * You should usually call [Builder.billableMetricId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billableMetricId(billableMetricId: JsonField) = apply { - this.billableMetricId = billableMetricId - } - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is - * true, and in-arrears if this is false. - */ - fun billedInAdvance(billedInAdvance: Boolean?) = - billedInAdvance(JsonField.ofNullable(billedInAdvance)) - - /** - * Alias for [Builder.billedInAdvance]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun billedInAdvance(billedInAdvance: Boolean) = billedInAdvance(billedInAdvance as Boolean?) - - /** - * Sets [Builder.billedInAdvance] to an arbitrary JSON value. - * - * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billedInAdvance(billedInAdvance: JsonField) = apply { - this.billedInAdvance = billedInAdvance - } - - /** For custom cadence: specifies the duration of the billing period in days or months. */ - fun billingCycleConfiguration(billingCycleConfiguration: NewBillingCycleConfiguration?) = - billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) - - /** - * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.billingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun billingCycleConfiguration( - billingCycleConfiguration: JsonField - ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } - - /** The per unit conversion rate of the price currency to the invoicing currency. */ - fun conversionRate(conversionRate: Double?) = - conversionRate(JsonField.ofNullable(conversionRate)) - - /** - * Alias for [Builder.conversionRate]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun conversionRate(conversionRate: Double) = conversionRate(conversionRate as Double?) - - /** - * Sets [Builder.conversionRate] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRate] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun conversionRate(conversionRate: JsonField) = apply { - this.conversionRate = conversionRate - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = - conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) - - /** - * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRateConfig] with a well-typed - * [ConversionRateConfig] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun conversionRateConfig(conversionRateConfig: JsonField) = apply { - this.conversionRateConfig = conversionRateConfig - } - - /** Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofUnit(unit)`. */ - fun conversionRateConfig(unit: UnitConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofUnit(unit)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * UnitConversionRateConfig.builder() - * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - * .unitConfig(unitConfig) - * .build() - * ``` - */ - fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = - conversionRateConfig( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig(unitConfig) - .build() - ) - - /** - * Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofTiered(tiered)`. - */ - fun conversionRateConfig(tiered: TieredConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * TieredConversionRateConfig.builder() - * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - * .tieredConfig(tieredConfig) - * .build() - * ``` - */ - fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = - conversionRateConfig( - TieredConversionRateConfig.builder() - .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - .tieredConfig(tieredConfig) - .build() - ) - - /** For dimensional price: specifies a price group and dimension values */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? - ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) - - /** - * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed - * [NewDimensionalPriceConfiguration] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: JsonField - ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } - - /** An alias for the price. */ - fun externalPriceId(externalPriceId: String?) = - externalPriceId(JsonField.ofNullable(externalPriceId)) - - /** - * Sets [Builder.externalPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.externalPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun externalPriceId(externalPriceId: JsonField) = apply { - this.externalPriceId = externalPriceId - } - - /** If the Price represents a fixed cost, this represents the quantity of units applied. */ - fun fixedPriceQuantity(fixedPriceQuantity: Double?) = - fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) - - /** - * Alias for [Builder.fixedPriceQuantity]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun fixedPriceQuantity(fixedPriceQuantity: Double) = - fixedPriceQuantity(fixedPriceQuantity as Double?) - - /** - * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. - * - * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { - this.fixedPriceQuantity = fixedPriceQuantity - } - - /** The property used to group this price on an invoice */ - fun invoiceGroupingKey(invoiceGroupingKey: String?) = - invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) - - /** - * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceGroupingKey] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { - this.invoiceGroupingKey = invoiceGroupingKey - } - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: NewBillingCycleConfiguration? - ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) - - /** - * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: JsonField - ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by - * setting the value to `null`, and the entire metadata mapping can be cleared by setting - * `metadata` to `null`. - */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [NewFloatingBpsPrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .bpsConfig() - * .cadence() - * .currency() - * .itemId() - * .modelType() - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): NewFloatingBpsPrice = - NewFloatingBpsPrice( - checkRequired("bpsConfig", bpsConfig), - checkRequired("cadence", cadence), - checkRequired("currency", currency), - checkRequired("itemId", itemId), - checkRequired("modelType", modelType), - checkRequired("name", name), - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): NewFloatingBpsPrice = apply { - if (validated) { - return@apply - } - - bpsConfig().validate() - cadence().validate() - currency() - itemId() - modelType().validate() - name() - billableMetricId() - billedInAdvance() - billingCycleConfiguration()?.validate() - conversionRate() - conversionRateConfig()?.validate() - dimensionalPriceConfiguration()?.validate() - externalPriceId() - fixedPriceQuantity() - invoiceGroupingKey() - invoicingCycleConfiguration()?.validate() - metadata()?.validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (bpsConfig.asKnown()?.validity() ?: 0) + - (cadence.asKnown()?.validity() ?: 0) + - (if (currency.asKnown() == null) 0 else 1) + - (if (itemId.asKnown() == null) 0 else 1) + - (modelType.asKnown()?.validity() ?: 0) + - (if (name.asKnown() == null) 0 else 1) + - (if (billableMetricId.asKnown() == null) 0 else 1) + - (if (billedInAdvance.asKnown() == null) 0 else 1) + - (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (if (conversionRate.asKnown() == null) 0 else 1) + - (conversionRateConfig.asKnown()?.validity() ?: 0) + - (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + - (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + - (metadata.asKnown()?.validity() ?: 0) - - /** The cadence to bill for this price on. */ - class Cadence @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 { - - val ANNUAL = of("annual") - - val SEMI_ANNUAL = of("semi_annual") - - val MONTHLY = of("monthly") - - val QUARTERLY = of("quarterly") - - val ONE_TIME = of("one_time") - - val CUSTOM = of("custom") - - fun of(value: String) = Cadence(JsonField.of(value)) - } - - /** An enum containing [Cadence]'s known values. */ - enum class Known { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - } - - /** - * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Cadence] 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 { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - /** An enum member indicating that [Cadence] 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) { - ANNUAL -> Value.ANNUAL - SEMI_ANNUAL -> Value.SEMI_ANNUAL - MONTHLY -> Value.MONTHLY - QUARTERLY -> Value.QUARTERLY - ONE_TIME -> Value.ONE_TIME - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - ANNUAL -> Known.ANNUAL - SEMI_ANNUAL -> Known.SEMI_ANNUAL - MONTHLY -> Known.MONTHLY - QUARTERLY -> Known.QUARTERLY - ONE_TIME -> Known.ONE_TIME - CUSTOM -> Known.CUSTOM - else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): Cadence = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class ModelType @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 { - - val BPS = of("bps") - - fun of(value: String) = ModelType(JsonField.of(value)) - } - - /** An enum containing [ModelType]'s known values. */ - enum class Known { - BPS - } - - /** - * An enum containing [ModelType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [ModelType] 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 { - BPS, - /** - * An enum member indicating that [ModelType] 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) { - BPS -> Value.BPS - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - BPS -> Known.BPS - else -> throw OrbInvalidDataException("Unknown ModelType: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): ModelType = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - */ - class Metadata - @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 [Metadata]. */ - fun builder() = Builder() - } - - /** A builder for [Metadata]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.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 [Metadata]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is NewFloatingBpsPrice && bpsConfig == other.bpsConfig && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bpsConfig, cadence, currency, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "NewFloatingBpsPrice{bpsConfig=$bpsConfig, cadence=$cadence, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBulkPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBulkPrice.kt index f74a94ee1..64a979ece 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBulkPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBulkPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingBulkPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val bulkConfig: JsonField, private val cadence: JsonField, @@ -115,6 +106,8 @@ private constructor( ) /** + * Configuration for bulk pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -145,6 +138,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -481,6 +476,7 @@ private constructor( additionalProperties = newFloatingBulkPrice.additionalProperties.toMutableMap() } + /** Configuration for bulk pricing */ fun bulkConfig(bulkConfig: BulkConfig) = bulkConfig(JsonField.of(bulkConfig)) /** @@ -525,6 +521,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1046,7 +1043,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1054,6 +1051,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1166,7 +1164,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1174,175 +1172,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1435,12 +1264,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1452,12 +1279,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingBulkPrice && bulkConfig == other.bulkConfig && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingBulkPrice && + bulkConfig == other.bulkConfig && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bulkConfig, cadence, currency, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + bulkConfig, + cadence, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBulkWithProrationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBulkWithProrationPrice.kt index 582cd8575..79143b0ba 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBulkWithProrationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBulkWithProrationPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingBulkWithProrationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val bulkWithProrationConfig: JsonField, private val cadence: JsonField, @@ -115,6 +107,8 @@ private constructor( ) /** + * Configuration for bulk_with_proration pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -146,6 +140,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -489,6 +485,7 @@ private constructor( newFloatingBulkWithProrationPrice.additionalProperties.toMutableMap() } + /** Configuration for bulk_with_proration pricing */ fun bulkWithProrationConfig(bulkWithProrationConfig: BulkWithProrationConfig) = bulkWithProrationConfig(JsonField.of(bulkWithProrationConfig)) @@ -537,6 +534,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -917,16 +915,43 @@ private constructor( (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (metadata.asKnown()?.validity() ?: 0) + /** Configuration for bulk_with_proration pricing */ class BulkWithProrationConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -934,6 +959,11 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [BulkWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` */ fun builder() = Builder() } @@ -941,12 +971,40 @@ private constructor( /** A builder for [BulkWithProrationConfig]. */ class Builder internal constructor() { + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(bulkWithProrationConfig: BulkWithProrationConfig) = apply { + tiers = bulkWithProrationConfig.tiers.map { it.toMutableList() } additionalProperties = bulkWithProrationConfig.additionalProperties.toMutableMap() } + /** Bulk tiers for rating based on total usage volume */ + 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) @@ -970,9 +1028,19 @@ private constructor( * Returns an immutable instance of [BulkWithProrationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): BulkWithProrationConfig = - BulkWithProrationConfig(additionalProperties.toImmutable()) + BulkWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -982,6 +1050,7 @@ private constructor( return@apply } + tiers().forEach { it.validate() } validated = true } @@ -999,25 +1068,240 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + internal fun validity(): Int = (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single bulk pricing tier with proration */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Cost per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun tierLowerBound(): String? = tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Cost per unit */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is BulkWithProrationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BulkWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "BulkWithProrationConfig{additionalProperties=$additionalProperties}" + "BulkWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" } /** The cadence to bill for this price on. */ @@ -1161,7 +1445,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1169,6 +1453,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1281,7 +1566,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1289,175 +1574,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1550,12 +1666,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1567,12 +1681,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingBulkWithProrationPrice && bulkWithProrationConfig == other.bulkWithProrationConfig && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingBulkWithProrationPrice && + bulkWithProrationConfig == other.bulkWithProrationConfig && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bulkWithProrationConfig, cadence, currency, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + bulkWithProrationConfig, + cadence, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingCumulativeGroupedBulkPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingCumulativeGroupedBulkPrice.kt index 0b53ff59f..56c456f24 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingCumulativeGroupedBulkPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingCumulativeGroupedBulkPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingCumulativeGroupedBulkPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val cumulativeGroupedBulkConfig: JsonField, @@ -123,6 +115,8 @@ private constructor( fun cadence(): Cadence = cadence.getRequired("cadence") /** + * Configuration for cumulative_grouped_bulk pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -146,6 +140,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -503,6 +499,7 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + /** Configuration for cumulative_grouped_bulk pricing */ fun cumulativeGroupedBulkConfig(cumulativeGroupedBulkConfig: CumulativeGroupedBulkConfig) = cumulativeGroupedBulkConfig(JsonField.of(cumulativeGroupedBulkConfig)) @@ -539,6 +536,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1060,7 +1058,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1068,16 +1066,66 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for cumulative_grouped_bulk pricing */ class CumulativeGroupedBulkConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val dimensionValues: JsonField>, + private val group: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("dimension_values") + @ExcludeMissing + dimensionValues: JsonField> = JsonMissing.of(), + @JsonProperty("group") @ExcludeMissing group: JsonField = JsonMissing.of(), + ) : this(dimensionValues, group, mutableMapOf()) + + /** + * Each tier lower bound must have the same group of values. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dimensionValues(): List = + dimensionValues.getRequired("dimension_values") + + /** + * Grouping key name + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun group(): String = group.getRequired("group") + + /** + * Returns the raw JSON value of [dimensionValues]. + * + * Unlike [dimensionValues], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dimension_values") + @ExcludeMissing + fun _dimensionValues(): JsonField> = dimensionValues + + /** + * Returns the raw JSON value of [group]. + * + * Unlike [group], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("group") @ExcludeMissing fun _group(): JsonField = group + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1086,6 +1134,12 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [CumulativeGroupedBulkConfig]. + * + * The following fields are required: + * ```kotlin + * .dimensionValues() + * .group() + * ``` */ fun builder() = Builder() } @@ -1093,13 +1147,57 @@ private constructor( /** A builder for [CumulativeGroupedBulkConfig]. */ class Builder internal constructor() { + private var dimensionValues: JsonField>? = null + private var group: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(cumulativeGroupedBulkConfig: CumulativeGroupedBulkConfig) = apply { + dimensionValues = + cumulativeGroupedBulkConfig.dimensionValues.map { it.toMutableList() } + group = cumulativeGroupedBulkConfig.group additionalProperties = cumulativeGroupedBulkConfig.additionalProperties.toMutableMap() } + /** Each tier lower bound must have the same group of values. */ + fun dimensionValues(dimensionValues: List) = + dimensionValues(JsonField.of(dimensionValues)) + + /** + * Sets [Builder.dimensionValues] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionValues] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun dimensionValues(dimensionValues: JsonField>) = apply { + this.dimensionValues = dimensionValues.map { it.toMutableList() } + } + + /** + * Adds a single [DimensionValue] to [dimensionValues]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDimensionValue(dimensionValue: DimensionValue) = apply { + dimensionValues = + (dimensionValues ?: JsonField.of(mutableListOf())).also { + checkKnown("dimensionValues", it).add(dimensionValue) + } + } + + /** Grouping key name */ + fun group(group: String) = group(JsonField.of(group)) + + /** + * Sets [Builder.group] to an arbitrary JSON value. + * + * You should usually call [Builder.group] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun group(group: JsonField) = apply { this.group = group } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1123,9 +1221,21 @@ private constructor( * Returns an immutable instance of [CumulativeGroupedBulkConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .dimensionValues() + * .group() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): CumulativeGroupedBulkConfig = - CumulativeGroupedBulkConfig(additionalProperties.toImmutable()) + CumulativeGroupedBulkConfig( + checkRequired("dimensionValues", dimensionValues).map { it.toImmutable() }, + checkRequired("group", group), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1135,6 +1245,8 @@ private constructor( return@apply } + dimensionValues().forEach { it.validate() } + group() validated = true } @@ -1153,26 +1265,295 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (dimensionValues.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (group.asKnown() == null) 0 else 1) + + /** Configuration for a dimension value entry */ + class DimensionValue + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(groupingKey, tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Grouping key value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Unit amount for this combination + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 [DimensionValue]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [DimensionValue]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(dimensionValue: DimensionValue) = apply { + groupingKey = dimensionValue.groupingKey + tierLowerBound = dimensionValue.tierLowerBound + unitAmount = dimensionValue.unitAmount + additionalProperties = dimensionValue.additionalProperties.toMutableMap() + } + + /** Grouping key value */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Unit amount for this combination */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [DimensionValue]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DimensionValue = + DimensionValue( + checkRequired("groupingKey", groupingKey), + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): DimensionValue = apply { + if (validated) { + return@apply + } + + groupingKey() + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DimensionValue && + groupingKey == other.groupingKey && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(groupingKey, tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DimensionValue{groupingKey=$groupingKey, tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is CumulativeGroupedBulkConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CumulativeGroupedBulkConfig && + dimensionValues == other.dimensionValues && + group == other.group && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(dimensionValues, group, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "CumulativeGroupedBulkConfig{additionalProperties=$additionalProperties}" + "CumulativeGroupedBulkConfig{dimensionValues=$dimensionValues, group=$group, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1285,7 +1666,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1293,175 +1674,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1554,12 +1766,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1571,12 +1781,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingCumulativeGroupedBulkPrice && cadence == other.cadence && cumulativeGroupedBulkConfig == other.cumulativeGroupedBulkConfig && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingCumulativeGroupedBulkPrice && + cadence == other.cadence && + cumulativeGroupedBulkConfig == other.cumulativeGroupedBulkConfig && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, cumulativeGroupedBulkConfig, currency, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedBulkConfig, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedAllocationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedAllocationPrice.kt index 7b811d709..8462624bb 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedAllocationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedAllocationPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingGroupedAllocationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -131,6 +122,8 @@ private constructor( fun currency(): String = currency.getRequired("currency") /** + * Configuration for grouped_allocation pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -146,6 +139,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -511,6 +506,7 @@ private constructor( */ fun currency(currency: JsonField) = apply { this.currency = currency } + /** Configuration for grouped_allocation pricing */ fun groupedAllocationConfig(groupedAllocationConfig: GroupedAllocationConfig) = groupedAllocationConfig(JsonField.of(groupedAllocationConfig)) @@ -537,6 +533,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1058,7 +1055,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1066,16 +1063,90 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_allocation pricing */ class GroupedAllocationConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val allocation: JsonField, + private val groupingKey: JsonField, + private val overageUnitRate: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("allocation") + @ExcludeMissing + allocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("overage_unit_rate") + @ExcludeMissing + overageUnitRate: JsonField = JsonMissing.of(), + ) : this(allocation, groupingKey, overageUnitRate, mutableMapOf()) + + /** + * Usage allocation per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun allocation(): String = allocation.getRequired("allocation") + + /** + * How to determine the groups that should each be allocated some quantity + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Unit rate for post-allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun overageUnitRate(): String = overageUnitRate.getRequired("overage_unit_rate") + + /** + * Returns the raw JSON value of [allocation]. + * + * Unlike [allocation], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allocation") + @ExcludeMissing + fun _allocation(): JsonField = allocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [overageUnitRate]. + * + * Unlike [overageUnitRate], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("overage_unit_rate") + @ExcludeMissing + fun _overageUnitRate(): JsonField = overageUnitRate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1083,6 +1154,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [GroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .groupingKey() + * .overageUnitRate() + * ``` */ fun builder() = Builder() } @@ -1090,12 +1168,59 @@ private constructor( /** A builder for [GroupedAllocationConfig]. */ class Builder internal constructor() { + private var allocation: JsonField? = null + private var groupingKey: JsonField? = null + private var overageUnitRate: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedAllocationConfig: GroupedAllocationConfig) = apply { + allocation = groupedAllocationConfig.allocation + groupingKey = groupedAllocationConfig.groupingKey + overageUnitRate = groupedAllocationConfig.overageUnitRate additionalProperties = groupedAllocationConfig.additionalProperties.toMutableMap() } + /** Usage allocation per group */ + fun allocation(allocation: String) = allocation(JsonField.of(allocation)) + + /** + * Sets [Builder.allocation] to an arbitrary JSON value. + * + * You should usually call [Builder.allocation] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun allocation(allocation: JsonField) = apply { this.allocation = allocation } + + /** How to determine the groups that should each be allocated some quantity */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Unit rate for post-allocation */ + fun overageUnitRate(overageUnitRate: String) = + overageUnitRate(JsonField.of(overageUnitRate)) + + /** + * Sets [Builder.overageUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.overageUnitRate] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun overageUnitRate(overageUnitRate: JsonField) = apply { + this.overageUnitRate = overageUnitRate + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1119,9 +1244,23 @@ private constructor( * Returns an immutable instance of [GroupedAllocationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .groupingKey() + * .overageUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedAllocationConfig = - GroupedAllocationConfig(additionalProperties.toImmutable()) + GroupedAllocationConfig( + checkRequired("allocation", allocation), + checkRequired("groupingKey", groupingKey), + checkRequired("overageUnitRate", overageUnitRate), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1131,6 +1270,9 @@ private constructor( return@apply } + allocation() + groupingKey() + overageUnitRate() validated = true } @@ -1149,26 +1291,33 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (allocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (overageUnitRate.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedAllocationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedAllocationConfig && + allocation == other.allocation && + groupingKey == other.groupingKey && + overageUnitRate == other.overageUnitRate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(allocation, groupingKey, overageUnitRate, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedAllocationConfig{additionalProperties=$additionalProperties}" + "GroupedAllocationConfig{allocation=$allocation, groupingKey=$groupingKey, overageUnitRate=$overageUnitRate, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1281,7 +1430,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1289,175 +1438,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1550,12 +1530,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1567,12 +1545,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingGroupedAllocationPrice && cadence == other.cadence && currency == other.currency && groupedAllocationConfig == other.groupedAllocationConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingGroupedAllocationPrice && + cadence == other.cadence && + currency == other.currency && + groupedAllocationConfig == other.groupedAllocationConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, groupedAllocationConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + groupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPackagePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPackagePrice.kt index ef90ef15b..e7ce8f3aa 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPackagePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPackagePrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingGroupedTieredPackagePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -131,6 +123,8 @@ private constructor( fun currency(): String = currency.getRequired("currency") /** + * Configuration for grouped_tiered_package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -146,6 +140,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -514,6 +510,7 @@ private constructor( */ fun currency(currency: JsonField) = apply { this.currency = currency } + /** Configuration for grouped_tiered_package pricing */ fun groupedTieredPackageConfig(groupedTieredPackageConfig: GroupedTieredPackageConfig) = groupedTieredPackageConfig(JsonField.of(groupedTieredPackageConfig)) @@ -539,6 +536,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1060,7 +1058,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1068,16 +1066,86 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_tiered_package pricing */ class GroupedTieredPackageConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(groupingKey, packageSize, tiers, mutableMapOf()) + + /** + * The event property used to group before tiering + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1086,6 +1154,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [GroupedTieredPackageConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1093,13 +1168,76 @@ private constructor( /** A builder for [GroupedTieredPackageConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedTieredPackageConfig: GroupedTieredPackageConfig) = apply { + groupingKey = groupedTieredPackageConfig.groupingKey + packageSize = groupedTieredPackageConfig.packageSize + tiers = groupedTieredPackageConfig.tiers.map { it.toMutableList() } additionalProperties = groupedTieredPackageConfig.additionalProperties.toMutableMap() } + /** The event property used to group before tiering */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + */ + 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) @@ -1123,9 +1261,23 @@ private constructor( * Returns an immutable instance of [GroupedTieredPackageConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedTieredPackageConfig = - GroupedTieredPackageConfig(additionalProperties.toImmutable()) + GroupedTieredPackageConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1135,6 +1287,9 @@ private constructor( return@apply } + groupingKey() + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -1153,26 +1308,247 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val perUnit: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("per_unit") + @ExcludeMissing + perUnit: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(perUnit, tierLowerBound, mutableMapOf()) + + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnit(): String = perUnit.getRequired("per_unit") + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Returns the raw JSON value of [perUnit]. + * + * Unlike [perUnit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("per_unit") @ExcludeMissing fun _perUnit(): JsonField = perUnit + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var perUnit: JsonField? = null + private var tierLowerBound: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + perUnit = tier.perUnit + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Price per package */ + fun perUnit(perUnit: String) = perUnit(JsonField.of(perUnit)) + + /** + * Sets [Builder.perUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnit] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun perUnit(perUnit: JsonField) = apply { this.perUnit = perUnit } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("perUnit", perUnit), + checkRequired("tierLowerBound", tierLowerBound), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + perUnit() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (perUnit.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + perUnit == other.perUnit && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(perUnit, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{perUnit=$perUnit, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedTieredPackageConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedTieredPackageConfig && + groupingKey == other.groupingKey && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(groupingKey, packageSize, tiers, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedTieredPackageConfig{additionalProperties=$additionalProperties}" + "GroupedTieredPackageConfig{groupingKey=$groupingKey, packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1285,7 +1661,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1293,175 +1669,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1554,12 +1761,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1571,12 +1776,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingGroupedTieredPackagePrice && cadence == other.cadence && currency == other.currency && groupedTieredPackageConfig == other.groupedTieredPackageConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingGroupedTieredPackagePrice && + cadence == other.cadence && + currency == other.currency && + groupedTieredPackageConfig == other.groupedTieredPackageConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, groupedTieredPackageConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + groupedTieredPackageConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPrice.kt index e5124542b..7cae4bdfe 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingGroupedTieredPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -131,6 +123,8 @@ private constructor( fun currency(): String = currency.getRequired("currency") /** + * Configuration for grouped_tiered pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -146,6 +140,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -507,6 +503,7 @@ private constructor( */ fun currency(currency: JsonField) = apply { this.currency = currency } + /** Configuration for grouped_tiered pricing */ fun groupedTieredConfig(groupedTieredConfig: GroupedTieredConfig) = groupedTieredConfig(JsonField.of(groupedTieredConfig)) @@ -532,6 +529,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1053,7 +1051,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1061,34 +1059,136 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_tiered pricing */ class GroupedTieredConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(groupingKey, tiers, mutableMapOf()) + + /** + * The billable metric property used to group before tiering + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Apply tiered pricing to each segment generated after grouping with the provided key + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) companion object { - /** Returns a mutable builder for constructing an instance of [GroupedTieredConfig]. */ + /** + * Returns a mutable builder for constructing an instance of [GroupedTieredConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tiers() + * ``` + */ fun builder() = Builder() } /** A builder for [GroupedTieredConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedTieredConfig: GroupedTieredConfig) = apply { + groupingKey = groupedTieredConfig.groupingKey + tiers = groupedTieredConfig.tiers.map { it.toMutableList() } additionalProperties = groupedTieredConfig.additionalProperties.toMutableMap() } + /** The billable metric property used to group before tiering */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** + * Apply tiered pricing to each segment generated after grouping with the provided key + */ + 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) @@ -1112,9 +1212,21 @@ private constructor( * Returns an immutable instance of [GroupedTieredConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedTieredConfig = - GroupedTieredConfig(additionalProperties.toImmutable()) + GroupedTieredConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1124,6 +1236,8 @@ private constructor( return@apply } + groupingKey() + tiers().forEach { it.validate() } validated = true } @@ -1142,25 +1256,248 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedTieredConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedTieredConfig && + groupingKey == other.groupingKey && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { Objects.hash(groupingKey, tiers, additionalProperties) } override fun hashCode(): Int = hashCode - override fun toString() = "GroupedTieredConfig{additionalProperties=$additionalProperties}" + override fun toString() = + "GroupedTieredConfig{groupingKey=$groupingKey, tiers=$tiers, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1273,7 +1610,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1281,175 +1618,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1542,12 +1710,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1559,12 +1725,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingGroupedTieredPrice && cadence == other.cadence && currency == other.currency && groupedTieredConfig == other.groupedTieredConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingGroupedTieredPrice && + cadence == other.cadence && + currency == other.currency && + groupedTieredConfig == other.groupedTieredConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, groupedTieredConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + groupedTieredConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedWithMeteredMinimumPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedWithMeteredMinimumPrice.kt index b267b1928..e398dbe78 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedWithMeteredMinimumPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedWithMeteredMinimumPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingGroupedWithMeteredMinimumPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -132,6 +124,8 @@ private constructor( fun currency(): String = currency.getRequired("currency") /** + * Configuration for grouped_with_metered_minimum pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -147,6 +141,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -516,6 +512,7 @@ private constructor( */ fun currency(currency: JsonField) = apply { this.currency = currency } + /** Configuration for grouped_with_metered_minimum pricing */ fun groupedWithMeteredMinimumConfig( groupedWithMeteredMinimumConfig: GroupedWithMeteredMinimumConfig ) = groupedWithMeteredMinimumConfig(JsonField.of(groupedWithMeteredMinimumConfig)) @@ -542,6 +539,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1063,7 +1061,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1071,16 +1069,163 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_with_metered_minimum pricing */ class GroupedWithMeteredMinimumConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val minimumUnitAmount: JsonField, + private val pricingKey: JsonField, + private val scalingFactors: JsonField>, + private val scalingKey: JsonField, + private val unitAmounts: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("minimum_unit_amount") + @ExcludeMissing + minimumUnitAmount: JsonField = JsonMissing.of(), + @JsonProperty("pricing_key") + @ExcludeMissing + pricingKey: JsonField = JsonMissing.of(), + @JsonProperty("scaling_factors") + @ExcludeMissing + scalingFactors: JsonField> = JsonMissing.of(), + @JsonProperty("scaling_key") + @ExcludeMissing + scalingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amounts") + @ExcludeMissing + unitAmounts: JsonField> = JsonMissing.of(), + ) : this( + groupingKey, + minimumUnitAmount, + pricingKey, + scalingFactors, + scalingKey, + unitAmounts, + mutableMapOf(), + ) + + /** + * Used to partition the usage into groups. The minimum amount is applied to each group. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The minimum amount to charge per group per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun minimumUnitAmount(): String = minimumUnitAmount.getRequired("minimum_unit_amount") + + /** + * Used to determine the unit rate + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun pricingKey(): String = pricingKey.getRequired("pricing_key") + + /** + * Scale the unit rates by the scaling factor. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun scalingFactors(): List = scalingFactors.getRequired("scaling_factors") + + /** + * Used to determine the unit rate scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun scalingKey(): String = scalingKey.getRequired("scaling_key") + + /** + * Apply per unit pricing to each pricing value. The minimum amount is applied any unmatched + * usage. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmounts(): List = unitAmounts.getRequired("unit_amounts") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [minimumUnitAmount]. + * + * Unlike [minimumUnitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_unit_amount") + @ExcludeMissing + fun _minimumUnitAmount(): JsonField = minimumUnitAmount + + /** + * Returns the raw JSON value of [pricingKey]. + * + * Unlike [pricingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("pricing_key") + @ExcludeMissing + fun _pricingKey(): JsonField = pricingKey + + /** + * Returns the raw JSON value of [scalingFactors]. + * + * Unlike [scalingFactors], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_factors") + @ExcludeMissing + fun _scalingFactors(): JsonField> = scalingFactors + + /** + * Returns the raw JSON value of [scalingKey]. + * + * Unlike [scalingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("scaling_key") + @ExcludeMissing + fun _scalingKey(): JsonField = scalingKey + + /** + * Returns the raw JSON value of [unitAmounts]. + * + * Unlike [unitAmounts], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amounts") + @ExcludeMissing + fun _unitAmounts(): JsonField> = unitAmounts + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1089,6 +1234,16 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [GroupedWithMeteredMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimumUnitAmount() + * .pricingKey() + * .scalingFactors() + * .scalingKey() + * .unitAmounts() + * ``` */ fun builder() = Builder() } @@ -1096,14 +1251,139 @@ private constructor( /** A builder for [GroupedWithMeteredMinimumConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var minimumUnitAmount: JsonField? = null + private var pricingKey: JsonField? = null + private var scalingFactors: JsonField>? = null + private var scalingKey: JsonField? = null + private var unitAmounts: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedWithMeteredMinimumConfig: GroupedWithMeteredMinimumConfig) = apply { + groupingKey = groupedWithMeteredMinimumConfig.groupingKey + minimumUnitAmount = groupedWithMeteredMinimumConfig.minimumUnitAmount + pricingKey = groupedWithMeteredMinimumConfig.pricingKey + scalingFactors = + groupedWithMeteredMinimumConfig.scalingFactors.map { it.toMutableList() } + scalingKey = groupedWithMeteredMinimumConfig.scalingKey + unitAmounts = + groupedWithMeteredMinimumConfig.unitAmounts.map { it.toMutableList() } additionalProperties = groupedWithMeteredMinimumConfig.additionalProperties.toMutableMap() } + /** + * Used to partition the usage into groups. The minimum amount is applied to each group. + */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The minimum amount to charge per group per unit */ + fun minimumUnitAmount(minimumUnitAmount: String) = + minimumUnitAmount(JsonField.of(minimumUnitAmount)) + + /** + * Sets [Builder.minimumUnitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumUnitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimumUnitAmount(minimumUnitAmount: JsonField) = apply { + this.minimumUnitAmount = minimumUnitAmount + } + + /** Used to determine the unit rate */ + fun pricingKey(pricingKey: String) = pricingKey(JsonField.of(pricingKey)) + + /** + * Sets [Builder.pricingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.pricingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun pricingKey(pricingKey: JsonField) = apply { this.pricingKey = pricingKey } + + /** Scale the unit rates by the scaling factor. */ + fun scalingFactors(scalingFactors: List) = + scalingFactors(JsonField.of(scalingFactors)) + + /** + * Sets [Builder.scalingFactors] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactors] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun scalingFactors(scalingFactors: JsonField>) = apply { + this.scalingFactors = scalingFactors.map { it.toMutableList() } + } + + /** + * Adds a single [ScalingFactor] to [scalingFactors]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addScalingFactor(scalingFactor: ScalingFactor) = apply { + scalingFactors = + (scalingFactors ?: JsonField.of(mutableListOf())).also { + checkKnown("scalingFactors", it).add(scalingFactor) + } + } + + /** Used to determine the unit rate scaling factor */ + fun scalingKey(scalingKey: String) = scalingKey(JsonField.of(scalingKey)) + + /** + * Sets [Builder.scalingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun scalingKey(scalingKey: JsonField) = apply { this.scalingKey = scalingKey } + + /** + * Apply per unit pricing to each pricing value. The minimum amount is applied any + * unmatched usage. + */ + fun unitAmounts(unitAmounts: List) = unitAmounts(JsonField.of(unitAmounts)) + + /** + * Sets [Builder.unitAmounts] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmounts] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmounts(unitAmounts: JsonField>) = apply { + this.unitAmounts = unitAmounts.map { it.toMutableList() } + } + + /** + * Adds a single [UnitAmount] to [unitAmounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUnitAmount(unitAmount: UnitAmount) = apply { + unitAmounts = + (unitAmounts ?: JsonField.of(mutableListOf())).also { + checkKnown("unitAmounts", it).add(unitAmount) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1127,9 +1407,29 @@ private constructor( * Returns an immutable instance of [GroupedWithMeteredMinimumConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimumUnitAmount() + * .pricingKey() + * .scalingFactors() + * .scalingKey() + * .unitAmounts() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedWithMeteredMinimumConfig = - GroupedWithMeteredMinimumConfig(additionalProperties.toImmutable()) + GroupedWithMeteredMinimumConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("minimumUnitAmount", minimumUnitAmount), + checkRequired("pricingKey", pricingKey), + checkRequired("scalingFactors", scalingFactors).map { it.toImmutable() }, + checkRequired("scalingKey", scalingKey), + checkRequired("unitAmounts", unitAmounts).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1139,6 +1439,12 @@ private constructor( return@apply } + groupingKey() + minimumUnitAmount() + pricingKey() + scalingFactors().forEach { it.validate() } + scalingKey() + unitAmounts().forEach { it.validate() } validated = true } @@ -1157,26 +1463,484 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (minimumUnitAmount.asKnown() == null) 0 else 1) + + (if (pricingKey.asKnown() == null) 0 else 1) + + (scalingFactors.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (scalingKey.asKnown() == null) 0 else 1) + + (unitAmounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a scaling factor */ + class ScalingFactor + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val scalingFactor: JsonField, + private val scalingValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("scaling_factor") + @ExcludeMissing + scalingFactor: JsonField = JsonMissing.of(), + @JsonProperty("scaling_value") + @ExcludeMissing + scalingValue: JsonField = JsonMissing.of(), + ) : this(scalingFactor, scalingValue, mutableMapOf()) + + /** + * Scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingFactor(): String = scalingFactor.getRequired("scaling_factor") + + /** + * Scaling value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingValue(): String = scalingValue.getRequired("scaling_value") + + /** + * Returns the raw JSON value of [scalingFactor]. + * + * Unlike [scalingFactor], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_factor") + @ExcludeMissing + fun _scalingFactor(): JsonField = scalingFactor + + /** + * Returns the raw JSON value of [scalingValue]. + * + * Unlike [scalingValue], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_value") + @ExcludeMissing + fun _scalingValue(): JsonField = scalingValue + + @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 [ScalingFactor]. + * + * The following fields are required: + * ```kotlin + * .scalingFactor() + * .scalingValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ScalingFactor]. */ + class Builder internal constructor() { + + private var scalingFactor: JsonField? = null + private var scalingValue: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(scalingFactor: ScalingFactor) = apply { + this.scalingFactor = scalingFactor.scalingFactor + scalingValue = scalingFactor.scalingValue + additionalProperties = scalingFactor.additionalProperties.toMutableMap() + } + + /** Scaling factor */ + fun scalingFactor(scalingFactor: String) = + scalingFactor(JsonField.of(scalingFactor)) + + /** + * Sets [Builder.scalingFactor] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactor] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun scalingFactor(scalingFactor: JsonField) = apply { + this.scalingFactor = scalingFactor + } + + /** Scaling value */ + fun scalingValue(scalingValue: String) = scalingValue(JsonField.of(scalingValue)) + + /** + * Sets [Builder.scalingValue] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingValue] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun scalingValue(scalingValue: JsonField) = apply { + this.scalingValue = scalingValue + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ScalingFactor]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .scalingFactor() + * .scalingValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ScalingFactor = + ScalingFactor( + checkRequired("scalingFactor", scalingFactor), + checkRequired("scalingValue", scalingValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ScalingFactor = apply { + if (validated) { + return@apply + } + + scalingFactor() + scalingValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (scalingFactor.asKnown() == null) 0 else 1) + + (if (scalingValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ScalingFactor && + scalingFactor == other.scalingFactor && + scalingValue == other.scalingValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(scalingFactor, scalingValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScalingFactor{scalingFactor=$scalingFactor, scalingValue=$scalingValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a unit amount */ + class UnitAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val pricingValue: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("pricing_value") + @ExcludeMissing + pricingValue: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(pricingValue, unitAmount, mutableMapOf()) + + /** + * Pricing value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun pricingValue(): String = pricingValue.getRequired("pricing_value") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [pricingValue]. + * + * Unlike [pricingValue], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pricing_value") + @ExcludeMissing + fun _pricingValue(): JsonField = pricingValue + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 [UnitAmount]. + * + * The following fields are required: + * ```kotlin + * .pricingValue() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [UnitAmount]. */ + class Builder internal constructor() { + + private var pricingValue: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(unitAmount: UnitAmount) = apply { + pricingValue = unitAmount.pricingValue + this.unitAmount = unitAmount.unitAmount + additionalProperties = unitAmount.additionalProperties.toMutableMap() + } + + /** Pricing value */ + fun pricingValue(pricingValue: String) = pricingValue(JsonField.of(pricingValue)) + + /** + * Sets [Builder.pricingValue] to an arbitrary JSON value. + * + * You should usually call [Builder.pricingValue] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun pricingValue(pricingValue: JsonField) = apply { + this.pricingValue = pricingValue + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UnitAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .pricingValue() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnitAmount = + UnitAmount( + checkRequired("pricingValue", pricingValue), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): UnitAmount = apply { + if (validated) { + return@apply + } + + pricingValue() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (pricingValue.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnitAmount && + pricingValue == other.pricingValue && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(pricingValue, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UnitAmount{pricingValue=$pricingValue, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedWithMeteredMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedWithMeteredMinimumConfig && + groupingKey == other.groupingKey && + minimumUnitAmount == other.minimumUnitAmount && + pricingKey == other.pricingKey && + scalingFactors == other.scalingFactors && + scalingKey == other.scalingKey && + unitAmounts == other.unitAmounts && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + minimumUnitAmount, + pricingKey, + scalingFactors, + scalingKey, + unitAmounts, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedWithMeteredMinimumConfig{additionalProperties=$additionalProperties}" + "GroupedWithMeteredMinimumConfig{groupingKey=$groupingKey, minimumUnitAmount=$minimumUnitAmount, pricingKey=$pricingKey, scalingFactors=$scalingFactors, scalingKey=$scalingKey, unitAmounts=$unitAmounts, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1289,7 +2053,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1297,175 +2061,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1558,12 +2153,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1575,12 +2168,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingGroupedWithMeteredMinimumPrice && cadence == other.cadence && currency == other.currency && groupedWithMeteredMinimumConfig == other.groupedWithMeteredMinimumConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingGroupedWithMeteredMinimumPrice && + cadence == other.cadence && + currency == other.currency && + groupedWithMeteredMinimumConfig == other.groupedWithMeteredMinimumConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, groupedWithMeteredMinimumConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + groupedWithMeteredMinimumConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedWithProratedMinimumPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedWithProratedMinimumPrice.kt index a21a6d231..2b2c17136 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedWithProratedMinimumPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingGroupedWithProratedMinimumPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingGroupedWithProratedMinimumPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -132,6 +123,8 @@ private constructor( fun currency(): String = currency.getRequired("currency") /** + * Configuration for grouped_with_prorated_minimum pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -147,6 +140,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -516,6 +511,7 @@ private constructor( */ fun currency(currency: JsonField) = apply { this.currency = currency } + /** Configuration for grouped_with_prorated_minimum pricing */ fun groupedWithProratedMinimumConfig( groupedWithProratedMinimumConfig: GroupedWithProratedMinimumConfig ) = groupedWithProratedMinimumConfig(JsonField.of(groupedWithProratedMinimumConfig)) @@ -542,6 +538,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1063,7 +1060,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1071,16 +1068,83 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_with_prorated_minimum pricing */ class GroupedWithProratedMinimumConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val minimum: JsonField, + private val unitRate: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("minimum") @ExcludeMissing minimum: JsonField = JsonMissing.of(), + @JsonProperty("unit_rate") + @ExcludeMissing + unitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, minimum, unitRate, mutableMapOf()) + + /** + * How to determine the groups that should each have a minimum + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The minimum amount to charge per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun minimum(): String = minimum.getRequired("minimum") + + /** + * The amount to charge per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitRate(): String = unitRate.getRequired("unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [minimum]. + * + * Unlike [minimum], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("minimum") @ExcludeMissing fun _minimum(): JsonField = minimum + + /** + * Returns the raw JSON value of [unitRate]. + * + * Unlike [unitRate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_rate") @ExcludeMissing fun _unitRate(): JsonField = unitRate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1089,6 +1153,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [GroupedWithProratedMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimum() + * .unitRate() + * ``` */ fun builder() = Builder() } @@ -1096,14 +1167,58 @@ private constructor( /** A builder for [GroupedWithProratedMinimumConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var minimum: JsonField? = null + private var unitRate: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedWithProratedMinimumConfig: GroupedWithProratedMinimumConfig) = apply { + groupingKey = groupedWithProratedMinimumConfig.groupingKey + minimum = groupedWithProratedMinimumConfig.minimum + unitRate = groupedWithProratedMinimumConfig.unitRate additionalProperties = groupedWithProratedMinimumConfig.additionalProperties.toMutableMap() } + /** How to determine the groups that should each have a minimum */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The minimum amount to charge per group */ + fun minimum(minimum: String) = minimum(JsonField.of(minimum)) + + /** + * Sets [Builder.minimum] to an arbitrary JSON value. + * + * You should usually call [Builder.minimum] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimum(minimum: JsonField) = apply { this.minimum = minimum } + + /** The amount to charge per unit */ + fun unitRate(unitRate: String) = unitRate(JsonField.of(unitRate)) + + /** + * Sets [Builder.unitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRate] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun unitRate(unitRate: JsonField) = apply { this.unitRate = unitRate } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1127,9 +1242,23 @@ private constructor( * Returns an immutable instance of [GroupedWithProratedMinimumConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimum() + * .unitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedWithProratedMinimumConfig = - GroupedWithProratedMinimumConfig(additionalProperties.toImmutable()) + GroupedWithProratedMinimumConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("minimum", minimum), + checkRequired("unitRate", unitRate), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1139,6 +1268,9 @@ private constructor( return@apply } + groupingKey() + minimum() + unitRate() validated = true } @@ -1157,26 +1289,33 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (minimum.asKnown() == null) 0 else 1) + + (if (unitRate.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedWithProratedMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedWithProratedMinimumConfig && + groupingKey == other.groupingKey && + minimum == other.minimum && + unitRate == other.unitRate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(groupingKey, minimum, unitRate, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedWithProratedMinimumConfig{additionalProperties=$additionalProperties}" + "GroupedWithProratedMinimumConfig{groupingKey=$groupingKey, minimum=$minimum, unitRate=$unitRate, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1289,7 +1428,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1297,175 +1436,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1558,12 +1528,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1575,12 +1543,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingGroupedWithProratedMinimumPrice && cadence == other.cadence && currency == other.currency && groupedWithProratedMinimumConfig == other.groupedWithProratedMinimumConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingGroupedWithProratedMinimumPrice && + cadence == other.cadence && + currency == other.currency && + groupedWithProratedMinimumConfig == other.groupedWithProratedMinimumConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, groupedWithProratedMinimumConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + groupedWithProratedMinimumConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMatrixPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMatrixPrice.kt index e7484599c..22a6cb68e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMatrixPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMatrixPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingMatrixPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,12 +130,16 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * Configuration for matrix pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ fun matrixConfig(): MatrixConfig = matrixConfig.getRequired("matrix_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -514,6 +509,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for matrix pricing */ fun matrixConfig(matrixConfig: MatrixConfig) = matrixConfig(JsonField.of(matrixConfig)) /** @@ -527,6 +523,7 @@ private constructor( this.matrixConfig = matrixConfig } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1048,7 +1045,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1056,6 +1053,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1168,7 +1166,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1176,175 +1174,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1437,12 +1266,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1454,12 +1281,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingMatrixPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && matrixConfig == other.matrixConfig && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingMatrixPrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + matrixConfig == other.matrixConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, matrixConfig, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + matrixConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMatrixWithAllocationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMatrixWithAllocationPrice.kt index 489c43007..3dc9bdce0 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMatrixWithAllocationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMatrixWithAllocationPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingMatrixWithAllocationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,6 +130,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * Configuration for matrix_with_allocation pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -146,6 +139,8 @@ private constructor( matrixWithAllocationConfig.getRequired("matrix_with_allocation_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -525,6 +520,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for matrix_with_allocation pricing */ fun matrixWithAllocationConfig(matrixWithAllocationConfig: MatrixWithAllocationConfig) = matrixWithAllocationConfig(JsonField.of(matrixWithAllocationConfig)) @@ -539,6 +535,7 @@ private constructor( matrixWithAllocationConfig: JsonField ) = apply { this.matrixWithAllocationConfig = matrixWithAllocationConfig } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1060,7 +1057,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1068,6 +1065,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1180,7 +1178,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1188,175 +1186,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1449,12 +1278,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1466,12 +1293,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingMatrixWithAllocationPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && matrixWithAllocationConfig == other.matrixWithAllocationConfig && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingMatrixWithAllocationPrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + matrixWithAllocationConfig == other.matrixWithAllocationConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, matrixWithAllocationConfig, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + matrixWithAllocationConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMatrixWithDisplayNamePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMatrixWithDisplayNamePrice.kt index 8b1806a21..4f282c571 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMatrixWithDisplayNamePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMatrixWithDisplayNamePrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingMatrixWithDisplayNamePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,6 +131,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * Configuration for matrix_with_display_name pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -146,6 +140,8 @@ private constructor( matrixWithDisplayNameConfig.getRequired("matrix_with_display_name_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -525,6 +521,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for matrix_with_display_name pricing */ fun matrixWithDisplayNameConfig(matrixWithDisplayNameConfig: MatrixWithDisplayNameConfig) = matrixWithDisplayNameConfig(JsonField.of(matrixWithDisplayNameConfig)) @@ -539,6 +536,7 @@ private constructor( matrixWithDisplayNameConfig: JsonField ) = apply { this.matrixWithDisplayNameConfig = matrixWithDisplayNameConfig } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1060,7 +1058,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1068,16 +1066,66 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for matrix_with_display_name pricing */ class MatrixWithDisplayNameConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val dimension: JsonField, + private val unitAmounts: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("dimension") + @ExcludeMissing + dimension: JsonField = JsonMissing.of(), + @JsonProperty("unit_amounts") + @ExcludeMissing + unitAmounts: JsonField> = JsonMissing.of(), + ) : this(dimension, unitAmounts, mutableMapOf()) + + /** + * Used to determine the unit rate + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dimension(): String = dimension.getRequired("dimension") + + /** + * Apply per unit pricing to each dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmounts(): List = unitAmounts.getRequired("unit_amounts") + + /** + * Returns the raw JSON value of [dimension]. + * + * Unlike [dimension], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("dimension") @ExcludeMissing fun _dimension(): JsonField = dimension + + /** + * Returns the raw JSON value of [unitAmounts]. + * + * Unlike [unitAmounts], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amounts") + @ExcludeMissing + fun _unitAmounts(): JsonField> = unitAmounts + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1086,6 +1134,12 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [MatrixWithDisplayNameConfig]. + * + * The following fields are required: + * ```kotlin + * .dimension() + * .unitAmounts() + * ``` */ fun builder() = Builder() } @@ -1093,13 +1147,55 @@ private constructor( /** A builder for [MatrixWithDisplayNameConfig]. */ class Builder internal constructor() { + private var dimension: JsonField? = null + private var unitAmounts: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(matrixWithDisplayNameConfig: MatrixWithDisplayNameConfig) = apply { + dimension = matrixWithDisplayNameConfig.dimension + unitAmounts = matrixWithDisplayNameConfig.unitAmounts.map { it.toMutableList() } additionalProperties = matrixWithDisplayNameConfig.additionalProperties.toMutableMap() } + /** Used to determine the unit rate */ + fun dimension(dimension: String) = dimension(JsonField.of(dimension)) + + /** + * Sets [Builder.dimension] to an arbitrary JSON value. + * + * You should usually call [Builder.dimension] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun dimension(dimension: JsonField) = apply { this.dimension = dimension } + + /** Apply per unit pricing to each dimension value */ + fun unitAmounts(unitAmounts: List) = unitAmounts(JsonField.of(unitAmounts)) + + /** + * Sets [Builder.unitAmounts] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmounts] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmounts(unitAmounts: JsonField>) = apply { + this.unitAmounts = unitAmounts.map { it.toMutableList() } + } + + /** + * Adds a single [UnitAmount] to [unitAmounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUnitAmount(unitAmount: UnitAmount) = apply { + unitAmounts = + (unitAmounts ?: JsonField.of(mutableListOf())).also { + checkKnown("unitAmounts", it).add(unitAmount) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1123,9 +1219,21 @@ private constructor( * Returns an immutable instance of [MatrixWithDisplayNameConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .dimension() + * .unitAmounts() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): MatrixWithDisplayNameConfig = - MatrixWithDisplayNameConfig(additionalProperties.toImmutable()) + MatrixWithDisplayNameConfig( + checkRequired("dimension", dimension), + checkRequired("unitAmounts", unitAmounts).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1135,6 +1243,8 @@ private constructor( return@apply } + dimension() + unitAmounts().forEach { it.validate() } validated = true } @@ -1153,26 +1263,295 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (dimension.asKnown() == null) 0 else 1) + + (unitAmounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a unit amount item */ + class UnitAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val dimensionValue: JsonField, + private val displayName: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("dimension_value") + @ExcludeMissing + dimensionValue: JsonField = JsonMissing.of(), + @JsonProperty("display_name") + @ExcludeMissing + displayName: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(dimensionValue, displayName, unitAmount, mutableMapOf()) + + /** + * The dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun dimensionValue(): String = dimensionValue.getRequired("dimension_value") + + /** + * Display name for this dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun displayName(): String = displayName.getRequired("display_name") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [dimensionValue]. + * + * Unlike [dimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("dimension_value") + @ExcludeMissing + fun _dimensionValue(): JsonField = dimensionValue + + /** + * Returns the raw JSON value of [displayName]. + * + * Unlike [displayName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("display_name") + @ExcludeMissing + fun _displayName(): JsonField = displayName + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 [UnitAmount]. + * + * The following fields are required: + * ```kotlin + * .dimensionValue() + * .displayName() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [UnitAmount]. */ + class Builder internal constructor() { + + private var dimensionValue: JsonField? = null + private var displayName: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(unitAmount: UnitAmount) = apply { + dimensionValue = unitAmount.dimensionValue + displayName = unitAmount.displayName + this.unitAmount = unitAmount.unitAmount + additionalProperties = unitAmount.additionalProperties.toMutableMap() + } + + /** The dimension value */ + fun dimensionValue(dimensionValue: String) = + dimensionValue(JsonField.of(dimensionValue)) + + /** + * Sets [Builder.dimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionValue] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun dimensionValue(dimensionValue: JsonField) = apply { + this.dimensionValue = dimensionValue + } + + /** Display name for this dimension value */ + fun displayName(displayName: String) = displayName(JsonField.of(displayName)) + + /** + * Sets [Builder.displayName] to an arbitrary JSON value. + * + * You should usually call [Builder.displayName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun displayName(displayName: JsonField) = apply { + this.displayName = displayName + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UnitAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .dimensionValue() + * .displayName() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnitAmount = + UnitAmount( + checkRequired("dimensionValue", dimensionValue), + checkRequired("displayName", displayName), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): UnitAmount = apply { + if (validated) { + return@apply + } + + dimensionValue() + displayName() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (dimensionValue.asKnown() == null) 0 else 1) + + (if (displayName.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnitAmount && + dimensionValue == other.dimensionValue && + displayName == other.displayName && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(dimensionValue, displayName, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UnitAmount{dimensionValue=$dimensionValue, displayName=$displayName, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MatrixWithDisplayNameConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MatrixWithDisplayNameConfig && + dimension == other.dimension && + unitAmounts == other.unitAmounts && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(dimension, unitAmounts, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "MatrixWithDisplayNameConfig{additionalProperties=$additionalProperties}" + "MatrixWithDisplayNameConfig{dimension=$dimension, unitAmounts=$unitAmounts, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1285,7 +1664,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1293,175 +1672,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1554,12 +1764,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1571,12 +1779,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingMatrixWithDisplayNamePrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && matrixWithDisplayNameConfig == other.matrixWithDisplayNameConfig && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingMatrixWithDisplayNamePrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + matrixWithDisplayNameConfig == other.matrixWithDisplayNameConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, matrixWithDisplayNameConfig, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + matrixWithDisplayNameConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMaxGroupTieredPackagePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMaxGroupTieredPackagePrice.kt index 481716158..884401bca 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMaxGroupTieredPackagePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMaxGroupTieredPackagePrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingMaxGroupTieredPackagePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,6 +131,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * Configuration for max_group_tiered_package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -146,6 +140,8 @@ private constructor( maxGroupTieredPackageConfig.getRequired("max_group_tiered_package_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -525,6 +521,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for max_group_tiered_package pricing */ fun maxGroupTieredPackageConfig(maxGroupTieredPackageConfig: MaxGroupTieredPackageConfig) = maxGroupTieredPackageConfig(JsonField.of(maxGroupTieredPackageConfig)) @@ -539,6 +536,7 @@ private constructor( maxGroupTieredPackageConfig: JsonField ) = apply { this.maxGroupTieredPackageConfig = maxGroupTieredPackageConfig } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1060,7 +1058,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1068,16 +1066,85 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for max_group_tiered_package pricing */ class MaxGroupTieredPackageConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(groupingKey, packageSize, tiers, mutableMapOf()) + + /** + * The event property used to group before tiering the group with the highest value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing to the largest group after grouping with the provided key. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1086,6 +1153,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [MaxGroupTieredPackageConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1093,13 +1167,73 @@ private constructor( /** A builder for [MaxGroupTieredPackageConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(maxGroupTieredPackageConfig: MaxGroupTieredPackageConfig) = apply { + groupingKey = maxGroupTieredPackageConfig.groupingKey + packageSize = maxGroupTieredPackageConfig.packageSize + tiers = maxGroupTieredPackageConfig.tiers.map { it.toMutableList() } additionalProperties = maxGroupTieredPackageConfig.additionalProperties.toMutableMap() } + /** The event property used to group before tiering the group with the highest value */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** Apply tiered pricing to the largest group after grouping with the provided key. */ + 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) @@ -1123,9 +1257,23 @@ private constructor( * Returns an immutable instance of [MaxGroupTieredPackageConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): MaxGroupTieredPackageConfig = - MaxGroupTieredPackageConfig(additionalProperties.toImmutable()) + MaxGroupTieredPackageConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1135,6 +1283,9 @@ private constructor( return@apply } + groupingKey() + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -1153,26 +1304,252 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MaxGroupTieredPackageConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MaxGroupTieredPackageConfig && + groupingKey == other.groupingKey && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(groupingKey, packageSize, tiers, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "MaxGroupTieredPackageConfig{additionalProperties=$additionalProperties}" + "MaxGroupTieredPackageConfig{groupingKey=$groupingKey, packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1285,7 +1662,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1293,175 +1670,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1554,12 +1762,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1571,12 +1777,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingMaxGroupTieredPackagePrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && maxGroupTieredPackageConfig == other.maxGroupTieredPackageConfig && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingMaxGroupTieredPackagePrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + maxGroupTieredPackageConfig == other.maxGroupTieredPackageConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, maxGroupTieredPackageConfig, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + maxGroupTieredPackageConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBulkBpsPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMinimumCompositePrice.kt similarity index 79% rename from orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBulkBpsPrice.kt rename to orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMinimumCompositePrice.kt index 3fb542240..9df1bffff 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingBulkBpsPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingMinimumCompositePrice.kt @@ -6,33 +6,24 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects -class NewFloatingBulkBpsPrice +class NewFloatingMinimumCompositePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val bulkBpsConfig: JsonField, private val cadence: JsonField, private val currency: JsonField, private val itemId: JsonField, + private val minimumConfig: JsonField, private val modelType: JsonField, private val name: JsonField, private val billableMetricId: JsonField, @@ -51,12 +42,12 @@ private constructor( @JsonCreator private constructor( - @JsonProperty("bulk_bps_config") - @ExcludeMissing - bulkBpsConfig: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("item_id") @ExcludeMissing itemId: JsonField = JsonMissing.of(), + @JsonProperty("minimum_config") + @ExcludeMissing + minimumConfig: JsonField = JsonMissing.of(), @JsonProperty("model_type") @ExcludeMissing modelType: JsonField = JsonMissing.of(), @@ -94,10 +85,10 @@ private constructor( invoicingCycleConfiguration: JsonField = JsonMissing.of(), @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), ) : this( - bulkBpsConfig, cadence, currency, itemId, + minimumConfig, modelType, name, billableMetricId, @@ -114,12 +105,6 @@ private constructor( mutableMapOf(), ) - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun bulkBpsConfig(): BulkBpsConfig = bulkBpsConfig.getRequired("bulk_bps_config") - /** * The cadence to bill for this price on. * @@ -145,6 +130,16 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * Configuration for minimum pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun minimumConfig(): MinimumConfig = minimumConfig.getRequired("minimum_config") + + /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -254,15 +249,6 @@ private constructor( */ fun metadata(): Metadata? = metadata.getNullable("metadata") - /** - * Returns the raw JSON value of [bulkBpsConfig]. - * - * Unlike [bulkBpsConfig], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("bulk_bps_config") - @ExcludeMissing - fun _bulkBpsConfig(): JsonField = bulkBpsConfig - /** * Returns the raw JSON value of [cadence]. * @@ -284,6 +270,15 @@ private constructor( */ @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + /** + * Returns the raw JSON value of [minimumConfig]. + * + * Unlike [minimumConfig], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("minimum_config") + @ExcludeMissing + fun _minimumConfig(): JsonField = minimumConfig + /** * Returns the raw JSON value of [modelType]. * @@ -420,14 +415,15 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [NewFloatingBulkBpsPrice]. + * Returns a mutable builder for constructing an instance of + * [NewFloatingMinimumCompositePrice]. * * The following fields are required: * ```kotlin - * .bulkBpsConfig() * .cadence() * .currency() * .itemId() + * .minimumConfig() * .modelType() * .name() * ``` @@ -435,13 +431,13 @@ private constructor( fun builder() = Builder() } - /** A builder for [NewFloatingBulkBpsPrice]. */ + /** A builder for [NewFloatingMinimumCompositePrice]. */ class Builder internal constructor() { - private var bulkBpsConfig: JsonField? = null private var cadence: JsonField? = null private var currency: JsonField? = null private var itemId: JsonField? = null + private var minimumConfig: JsonField? = null private var modelType: JsonField? = null private var name: JsonField? = null private var billableMetricId: JsonField = JsonMissing.of() @@ -460,39 +456,31 @@ private constructor( private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(newFloatingBulkBpsPrice: NewFloatingBulkBpsPrice) = apply { - bulkBpsConfig = newFloatingBulkBpsPrice.bulkBpsConfig - cadence = newFloatingBulkBpsPrice.cadence - currency = newFloatingBulkBpsPrice.currency - itemId = newFloatingBulkBpsPrice.itemId - modelType = newFloatingBulkBpsPrice.modelType - name = newFloatingBulkBpsPrice.name - billableMetricId = newFloatingBulkBpsPrice.billableMetricId - billedInAdvance = newFloatingBulkBpsPrice.billedInAdvance - billingCycleConfiguration = newFloatingBulkBpsPrice.billingCycleConfiguration - conversionRate = newFloatingBulkBpsPrice.conversionRate - conversionRateConfig = newFloatingBulkBpsPrice.conversionRateConfig - dimensionalPriceConfiguration = newFloatingBulkBpsPrice.dimensionalPriceConfiguration - externalPriceId = newFloatingBulkBpsPrice.externalPriceId - fixedPriceQuantity = newFloatingBulkBpsPrice.fixedPriceQuantity - invoiceGroupingKey = newFloatingBulkBpsPrice.invoiceGroupingKey - invoicingCycleConfiguration = newFloatingBulkBpsPrice.invoicingCycleConfiguration - metadata = newFloatingBulkBpsPrice.metadata - additionalProperties = newFloatingBulkBpsPrice.additionalProperties.toMutableMap() - } - - fun bulkBpsConfig(bulkBpsConfig: BulkBpsConfig) = bulkBpsConfig(JsonField.of(bulkBpsConfig)) - - /** - * Sets [Builder.bulkBpsConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.bulkBpsConfig] with a well-typed [BulkBpsConfig] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun bulkBpsConfig(bulkBpsConfig: JsonField) = apply { - this.bulkBpsConfig = bulkBpsConfig - } + internal fun from(newFloatingMinimumCompositePrice: NewFloatingMinimumCompositePrice) = + apply { + cadence = newFloatingMinimumCompositePrice.cadence + currency = newFloatingMinimumCompositePrice.currency + itemId = newFloatingMinimumCompositePrice.itemId + minimumConfig = newFloatingMinimumCompositePrice.minimumConfig + modelType = newFloatingMinimumCompositePrice.modelType + name = newFloatingMinimumCompositePrice.name + billableMetricId = newFloatingMinimumCompositePrice.billableMetricId + billedInAdvance = newFloatingMinimumCompositePrice.billedInAdvance + billingCycleConfiguration = + newFloatingMinimumCompositePrice.billingCycleConfiguration + conversionRate = newFloatingMinimumCompositePrice.conversionRate + conversionRateConfig = newFloatingMinimumCompositePrice.conversionRateConfig + dimensionalPriceConfiguration = + newFloatingMinimumCompositePrice.dimensionalPriceConfiguration + externalPriceId = newFloatingMinimumCompositePrice.externalPriceId + fixedPriceQuantity = newFloatingMinimumCompositePrice.fixedPriceQuantity + invoiceGroupingKey = newFloatingMinimumCompositePrice.invoiceGroupingKey + invoicingCycleConfiguration = + newFloatingMinimumCompositePrice.invoicingCycleConfiguration + metadata = newFloatingMinimumCompositePrice.metadata + additionalProperties = + newFloatingMinimumCompositePrice.additionalProperties.toMutableMap() + } /** The cadence to bill for this price on. */ fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) @@ -527,6 +515,21 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for minimum pricing */ + fun minimumConfig(minimumConfig: MinimumConfig) = minimumConfig(JsonField.of(minimumConfig)) + + /** + * Sets [Builder.minimumConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumConfig] with a well-typed [MinimumConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimumConfig(minimumConfig: JsonField) = apply { + this.minimumConfig = minimumConfig + } + + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -809,28 +812,28 @@ private constructor( } /** - * Returns an immutable instance of [NewFloatingBulkBpsPrice]. + * Returns an immutable instance of [NewFloatingMinimumCompositePrice]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```kotlin - * .bulkBpsConfig() * .cadence() * .currency() * .itemId() + * .minimumConfig() * .modelType() * .name() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): NewFloatingBulkBpsPrice = - NewFloatingBulkBpsPrice( - checkRequired("bulkBpsConfig", bulkBpsConfig), + fun build(): NewFloatingMinimumCompositePrice = + NewFloatingMinimumCompositePrice( checkRequired("cadence", cadence), checkRequired("currency", currency), checkRequired("itemId", itemId), + checkRequired("minimumConfig", minimumConfig), checkRequired("modelType", modelType), checkRequired("name", name), billableMetricId, @@ -850,15 +853,15 @@ private constructor( private var validated: Boolean = false - fun validate(): NewFloatingBulkBpsPrice = apply { + fun validate(): NewFloatingMinimumCompositePrice = apply { if (validated) { return@apply } - bulkBpsConfig().validate() cadence().validate() currency() itemId() + minimumConfig().validate() modelType().validate() name() billableMetricId() @@ -889,10 +892,10 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - (bulkBpsConfig.asKnown()?.validity() ?: 0) + - (cadence.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + (if (currency.asKnown() == null) 0 else 1) + (if (itemId.asKnown() == null) 0 else 1) + + (minimumConfig.asKnown()?.validity() ?: 0) + (modelType.asKnown()?.validity() ?: 0) + (if (name.asKnown() == null) 0 else 1) + (if (billableMetricId.asKnown() == null) 0 else 1) + @@ -1048,7 +1051,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1056,6 +1059,213 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for minimum pricing */ + class MinimumConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val minimumAmount: JsonField, + private val prorated: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("prorated") + @ExcludeMissing + prorated: JsonField = JsonMissing.of(), + ) : this(minimumAmount, prorated, mutableMapOf()) + + /** + * The minimum amount to apply + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun minimumAmount(): String = minimumAmount.getRequired("minimum_amount") + + /** + * If true, subtotals from this price are prorated based on the service period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorated(): Boolean? = prorated.getNullable("prorated") + + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount + + /** + * Returns the raw JSON value of [prorated]. + * + * Unlike [prorated], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorated") @ExcludeMissing fun _prorated(): JsonField = prorated + + @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 [MinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [MinimumConfig]. */ + class Builder internal constructor() { + + private var minimumAmount: JsonField? = null + private var prorated: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(minimumConfig: MinimumConfig) = apply { + minimumAmount = minimumConfig.minimumAmount + prorated = minimumConfig.prorated + additionalProperties = minimumConfig.additionalProperties.toMutableMap() + } + + /** The minimum amount to apply */ + fun minimumAmount(minimumAmount: String) = minimumAmount(JsonField.of(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } + + /** If true, subtotals from this price are prorated based on the service period */ + fun prorated(prorated: Boolean) = prorated(JsonField.of(prorated)) + + /** + * Sets [Builder.prorated] to an arbitrary JSON value. + * + * You should usually call [Builder.prorated] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prorated(prorated: JsonField) = apply { this.prorated = prorated } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [MinimumConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MinimumConfig = + MinimumConfig( + checkRequired("minimumAmount", minimumAmount), + prorated, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MinimumConfig = apply { + if (validated) { + return@apply + } + + minimumAmount() + prorated() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (minimumAmount.asKnown() == null) 0 else 1) + + (if (prorated.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MinimumConfig && + minimumAmount == other.minimumAmount && + prorated == other.prorated && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(minimumAmount, prorated, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MinimumConfig{minimumAmount=$minimumAmount, prorated=$prorated, additionalProperties=$additionalProperties}" + } + + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1070,14 +1280,14 @@ private constructor( companion object { - val BULK_BPS = of("bulk_bps") + val MINIMUM = of("minimum") fun of(value: String) = ModelType(JsonField.of(value)) } /** An enum containing [ModelType]'s known values. */ enum class Known { - BULK_BPS + MINIMUM } /** @@ -1090,7 +1300,7 @@ private constructor( * - It was constructed with an arbitrary value using the [of] method. */ enum class Value { - BULK_BPS, + MINIMUM, /** * An enum member indicating that [ModelType] was instantiated with an unknown value. */ @@ -1106,7 +1316,7 @@ private constructor( */ fun value(): Value = when (this) { - BULK_BPS -> Value.BULK_BPS + MINIMUM -> Value.MINIMUM else -> Value._UNKNOWN } @@ -1120,7 +1330,7 @@ private constructor( */ fun known(): Known = when (this) { - BULK_BPS -> Known.BULK_BPS + MINIMUM -> Known.MINIMUM else -> throw OrbInvalidDataException("Unknown ModelType: $value") } @@ -1168,7 +1378,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1176,175 +1386,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1437,12 +1478,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1454,15 +1493,52 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingBulkBpsPrice && bulkBpsConfig == other.bulkBpsConfig && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingMinimumCompositePrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + minimumConfig == other.minimumConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bulkBpsConfig, cadence, currency, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + minimumConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "NewFloatingBulkBpsPrice{bulkBpsConfig=$bulkBpsConfig, cadence=$cadence, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + "NewFloatingMinimumCompositePrice{cadence=$cadence, currency=$currency, itemId=$itemId, minimumConfig=$minimumConfig, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingPackagePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingPackagePrice.kt index e711b9849..deae399c2 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingPackagePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingPackagePrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingPackagePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,6 +130,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -153,6 +146,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -514,6 +509,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -536,6 +532,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for package pricing */ fun packageConfig(packageConfig: PackageConfig) = packageConfig(JsonField.of(packageConfig)) /** @@ -1048,7 +1045,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1056,6 +1053,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1168,7 +1166,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1176,175 +1174,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1437,12 +1266,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1454,12 +1281,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingPackagePrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && packageConfig == other.packageConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingPackagePrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + packageConfig == other.packageConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, packageConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + packageConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingPackageWithAllocationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingPackageWithAllocationPrice.kt index f2d69841a..6a9305b4f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingPackageWithAllocationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingPackageWithAllocationPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingPackageWithAllocationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,6 +130,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -153,6 +146,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for package_with_allocation pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -525,6 +520,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -547,6 +543,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for package_with_allocation pricing */ fun packageWithAllocationConfig(packageWithAllocationConfig: PackageWithAllocationConfig) = packageWithAllocationConfig(JsonField.of(packageWithAllocationConfig)) @@ -1060,7 +1057,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1068,6 +1065,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1180,7 +1178,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1188,16 +1186,90 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for package_with_allocation pricing */ class PackageWithAllocationConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val allocation: JsonField, + private val packageAmount: JsonField, + private val packageSize: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("allocation") + @ExcludeMissing + allocation: JsonField = JsonMissing.of(), + @JsonProperty("package_amount") + @ExcludeMissing + packageAmount: JsonField = JsonMissing.of(), + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + ) : this(allocation, packageAmount, packageSize, mutableMapOf()) + + /** + * Usage allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun allocation(): String = allocation.getRequired("allocation") + + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageAmount(): String = packageAmount.getRequired("package_amount") + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Returns the raw JSON value of [allocation]. + * + * Unlike [allocation], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allocation") + @ExcludeMissing + fun _allocation(): JsonField = allocation + + /** + * Returns the raw JSON value of [packageAmount]. + * + * Unlike [packageAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("package_amount") + @ExcludeMissing + fun _packageAmount(): JsonField = packageAmount + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1206,6 +1278,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [PackageWithAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .packageAmount() + * .packageSize() + * ``` */ fun builder() = Builder() } @@ -1213,13 +1292,59 @@ private constructor( /** A builder for [PackageWithAllocationConfig]. */ class Builder internal constructor() { + private var allocation: JsonField? = null + private var packageAmount: JsonField? = null + private var packageSize: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(packageWithAllocationConfig: PackageWithAllocationConfig) = apply { + allocation = packageWithAllocationConfig.allocation + packageAmount = packageWithAllocationConfig.packageAmount + packageSize = packageWithAllocationConfig.packageSize additionalProperties = packageWithAllocationConfig.additionalProperties.toMutableMap() } + /** Usage allocation */ + fun allocation(allocation: String) = allocation(JsonField.of(allocation)) + + /** + * Sets [Builder.allocation] to an arbitrary JSON value. + * + * You should usually call [Builder.allocation] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun allocation(allocation: JsonField) = apply { this.allocation = allocation } + + /** Price per package */ + fun packageAmount(packageAmount: String) = packageAmount(JsonField.of(packageAmount)) + + /** + * Sets [Builder.packageAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.packageAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageAmount(packageAmount: JsonField) = apply { + this.packageAmount = packageAmount + } + + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1243,9 +1368,23 @@ private constructor( * Returns an immutable instance of [PackageWithAllocationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .packageAmount() + * .packageSize() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): PackageWithAllocationConfig = - PackageWithAllocationConfig(additionalProperties.toImmutable()) + PackageWithAllocationConfig( + checkRequired("allocation", allocation), + checkRequired("packageAmount", packageAmount), + checkRequired("packageSize", packageSize), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1255,6 +1394,9 @@ private constructor( return@apply } + allocation() + packageAmount() + packageSize() validated = true } @@ -1273,193 +1415,30 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (allocation.asKnown() == null) 0 else 1) + + (if (packageAmount.asKnown() == null) 0 else 1) + + (if (packageSize.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PackageWithAllocationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PackageWithAllocationConfig && + allocation == other.allocation && + packageAmount == other.packageAmount && + packageSize == other.packageSize && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(allocation, packageAmount, packageSize, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "PackageWithAllocationConfig{additionalProperties=$additionalProperties}" - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } + "PackageWithAllocationConfig{allocation=$allocation, packageAmount=$packageAmount, packageSize=$packageSize, additionalProperties=$additionalProperties}" } /** @@ -1554,12 +1533,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1571,12 +1548,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingPackageWithAllocationPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && packageWithAllocationConfig == other.packageWithAllocationConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingPackageWithAllocationPrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + packageWithAllocationConfig == other.packageWithAllocationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, packageWithAllocationConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + packageWithAllocationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithTieredPricingPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithTieredPricingPrice.kt index f82bafef1..68517093f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithTieredPricingPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithTieredPricingPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingScalableMatrixWithTieredPricingPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -141,6 +133,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -155,6 +149,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for scalable_matrix_with_tiered_pricing pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -534,6 +530,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -556,6 +553,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for scalable_matrix_with_tiered_pricing pricing */ fun scalableMatrixWithTieredPricingConfig( scalableMatrixWithTieredPricingConfig: ScalableMatrixWithTieredPricingConfig ) = @@ -1078,7 +1076,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1086,6 +1084,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1198,7 +1197,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1206,16 +1205,110 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for scalable_matrix_with_tiered_pricing pricing */ class ScalableMatrixWithTieredPricingConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val firstDimension: JsonField, + private val matrixScalingFactors: JsonField>, + private val tiers: JsonField>, + private val secondDimension: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("first_dimension") + @ExcludeMissing + firstDimension: JsonField = JsonMissing.of(), + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + matrixScalingFactors: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + @JsonProperty("second_dimension") + @ExcludeMissing + secondDimension: JsonField = JsonMissing.of(), + ) : this(firstDimension, matrixScalingFactors, tiers, secondDimension, mutableMapOf()) + + /** + * Used for the scalable matrix first dimension + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun firstDimension(): String = firstDimension.getRequired("first_dimension") + + /** + * Apply a scaling factor to each dimension + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun matrixScalingFactors(): List = + matrixScalingFactors.getRequired("matrix_scaling_factors") + + /** + * Tier pricing structure + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Used for the scalable matrix second dimension (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimension(): String? = secondDimension.getNullable("second_dimension") + + /** + * Returns the raw JSON value of [firstDimension]. + * + * Unlike [firstDimension], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("first_dimension") + @ExcludeMissing + fun _firstDimension(): JsonField = firstDimension + + /** + * Returns the raw JSON value of [matrixScalingFactors]. + * + * Unlike [matrixScalingFactors], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + fun _matrixScalingFactors(): JsonField> = matrixScalingFactors + + /** + * 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 + + /** + * Returns the raw JSON value of [secondDimension]. + * + * Unlike [secondDimension], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("second_dimension") + @ExcludeMissing + fun _secondDimension(): JsonField = secondDimension + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1224,6 +1317,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [ScalableMatrixWithTieredPricingConfig]. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1231,15 +1331,110 @@ private constructor( /** A builder for [ScalableMatrixWithTieredPricingConfig]. */ class Builder internal constructor() { + private var firstDimension: JsonField? = null + private var matrixScalingFactors: JsonField>? = null + private var tiers: JsonField>? = null + private var secondDimension: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from( scalableMatrixWithTieredPricingConfig: ScalableMatrixWithTieredPricingConfig ) = apply { + firstDimension = scalableMatrixWithTieredPricingConfig.firstDimension + matrixScalingFactors = + scalableMatrixWithTieredPricingConfig.matrixScalingFactors.map { + it.toMutableList() + } + tiers = scalableMatrixWithTieredPricingConfig.tiers.map { it.toMutableList() } + secondDimension = scalableMatrixWithTieredPricingConfig.secondDimension additionalProperties = scalableMatrixWithTieredPricingConfig.additionalProperties.toMutableMap() } + /** Used for the scalable matrix first dimension */ + fun firstDimension(firstDimension: String) = + firstDimension(JsonField.of(firstDimension)) + + /** + * Sets [Builder.firstDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun firstDimension(firstDimension: JsonField) = apply { + this.firstDimension = firstDimension + } + + /** Apply a scaling factor to each dimension */ + fun matrixScalingFactors(matrixScalingFactors: List) = + matrixScalingFactors(JsonField.of(matrixScalingFactors)) + + /** + * Sets [Builder.matrixScalingFactors] to an arbitrary JSON value. + * + * You should usually call [Builder.matrixScalingFactors] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun matrixScalingFactors(matrixScalingFactors: JsonField>) = + apply { + this.matrixScalingFactors = matrixScalingFactors.map { it.toMutableList() } + } + + /** + * Adds a single [MatrixScalingFactor] to [matrixScalingFactors]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMatrixScalingFactor(matrixScalingFactor: MatrixScalingFactor) = apply { + matrixScalingFactors = + (matrixScalingFactors ?: JsonField.of(mutableListOf())).also { + checkKnown("matrixScalingFactors", it).add(matrixScalingFactor) + } + } + + /** Tier pricing structure */ + 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) + } + } + + /** Used for the scalable matrix second dimension (optional) */ + fun secondDimension(secondDimension: String?) = + secondDimension(JsonField.ofNullable(secondDimension)) + + /** + * Sets [Builder.secondDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun secondDimension(secondDimension: JsonField) = apply { + this.secondDimension = secondDimension + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1263,9 +1458,26 @@ private constructor( * Returns an immutable instance of [ScalableMatrixWithTieredPricingConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): ScalableMatrixWithTieredPricingConfig = - ScalableMatrixWithTieredPricingConfig(additionalProperties.toImmutable()) + ScalableMatrixWithTieredPricingConfig( + checkRequired("firstDimension", firstDimension), + checkRequired("matrixScalingFactors", matrixScalingFactors).map { + it.toImmutable() + }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + secondDimension, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1275,6 +1487,10 @@ private constructor( return@apply } + firstDimension() + matrixScalingFactors().forEach { it.validate() } + tiers().forEach { it.validate() } + secondDimension() validated = true } @@ -1293,193 +1509,527 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (firstDimension.asKnown() == null) 0 else 1) + + (matrixScalingFactors.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (secondDimension.asKnown() == null) 0 else 1) + + /** Configuration for a single matrix scaling factor */ + class MatrixScalingFactor + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val firstDimensionValue: JsonField, + private val scalingFactor: JsonField, + private val secondDimensionValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("first_dimension_value") + @ExcludeMissing + firstDimensionValue: JsonField = JsonMissing.of(), + @JsonProperty("scaling_factor") + @ExcludeMissing + scalingFactor: JsonField = JsonMissing.of(), + @JsonProperty("second_dimension_value") + @ExcludeMissing + secondDimensionValue: JsonField = JsonMissing.of(), + ) : this(firstDimensionValue, scalingFactor, secondDimensionValue, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * First dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun firstDimensionValue(): String = + firstDimensionValue.getRequired("first_dimension_value") - return /* spotless:off */ other is ScalableMatrixWithTieredPricingConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingFactor(): String = scalingFactor.getRequired("scaling_factor") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Second dimension value (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimensionValue(): String? = + secondDimensionValue.getNullable("second_dimension_value") - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [firstDimensionValue]. + * + * Unlike [firstDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("first_dimension_value") + @ExcludeMissing + fun _firstDimensionValue(): JsonField = firstDimensionValue - override fun toString() = - "ScalableMatrixWithTieredPricingConfig{additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [scalingFactor]. + * + * Unlike [scalingFactor], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_factor") + @ExcludeMissing + fun _scalingFactor(): JsonField = scalingFactor - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + /** + * Returns the raw JSON value of [secondDimensionValue]. + * + * Unlike [secondDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("second_dimension_value") + @ExcludeMissing + fun _secondDimensionValue(): JsonField = secondDimensionValue - fun unit(): UnitConversionRateConfig? = unit + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [MatrixScalingFactor]. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + */ + fun builder() = Builder() + } - fun isUnit(): Boolean = unit != null + /** A builder for [MatrixScalingFactor]. */ + class Builder internal constructor() { - fun isTiered(): Boolean = tiered != null + private var firstDimensionValue: JsonField? = null + private var scalingFactor: JsonField? = null + private var secondDimensionValue: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + internal fun from(matrixScalingFactor: MatrixScalingFactor) = apply { + firstDimensionValue = matrixScalingFactor.firstDimensionValue + scalingFactor = matrixScalingFactor.scalingFactor + secondDimensionValue = matrixScalingFactor.secondDimensionValue + additionalProperties = matrixScalingFactor.additionalProperties.toMutableMap() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** First dimension value */ + fun firstDimensionValue(firstDimensionValue: String) = + firstDimensionValue(JsonField.of(firstDimensionValue)) + + /** + * Sets [Builder.firstDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimensionValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun firstDimensionValue(firstDimensionValue: JsonField) = apply { + this.firstDimensionValue = firstDimensionValue + } - fun _json(): JsonValue? = _json + /** Scaling factor */ + fun scalingFactor(scalingFactor: String) = + scalingFactor(JsonField.of(scalingFactor)) + + /** + * Sets [Builder.scalingFactor] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactor] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun scalingFactor(scalingFactor: JsonField) = apply { + this.scalingFactor = scalingFactor + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + /** Second dimension value (optional) */ + fun secondDimensionValue(secondDimensionValue: String?) = + secondDimensionValue(JsonField.ofNullable(secondDimensionValue)) + + /** + * Sets [Builder.secondDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimensionValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun secondDimensionValue(secondDimensionValue: JsonField) = apply { + this.secondDimensionValue = secondDimensionValue + } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + /** + * Returns an immutable instance of [MatrixScalingFactor]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MatrixScalingFactor = + MatrixScalingFactor( + checkRequired("firstDimensionValue", firstDimensionValue), + checkRequired("scalingFactor", scalingFactor), + secondDimensionValue, + additionalProperties.toMutableMap(), + ) + } - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() + private var validated: Boolean = false - override fun unknown(json: JsonValue?) = 0 + fun validate(): MatrixScalingFactor = apply { + if (validated) { + return@apply } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + firstDimensionValue() + scalingFactor() + secondDimensionValue() + validated = true } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (firstDimensionValue.asKnown() == null) 0 else 1) + + (if (scalingFactor.asKnown() == null) 0 else 1) + + (if (secondDimensionValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + return other is MatrixScalingFactor && + firstDimensionValue == other.firstDimensionValue && + scalingFactor == other.scalingFactor && + secondDimensionValue == other.secondDimensionValue && + additionalProperties == other.additionalProperties } - companion object { + private val hashCode: Int by lazy { + Objects.hash( + firstDimensionValue, + scalingFactor, + secondDimensionValue, + additionalProperties, + ) + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + override fun hashCode(): Int = hashCode - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) + override fun toString() = + "MatrixScalingFactor{firstDimensionValue=$firstDimensionValue, scalingFactor=$scalingFactor, secondDimensionValue=$secondDimensionValue, additionalProperties=$additionalProperties}" } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { + /** Configuration for a single tier entry with business logic */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) - fun visitUnit(unit: UnitConversionRateConfig): T + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - fun visitTiered(tiered: TieredConversionRateConfig): T + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns the raw JSON value of [tierLowerBound]. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. * - * @throws OrbInvalidDataException in the default implementation. + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + /** A builder for [Tier]. */ + class Builder internal constructor() { - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - return ConversionRateConfig(_json = json) + 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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is ScalableMatrixWithTieredPricingConfig && + firstDimension == other.firstDimension && + matrixScalingFactors == other.matrixScalingFactors && + tiers == other.tiers && + secondDimension == other.secondDimension && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + firstDimension, + matrixScalingFactors, + tiers, + secondDimension, + additionalProperties, + ) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScalableMatrixWithTieredPricingConfig{firstDimension=$firstDimension, matrixScalingFactors=$matrixScalingFactors, tiers=$tiers, secondDimension=$secondDimension, additionalProperties=$additionalProperties}" } /** @@ -1574,12 +2124,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1591,12 +2139,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingScalableMatrixWithTieredPricingPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && scalableMatrixWithTieredPricingConfig == other.scalableMatrixWithTieredPricingConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingScalableMatrixWithTieredPricingPrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + scalableMatrixWithTieredPricingConfig == other.scalableMatrixWithTieredPricingConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, scalableMatrixWithTieredPricingConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + scalableMatrixWithTieredPricingConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithUnitPricingPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithUnitPricingPrice.kt index 2c85cf5f8..4d390fb36 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithUnitPricingPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithUnitPricingPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingScalableMatrixWithUnitPricingPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -140,6 +132,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -154,6 +148,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for scalable_matrix_with_unit_pricing pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -530,6 +526,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -552,6 +549,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for scalable_matrix_with_unit_pricing pricing */ fun scalableMatrixWithUnitPricingConfig( scalableMatrixWithUnitPricingConfig: ScalableMatrixWithUnitPricingConfig ) = scalableMatrixWithUnitPricingConfig(JsonField.of(scalableMatrixWithUnitPricingConfig)) @@ -1069,7 +1067,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1077,6 +1075,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1189,7 +1188,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1197,16 +1196,136 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for scalable_matrix_with_unit_pricing pricing */ class ScalableMatrixWithUnitPricingConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val firstDimension: JsonField, + private val matrixScalingFactors: JsonField>, + private val unitPrice: JsonField, + private val prorate: JsonField, + private val secondDimension: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("first_dimension") + @ExcludeMissing + firstDimension: JsonField = JsonMissing.of(), + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + matrixScalingFactors: JsonField> = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + @JsonProperty("prorate") @ExcludeMissing prorate: JsonField = JsonMissing.of(), + @JsonProperty("second_dimension") + @ExcludeMissing + secondDimension: JsonField = JsonMissing.of(), + ) : this( + firstDimension, + matrixScalingFactors, + unitPrice, + prorate, + secondDimension, + mutableMapOf(), + ) + + /** + * Used to determine the unit rate + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun firstDimension(): String = firstDimension.getRequired("first_dimension") + + /** + * Apply a scaling factor to each dimension + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun matrixScalingFactors(): List = + matrixScalingFactors.getRequired("matrix_scaling_factors") + + /** + * The final unit price to rate against the output of the matrix + * + * @throws OrbInvalidDataException if 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(): String = unitPrice.getRequired("unit_price") + + /** + * If true, the unit price will be prorated to the billing period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorate(): Boolean? = prorate.getNullable("prorate") + + /** + * Used to determine the unit rate (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimension(): String? = secondDimension.getNullable("second_dimension") + + /** + * Returns the raw JSON value of [firstDimension]. + * + * Unlike [firstDimension], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("first_dimension") + @ExcludeMissing + fun _firstDimension(): JsonField = firstDimension + + /** + * Returns the raw JSON value of [matrixScalingFactors]. + * + * Unlike [matrixScalingFactors], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + fun _matrixScalingFactors(): JsonField> = matrixScalingFactors + + /** + * 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 [prorate]. + * + * Unlike [prorate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorate") @ExcludeMissing fun _prorate(): JsonField = prorate + + /** + * Returns the raw JSON value of [secondDimension]. + * + * Unlike [secondDimension], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("second_dimension") + @ExcludeMissing + fun _secondDimension(): JsonField = secondDimension + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1215,6 +1334,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [ScalableMatrixWithUnitPricingConfig]. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .unitPrice() + * ``` */ fun builder() = Builder() } @@ -1222,15 +1348,117 @@ private constructor( /** A builder for [ScalableMatrixWithUnitPricingConfig]. */ class Builder internal constructor() { + private var firstDimension: JsonField? = null + private var matrixScalingFactors: JsonField>? = null + private var unitPrice: JsonField? = null + private var prorate: JsonField = JsonMissing.of() + private var secondDimension: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from( scalableMatrixWithUnitPricingConfig: ScalableMatrixWithUnitPricingConfig ) = apply { + firstDimension = scalableMatrixWithUnitPricingConfig.firstDimension + matrixScalingFactors = + scalableMatrixWithUnitPricingConfig.matrixScalingFactors.map { + it.toMutableList() + } + unitPrice = scalableMatrixWithUnitPricingConfig.unitPrice + prorate = scalableMatrixWithUnitPricingConfig.prorate + secondDimension = scalableMatrixWithUnitPricingConfig.secondDimension additionalProperties = scalableMatrixWithUnitPricingConfig.additionalProperties.toMutableMap() } + /** Used to determine the unit rate */ + fun firstDimension(firstDimension: String) = + firstDimension(JsonField.of(firstDimension)) + + /** + * Sets [Builder.firstDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun firstDimension(firstDimension: JsonField) = apply { + this.firstDimension = firstDimension + } + + /** Apply a scaling factor to each dimension */ + fun matrixScalingFactors(matrixScalingFactors: List) = + matrixScalingFactors(JsonField.of(matrixScalingFactors)) + + /** + * Sets [Builder.matrixScalingFactors] to an arbitrary JSON value. + * + * You should usually call [Builder.matrixScalingFactors] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun matrixScalingFactors(matrixScalingFactors: JsonField>) = + apply { + this.matrixScalingFactors = matrixScalingFactors.map { it.toMutableList() } + } + + /** + * Adds a single [MatrixScalingFactor] to [matrixScalingFactors]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMatrixScalingFactor(matrixScalingFactor: MatrixScalingFactor) = apply { + matrixScalingFactors = + (matrixScalingFactors ?: JsonField.of(mutableListOf())).also { + checkKnown("matrixScalingFactors", it).add(matrixScalingFactor) + } + } + + /** The final unit price to rate against the output of the matrix */ + fun unitPrice(unitPrice: String) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [String] 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 } + + /** If true, the unit price will be prorated to the billing period */ + fun prorate(prorate: Boolean?) = prorate(JsonField.ofNullable(prorate)) + + /** + * Alias for [Builder.prorate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun prorate(prorate: Boolean) = prorate(prorate as Boolean?) + + /** + * Sets [Builder.prorate] to an arbitrary JSON value. + * + * You should usually call [Builder.prorate] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prorate(prorate: JsonField) = apply { this.prorate = prorate } + + /** Used to determine the unit rate (optional) */ + fun secondDimension(secondDimension: String?) = + secondDimension(JsonField.ofNullable(secondDimension)) + + /** + * Sets [Builder.secondDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun secondDimension(secondDimension: JsonField) = apply { + this.secondDimension = secondDimension + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1254,9 +1482,27 @@ private constructor( * Returns an immutable instance of [ScalableMatrixWithUnitPricingConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .unitPrice() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): ScalableMatrixWithUnitPricingConfig = - ScalableMatrixWithUnitPricingConfig(additionalProperties.toImmutable()) + ScalableMatrixWithUnitPricingConfig( + checkRequired("firstDimension", firstDimension), + checkRequired("matrixScalingFactors", matrixScalingFactors).map { + it.toImmutable() + }, + checkRequired("unitPrice", unitPrice), + prorate, + secondDimension, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1266,6 +1512,11 @@ private constructor( return@apply } + firstDimension() + matrixScalingFactors().forEach { it.validate() } + unitPrice() + prorate() + secondDimension() validated = true } @@ -1284,193 +1535,311 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (firstDimension.asKnown() == null) 0 else 1) + + (matrixScalingFactors.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (unitPrice.asKnown() == null) 0 else 1) + + (if (prorate.asKnown() == null) 0 else 1) + + (if (secondDimension.asKnown() == null) 0 else 1) + + /** Configuration for a single matrix scaling factor */ + class MatrixScalingFactor + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val firstDimensionValue: JsonField, + private val scalingFactor: JsonField, + private val secondDimensionValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("first_dimension_value") + @ExcludeMissing + firstDimensionValue: JsonField = JsonMissing.of(), + @JsonProperty("scaling_factor") + @ExcludeMissing + scalingFactor: JsonField = JsonMissing.of(), + @JsonProperty("second_dimension_value") + @ExcludeMissing + secondDimensionValue: JsonField = JsonMissing.of(), + ) : this(firstDimensionValue, scalingFactor, secondDimensionValue, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * First dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun firstDimensionValue(): String = + firstDimensionValue.getRequired("first_dimension_value") - return /* spotless:off */ other is ScalableMatrixWithUnitPricingConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingFactor(): String = scalingFactor.getRequired("scaling_factor") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Second dimension value (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimensionValue(): String? = + secondDimensionValue.getNullable("second_dimension_value") - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [firstDimensionValue]. + * + * Unlike [firstDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("first_dimension_value") + @ExcludeMissing + fun _firstDimensionValue(): JsonField = firstDimensionValue - override fun toString() = - "ScalableMatrixWithUnitPricingConfig{additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [scalingFactor]. + * + * Unlike [scalingFactor], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_factor") + @ExcludeMissing + fun _scalingFactor(): JsonField = scalingFactor - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + /** + * Returns the raw JSON value of [secondDimensionValue]. + * + * Unlike [secondDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("second_dimension_value") + @ExcludeMissing + fun _secondDimensionValue(): JsonField = secondDimensionValue - fun unit(): UnitConversionRateConfig? = unit + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [MatrixScalingFactor]. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + */ + fun builder() = Builder() + } - fun isUnit(): Boolean = unit != null + /** A builder for [MatrixScalingFactor]. */ + class Builder internal constructor() { - fun isTiered(): Boolean = tiered != null + private var firstDimensionValue: JsonField? = null + private var scalingFactor: JsonField? = null + private var secondDimensionValue: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + internal fun from(matrixScalingFactor: MatrixScalingFactor) = apply { + firstDimensionValue = matrixScalingFactor.firstDimensionValue + scalingFactor = matrixScalingFactor.scalingFactor + secondDimensionValue = matrixScalingFactor.secondDimensionValue + additionalProperties = matrixScalingFactor.additionalProperties.toMutableMap() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** First dimension value */ + fun firstDimensionValue(firstDimensionValue: String) = + firstDimensionValue(JsonField.of(firstDimensionValue)) + + /** + * Sets [Builder.firstDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimensionValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun firstDimensionValue(firstDimensionValue: JsonField) = apply { + this.firstDimensionValue = firstDimensionValue + } - fun _json(): JsonValue? = _json + /** Scaling factor */ + fun scalingFactor(scalingFactor: String) = + scalingFactor(JsonField.of(scalingFactor)) + + /** + * Sets [Builder.scalingFactor] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactor] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun scalingFactor(scalingFactor: JsonField) = apply { + this.scalingFactor = scalingFactor + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + /** Second dimension value (optional) */ + fun secondDimensionValue(secondDimensionValue: String?) = + secondDimensionValue(JsonField.ofNullable(secondDimensionValue)) + + /** + * Sets [Builder.secondDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimensionValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun secondDimensionValue(secondDimensionValue: JsonField) = apply { + this.secondDimensionValue = secondDimensionValue + } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 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 [MatrixScalingFactor]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MatrixScalingFactor = + MatrixScalingFactor( + checkRequired("firstDimensionValue", firstDimensionValue), + checkRequired("scalingFactor", scalingFactor), + secondDimensionValue, + additionalProperties.toMutableMap(), + ) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + private var validated: Boolean = false - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun validate(): MatrixScalingFactor = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + firstDimensionValue() + scalingFactor() + secondDimensionValue() + validated = true } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + internal fun validity(): Int = + (if (firstDimensionValue.asKnown() == null) 0 else 1) + + (if (scalingFactor.asKnown() == null) 0 else 1) + + (if (secondDimensionValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MatrixScalingFactor && + firstDimensionValue == other.firstDimensionValue && + scalingFactor == other.scalingFactor && + secondDimensionValue == other.secondDimensionValue && + additionalProperties == other.additionalProperties } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + private val hashCode: Int by lazy { + Objects.hash( + firstDimensionValue, + scalingFactor, + secondDimensionValue, + additionalProperties, + ) + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + override fun hashCode(): Int = hashCode - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + override fun toString() = + "MatrixScalingFactor{firstDimensionValue=$firstDimensionValue, scalingFactor=$scalingFactor, secondDimensionValue=$secondDimensionValue, additionalProperties=$additionalProperties}" + } - return ConversionRateConfig(_json = json) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is ScalableMatrixWithUnitPricingConfig && + firstDimension == other.firstDimension && + matrixScalingFactors == other.matrixScalingFactors && + unitPrice == other.unitPrice && + prorate == other.prorate && + secondDimension == other.secondDimension && + additionalProperties == other.additionalProperties } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } + private val hashCode: Int by lazy { + Objects.hash( + firstDimension, + matrixScalingFactors, + unitPrice, + prorate, + secondDimension, + additionalProperties, + ) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScalableMatrixWithUnitPricingConfig{firstDimension=$firstDimension, matrixScalingFactors=$matrixScalingFactors, unitPrice=$unitPrice, prorate=$prorate, secondDimension=$secondDimension, additionalProperties=$additionalProperties}" } /** @@ -1565,12 +1934,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1582,12 +1949,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingScalableMatrixWithUnitPricingPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && scalableMatrixWithUnitPricingConfig == other.scalableMatrixWithUnitPricingConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingScalableMatrixWithUnitPricingPrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + scalableMatrixWithUnitPricingConfig == other.scalableMatrixWithUnitPricingConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, scalableMatrixWithUnitPricingConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + scalableMatrixWithUnitPricingConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingThresholdTotalAmountPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingThresholdTotalAmountPrice.kt index fdb7ca53f..beb755da1 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingThresholdTotalAmountPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingThresholdTotalAmountPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingThresholdTotalAmountPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,6 +131,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -153,6 +147,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for threshold_total_amount pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -525,6 +521,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -547,6 +544,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for threshold_total_amount pricing */ fun thresholdTotalAmountConfig(thresholdTotalAmountConfig: ThresholdTotalAmountConfig) = thresholdTotalAmountConfig(JsonField.of(thresholdTotalAmountConfig)) @@ -1060,7 +1058,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1068,6 +1066,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1180,7 +1179,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1188,16 +1187,67 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for threshold_total_amount pricing */ class ThresholdTotalAmountConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val consumptionTable: JsonField>, + private val prorate: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("consumption_table") + @ExcludeMissing + consumptionTable: JsonField> = JsonMissing.of(), + @JsonProperty("prorate") @ExcludeMissing prorate: JsonField = JsonMissing.of(), + ) : this(consumptionTable, prorate, mutableMapOf()) + + /** + * When the quantity consumed passes a provided threshold, the configured total will be + * charged + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun consumptionTable(): List = + consumptionTable.getRequired("consumption_table") + + /** + * If true, the unit price will be prorated to the billing period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorate(): Boolean? = prorate.getNullable("prorate") + + /** + * Returns the raw JSON value of [consumptionTable]. + * + * Unlike [consumptionTable], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("consumption_table") + @ExcludeMissing + fun _consumptionTable(): JsonField> = consumptionTable + + /** + * Returns the raw JSON value of [prorate]. + * + * Unlike [prorate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorate") @ExcludeMissing fun _prorate(): JsonField = prorate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1206,6 +1256,11 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [ThresholdTotalAmountConfig]. + * + * The following fields are required: + * ```kotlin + * .consumptionTable() + * ``` */ fun builder() = Builder() } @@ -1213,13 +1268,67 @@ private constructor( /** A builder for [ThresholdTotalAmountConfig]. */ class Builder internal constructor() { + private var consumptionTable: JsonField>? = null + private var prorate: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(thresholdTotalAmountConfig: ThresholdTotalAmountConfig) = apply { + consumptionTable = + thresholdTotalAmountConfig.consumptionTable.map { it.toMutableList() } + prorate = thresholdTotalAmountConfig.prorate additionalProperties = thresholdTotalAmountConfig.additionalProperties.toMutableMap() } + /** + * When the quantity consumed passes a provided threshold, the configured total will be + * charged + */ + fun consumptionTable(consumptionTable: List) = + consumptionTable(JsonField.of(consumptionTable)) + + /** + * Sets [Builder.consumptionTable] to an arbitrary JSON value. + * + * You should usually call [Builder.consumptionTable] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun consumptionTable(consumptionTable: JsonField>) = apply { + this.consumptionTable = consumptionTable.map { it.toMutableList() } + } + + /** + * Adds a single [ConsumptionTable] to [Builder.consumptionTable]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addConsumptionTable(consumptionTable: ConsumptionTable) = apply { + this.consumptionTable = + (this.consumptionTable ?: JsonField.of(mutableListOf())).also { + checkKnown("consumptionTable", it).add(consumptionTable) + } + } + + /** If true, the unit price will be prorated to the billing period */ + fun prorate(prorate: Boolean?) = prorate(JsonField.ofNullable(prorate)) + + /** + * Alias for [Builder.prorate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun prorate(prorate: Boolean) = prorate(prorate as Boolean?) + + /** + * Sets [Builder.prorate] to an arbitrary JSON value. + * + * You should usually call [Builder.prorate] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prorate(prorate: JsonField) = apply { this.prorate = prorate } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1243,9 +1352,20 @@ private constructor( * Returns an immutable instance of [ThresholdTotalAmountConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .consumptionTable() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): ThresholdTotalAmountConfig = - ThresholdTotalAmountConfig(additionalProperties.toImmutable()) + ThresholdTotalAmountConfig( + checkRequired("consumptionTable", consumptionTable).map { it.toImmutable() }, + prorate, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1255,6 +1375,8 @@ private constructor( return@apply } + consumptionTable().forEach { it.validate() } + prorate() validated = true } @@ -1273,193 +1395,244 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (consumptionTable.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (prorate.asKnown() == null) 0 else 1) + + /** Configuration for a single threshold */ + class ConsumptionTable + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val threshold: JsonField, + private val totalAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("threshold") + @ExcludeMissing + threshold: JsonField = JsonMissing.of(), + @JsonProperty("total_amount") + @ExcludeMissing + totalAmount: JsonField = JsonMissing.of(), + ) : this(threshold, totalAmount, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Quantity threshold + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun threshold(): String = threshold.getRequired("threshold") - return /* spotless:off */ other is ThresholdTotalAmountConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Total amount for this threshold + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun totalAmount(): String = totalAmount.getRequired("total_amount") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Returns the raw JSON value of [threshold]. + * + * Unlike [threshold], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("threshold") + @ExcludeMissing + fun _threshold(): JsonField = threshold - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [totalAmount]. + * + * Unlike [totalAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("total_amount") + @ExcludeMissing + fun _totalAmount(): JsonField = totalAmount - override fun toString() = - "ThresholdTotalAmountConfig{additionalProperties=$additionalProperties}" - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ConsumptionTable]. + * + * The following fields are required: + * ```kotlin + * .threshold() + * .totalAmount() + * ``` + */ + fun builder() = Builder() + } - fun unit(): UnitConversionRateConfig? = unit + /** A builder for [ConsumptionTable]. */ + class Builder internal constructor() { - fun tiered(): TieredConversionRateConfig? = tiered + private var threshold: JsonField? = null + private var totalAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun isUnit(): Boolean = unit != null + internal fun from(consumptionTable: ConsumptionTable) = apply { + threshold = consumptionTable.threshold + totalAmount = consumptionTable.totalAmount + additionalProperties = consumptionTable.additionalProperties.toMutableMap() + } - fun isTiered(): Boolean = tiered != null + /** Quantity threshold */ + fun threshold(threshold: String) = threshold(JsonField.of(threshold)) + + /** + * Sets [Builder.threshold] to an arbitrary JSON value. + * + * You should usually call [Builder.threshold] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun threshold(threshold: JsonField) = apply { this.threshold = threshold } + + /** Total amount for this threshold */ + fun totalAmount(totalAmount: String) = totalAmount(JsonField.of(totalAmount)) + + /** + * Sets [Builder.totalAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.totalAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun totalAmount(totalAmount: JsonField) = apply { + this.totalAmount = totalAmount + } - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun _json(): JsonValue? = _json + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - private var validated: Boolean = false + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Returns an immutable instance of [ConsumptionTable]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .threshold() + * .totalAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ConsumptionTable = + ConsumptionTable( + checkRequired("threshold", threshold), + checkRequired("totalAmount", totalAmount), + additionalProperties.toMutableMap(), + ) } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } + private var validated: Boolean = false - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun validate(): ConsumptionTable = apply { + if (validated) { + return@apply } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + threshold() + totalAmount() + validated = true } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (threshold.asKnown() == null) 0 else 1) + + (if (totalAmount.asKnown() == null) 0 else 1) - override fun unknown(json: JsonValue?) = 0 + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + return other is ConsumptionTable && + threshold == other.threshold && + totalAmount == other.totalAmount && + additionalProperties == other.additionalProperties } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + private val hashCode: Int by lazy { + Objects.hash(threshold, totalAmount, additionalProperties) } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + override fun hashCode(): Int = hashCode - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) + override fun toString() = + "ConsumptionTable{threshold=$threshold, totalAmount=$totalAmount, additionalProperties=$additionalProperties}" } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - return ConversionRateConfig(_json = json) - } + return other is ThresholdTotalAmountConfig && + consumptionTable == other.consumptionTable && + prorate == other.prorate && + additionalProperties == other.additionalProperties } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } + private val hashCode: Int by lazy { + Objects.hash(consumptionTable, prorate, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThresholdTotalAmountConfig{consumptionTable=$consumptionTable, prorate=$prorate, additionalProperties=$additionalProperties}" } /** @@ -1554,12 +1727,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1571,12 +1742,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingThresholdTotalAmountPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && thresholdTotalAmountConfig == other.thresholdTotalAmountConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingThresholdTotalAmountPrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + thresholdTotalAmountConfig == other.thresholdTotalAmountConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, thresholdTotalAmountConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + thresholdTotalAmountConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredBpsPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredBpsPrice.kt deleted file mode 100644 index 085b42ca2..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredBpsPrice.kt +++ /dev/null @@ -1,1469 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer -import com.withorb.api.core.Enum -import com.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow -import com.withorb.api.core.toImmutable -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class NewFloatingTieredBpsPrice -private constructor( - private val cadence: JsonField, - private val currency: JsonField, - private val itemId: JsonField, - private val modelType: JsonField, - private val name: JsonField, - private val tieredBpsConfig: JsonField, - private val billableMetricId: JsonField, - private val billedInAdvance: JsonField, - private val billingCycleConfiguration: JsonField, - private val conversionRate: JsonField, - private val conversionRateConfig: JsonField, - private val dimensionalPriceConfiguration: JsonField, - private val externalPriceId: JsonField, - private val fixedPriceQuantity: JsonField, - private val invoiceGroupingKey: JsonField, - private val invoicingCycleConfiguration: JsonField, - private val metadata: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), - @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), - @JsonProperty("item_id") @ExcludeMissing itemId: JsonField = JsonMissing.of(), - @JsonProperty("model_type") - @ExcludeMissing - modelType: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("tiered_bps_config") - @ExcludeMissing - tieredBpsConfig: JsonField = JsonMissing.of(), - @JsonProperty("billable_metric_id") - @ExcludeMissing - billableMetricId: JsonField = JsonMissing.of(), - @JsonProperty("billed_in_advance") - @ExcludeMissing - billedInAdvance: JsonField = JsonMissing.of(), - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - billingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate") - @ExcludeMissing - conversionRate: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate_config") - @ExcludeMissing - conversionRateConfig: JsonField = JsonMissing.of(), - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - dimensionalPriceConfiguration: JsonField = - JsonMissing.of(), - @JsonProperty("external_price_id") - @ExcludeMissing - externalPriceId: JsonField = JsonMissing.of(), - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - invoiceGroupingKey: JsonField = JsonMissing.of(), - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - invoicingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), - ) : this( - cadence, - currency, - itemId, - modelType, - name, - tieredBpsConfig, - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - mutableMapOf(), - ) - - /** - * The cadence to bill for this price on. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun cadence(): Cadence = cadence.getRequired("cadence") - - /** - * An ISO 4217 currency string for which this price is billed in. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun currency(): String = currency.getRequired("currency") - - /** - * The id of the item the price will be associated with. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun itemId(): String = itemId.getRequired("item_id") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun modelType(): ModelType = modelType.getRequired("model_type") - - /** - * The name of the price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun name(): String = name.getRequired("name") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun tieredBpsConfig(): TieredBpsConfig = tieredBpsConfig.getRequired("tiered_bps_config") - - /** - * The id of the billable metric for the price. Only needed if the price is usage-based. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is true, - * and in-arrears if this is false. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - - /** - * For custom cadence: specifies the duration of the billing period in days or months. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billingCycleConfiguration(): NewBillingCycleConfiguration? = - billingCycleConfiguration.getNullable("billing_cycle_configuration") - - /** - * The per unit conversion rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - - /** - * The configuration for the rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRateConfig(): ConversionRateConfig? = - conversionRateConfig.getNullable("conversion_rate_config") - - /** - * For dimensional price: specifies a price group and dimension values - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = - dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - - /** - * An alias for the price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - - /** - * If the Price represents a fixed cost, this represents the quantity of units applied. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") - - /** - * The property used to group this price on an invoice - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoiceGroupingKey(): String? = invoiceGroupingKey.getNullable("invoice_grouping_key") - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = - invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun metadata(): Metadata? = metadata.getNullable("metadata") - - /** - * Returns the raw JSON value of [cadence]. - * - * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence - - /** - * Returns the raw JSON value of [currency]. - * - * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency - - /** - * Returns the raw JSON value of [itemId]. - * - * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - - /** - * Returns the raw JSON value of [modelType]. - * - * Unlike [modelType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonField = modelType - - /** - * 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 [tieredBpsConfig]. - * - * Unlike [tieredBpsConfig], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("tiered_bps_config") - @ExcludeMissing - fun _tieredBpsConfig(): JsonField = tieredBpsConfig - - /** - * Returns the raw JSON value of [billableMetricId]. - * - * Unlike [billableMetricId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("billable_metric_id") - @ExcludeMissing - fun _billableMetricId(): JsonField = billableMetricId - - /** - * Returns the raw JSON value of [billedInAdvance]. - * - * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("billed_in_advance") - @ExcludeMissing - fun _billedInAdvance(): JsonField = billedInAdvance - - /** - * Returns the raw JSON value of [billingCycleConfiguration]. - * - * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - fun _billingCycleConfiguration(): JsonField = - billingCycleConfiguration - - /** - * Returns the raw JSON value of [conversionRate]. - * - * Unlike [conversionRate], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("conversion_rate") - @ExcludeMissing - fun _conversionRate(): JsonField = conversionRate - - /** - * Returns the raw JSON value of [conversionRateConfig]. - * - * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("conversion_rate_config") - @ExcludeMissing - fun _conversionRateConfig(): JsonField = conversionRateConfig - - /** - * Returns the raw JSON value of [dimensionalPriceConfiguration]. - * - * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - fun _dimensionalPriceConfiguration(): JsonField = - dimensionalPriceConfiguration - - /** - * Returns the raw JSON value of [externalPriceId]. - * - * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("external_price_id") - @ExcludeMissing - fun _externalPriceId(): JsonField = externalPriceId - - /** - * Returns the raw JSON value of [fixedPriceQuantity]. - * - * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - - /** - * Returns the raw JSON value of [invoiceGroupingKey]. - * - * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - - /** - * Returns the raw JSON value of [invoicingCycleConfiguration]. - * - * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - fun _invoicingCycleConfiguration(): JsonField = - invoicingCycleConfiguration - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - - @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 [NewFloatingTieredBpsPrice]. - * - * The following fields are required: - * ```kotlin - * .cadence() - * .currency() - * .itemId() - * .modelType() - * .name() - * .tieredBpsConfig() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [NewFloatingTieredBpsPrice]. */ - class Builder internal constructor() { - - private var cadence: JsonField? = null - private var currency: JsonField? = null - private var itemId: JsonField? = null - private var modelType: JsonField? = null - private var name: JsonField? = null - private var tieredBpsConfig: JsonField? = null - private var billableMetricId: JsonField = JsonMissing.of() - private var billedInAdvance: JsonField = JsonMissing.of() - private var billingCycleConfiguration: JsonField = - JsonMissing.of() - private var conversionRate: JsonField = JsonMissing.of() - private var conversionRateConfig: JsonField = JsonMissing.of() - private var dimensionalPriceConfiguration: JsonField = - JsonMissing.of() - private var externalPriceId: JsonField = JsonMissing.of() - private var fixedPriceQuantity: JsonField = JsonMissing.of() - private var invoiceGroupingKey: JsonField = JsonMissing.of() - private var invoicingCycleConfiguration: JsonField = - JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(newFloatingTieredBpsPrice: NewFloatingTieredBpsPrice) = apply { - cadence = newFloatingTieredBpsPrice.cadence - currency = newFloatingTieredBpsPrice.currency - itemId = newFloatingTieredBpsPrice.itemId - modelType = newFloatingTieredBpsPrice.modelType - name = newFloatingTieredBpsPrice.name - tieredBpsConfig = newFloatingTieredBpsPrice.tieredBpsConfig - billableMetricId = newFloatingTieredBpsPrice.billableMetricId - billedInAdvance = newFloatingTieredBpsPrice.billedInAdvance - billingCycleConfiguration = newFloatingTieredBpsPrice.billingCycleConfiguration - conversionRate = newFloatingTieredBpsPrice.conversionRate - conversionRateConfig = newFloatingTieredBpsPrice.conversionRateConfig - dimensionalPriceConfiguration = newFloatingTieredBpsPrice.dimensionalPriceConfiguration - externalPriceId = newFloatingTieredBpsPrice.externalPriceId - fixedPriceQuantity = newFloatingTieredBpsPrice.fixedPriceQuantity - invoiceGroupingKey = newFloatingTieredBpsPrice.invoiceGroupingKey - invoicingCycleConfiguration = newFloatingTieredBpsPrice.invoicingCycleConfiguration - metadata = newFloatingTieredBpsPrice.metadata - additionalProperties = newFloatingTieredBpsPrice.additionalProperties.toMutableMap() - } - - /** The cadence to bill for this price on. */ - fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) - - /** - * Sets [Builder.cadence] to an arbitrary JSON value. - * - * You should usually call [Builder.cadence] with a well-typed [Cadence] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun cadence(cadence: JsonField) = apply { this.cadence = cadence } - - /** An ISO 4217 currency string for which this price is billed in. */ - fun currency(currency: String) = currency(JsonField.of(currency)) - - /** - * Sets [Builder.currency] to an arbitrary JSON value. - * - * You should usually call [Builder.currency] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun currency(currency: JsonField) = apply { this.currency = currency } - - /** The id of the item the price will be associated with. */ - fun itemId(itemId: String) = itemId(JsonField.of(itemId)) - - /** - * Sets [Builder.itemId] to an arbitrary JSON value. - * - * You should usually call [Builder.itemId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun itemId(itemId: JsonField) = apply { this.itemId = itemId } - - fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) - - /** - * Sets [Builder.modelType] to an arbitrary JSON value. - * - * You should usually call [Builder.modelType] with a well-typed [ModelType] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun modelType(modelType: JsonField) = apply { this.modelType = modelType } - - /** The name of the price. */ - 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 tieredBpsConfig(tieredBpsConfig: TieredBpsConfig) = - tieredBpsConfig(JsonField.of(tieredBpsConfig)) - - /** - * Sets [Builder.tieredBpsConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.tieredBpsConfig] with a well-typed [TieredBpsConfig] - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun tieredBpsConfig(tieredBpsConfig: JsonField) = apply { - this.tieredBpsConfig = tieredBpsConfig - } - - /** The id of the billable metric for the price. Only needed if the price is usage-based. */ - fun billableMetricId(billableMetricId: String?) = - billableMetricId(JsonField.ofNullable(billableMetricId)) - - /** - * Sets [Builder.billableMetricId] to an arbitrary JSON value. - * - * You should usually call [Builder.billableMetricId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billableMetricId(billableMetricId: JsonField) = apply { - this.billableMetricId = billableMetricId - } - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is - * true, and in-arrears if this is false. - */ - fun billedInAdvance(billedInAdvance: Boolean?) = - billedInAdvance(JsonField.ofNullable(billedInAdvance)) - - /** - * Alias for [Builder.billedInAdvance]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun billedInAdvance(billedInAdvance: Boolean) = billedInAdvance(billedInAdvance as Boolean?) - - /** - * Sets [Builder.billedInAdvance] to an arbitrary JSON value. - * - * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billedInAdvance(billedInAdvance: JsonField) = apply { - this.billedInAdvance = billedInAdvance - } - - /** For custom cadence: specifies the duration of the billing period in days or months. */ - fun billingCycleConfiguration(billingCycleConfiguration: NewBillingCycleConfiguration?) = - billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) - - /** - * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.billingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun billingCycleConfiguration( - billingCycleConfiguration: JsonField - ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } - - /** The per unit conversion rate of the price currency to the invoicing currency. */ - fun conversionRate(conversionRate: Double?) = - conversionRate(JsonField.ofNullable(conversionRate)) - - /** - * Alias for [Builder.conversionRate]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun conversionRate(conversionRate: Double) = conversionRate(conversionRate as Double?) - - /** - * Sets [Builder.conversionRate] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRate] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun conversionRate(conversionRate: JsonField) = apply { - this.conversionRate = conversionRate - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = - conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) - - /** - * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRateConfig] with a well-typed - * [ConversionRateConfig] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun conversionRateConfig(conversionRateConfig: JsonField) = apply { - this.conversionRateConfig = conversionRateConfig - } - - /** Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofUnit(unit)`. */ - fun conversionRateConfig(unit: UnitConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofUnit(unit)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * UnitConversionRateConfig.builder() - * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - * .unitConfig(unitConfig) - * .build() - * ``` - */ - fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = - conversionRateConfig( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig(unitConfig) - .build() - ) - - /** - * Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofTiered(tiered)`. - */ - fun conversionRateConfig(tiered: TieredConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * TieredConversionRateConfig.builder() - * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - * .tieredConfig(tieredConfig) - * .build() - * ``` - */ - fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = - conversionRateConfig( - TieredConversionRateConfig.builder() - .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - .tieredConfig(tieredConfig) - .build() - ) - - /** For dimensional price: specifies a price group and dimension values */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? - ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) - - /** - * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed - * [NewDimensionalPriceConfiguration] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: JsonField - ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } - - /** An alias for the price. */ - fun externalPriceId(externalPriceId: String?) = - externalPriceId(JsonField.ofNullable(externalPriceId)) - - /** - * Sets [Builder.externalPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.externalPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun externalPriceId(externalPriceId: JsonField) = apply { - this.externalPriceId = externalPriceId - } - - /** If the Price represents a fixed cost, this represents the quantity of units applied. */ - fun fixedPriceQuantity(fixedPriceQuantity: Double?) = - fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) - - /** - * Alias for [Builder.fixedPriceQuantity]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun fixedPriceQuantity(fixedPriceQuantity: Double) = - fixedPriceQuantity(fixedPriceQuantity as Double?) - - /** - * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. - * - * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { - this.fixedPriceQuantity = fixedPriceQuantity - } - - /** The property used to group this price on an invoice */ - fun invoiceGroupingKey(invoiceGroupingKey: String?) = - invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) - - /** - * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceGroupingKey] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { - this.invoiceGroupingKey = invoiceGroupingKey - } - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: NewBillingCycleConfiguration? - ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) - - /** - * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: JsonField - ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by - * setting the value to `null`, and the entire metadata mapping can be cleared by setting - * `metadata` to `null`. - */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [NewFloatingTieredBpsPrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .cadence() - * .currency() - * .itemId() - * .modelType() - * .name() - * .tieredBpsConfig() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): NewFloatingTieredBpsPrice = - NewFloatingTieredBpsPrice( - checkRequired("cadence", cadence), - checkRequired("currency", currency), - checkRequired("itemId", itemId), - checkRequired("modelType", modelType), - checkRequired("name", name), - checkRequired("tieredBpsConfig", tieredBpsConfig), - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): NewFloatingTieredBpsPrice = apply { - if (validated) { - return@apply - } - - cadence().validate() - currency() - itemId() - modelType().validate() - name() - tieredBpsConfig().validate() - billableMetricId() - billedInAdvance() - billingCycleConfiguration()?.validate() - conversionRate() - conversionRateConfig()?.validate() - dimensionalPriceConfiguration()?.validate() - externalPriceId() - fixedPriceQuantity() - invoiceGroupingKey() - invoicingCycleConfiguration()?.validate() - metadata()?.validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (cadence.asKnown()?.validity() ?: 0) + - (if (currency.asKnown() == null) 0 else 1) + - (if (itemId.asKnown() == null) 0 else 1) + - (modelType.asKnown()?.validity() ?: 0) + - (if (name.asKnown() == null) 0 else 1) + - (tieredBpsConfig.asKnown()?.validity() ?: 0) + - (if (billableMetricId.asKnown() == null) 0 else 1) + - (if (billedInAdvance.asKnown() == null) 0 else 1) + - (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (if (conversionRate.asKnown() == null) 0 else 1) + - (conversionRateConfig.asKnown()?.validity() ?: 0) + - (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + - (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + - (metadata.asKnown()?.validity() ?: 0) - - /** The cadence to bill for this price on. */ - class Cadence @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 { - - val ANNUAL = of("annual") - - val SEMI_ANNUAL = of("semi_annual") - - val MONTHLY = of("monthly") - - val QUARTERLY = of("quarterly") - - val ONE_TIME = of("one_time") - - val CUSTOM = of("custom") - - fun of(value: String) = Cadence(JsonField.of(value)) - } - - /** An enum containing [Cadence]'s known values. */ - enum class Known { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - } - - /** - * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Cadence] 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 { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - /** An enum member indicating that [Cadence] 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) { - ANNUAL -> Value.ANNUAL - SEMI_ANNUAL -> Value.SEMI_ANNUAL - MONTHLY -> Value.MONTHLY - QUARTERLY -> Value.QUARTERLY - ONE_TIME -> Value.ONE_TIME - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - ANNUAL -> Known.ANNUAL - SEMI_ANNUAL -> Known.SEMI_ANNUAL - MONTHLY -> Known.MONTHLY - QUARTERLY -> Known.QUARTERLY - ONE_TIME -> Known.ONE_TIME - CUSTOM -> Known.CUSTOM - else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): Cadence = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class ModelType @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 { - - val TIERED_BPS = of("tiered_bps") - - fun of(value: String) = ModelType(JsonField.of(value)) - } - - /** An enum containing [ModelType]'s known values. */ - enum class Known { - TIERED_BPS - } - - /** - * An enum containing [ModelType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [ModelType] 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 { - TIERED_BPS, - /** - * An enum member indicating that [ModelType] 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) { - TIERED_BPS -> Value.TIERED_BPS - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - TIERED_BPS -> Known.TIERED_BPS - else -> throw OrbInvalidDataException("Unknown ModelType: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): ModelType = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - */ - class Metadata - @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 [Metadata]. */ - fun builder() = Builder() - } - - /** A builder for [Metadata]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.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 [Metadata]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is NewFloatingTieredBpsPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredBpsConfig == other.tieredBpsConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, tieredBpsConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "NewFloatingTieredBpsPrice{cadence=$cadence, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, tieredBpsConfig=$tieredBpsConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredPackagePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredPackagePrice.kt index 5eb5a458f..2536207f8 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredPackagePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredPackagePrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingTieredPackagePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,6 +131,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -153,6 +147,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for tiered_package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -518,6 +514,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -540,6 +537,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for tiered_package pricing */ fun tieredPackageConfig(tieredPackageConfig: TieredPackageConfig) = tieredPackageConfig(JsonField.of(tieredPackageConfig)) @@ -1053,7 +1051,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1061,6 +1059,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1173,7 +1172,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1181,34 +1180,142 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for tiered_package pricing */ class TieredPackageConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(packageSize, tiers, mutableMapOf()) + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. The tier bounds are defined based on the total + * quantity rather than the number of packages, so they must be multiples of the package + * size. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) companion object { - /** Returns a mutable builder for constructing an instance of [TieredPackageConfig]. */ + /** + * Returns a mutable builder for constructing an instance of [TieredPackageConfig]. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` + */ fun builder() = Builder() } /** A builder for [TieredPackageConfig]. */ class Builder internal constructor() { + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(tieredPackageConfig: TieredPackageConfig) = apply { + packageSize = tieredPackageConfig.packageSize + tiers = tieredPackageConfig.tiers.map { it.toMutableList() } additionalProperties = tieredPackageConfig.additionalProperties.toMutableMap() } + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. The tier bounds are defined based on the total + * quantity rather than the number of packages, so they must be multiples of the package + * size. + */ + 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) @@ -1232,9 +1339,21 @@ private constructor( * Returns an immutable instance of [TieredPackageConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): TieredPackageConfig = - TieredPackageConfig(additionalProperties.toImmutable()) + TieredPackageConfig( + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1244,6 +1363,8 @@ private constructor( return@apply } + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -1262,192 +1383,240 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier with business logic */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val perUnit: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("per_unit") + @ExcludeMissing + perUnit: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(perUnit, tierLowerBound, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnit(): String = perUnit.getRequired("per_unit") - return /* spotless:off */ other is TieredPackageConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Returns the raw JSON value of [perUnit]. + * + * Unlike [perUnit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("per_unit") @ExcludeMissing fun _perUnit(): JsonField = perUnit - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound - override fun toString() = "TieredPackageConfig{additionalProperties=$additionalProperties}" - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + @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: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + */ + fun builder() = Builder() + } - fun unit(): UnitConversionRateConfig? = unit + /** A builder for [Tier]. */ + class Builder internal constructor() { - fun tiered(): TieredConversionRateConfig? = tiered + private var perUnit: JsonField? = null + private var tierLowerBound: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun isUnit(): Boolean = unit != null + internal fun from(tier: Tier) = apply { + perUnit = tier.perUnit + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } - fun isTiered(): Boolean = tiered != null + /** Price per package */ + fun perUnit(perUnit: String) = perUnit(JsonField.of(perUnit)) + + /** + * Sets [Builder.perUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnit] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun perUnit(perUnit: JsonField) = apply { this.perUnit = perUnit } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun _json(): JsonValue? = _json + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - private var validated: Boolean = false + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Returns an immutable instance of [Tier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("perUnit", perUnit), + checkRequired("tierLowerBound", tierLowerBound), + additionalProperties.toMutableMap(), + ) } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } + private var validated: Boolean = false - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun validate(): Tier = apply { + if (validated) { + return@apply } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + perUnit() + tierLowerBound() + validated = true } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (perUnit.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) - override fun unknown(json: JsonValue?) = 0 + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + return other is Tier && + perUnit == other.perUnit && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + private val hashCode: Int by lazy { + Objects.hash(perUnit, tierLowerBound, additionalProperties) } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + override fun hashCode(): Int = hashCode - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) + override fun toString() = + "Tier{perUnit=$perUnit, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + return other is TieredPackageConfig && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + private val hashCode: Int by lazy { Objects.hash(packageSize, tiers, additionalProperties) } - return ConversionRateConfig(_json = json) - } - } + override fun hashCode(): Int = hashCode - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } + override fun toString() = + "TieredPackageConfig{packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } /** @@ -1542,12 +1711,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1559,12 +1726,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingTieredPackagePrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredPackageConfig == other.tieredPackageConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingTieredPackagePrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredPackageConfig == other.tieredPackageConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, tieredPackageConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + tieredPackageConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredPackageWithMinimumPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredPackageWithMinimumPrice.kt index 8054907fc..6d208f201 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredPackageWithMinimumPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredPackageWithMinimumPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingTieredPackageWithMinimumPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -140,6 +132,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -154,6 +148,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for tiered_package_with_minimum pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -527,6 +523,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -549,6 +546,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for tiered_package_with_minimum pricing */ fun tieredPackageWithMinimumConfig( tieredPackageWithMinimumConfig: TieredPackageWithMinimumConfig ) = tieredPackageWithMinimumConfig(JsonField.of(tieredPackageWithMinimumConfig)) @@ -1063,7 +1061,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1071,6 +1069,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1183,7 +1182,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1191,16 +1190,65 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for tiered_package_with_minimum pricing */ class TieredPackageWithMinimumConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(packageSize, tiers, mutableMapOf()) + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): Double = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1209,6 +1257,12 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [TieredPackageWithMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1216,14 +1270,61 @@ private constructor( /** A builder for [TieredPackageWithMinimumConfig]. */ class Builder internal constructor() { + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(tieredPackageWithMinimumConfig: TieredPackageWithMinimumConfig) = apply { + packageSize = tieredPackageWithMinimumConfig.packageSize + tiers = tieredPackageWithMinimumConfig.tiers.map { it.toMutableList() } additionalProperties = tieredPackageWithMinimumConfig.additionalProperties.toMutableMap() } + /** Package size */ + fun packageSize(packageSize: Double) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + */ + 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) @@ -1247,9 +1348,21 @@ private constructor( * Returns an immutable instance of [TieredPackageWithMinimumConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): TieredPackageWithMinimumConfig = - TieredPackageWithMinimumConfig(additionalProperties.toImmutable()) + TieredPackageWithMinimumConfig( + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1259,6 +1372,8 @@ private constructor( return@apply } + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -1277,193 +1392,286 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val minimumAmount: JsonField, + private val perUnit: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("per_unit") + @ExcludeMissing + perUnit: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(minimumAmount, perUnit, tierLowerBound, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TieredPackageWithMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Minimum amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun minimumAmount(): String = minimumAmount.getRequired("minimum_amount") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnit(): String = perUnit.getRequired("per_unit") - override fun hashCode(): Int = hashCode + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - override fun toString() = - "TieredPackageWithMinimumConfig{additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + /** + * Returns the raw JSON value of [perUnit]. + * + * Unlike [perUnit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("per_unit") @ExcludeMissing fun _perUnit(): JsonField = perUnit - fun unit(): UnitConversionRateConfig? = unit + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun isUnit(): Boolean = unit != null + @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: + * ```kotlin + * .minimumAmount() + * .perUnit() + * .tierLowerBound() + * ``` + */ + fun builder() = Builder() + } - fun isTiered(): Boolean = tiered != null + /** A builder for [Tier]. */ + class Builder internal constructor() { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + private var minimumAmount: JsonField? = null + private var perUnit: JsonField? = null + private var tierLowerBound: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + internal fun from(tier: Tier) = apply { + minimumAmount = tier.minimumAmount + perUnit = tier.perUnit + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } - fun _json(): JsonValue? = _json + /** Minimum amount */ + fun minimumAmount(minimumAmount: String) = + minimumAmount(JsonField.of(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + /** Price per package */ + fun perUnit(perUnit: String) = perUnit(JsonField.of(perUnit)) + + /** + * Sets [Builder.perUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnit] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun perUnit(perUnit: JsonField) = apply { this.perUnit = perUnit } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 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 [Tier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * .perUnit() + * .tierLowerBound() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("minimumAmount", minimumAmount), + checkRequired("perUnit", perUnit), + checkRequired("tierLowerBound", tierLowerBound), + additionalProperties.toMutableMap(), + ) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + private var validated: Boolean = false - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun validate(): Tier = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + minimumAmount() + perUnit() + tierLowerBound() + validated = true } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } + internal fun validity(): Int = + (if (minimumAmount.asKnown() == null) 0 else 1) + + (if (perUnit.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + return other is Tier && + minimumAmount == other.minimumAmount && + perUnit == other.perUnit && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + private val hashCode: Int by lazy { + Objects.hash(minimumAmount, perUnit, tierLowerBound, additionalProperties) + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + override fun hashCode(): Int = hashCode - return ConversionRateConfig(_json = json) - } + override fun toString() = + "Tier{minimumAmount=$minimumAmount, perUnit=$perUnit, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is TieredPackageWithMinimumConfig && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties } + + private val hashCode: Int by lazy { Objects.hash(packageSize, tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredPackageWithMinimumConfig{packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } /** @@ -1558,12 +1766,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1575,12 +1781,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingTieredPackageWithMinimumPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredPackageWithMinimumConfig == other.tieredPackageWithMinimumConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingTieredPackageWithMinimumPrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredPackageWithMinimumConfig == other.tieredPackageWithMinimumConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, tieredPackageWithMinimumConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + tieredPackageWithMinimumConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredPrice.kt index ce86b9aa7..88f9c93dc 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingTieredPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,6 +130,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -153,6 +146,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for tiered pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -514,6 +509,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -536,6 +532,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for tiered pricing */ fun tieredConfig(tieredConfig: TieredConfig) = tieredConfig(JsonField.of(tieredConfig)) /** @@ -1048,7 +1045,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1056,6 +1053,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1168,7 +1166,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1176,175 +1174,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1437,12 +1266,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1454,12 +1281,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingTieredPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredConfig == other.tieredConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingTieredPrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredConfig == other.tieredConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, tieredConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + tieredConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredWithMinimumPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredWithMinimumPrice.kt index 0ef8be3c8..34af1a3ab 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredWithMinimumPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredWithMinimumPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingTieredWithMinimumPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,6 +131,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -153,6 +147,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for tiered_with_minimum pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -522,6 +518,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -544,6 +541,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for tiered_with_minimum pricing */ fun tieredWithMinimumConfig(tieredWithMinimumConfig: TieredWithMinimumConfig) = tieredWithMinimumConfig(JsonField.of(tieredWithMinimumConfig)) @@ -1058,7 +1056,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1066,6 +1064,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1178,7 +1177,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1186,16 +1185,84 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for tiered_with_minimum pricing */ class TieredWithMinimumConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val tiers: JsonField>, + private val hideZeroAmountTiers: JsonField, + private val prorate: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + @JsonProperty("hide_zero_amount_tiers") + @ExcludeMissing + hideZeroAmountTiers: JsonField = JsonMissing.of(), + @JsonProperty("prorate") @ExcludeMissing prorate: JsonField = JsonMissing.of(), + ) : this(tiers, hideZeroAmountTiers, prorate, mutableMapOf()) + + /** + * Tiered pricing with a minimum amount dependent on the volume tier. Tiers are defined + * using exclusive lower bounds. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * If true, tiers with an accrued amount of 0 will not be included in the rating. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun hideZeroAmountTiers(): Boolean? = + hideZeroAmountTiers.getNullable("hide_zero_amount_tiers") + + /** + * If true, the unit price will be prorated to the billing period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorate(): Boolean? = prorate.getNullable("prorate") + + /** + * 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 + + /** + * Returns the raw JSON value of [hideZeroAmountTiers]. + * + * Unlike [hideZeroAmountTiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("hide_zero_amount_tiers") + @ExcludeMissing + fun _hideZeroAmountTiers(): JsonField = hideZeroAmountTiers + + /** + * Returns the raw JSON value of [prorate]. + * + * Unlike [prorate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorate") @ExcludeMissing fun _prorate(): JsonField = prorate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1203,6 +1270,11 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [TieredWithMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1210,12 +1282,74 @@ private constructor( /** A builder for [TieredWithMinimumConfig]. */ class Builder internal constructor() { + private var tiers: JsonField>? = null + private var hideZeroAmountTiers: JsonField = JsonMissing.of() + private var prorate: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(tieredWithMinimumConfig: TieredWithMinimumConfig) = apply { + tiers = tieredWithMinimumConfig.tiers.map { it.toMutableList() } + hideZeroAmountTiers = tieredWithMinimumConfig.hideZeroAmountTiers + prorate = tieredWithMinimumConfig.prorate additionalProperties = tieredWithMinimumConfig.additionalProperties.toMutableMap() } + /** + * Tiered pricing with a minimum amount dependent on the volume tier. Tiers are defined + * using exclusive lower bounds. + */ + 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) + } + } + + /** If true, tiers with an accrued amount of 0 will not be included in the rating. */ + fun hideZeroAmountTiers(hideZeroAmountTiers: Boolean) = + hideZeroAmountTiers(JsonField.of(hideZeroAmountTiers)) + + /** + * Sets [Builder.hideZeroAmountTiers] to an arbitrary JSON value. + * + * You should usually call [Builder.hideZeroAmountTiers] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun hideZeroAmountTiers(hideZeroAmountTiers: JsonField) = apply { + this.hideZeroAmountTiers = hideZeroAmountTiers + } + + /** If true, the unit price will be prorated to the billing period */ + fun prorate(prorate: Boolean) = prorate(JsonField.of(prorate)) + + /** + * Sets [Builder.prorate] to an arbitrary JSON value. + * + * You should usually call [Builder.prorate] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prorate(prorate: JsonField) = apply { this.prorate = prorate } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1239,9 +1373,21 @@ private constructor( * Returns an immutable instance of [TieredWithMinimumConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): TieredWithMinimumConfig = - TieredWithMinimumConfig(additionalProperties.toImmutable()) + TieredWithMinimumConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + hideZeroAmountTiers, + prorate, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1251,6 +1397,9 @@ private constructor( return@apply } + tiers().forEach { it.validate() } + hideZeroAmountTiers() + prorate() validated = true } @@ -1269,193 +1418,295 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (hideZeroAmountTiers.asKnown() == null) 0 else 1) + + (if (prorate.asKnown() == null) 0 else 1) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val minimumAmount: JsonField, + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(minimumAmount, tierLowerBound, unitAmount, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Minimum amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun minimumAmount(): String = minimumAmount.getRequired("minimum_amount") - return /* spotless:off */ other is TieredWithMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount - override fun toString() = - "TieredWithMinimumConfig{additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount - fun unit(): UnitConversionRateConfig? = unit + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @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: + * ```kotlin + * .minimumAmount() + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - fun isUnit(): Boolean = unit != null + /** A builder for [Tier]. */ + class Builder internal constructor() { - fun isTiered(): Boolean = tiered != null + private var minimumAmount: JsonField? = null + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + internal fun from(tier: Tier) = apply { + minimumAmount = tier.minimumAmount + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** Minimum amount */ + fun minimumAmount(minimumAmount: String) = + minimumAmount(JsonField.of(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } - fun _json(): JsonValue? = _json + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - override fun unknown(json: JsonValue?) = 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 [Tier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("minimumAmount", minimumAmount), + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + private var validated: Boolean = false - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun validate(): Tier = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + minimumAmount() + tierLowerBound() + unitAmount() + validated = true } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + internal fun validity(): Int = + (if (minimumAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + minimumAmount == other.minimumAmount && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + private val hashCode: Int by lazy { + Objects.hash(minimumAmount, tierLowerBound, unitAmount, additionalProperties) + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + override fun hashCode(): Int = hashCode - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + override fun toString() = + "Tier{minimumAmount=$minimumAmount, tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } - return ConversionRateConfig(_json = json) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is TieredWithMinimumConfig && + tiers == other.tiers && + hideZeroAmountTiers == other.hideZeroAmountTiers && + prorate == other.prorate && + additionalProperties == other.additionalProperties } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } + private val hashCode: Int by lazy { + Objects.hash(tiers, hideZeroAmountTiers, prorate, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithMinimumConfig{tiers=$tiers, hideZeroAmountTiers=$hideZeroAmountTiers, prorate=$prorate, additionalProperties=$additionalProperties}" } /** @@ -1550,12 +1801,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1567,12 +1816,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingTieredWithMinimumPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredWithMinimumConfig == other.tieredWithMinimumConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingTieredWithMinimumPrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredWithMinimumConfig == other.tieredWithMinimumConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, tieredWithMinimumConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + tieredWithMinimumConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredWithProrationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredWithProrationPrice.kt index 0aa206ab4..20ff69406 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredWithProrationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingTieredWithProrationPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingTieredWithProrationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,6 +131,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -153,6 +147,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for tiered_with_proration pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -525,6 +521,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -547,6 +544,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for tiered_with_proration pricing */ fun tieredWithProrationConfig(tieredWithProrationConfig: TieredWithProrationConfig) = tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) @@ -1060,7 +1058,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1068,6 +1066,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1180,7 +1179,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1188,16 +1187,43 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for tiered_with_proration pricing */ class TieredWithProrationConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Tiers for rating based on total usage quantities into the specified tier with proration + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1206,6 +1232,11 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [TieredWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1213,12 +1244,43 @@ private constructor( /** A builder for [TieredWithProrationConfig]. */ class Builder internal constructor() { + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = apply { + tiers = tieredWithProrationConfig.tiers.map { it.toMutableList() } additionalProperties = tieredWithProrationConfig.additionalProperties.toMutableMap() } + /** + * Tiers for rating based on total usage quantities into the specified tier with + * proration + */ + 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) @@ -1242,9 +1304,19 @@ private constructor( * Returns an immutable instance of [TieredWithProrationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): TieredWithProrationConfig = - TieredWithProrationConfig(additionalProperties.toImmutable()) + TieredWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1254,6 +1326,7 @@ private constructor( return@apply } + tiers().forEach { it.validate() } validated = true } @@ -1271,194 +1344,243 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + internal fun validity(): Int = (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tiered with proration tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Inclusive tier starting value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - return /* spotless:off */ other is TieredWithProrationConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount - override fun toString() = - "TieredWithProrationConfig{additionalProperties=$additionalProperties}" - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - fun unit(): UnitConversionRateConfig? = unit + /** A builder for [Tier]. */ + class Builder internal constructor() { - fun tiered(): TieredConversionRateConfig? = tiered + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun isUnit(): Boolean = unit != null + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } - fun isTiered(): Boolean = tiered != null + /** Inclusive tier starting value */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** Amount per unit */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun _json(): JsonValue? = _json + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - private var validated: Boolean = false + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + 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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } + private var validated: Boolean = false - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun validate(): Tier = apply { + if (validated) { + return@apply } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + tierLowerBound() + unitAmount() + validated = true } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) - override fun unknown(json: JsonValue?) = 0 + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + override fun hashCode(): Int = hashCode - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + return other is TieredWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } - return ConversionRateConfig(_json = json) - } - } + override fun hashCode(): Int = hashCode - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } + override fun toString() = + "TieredWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" } /** @@ -1553,12 +1675,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1570,12 +1690,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingTieredWithProrationPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredWithProrationConfig == other.tieredWithProrationConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingTieredWithProrationPrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredWithProrationConfig == other.tieredWithProrationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, tieredWithProrationConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingUnitPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingUnitPrice.kt index 804237ad4..d3bed4168 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingUnitPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingUnitPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingUnitPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,6 +130,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -153,6 +146,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for unit pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -514,6 +509,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -536,6 +532,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for unit pricing */ fun unitConfig(unitConfig: UnitConfig) = unitConfig(JsonField.of(unitConfig)) /** @@ -1046,7 +1043,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1054,6 +1051,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1166,7 +1164,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1174,175 +1172,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1435,12 +1264,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1452,12 +1279,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingUnitPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && unitConfig == other.unitConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingUnitPrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + unitConfig == other.unitConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, unitConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + unitConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingUnitWithPercentPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingUnitWithPercentPrice.kt index 99a34682d..d557569fb 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingUnitWithPercentPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingUnitWithPercentPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingUnitWithPercentPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,6 +130,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -153,6 +146,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for unit_with_percent pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -522,6 +517,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -544,6 +540,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for unit_with_percent pricing */ fun unitWithPercentConfig(unitWithPercentConfig: UnitWithPercentConfig) = unitWithPercentConfig(JsonField.of(unitWithPercentConfig)) @@ -1057,7 +1054,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1065,6 +1062,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1177,7 +1175,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1185,16 +1183,64 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for unit_with_percent pricing */ class UnitWithPercentConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val percent: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("percent") @ExcludeMissing percent: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(percent, unitAmount, mutableMapOf()) + + /** + * What percent, out of 100, of the calculated total to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun percent(): String = percent.getRequired("percent") + + /** + * Rate per unit of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("percent") @ExcludeMissing fun _percent(): JsonField = percent + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1202,6 +1248,12 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [UnitWithPercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * .unitAmount() + * ``` */ fun builder() = Builder() } @@ -1209,12 +1261,40 @@ private constructor( /** A builder for [UnitWithPercentConfig]. */ class Builder internal constructor() { + private var percent: JsonField? = null + private var unitAmount: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(unitWithPercentConfig: UnitWithPercentConfig) = apply { + percent = unitWithPercentConfig.percent + unitAmount = unitWithPercentConfig.unitAmount additionalProperties = unitWithPercentConfig.additionalProperties.toMutableMap() } + /** What percent, out of 100, of the calculated total to charge */ + fun percent(percent: String) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + /** Rate per unit of usage */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { this.unitAmount = unitAmount } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1238,9 +1318,21 @@ private constructor( * Returns an immutable instance of [UnitWithPercentConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): UnitWithPercentConfig = - UnitWithPercentConfig(additionalProperties.toImmutable()) + UnitWithPercentConfig( + checkRequired("percent", percent), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1250,6 +1342,8 @@ private constructor( return@apply } + percent() + unitAmount() validated = true } @@ -1268,193 +1362,27 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (percent.asKnown() == null) 0 else 1) + (if (unitAmount.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is UnitWithPercentConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UnitWithPercentConfig && + percent == other.percent && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(percent, unitAmount, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "UnitWithPercentConfig{additionalProperties=$additionalProperties}" - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } + "UnitWithPercentConfig{percent=$percent, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" } /** @@ -1549,12 +1477,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1566,12 +1492,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingUnitWithPercentPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && unitWithPercentConfig == other.unitWithPercentConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingUnitWithPercentPrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + unitWithPercentConfig == other.unitWithPercentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, unitWithPercentConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + unitWithPercentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingUnitWithProrationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingUnitWithProrationPrice.kt index 18b115c99..055f55045 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingUnitWithProrationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewFloatingUnitWithProrationPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewFloatingUnitWithProrationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val currency: JsonField, @@ -139,6 +130,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -153,6 +146,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for unit_with_proration pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -522,6 +517,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -544,6 +540,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for unit_with_proration pricing */ fun unitWithProrationConfig(unitWithProrationConfig: UnitWithProrationConfig) = unitWithProrationConfig(JsonField.of(unitWithProrationConfig)) @@ -1058,7 +1055,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1066,6 +1063,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1178,7 +1176,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1186,16 +1184,47 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for unit_with_proration pricing */ class UnitWithProrationConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of() + ) : this(unitAmount, mutableMapOf()) + + /** + * Rate per unit of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1203,6 +1232,11 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [UnitWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .unitAmount() + * ``` */ fun builder() = Builder() } @@ -1210,12 +1244,26 @@ private constructor( /** A builder for [UnitWithProrationConfig]. */ class Builder internal constructor() { + private var unitAmount: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(unitWithProrationConfig: UnitWithProrationConfig) = apply { + unitAmount = unitWithProrationConfig.unitAmount additionalProperties = unitWithProrationConfig.additionalProperties.toMutableMap() } + /** Rate per unit of usage */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { this.unitAmount = unitAmount } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1239,9 +1287,19 @@ private constructor( * Returns an immutable instance of [UnitWithProrationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): UnitWithProrationConfig = - UnitWithProrationConfig(additionalProperties.toImmutable()) + UnitWithProrationConfig( + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1251,6 +1309,7 @@ private constructor( return@apply } + unitAmount() validated = true } @@ -1268,194 +1327,24 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + internal fun validity(): Int = (if (unitAmount.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is UnitWithProrationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UnitWithProrationConfig && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { Objects.hash(unitAmount, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "UnitWithProrationConfig{additionalProperties=$additionalProperties}" - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } + "UnitWithProrationConfig{unitAmount=$unitAmount, additionalProperties=$additionalProperties}" } /** @@ -1550,12 +1439,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1567,12 +1454,49 @@ private constructor( return true } - return /* spotless:off */ other is NewFloatingUnitWithProrationPrice && cadence == other.cadence && currency == other.currency && itemId == other.itemId && modelType == other.modelType && name == other.name && unitWithProrationConfig == other.unitWithProrationConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewFloatingUnitWithProrationPrice && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + unitWithProrationConfig == other.unitWithProrationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, currency, itemId, modelType, name, unitWithProrationConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + unitWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewMaximum.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewMaximum.kt index 7253a46a8..eec7389a5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewMaximum.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewMaximum.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class NewMaximum +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val adjustmentType: JsonField, private val maximumAmount: JsonField, @@ -26,7 +27,7 @@ private constructor( private val appliesToItemIds: JsonField>, private val appliesToPriceIds: JsonField>, private val currency: JsonField, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val priceType: JsonField, private val additionalProperties: MutableMap, @@ -52,7 +53,7 @@ private constructor( @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -122,7 +123,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). */ - fun filters(): List? = filters.getNullable("filters") + fun filters(): List? = filters.getNullable("filters") /** * When false, this adjustment will be applied to a single price. Otherwise, it will be applied @@ -200,9 +201,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -255,7 +254,7 @@ private constructor( private var appliesToItemIds: JsonField>? = null private var appliesToPriceIds: JsonField>? = null private var currency: JsonField = JsonMissing.of() - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField = JsonMissing.of() private var priceType: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -381,25 +380,25 @@ private constructor( fun currency(currency: JsonField) = apply { this.currency = currency } /** A list of filters that determine which prices this adjustment will apply to. */ - fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -639,7 +638,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -758,7 +757,7 @@ private constructor( return true } - return /* spotless:off */ other is AppliesToAll && value == other.value /* spotless:on */ + return other is AppliesToAll && value == other.value } override fun hashCode() = value.hashCode() @@ -766,6 +765,534 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + /** If set, only prices of the specified type will have the adjustment applied. */ class PriceType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -903,7 +1430,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -916,12 +1443,33 @@ private constructor( return true } - return /* spotless:off */ other is NewMaximum && adjustmentType == other.adjustmentType && maximumAmount == other.maximumAmount && appliesToAll == other.appliesToAll && appliesToItemIds == other.appliesToItemIds && appliesToPriceIds == other.appliesToPriceIds && currency == other.currency && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && priceType == other.priceType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewMaximum && + adjustmentType == other.adjustmentType && + maximumAmount == other.maximumAmount && + appliesToAll == other.appliesToAll && + appliesToItemIds == other.appliesToItemIds && + appliesToPriceIds == other.appliesToPriceIds && + currency == other.currency && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + priceType == other.priceType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustmentType, maximumAmount, appliesToAll, appliesToItemIds, appliesToPriceIds, currency, filters, isInvoiceLevel, priceType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + adjustmentType, + maximumAmount, + appliesToAll, + appliesToItemIds, + appliesToPriceIds, + currency, + filters, + isInvoiceLevel, + priceType, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewMinimum.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewMinimum.kt index 60d82f071..5950f203c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewMinimum.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewMinimum.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class NewMinimum +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val adjustmentType: JsonField, private val itemId: JsonField, @@ -27,7 +28,7 @@ private constructor( private val appliesToItemIds: JsonField>, private val appliesToPriceIds: JsonField>, private val currency: JsonField, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val priceType: JsonField, private val additionalProperties: MutableMap, @@ -54,7 +55,7 @@ private constructor( @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -133,7 +134,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). */ - fun filters(): List? = filters.getNullable("filters") + fun filters(): List? = filters.getNullable("filters") /** * When false, this adjustment will be applied to a single price. Otherwise, it will be applied @@ -218,9 +219,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -275,7 +274,7 @@ private constructor( private var appliesToItemIds: JsonField>? = null private var appliesToPriceIds: JsonField>? = null private var currency: JsonField = JsonMissing.of() - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField = JsonMissing.of() private var priceType: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -413,25 +412,25 @@ private constructor( fun currency(currency: JsonField) = apply { this.currency = currency } /** A list of filters that determine which prices this adjustment will apply to. */ - fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -675,7 +674,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -794,7 +793,7 @@ private constructor( return true } - return /* spotless:off */ other is AppliesToAll && value == other.value /* spotless:on */ + return other is AppliesToAll && value == other.value } override fun hashCode() = value.hashCode() @@ -802,6 +801,534 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + /** If set, only prices of the specified type will have the adjustment applied. */ class PriceType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -939,7 +1466,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -952,12 +1479,35 @@ private constructor( return true } - return /* spotless:off */ other is NewMinimum && adjustmentType == other.adjustmentType && itemId == other.itemId && minimumAmount == other.minimumAmount && appliesToAll == other.appliesToAll && appliesToItemIds == other.appliesToItemIds && appliesToPriceIds == other.appliesToPriceIds && currency == other.currency && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && priceType == other.priceType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewMinimum && + adjustmentType == other.adjustmentType && + itemId == other.itemId && + minimumAmount == other.minimumAmount && + appliesToAll == other.appliesToAll && + appliesToItemIds == other.appliesToItemIds && + appliesToPriceIds == other.appliesToPriceIds && + currency == other.currency && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + priceType == other.priceType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustmentType, itemId, minimumAmount, appliesToAll, appliesToItemIds, appliesToPriceIds, currency, filters, isInvoiceLevel, priceType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + adjustmentType, + itemId, + minimumAmount, + appliesToAll, + appliesToItemIds, + appliesToPriceIds, + currency, + filters, + isInvoiceLevel, + priceType, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPercentageDiscount.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPercentageDiscount.kt index a5f87cc4e..a122b84f6 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPercentageDiscount.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPercentageDiscount.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class NewPercentageDiscount +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val adjustmentType: JsonField, private val percentageDiscount: JsonField, @@ -26,7 +27,7 @@ private constructor( private val appliesToItemIds: JsonField>, private val appliesToPriceIds: JsonField>, private val currency: JsonField, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val priceType: JsonField, private val additionalProperties: MutableMap, @@ -52,7 +53,7 @@ private constructor( @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -122,7 +123,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). */ - fun filters(): List? = filters.getNullable("filters") + fun filters(): List? = filters.getNullable("filters") /** * When false, this adjustment will be applied to a single price. Otherwise, it will be applied @@ -201,9 +202,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -256,7 +255,7 @@ private constructor( private var appliesToItemIds: JsonField>? = null private var appliesToPriceIds: JsonField>? = null private var currency: JsonField = JsonMissing.of() - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField = JsonMissing.of() private var priceType: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -383,25 +382,25 @@ private constructor( fun currency(currency: JsonField) = apply { this.currency = currency } /** A list of filters that determine which prices this adjustment will apply to. */ - fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -641,7 +640,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -760,7 +759,7 @@ private constructor( return true } - return /* spotless:off */ other is AppliesToAll && value == other.value /* spotless:on */ + return other is AppliesToAll && value == other.value } override fun hashCode() = value.hashCode() @@ -768,6 +767,534 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + /** If set, only prices of the specified type will have the adjustment applied. */ class PriceType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -905,7 +1432,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -918,12 +1445,33 @@ private constructor( return true } - return /* spotless:off */ other is NewPercentageDiscount && adjustmentType == other.adjustmentType && percentageDiscount == other.percentageDiscount && appliesToAll == other.appliesToAll && appliesToItemIds == other.appliesToItemIds && appliesToPriceIds == other.appliesToPriceIds && currency == other.currency && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && priceType == other.priceType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPercentageDiscount && + adjustmentType == other.adjustmentType && + percentageDiscount == other.percentageDiscount && + appliesToAll == other.appliesToAll && + appliesToItemIds == other.appliesToItemIds && + appliesToPriceIds == other.appliesToPriceIds && + currency == other.currency && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + priceType == other.priceType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustmentType, percentageDiscount, appliesToAll, appliesToItemIds, appliesToPriceIds, currency, filters, isInvoiceLevel, priceType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + adjustmentType, + percentageDiscount, + appliesToAll, + appliesToItemIds, + appliesToPriceIds, + currency, + filters, + isInvoiceLevel, + priceType, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBpsPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBpsPrice.kt deleted file mode 100644 index 8a2ae2166..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBpsPrice.kt +++ /dev/null @@ -1,1509 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer -import com.withorb.api.core.Enum -import com.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow -import com.withorb.api.core.toImmutable -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class NewPlanBpsPrice -private constructor( - private val bpsConfig: JsonField, - private val cadence: JsonField, - private val itemId: JsonField, - private val modelType: JsonField, - private val name: JsonField, - private val billableMetricId: JsonField, - private val billedInAdvance: JsonField, - private val billingCycleConfiguration: JsonField, - private val conversionRate: JsonField, - private val conversionRateConfig: JsonField, - private val currency: JsonField, - private val dimensionalPriceConfiguration: JsonField, - private val externalPriceId: JsonField, - private val fixedPriceQuantity: JsonField, - private val invoiceGroupingKey: JsonField, - private val invoicingCycleConfiguration: JsonField, - private val metadata: JsonField, - private val referenceId: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("bps_config") - @ExcludeMissing - bpsConfig: JsonField = JsonMissing.of(), - @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), - @JsonProperty("item_id") @ExcludeMissing itemId: JsonField = JsonMissing.of(), - @JsonProperty("model_type") - @ExcludeMissing - modelType: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("billable_metric_id") - @ExcludeMissing - billableMetricId: JsonField = JsonMissing.of(), - @JsonProperty("billed_in_advance") - @ExcludeMissing - billedInAdvance: JsonField = JsonMissing.of(), - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - billingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate") - @ExcludeMissing - conversionRate: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate_config") - @ExcludeMissing - conversionRateConfig: JsonField = JsonMissing.of(), - @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - dimensionalPriceConfiguration: JsonField = - JsonMissing.of(), - @JsonProperty("external_price_id") - @ExcludeMissing - externalPriceId: JsonField = JsonMissing.of(), - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - invoiceGroupingKey: JsonField = JsonMissing.of(), - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - invoicingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), - @JsonProperty("reference_id") - @ExcludeMissing - referenceId: JsonField = JsonMissing.of(), - ) : this( - bpsConfig, - cadence, - itemId, - modelType, - name, - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - currency, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - referenceId, - mutableMapOf(), - ) - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun bpsConfig(): BpsConfig = bpsConfig.getRequired("bps_config") - - /** - * The cadence to bill for this price on. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun cadence(): Cadence = cadence.getRequired("cadence") - - /** - * The id of the item the price will be associated with. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun itemId(): String = itemId.getRequired("item_id") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun modelType(): ModelType = modelType.getRequired("model_type") - - /** - * The name of the price. - * - * @throws OrbInvalidDataException if 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") - - /** - * The id of the billable metric for the price. Only needed if the price is usage-based. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is true, - * and in-arrears if this is false. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - - /** - * For custom cadence: specifies the duration of the billing period in days or months. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billingCycleConfiguration(): NewBillingCycleConfiguration? = - billingCycleConfiguration.getNullable("billing_cycle_configuration") - - /** - * The per unit conversion rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - - /** - * The configuration for the rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRateConfig(): ConversionRateConfig? = - conversionRateConfig.getNullable("conversion_rate_config") - - /** - * An ISO 4217 currency string, or custom pricing unit identifier, in which this price is - * billed. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun currency(): String? = currency.getNullable("currency") - - /** - * For dimensional price: specifies a price group and dimension values - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = - dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - - /** - * An alias for the price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - - /** - * If the Price represents a fixed cost, this represents the quantity of units applied. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") - - /** - * The property used to group this price on an invoice - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoiceGroupingKey(): String? = invoiceGroupingKey.getNullable("invoice_grouping_key") - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = - invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun metadata(): Metadata? = metadata.getNullable("metadata") - - /** - * A transient ID that can be used to reference this price when adding adjustments in the same - * API call. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun referenceId(): String? = referenceId.getNullable("reference_id") - - /** - * Returns the raw JSON value of [bpsConfig]. - * - * Unlike [bpsConfig], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("bps_config") @ExcludeMissing fun _bpsConfig(): JsonField = bpsConfig - - /** - * Returns the raw JSON value of [cadence]. - * - * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence - - /** - * Returns the raw JSON value of [itemId]. - * - * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - - /** - * Returns the raw JSON value of [modelType]. - * - * Unlike [modelType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonField = modelType - - /** - * 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 [billableMetricId]. - * - * Unlike [billableMetricId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("billable_metric_id") - @ExcludeMissing - fun _billableMetricId(): JsonField = billableMetricId - - /** - * Returns the raw JSON value of [billedInAdvance]. - * - * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("billed_in_advance") - @ExcludeMissing - fun _billedInAdvance(): JsonField = billedInAdvance - - /** - * Returns the raw JSON value of [billingCycleConfiguration]. - * - * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - fun _billingCycleConfiguration(): JsonField = - billingCycleConfiguration - - /** - * Returns the raw JSON value of [conversionRate]. - * - * Unlike [conversionRate], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("conversion_rate") - @ExcludeMissing - fun _conversionRate(): JsonField = conversionRate - - /** - * Returns the raw JSON value of [conversionRateConfig]. - * - * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("conversion_rate_config") - @ExcludeMissing - fun _conversionRateConfig(): JsonField = conversionRateConfig - - /** - * Returns the raw JSON value of [currency]. - * - * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency - - /** - * Returns the raw JSON value of [dimensionalPriceConfiguration]. - * - * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - fun _dimensionalPriceConfiguration(): JsonField = - dimensionalPriceConfiguration - - /** - * Returns the raw JSON value of [externalPriceId]. - * - * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("external_price_id") - @ExcludeMissing - fun _externalPriceId(): JsonField = externalPriceId - - /** - * Returns the raw JSON value of [fixedPriceQuantity]. - * - * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - - /** - * Returns the raw JSON value of [invoiceGroupingKey]. - * - * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - - /** - * Returns the raw JSON value of [invoicingCycleConfiguration]. - * - * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - fun _invoicingCycleConfiguration(): JsonField = - invoicingCycleConfiguration - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - - /** - * Returns the raw JSON value of [referenceId]. - * - * Unlike [referenceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("reference_id") - @ExcludeMissing - fun _referenceId(): JsonField = referenceId - - @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 [NewPlanBpsPrice]. - * - * The following fields are required: - * ```kotlin - * .bpsConfig() - * .cadence() - * .itemId() - * .modelType() - * .name() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [NewPlanBpsPrice]. */ - class Builder internal constructor() { - - private var bpsConfig: JsonField? = null - private var cadence: JsonField? = null - private var itemId: JsonField? = null - private var modelType: JsonField? = null - private var name: JsonField? = null - private var billableMetricId: JsonField = JsonMissing.of() - private var billedInAdvance: JsonField = JsonMissing.of() - private var billingCycleConfiguration: JsonField = - JsonMissing.of() - private var conversionRate: JsonField = JsonMissing.of() - private var conversionRateConfig: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var dimensionalPriceConfiguration: JsonField = - JsonMissing.of() - private var externalPriceId: JsonField = JsonMissing.of() - private var fixedPriceQuantity: JsonField = JsonMissing.of() - private var invoiceGroupingKey: JsonField = JsonMissing.of() - private var invoicingCycleConfiguration: JsonField = - JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var referenceId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(newPlanBpsPrice: NewPlanBpsPrice) = apply { - bpsConfig = newPlanBpsPrice.bpsConfig - cadence = newPlanBpsPrice.cadence - itemId = newPlanBpsPrice.itemId - modelType = newPlanBpsPrice.modelType - name = newPlanBpsPrice.name - billableMetricId = newPlanBpsPrice.billableMetricId - billedInAdvance = newPlanBpsPrice.billedInAdvance - billingCycleConfiguration = newPlanBpsPrice.billingCycleConfiguration - conversionRate = newPlanBpsPrice.conversionRate - conversionRateConfig = newPlanBpsPrice.conversionRateConfig - currency = newPlanBpsPrice.currency - dimensionalPriceConfiguration = newPlanBpsPrice.dimensionalPriceConfiguration - externalPriceId = newPlanBpsPrice.externalPriceId - fixedPriceQuantity = newPlanBpsPrice.fixedPriceQuantity - invoiceGroupingKey = newPlanBpsPrice.invoiceGroupingKey - invoicingCycleConfiguration = newPlanBpsPrice.invoicingCycleConfiguration - metadata = newPlanBpsPrice.metadata - referenceId = newPlanBpsPrice.referenceId - additionalProperties = newPlanBpsPrice.additionalProperties.toMutableMap() - } - - fun bpsConfig(bpsConfig: BpsConfig) = bpsConfig(JsonField.of(bpsConfig)) - - /** - * Sets [Builder.bpsConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.bpsConfig] with a well-typed [BpsConfig] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun bpsConfig(bpsConfig: JsonField) = apply { this.bpsConfig = bpsConfig } - - /** The cadence to bill for this price on. */ - fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) - - /** - * Sets [Builder.cadence] to an arbitrary JSON value. - * - * You should usually call [Builder.cadence] with a well-typed [Cadence] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun cadence(cadence: JsonField) = apply { this.cadence = cadence } - - /** The id of the item the price will be associated with. */ - fun itemId(itemId: String) = itemId(JsonField.of(itemId)) - - /** - * Sets [Builder.itemId] to an arbitrary JSON value. - * - * You should usually call [Builder.itemId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun itemId(itemId: JsonField) = apply { this.itemId = itemId } - - fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) - - /** - * Sets [Builder.modelType] to an arbitrary JSON value. - * - * You should usually call [Builder.modelType] with a well-typed [ModelType] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun modelType(modelType: JsonField) = apply { this.modelType = modelType } - - /** The name of the price. */ - 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 id of the billable metric for the price. Only needed if the price is usage-based. */ - fun billableMetricId(billableMetricId: String?) = - billableMetricId(JsonField.ofNullable(billableMetricId)) - - /** - * Sets [Builder.billableMetricId] to an arbitrary JSON value. - * - * You should usually call [Builder.billableMetricId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billableMetricId(billableMetricId: JsonField) = apply { - this.billableMetricId = billableMetricId - } - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is - * true, and in-arrears if this is false. - */ - fun billedInAdvance(billedInAdvance: Boolean?) = - billedInAdvance(JsonField.ofNullable(billedInAdvance)) - - /** - * Alias for [Builder.billedInAdvance]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun billedInAdvance(billedInAdvance: Boolean) = billedInAdvance(billedInAdvance as Boolean?) - - /** - * Sets [Builder.billedInAdvance] to an arbitrary JSON value. - * - * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billedInAdvance(billedInAdvance: JsonField) = apply { - this.billedInAdvance = billedInAdvance - } - - /** For custom cadence: specifies the duration of the billing period in days or months. */ - fun billingCycleConfiguration(billingCycleConfiguration: NewBillingCycleConfiguration?) = - billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) - - /** - * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.billingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun billingCycleConfiguration( - billingCycleConfiguration: JsonField - ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } - - /** The per unit conversion rate of the price currency to the invoicing currency. */ - fun conversionRate(conversionRate: Double?) = - conversionRate(JsonField.ofNullable(conversionRate)) - - /** - * Alias for [Builder.conversionRate]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun conversionRate(conversionRate: Double) = conversionRate(conversionRate as Double?) - - /** - * Sets [Builder.conversionRate] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRate] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun conversionRate(conversionRate: JsonField) = apply { - this.conversionRate = conversionRate - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = - conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) - - /** - * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRateConfig] with a well-typed - * [ConversionRateConfig] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun conversionRateConfig(conversionRateConfig: JsonField) = apply { - this.conversionRateConfig = conversionRateConfig - } - - /** Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofUnit(unit)`. */ - fun conversionRateConfig(unit: UnitConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofUnit(unit)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * UnitConversionRateConfig.builder() - * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - * .unitConfig(unitConfig) - * .build() - * ``` - */ - fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = - conversionRateConfig( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig(unitConfig) - .build() - ) - - /** - * Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofTiered(tiered)`. - */ - fun conversionRateConfig(tiered: TieredConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * TieredConversionRateConfig.builder() - * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - * .tieredConfig(tieredConfig) - * .build() - * ``` - */ - fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = - conversionRateConfig( - TieredConversionRateConfig.builder() - .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - .tieredConfig(tieredConfig) - .build() - ) - - /** - * An ISO 4217 currency string, or custom pricing unit identifier, in which this price is - * billed. - */ - fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) - - /** - * Sets [Builder.currency] to an arbitrary JSON value. - * - * You should usually call [Builder.currency] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun currency(currency: JsonField) = apply { this.currency = currency } - - /** For dimensional price: specifies a price group and dimension values */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? - ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) - - /** - * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed - * [NewDimensionalPriceConfiguration] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: JsonField - ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } - - /** An alias for the price. */ - fun externalPriceId(externalPriceId: String?) = - externalPriceId(JsonField.ofNullable(externalPriceId)) - - /** - * Sets [Builder.externalPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.externalPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun externalPriceId(externalPriceId: JsonField) = apply { - this.externalPriceId = externalPriceId - } - - /** If the Price represents a fixed cost, this represents the quantity of units applied. */ - fun fixedPriceQuantity(fixedPriceQuantity: Double?) = - fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) - - /** - * Alias for [Builder.fixedPriceQuantity]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun fixedPriceQuantity(fixedPriceQuantity: Double) = - fixedPriceQuantity(fixedPriceQuantity as Double?) - - /** - * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. - * - * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { - this.fixedPriceQuantity = fixedPriceQuantity - } - - /** The property used to group this price on an invoice */ - fun invoiceGroupingKey(invoiceGroupingKey: String?) = - invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) - - /** - * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceGroupingKey] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { - this.invoiceGroupingKey = invoiceGroupingKey - } - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: NewBillingCycleConfiguration? - ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) - - /** - * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: JsonField - ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by - * setting the value to `null`, and the entire metadata mapping can be cleared by setting - * `metadata` to `null`. - */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - /** - * A transient ID that can be used to reference this price when adding adjustments in the - * same API call. - */ - fun referenceId(referenceId: String?) = referenceId(JsonField.ofNullable(referenceId)) - - /** - * Sets [Builder.referenceId] to an arbitrary JSON value. - * - * You should usually call [Builder.referenceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun referenceId(referenceId: JsonField) = apply { this.referenceId = referenceId } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [NewPlanBpsPrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .bpsConfig() - * .cadence() - * .itemId() - * .modelType() - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): NewPlanBpsPrice = - NewPlanBpsPrice( - checkRequired("bpsConfig", bpsConfig), - checkRequired("cadence", cadence), - checkRequired("itemId", itemId), - checkRequired("modelType", modelType), - checkRequired("name", name), - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - currency, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - referenceId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): NewPlanBpsPrice = apply { - if (validated) { - return@apply - } - - bpsConfig().validate() - cadence().validate() - itemId() - modelType().validate() - name() - billableMetricId() - billedInAdvance() - billingCycleConfiguration()?.validate() - conversionRate() - conversionRateConfig()?.validate() - currency() - dimensionalPriceConfiguration()?.validate() - externalPriceId() - fixedPriceQuantity() - invoiceGroupingKey() - invoicingCycleConfiguration()?.validate() - metadata()?.validate() - referenceId() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (bpsConfig.asKnown()?.validity() ?: 0) + - (cadence.asKnown()?.validity() ?: 0) + - (if (itemId.asKnown() == null) 0 else 1) + - (modelType.asKnown()?.validity() ?: 0) + - (if (name.asKnown() == null) 0 else 1) + - (if (billableMetricId.asKnown() == null) 0 else 1) + - (if (billedInAdvance.asKnown() == null) 0 else 1) + - (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (if (conversionRate.asKnown() == null) 0 else 1) + - (conversionRateConfig.asKnown()?.validity() ?: 0) + - (if (currency.asKnown() == null) 0 else 1) + - (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + - (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + - (metadata.asKnown()?.validity() ?: 0) + - (if (referenceId.asKnown() == null) 0 else 1) - - /** The cadence to bill for this price on. */ - class Cadence @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 { - - val ANNUAL = of("annual") - - val SEMI_ANNUAL = of("semi_annual") - - val MONTHLY = of("monthly") - - val QUARTERLY = of("quarterly") - - val ONE_TIME = of("one_time") - - val CUSTOM = of("custom") - - fun of(value: String) = Cadence(JsonField.of(value)) - } - - /** An enum containing [Cadence]'s known values. */ - enum class Known { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - } - - /** - * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Cadence] 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 { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - /** An enum member indicating that [Cadence] 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) { - ANNUAL -> Value.ANNUAL - SEMI_ANNUAL -> Value.SEMI_ANNUAL - MONTHLY -> Value.MONTHLY - QUARTERLY -> Value.QUARTERLY - ONE_TIME -> Value.ONE_TIME - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - ANNUAL -> Known.ANNUAL - SEMI_ANNUAL -> Known.SEMI_ANNUAL - MONTHLY -> Known.MONTHLY - QUARTERLY -> Known.QUARTERLY - ONE_TIME -> Known.ONE_TIME - CUSTOM -> Known.CUSTOM - else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): Cadence = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class ModelType @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 { - - val BPS = of("bps") - - fun of(value: String) = ModelType(JsonField.of(value)) - } - - /** An enum containing [ModelType]'s known values. */ - enum class Known { - BPS - } - - /** - * An enum containing [ModelType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [ModelType] 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 { - BPS, - /** - * An enum member indicating that [ModelType] 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) { - BPS -> Value.BPS - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - BPS -> Known.BPS - else -> throw OrbInvalidDataException("Unknown ModelType: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): ModelType = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - */ - class Metadata - @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 [Metadata]. */ - fun builder() = Builder() - } - - /** A builder for [Metadata]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.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 [Metadata]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is NewPlanBpsPrice && bpsConfig == other.bpsConfig && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bpsConfig, cadence, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "NewPlanBpsPrice{bpsConfig=$bpsConfig, cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBulkPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBulkPrice.kt index e127022ba..4a73e7f90 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBulkPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBulkPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanBulkPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val bulkConfig: JsonField, private val cadence: JsonField, @@ -120,6 +111,8 @@ private constructor( ) /** + * Configuration for bulk pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -142,6 +135,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -506,6 +501,7 @@ private constructor( additionalProperties = newPlanBulkPrice.additionalProperties.toMutableMap() } + /** Configuration for bulk pricing */ fun bulkConfig(bulkConfig: BulkConfig) = bulkConfig(JsonField.of(bulkConfig)) /** @@ -539,6 +535,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1091,7 +1088,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1099,6 +1096,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1211,7 +1209,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1219,175 +1217,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1480,12 +1309,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1497,12 +1324,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanBulkPrice && bulkConfig == other.bulkConfig && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanBulkPrice && + bulkConfig == other.bulkConfig && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bulkConfig, cadence, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + bulkConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBulkWithProrationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBulkWithProrationPrice.kt index d82290f0b..8eec7d2f0 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBulkWithProrationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBulkWithProrationPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanBulkWithProrationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val bulkWithProrationConfig: JsonField, private val cadence: JsonField, @@ -120,6 +112,8 @@ private constructor( ) /** + * Configuration for bulk_with_proration pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +137,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -510,6 +506,7 @@ private constructor( additionalProperties = newPlanBulkWithProrationPrice.additionalProperties.toMutableMap() } + /** Configuration for bulk_with_proration pricing */ fun bulkWithProrationConfig(bulkWithProrationConfig: BulkWithProrationConfig) = bulkWithProrationConfig(JsonField.of(bulkWithProrationConfig)) @@ -547,6 +544,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -958,16 +956,43 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (if (referenceId.asKnown() == null) 0 else 1) + /** Configuration for bulk_with_proration pricing */ class BulkWithProrationConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -975,6 +1000,11 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [BulkWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` */ fun builder() = Builder() } @@ -982,12 +1012,40 @@ private constructor( /** A builder for [BulkWithProrationConfig]. */ class Builder internal constructor() { + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(bulkWithProrationConfig: BulkWithProrationConfig) = apply { + tiers = bulkWithProrationConfig.tiers.map { it.toMutableList() } additionalProperties = bulkWithProrationConfig.additionalProperties.toMutableMap() } + /** Bulk tiers for rating based on total usage volume */ + 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) @@ -1011,9 +1069,19 @@ private constructor( * Returns an immutable instance of [BulkWithProrationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): BulkWithProrationConfig = - BulkWithProrationConfig(additionalProperties.toImmutable()) + BulkWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1023,6 +1091,7 @@ private constructor( return@apply } + tiers().forEach { it.validate() } validated = true } @@ -1040,25 +1109,240 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + internal fun validity(): Int = (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single bulk pricing tier with proration */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Cost per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun tierLowerBound(): String? = tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Cost per unit */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is BulkWithProrationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BulkWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "BulkWithProrationConfig{additionalProperties=$additionalProperties}" + "BulkWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" } /** The cadence to bill for this price on. */ @@ -1202,7 +1486,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1210,6 +1494,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1322,7 +1607,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1330,175 +1615,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1591,12 +1707,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1608,12 +1722,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanBulkWithProrationPrice && bulkWithProrationConfig == other.bulkWithProrationConfig && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanBulkWithProrationPrice && + bulkWithProrationConfig == other.bulkWithProrationConfig && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bulkWithProrationConfig, cadence, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + bulkWithProrationConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanCumulativeGroupedBulkPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanCumulativeGroupedBulkPrice.kt index ba612ba57..58a6e2be7 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanCumulativeGroupedBulkPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanCumulativeGroupedBulkPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanCumulativeGroupedBulkPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val cumulativeGroupedBulkConfig: JsonField, @@ -128,6 +120,8 @@ private constructor( fun cadence(): Cadence = cadence.getRequired("cadence") /** + * Configuration for cumulative_grouped_bulk pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +137,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -527,6 +523,7 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + /** Configuration for cumulative_grouped_bulk pricing */ fun cumulativeGroupedBulkConfig(cumulativeGroupedBulkConfig: CumulativeGroupedBulkConfig) = cumulativeGroupedBulkConfig(JsonField.of(cumulativeGroupedBulkConfig)) @@ -552,6 +549,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1104,7 +1102,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1112,16 +1110,66 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for cumulative_grouped_bulk pricing */ class CumulativeGroupedBulkConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val dimensionValues: JsonField>, + private val group: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("dimension_values") + @ExcludeMissing + dimensionValues: JsonField> = JsonMissing.of(), + @JsonProperty("group") @ExcludeMissing group: JsonField = JsonMissing.of(), + ) : this(dimensionValues, group, mutableMapOf()) + + /** + * Each tier lower bound must have the same group of values. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dimensionValues(): List = + dimensionValues.getRequired("dimension_values") + + /** + * Grouping key name + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun group(): String = group.getRequired("group") + + /** + * Returns the raw JSON value of [dimensionValues]. + * + * Unlike [dimensionValues], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dimension_values") + @ExcludeMissing + fun _dimensionValues(): JsonField> = dimensionValues + + /** + * Returns the raw JSON value of [group]. + * + * Unlike [group], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("group") @ExcludeMissing fun _group(): JsonField = group + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1130,6 +1178,12 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [CumulativeGroupedBulkConfig]. + * + * The following fields are required: + * ```kotlin + * .dimensionValues() + * .group() + * ``` */ fun builder() = Builder() } @@ -1137,13 +1191,57 @@ private constructor( /** A builder for [CumulativeGroupedBulkConfig]. */ class Builder internal constructor() { + private var dimensionValues: JsonField>? = null + private var group: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(cumulativeGroupedBulkConfig: CumulativeGroupedBulkConfig) = apply { + dimensionValues = + cumulativeGroupedBulkConfig.dimensionValues.map { it.toMutableList() } + group = cumulativeGroupedBulkConfig.group additionalProperties = cumulativeGroupedBulkConfig.additionalProperties.toMutableMap() } + /** Each tier lower bound must have the same group of values. */ + fun dimensionValues(dimensionValues: List) = + dimensionValues(JsonField.of(dimensionValues)) + + /** + * Sets [Builder.dimensionValues] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionValues] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun dimensionValues(dimensionValues: JsonField>) = apply { + this.dimensionValues = dimensionValues.map { it.toMutableList() } + } + + /** + * Adds a single [DimensionValue] to [dimensionValues]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDimensionValue(dimensionValue: DimensionValue) = apply { + dimensionValues = + (dimensionValues ?: JsonField.of(mutableListOf())).also { + checkKnown("dimensionValues", it).add(dimensionValue) + } + } + + /** Grouping key name */ + fun group(group: String) = group(JsonField.of(group)) + + /** + * Sets [Builder.group] to an arbitrary JSON value. + * + * You should usually call [Builder.group] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun group(group: JsonField) = apply { this.group = group } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1167,9 +1265,21 @@ private constructor( * Returns an immutable instance of [CumulativeGroupedBulkConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .dimensionValues() + * .group() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): CumulativeGroupedBulkConfig = - CumulativeGroupedBulkConfig(additionalProperties.toImmutable()) + CumulativeGroupedBulkConfig( + checkRequired("dimensionValues", dimensionValues).map { it.toImmutable() }, + checkRequired("group", group), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1179,6 +1289,8 @@ private constructor( return@apply } + dimensionValues().forEach { it.validate() } + group() validated = true } @@ -1197,26 +1309,295 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (dimensionValues.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (group.asKnown() == null) 0 else 1) + + /** Configuration for a dimension value entry */ + class DimensionValue + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(groupingKey, tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Grouping key value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Unit amount for this combination + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 [DimensionValue]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [DimensionValue]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(dimensionValue: DimensionValue) = apply { + groupingKey = dimensionValue.groupingKey + tierLowerBound = dimensionValue.tierLowerBound + unitAmount = dimensionValue.unitAmount + additionalProperties = dimensionValue.additionalProperties.toMutableMap() + } + + /** Grouping key value */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Unit amount for this combination */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [DimensionValue]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DimensionValue = + DimensionValue( + checkRequired("groupingKey", groupingKey), + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): DimensionValue = apply { + if (validated) { + return@apply + } + + groupingKey() + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DimensionValue && + groupingKey == other.groupingKey && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(groupingKey, tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DimensionValue{groupingKey=$groupingKey, tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is CumulativeGroupedBulkConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CumulativeGroupedBulkConfig && + dimensionValues == other.dimensionValues && + group == other.group && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(dimensionValues, group, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "CumulativeGroupedBulkConfig{additionalProperties=$additionalProperties}" + "CumulativeGroupedBulkConfig{dimensionValues=$dimensionValues, group=$group, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1329,7 +1710,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1337,175 +1718,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1598,12 +1810,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1615,12 +1825,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanCumulativeGroupedBulkPrice && cadence == other.cadence && cumulativeGroupedBulkConfig == other.cumulativeGroupedBulkConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanCumulativeGroupedBulkPrice && + cadence == other.cadence && + cumulativeGroupedBulkConfig == other.cumulativeGroupedBulkConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, cumulativeGroupedBulkConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedBulkConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedAllocationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedAllocationPrice.kt index 1283f2ca8..142851c2e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedAllocationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedAllocationPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanGroupedAllocationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val groupedAllocationConfig: JsonField, @@ -128,6 +119,8 @@ private constructor( fun cadence(): Cadence = cadence.getRequired("cadence") /** + * Configuration for grouped_allocation pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +136,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -521,6 +516,7 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + /** Configuration for grouped_allocation pricing */ fun groupedAllocationConfig(groupedAllocationConfig: GroupedAllocationConfig) = groupedAllocationConfig(JsonField.of(groupedAllocationConfig)) @@ -547,6 +543,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1099,7 +1096,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1107,16 +1104,90 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_allocation pricing */ class GroupedAllocationConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val allocation: JsonField, + private val groupingKey: JsonField, + private val overageUnitRate: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("allocation") + @ExcludeMissing + allocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("overage_unit_rate") + @ExcludeMissing + overageUnitRate: JsonField = JsonMissing.of(), + ) : this(allocation, groupingKey, overageUnitRate, mutableMapOf()) + + /** + * Usage allocation per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun allocation(): String = allocation.getRequired("allocation") + + /** + * How to determine the groups that should each be allocated some quantity + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Unit rate for post-allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun overageUnitRate(): String = overageUnitRate.getRequired("overage_unit_rate") + + /** + * Returns the raw JSON value of [allocation]. + * + * Unlike [allocation], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allocation") + @ExcludeMissing + fun _allocation(): JsonField = allocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [overageUnitRate]. + * + * Unlike [overageUnitRate], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("overage_unit_rate") + @ExcludeMissing + fun _overageUnitRate(): JsonField = overageUnitRate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1124,6 +1195,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [GroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .groupingKey() + * .overageUnitRate() + * ``` */ fun builder() = Builder() } @@ -1131,12 +1209,59 @@ private constructor( /** A builder for [GroupedAllocationConfig]. */ class Builder internal constructor() { + private var allocation: JsonField? = null + private var groupingKey: JsonField? = null + private var overageUnitRate: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedAllocationConfig: GroupedAllocationConfig) = apply { + allocation = groupedAllocationConfig.allocation + groupingKey = groupedAllocationConfig.groupingKey + overageUnitRate = groupedAllocationConfig.overageUnitRate additionalProperties = groupedAllocationConfig.additionalProperties.toMutableMap() } + /** Usage allocation per group */ + fun allocation(allocation: String) = allocation(JsonField.of(allocation)) + + /** + * Sets [Builder.allocation] to an arbitrary JSON value. + * + * You should usually call [Builder.allocation] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun allocation(allocation: JsonField) = apply { this.allocation = allocation } + + /** How to determine the groups that should each be allocated some quantity */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Unit rate for post-allocation */ + fun overageUnitRate(overageUnitRate: String) = + overageUnitRate(JsonField.of(overageUnitRate)) + + /** + * Sets [Builder.overageUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.overageUnitRate] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun overageUnitRate(overageUnitRate: JsonField) = apply { + this.overageUnitRate = overageUnitRate + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1160,9 +1285,23 @@ private constructor( * Returns an immutable instance of [GroupedAllocationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .groupingKey() + * .overageUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedAllocationConfig = - GroupedAllocationConfig(additionalProperties.toImmutable()) + GroupedAllocationConfig( + checkRequired("allocation", allocation), + checkRequired("groupingKey", groupingKey), + checkRequired("overageUnitRate", overageUnitRate), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1172,6 +1311,9 @@ private constructor( return@apply } + allocation() + groupingKey() + overageUnitRate() validated = true } @@ -1190,26 +1332,33 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (allocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (overageUnitRate.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedAllocationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedAllocationConfig && + allocation == other.allocation && + groupingKey == other.groupingKey && + overageUnitRate == other.overageUnitRate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(allocation, groupingKey, overageUnitRate, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedAllocationConfig{additionalProperties=$additionalProperties}" + "GroupedAllocationConfig{allocation=$allocation, groupingKey=$groupingKey, overageUnitRate=$overageUnitRate, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1322,7 +1471,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1330,175 +1479,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1591,12 +1571,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1608,12 +1586,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanGroupedAllocationPrice && cadence == other.cadence && groupedAllocationConfig == other.groupedAllocationConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanGroupedAllocationPrice && + cadence == other.cadence && + groupedAllocationConfig == other.groupedAllocationConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, groupedAllocationConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedTieredPackagePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedTieredPackagePrice.kt index c7e737456..05ea0e8c9 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedTieredPackagePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedTieredPackagePrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanGroupedTieredPackagePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val groupedTieredPackageConfig: JsonField, @@ -128,6 +120,8 @@ private constructor( fun cadence(): Cadence = cadence.getRequired("cadence") /** + * Configuration for grouped_tiered_package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +137,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -527,6 +523,7 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + /** Configuration for grouped_tiered_package pricing */ fun groupedTieredPackageConfig(groupedTieredPackageConfig: GroupedTieredPackageConfig) = groupedTieredPackageConfig(JsonField.of(groupedTieredPackageConfig)) @@ -552,6 +549,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1104,7 +1102,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1112,16 +1110,86 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_tiered_package pricing */ class GroupedTieredPackageConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(groupingKey, packageSize, tiers, mutableMapOf()) + + /** + * The event property used to group before tiering + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1130,6 +1198,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [GroupedTieredPackageConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1137,13 +1212,76 @@ private constructor( /** A builder for [GroupedTieredPackageConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedTieredPackageConfig: GroupedTieredPackageConfig) = apply { + groupingKey = groupedTieredPackageConfig.groupingKey + packageSize = groupedTieredPackageConfig.packageSize + tiers = groupedTieredPackageConfig.tiers.map { it.toMutableList() } additionalProperties = groupedTieredPackageConfig.additionalProperties.toMutableMap() } + /** The event property used to group before tiering */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + */ + 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) @@ -1167,9 +1305,23 @@ private constructor( * Returns an immutable instance of [GroupedTieredPackageConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedTieredPackageConfig = - GroupedTieredPackageConfig(additionalProperties.toImmutable()) + GroupedTieredPackageConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1179,6 +1331,9 @@ private constructor( return@apply } + groupingKey() + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -1197,26 +1352,247 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val perUnit: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("per_unit") + @ExcludeMissing + perUnit: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(perUnit, tierLowerBound, mutableMapOf()) + + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnit(): String = perUnit.getRequired("per_unit") + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Returns the raw JSON value of [perUnit]. + * + * Unlike [perUnit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("per_unit") @ExcludeMissing fun _perUnit(): JsonField = perUnit + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var perUnit: JsonField? = null + private var tierLowerBound: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + perUnit = tier.perUnit + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Price per package */ + fun perUnit(perUnit: String) = perUnit(JsonField.of(perUnit)) + + /** + * Sets [Builder.perUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnit] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun perUnit(perUnit: JsonField) = apply { this.perUnit = perUnit } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("perUnit", perUnit), + checkRequired("tierLowerBound", tierLowerBound), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + perUnit() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (perUnit.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + perUnit == other.perUnit && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(perUnit, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{perUnit=$perUnit, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedTieredPackageConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedTieredPackageConfig && + groupingKey == other.groupingKey && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(groupingKey, packageSize, tiers, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedTieredPackageConfig{additionalProperties=$additionalProperties}" + "GroupedTieredPackageConfig{groupingKey=$groupingKey, packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1329,7 +1705,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1337,175 +1713,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1598,12 +1805,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1615,12 +1820,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanGroupedTieredPackagePrice && cadence == other.cadence && groupedTieredPackageConfig == other.groupedTieredPackageConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanGroupedTieredPackagePrice && + cadence == other.cadence && + groupedTieredPackageConfig == other.groupedTieredPackageConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, groupedTieredPackageConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedTieredPackageConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedTieredPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedTieredPrice.kt index ec9a01fb6..2b6bbaabc 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedTieredPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedTieredPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanGroupedTieredPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val groupedTieredConfig: JsonField, @@ -128,6 +120,8 @@ private constructor( fun cadence(): Cadence = cadence.getRequired("cadence") /** + * Configuration for grouped_tiered pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +137,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -519,6 +515,7 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + /** Configuration for grouped_tiered pricing */ fun groupedTieredConfig(groupedTieredConfig: GroupedTieredConfig) = groupedTieredConfig(JsonField.of(groupedTieredConfig)) @@ -544,6 +541,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1096,7 +1094,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1104,34 +1102,136 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_tiered pricing */ class GroupedTieredConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(groupingKey, tiers, mutableMapOf()) + + /** + * The billable metric property used to group before tiering + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Apply tiered pricing to each segment generated after grouping with the provided key + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) companion object { - /** Returns a mutable builder for constructing an instance of [GroupedTieredConfig]. */ + /** + * Returns a mutable builder for constructing an instance of [GroupedTieredConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tiers() + * ``` + */ fun builder() = Builder() } /** A builder for [GroupedTieredConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedTieredConfig: GroupedTieredConfig) = apply { + groupingKey = groupedTieredConfig.groupingKey + tiers = groupedTieredConfig.tiers.map { it.toMutableList() } additionalProperties = groupedTieredConfig.additionalProperties.toMutableMap() } + /** The billable metric property used to group before tiering */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** + * Apply tiered pricing to each segment generated after grouping with the provided key + */ + 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) @@ -1155,9 +1255,21 @@ private constructor( * Returns an immutable instance of [GroupedTieredConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedTieredConfig = - GroupedTieredConfig(additionalProperties.toImmutable()) + GroupedTieredConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1167,6 +1279,8 @@ private constructor( return@apply } + groupingKey() + tiers().forEach { it.validate() } validated = true } @@ -1185,25 +1299,248 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedTieredConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedTieredConfig && + groupingKey == other.groupingKey && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { Objects.hash(groupingKey, tiers, additionalProperties) } override fun hashCode(): Int = hashCode - override fun toString() = "GroupedTieredConfig{additionalProperties=$additionalProperties}" + override fun toString() = + "GroupedTieredConfig{groupingKey=$groupingKey, tiers=$tiers, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1316,7 +1653,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1324,175 +1661,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1585,12 +1753,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1602,12 +1768,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanGroupedTieredPrice && cadence == other.cadence && groupedTieredConfig == other.groupedTieredConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanGroupedTieredPrice && + cadence == other.cadence && + groupedTieredConfig == other.groupedTieredConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, groupedTieredConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedTieredConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedWithMeteredMinimumPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedWithMeteredMinimumPrice.kt index 4ded74694..0cc06b219 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedWithMeteredMinimumPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedWithMeteredMinimumPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanGroupedWithMeteredMinimumPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val groupedWithMeteredMinimumConfig: JsonField, @@ -129,6 +121,8 @@ private constructor( fun cadence(): Cadence = cadence.getRequired("cadence") /** + * Configuration for grouped_with_metered_minimum pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -144,6 +138,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -530,6 +526,7 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + /** Configuration for grouped_with_metered_minimum pricing */ fun groupedWithMeteredMinimumConfig( groupedWithMeteredMinimumConfig: GroupedWithMeteredMinimumConfig ) = groupedWithMeteredMinimumConfig(JsonField.of(groupedWithMeteredMinimumConfig)) @@ -556,6 +553,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1108,7 +1106,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1116,16 +1114,163 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_with_metered_minimum pricing */ class GroupedWithMeteredMinimumConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val minimumUnitAmount: JsonField, + private val pricingKey: JsonField, + private val scalingFactors: JsonField>, + private val scalingKey: JsonField, + private val unitAmounts: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("minimum_unit_amount") + @ExcludeMissing + minimumUnitAmount: JsonField = JsonMissing.of(), + @JsonProperty("pricing_key") + @ExcludeMissing + pricingKey: JsonField = JsonMissing.of(), + @JsonProperty("scaling_factors") + @ExcludeMissing + scalingFactors: JsonField> = JsonMissing.of(), + @JsonProperty("scaling_key") + @ExcludeMissing + scalingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amounts") + @ExcludeMissing + unitAmounts: JsonField> = JsonMissing.of(), + ) : this( + groupingKey, + minimumUnitAmount, + pricingKey, + scalingFactors, + scalingKey, + unitAmounts, + mutableMapOf(), + ) + + /** + * Used to partition the usage into groups. The minimum amount is applied to each group. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The minimum amount to charge per group per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun minimumUnitAmount(): String = minimumUnitAmount.getRequired("minimum_unit_amount") + + /** + * Used to determine the unit rate + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun pricingKey(): String = pricingKey.getRequired("pricing_key") + + /** + * Scale the unit rates by the scaling factor. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun scalingFactors(): List = scalingFactors.getRequired("scaling_factors") + + /** + * Used to determine the unit rate scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun scalingKey(): String = scalingKey.getRequired("scaling_key") + + /** + * Apply per unit pricing to each pricing value. The minimum amount is applied any unmatched + * usage. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmounts(): List = unitAmounts.getRequired("unit_amounts") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [minimumUnitAmount]. + * + * Unlike [minimumUnitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_unit_amount") + @ExcludeMissing + fun _minimumUnitAmount(): JsonField = minimumUnitAmount + + /** + * Returns the raw JSON value of [pricingKey]. + * + * Unlike [pricingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("pricing_key") + @ExcludeMissing + fun _pricingKey(): JsonField = pricingKey + + /** + * Returns the raw JSON value of [scalingFactors]. + * + * Unlike [scalingFactors], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_factors") + @ExcludeMissing + fun _scalingFactors(): JsonField> = scalingFactors + + /** + * Returns the raw JSON value of [scalingKey]. + * + * Unlike [scalingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("scaling_key") + @ExcludeMissing + fun _scalingKey(): JsonField = scalingKey + + /** + * Returns the raw JSON value of [unitAmounts]. + * + * Unlike [unitAmounts], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amounts") + @ExcludeMissing + fun _unitAmounts(): JsonField> = unitAmounts + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1134,6 +1279,16 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [GroupedWithMeteredMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimumUnitAmount() + * .pricingKey() + * .scalingFactors() + * .scalingKey() + * .unitAmounts() + * ``` */ fun builder() = Builder() } @@ -1141,14 +1296,139 @@ private constructor( /** A builder for [GroupedWithMeteredMinimumConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var minimumUnitAmount: JsonField? = null + private var pricingKey: JsonField? = null + private var scalingFactors: JsonField>? = null + private var scalingKey: JsonField? = null + private var unitAmounts: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedWithMeteredMinimumConfig: GroupedWithMeteredMinimumConfig) = apply { + groupingKey = groupedWithMeteredMinimumConfig.groupingKey + minimumUnitAmount = groupedWithMeteredMinimumConfig.minimumUnitAmount + pricingKey = groupedWithMeteredMinimumConfig.pricingKey + scalingFactors = + groupedWithMeteredMinimumConfig.scalingFactors.map { it.toMutableList() } + scalingKey = groupedWithMeteredMinimumConfig.scalingKey + unitAmounts = + groupedWithMeteredMinimumConfig.unitAmounts.map { it.toMutableList() } additionalProperties = groupedWithMeteredMinimumConfig.additionalProperties.toMutableMap() } + /** + * Used to partition the usage into groups. The minimum amount is applied to each group. + */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The minimum amount to charge per group per unit */ + fun minimumUnitAmount(minimumUnitAmount: String) = + minimumUnitAmount(JsonField.of(minimumUnitAmount)) + + /** + * Sets [Builder.minimumUnitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumUnitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimumUnitAmount(minimumUnitAmount: JsonField) = apply { + this.minimumUnitAmount = minimumUnitAmount + } + + /** Used to determine the unit rate */ + fun pricingKey(pricingKey: String) = pricingKey(JsonField.of(pricingKey)) + + /** + * Sets [Builder.pricingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.pricingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun pricingKey(pricingKey: JsonField) = apply { this.pricingKey = pricingKey } + + /** Scale the unit rates by the scaling factor. */ + fun scalingFactors(scalingFactors: List) = + scalingFactors(JsonField.of(scalingFactors)) + + /** + * Sets [Builder.scalingFactors] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactors] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun scalingFactors(scalingFactors: JsonField>) = apply { + this.scalingFactors = scalingFactors.map { it.toMutableList() } + } + + /** + * Adds a single [ScalingFactor] to [scalingFactors]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addScalingFactor(scalingFactor: ScalingFactor) = apply { + scalingFactors = + (scalingFactors ?: JsonField.of(mutableListOf())).also { + checkKnown("scalingFactors", it).add(scalingFactor) + } + } + + /** Used to determine the unit rate scaling factor */ + fun scalingKey(scalingKey: String) = scalingKey(JsonField.of(scalingKey)) + + /** + * Sets [Builder.scalingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun scalingKey(scalingKey: JsonField) = apply { this.scalingKey = scalingKey } + + /** + * Apply per unit pricing to each pricing value. The minimum amount is applied any + * unmatched usage. + */ + fun unitAmounts(unitAmounts: List) = unitAmounts(JsonField.of(unitAmounts)) + + /** + * Sets [Builder.unitAmounts] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmounts] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmounts(unitAmounts: JsonField>) = apply { + this.unitAmounts = unitAmounts.map { it.toMutableList() } + } + + /** + * Adds a single [UnitAmount] to [unitAmounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUnitAmount(unitAmount: UnitAmount) = apply { + unitAmounts = + (unitAmounts ?: JsonField.of(mutableListOf())).also { + checkKnown("unitAmounts", it).add(unitAmount) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1172,9 +1452,29 @@ private constructor( * Returns an immutable instance of [GroupedWithMeteredMinimumConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimumUnitAmount() + * .pricingKey() + * .scalingFactors() + * .scalingKey() + * .unitAmounts() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedWithMeteredMinimumConfig = - GroupedWithMeteredMinimumConfig(additionalProperties.toImmutable()) + GroupedWithMeteredMinimumConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("minimumUnitAmount", minimumUnitAmount), + checkRequired("pricingKey", pricingKey), + checkRequired("scalingFactors", scalingFactors).map { it.toImmutable() }, + checkRequired("scalingKey", scalingKey), + checkRequired("unitAmounts", unitAmounts).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1184,6 +1484,12 @@ private constructor( return@apply } + groupingKey() + minimumUnitAmount() + pricingKey() + scalingFactors().forEach { it.validate() } + scalingKey() + unitAmounts().forEach { it.validate() } validated = true } @@ -1202,26 +1508,484 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (minimumUnitAmount.asKnown() == null) 0 else 1) + + (if (pricingKey.asKnown() == null) 0 else 1) + + (scalingFactors.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (scalingKey.asKnown() == null) 0 else 1) + + (unitAmounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a scaling factor */ + class ScalingFactor + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val scalingFactor: JsonField, + private val scalingValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("scaling_factor") + @ExcludeMissing + scalingFactor: JsonField = JsonMissing.of(), + @JsonProperty("scaling_value") + @ExcludeMissing + scalingValue: JsonField = JsonMissing.of(), + ) : this(scalingFactor, scalingValue, mutableMapOf()) + + /** + * Scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingFactor(): String = scalingFactor.getRequired("scaling_factor") + + /** + * Scaling value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingValue(): String = scalingValue.getRequired("scaling_value") + + /** + * Returns the raw JSON value of [scalingFactor]. + * + * Unlike [scalingFactor], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_factor") + @ExcludeMissing + fun _scalingFactor(): JsonField = scalingFactor + + /** + * Returns the raw JSON value of [scalingValue]. + * + * Unlike [scalingValue], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_value") + @ExcludeMissing + fun _scalingValue(): JsonField = scalingValue + + @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 [ScalingFactor]. + * + * The following fields are required: + * ```kotlin + * .scalingFactor() + * .scalingValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ScalingFactor]. */ + class Builder internal constructor() { + + private var scalingFactor: JsonField? = null + private var scalingValue: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(scalingFactor: ScalingFactor) = apply { + this.scalingFactor = scalingFactor.scalingFactor + scalingValue = scalingFactor.scalingValue + additionalProperties = scalingFactor.additionalProperties.toMutableMap() + } + + /** Scaling factor */ + fun scalingFactor(scalingFactor: String) = + scalingFactor(JsonField.of(scalingFactor)) + + /** + * Sets [Builder.scalingFactor] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactor] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun scalingFactor(scalingFactor: JsonField) = apply { + this.scalingFactor = scalingFactor + } + + /** Scaling value */ + fun scalingValue(scalingValue: String) = scalingValue(JsonField.of(scalingValue)) + + /** + * Sets [Builder.scalingValue] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingValue] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun scalingValue(scalingValue: JsonField) = apply { + this.scalingValue = scalingValue + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ScalingFactor]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .scalingFactor() + * .scalingValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ScalingFactor = + ScalingFactor( + checkRequired("scalingFactor", scalingFactor), + checkRequired("scalingValue", scalingValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ScalingFactor = apply { + if (validated) { + return@apply + } + + scalingFactor() + scalingValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (scalingFactor.asKnown() == null) 0 else 1) + + (if (scalingValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ScalingFactor && + scalingFactor == other.scalingFactor && + scalingValue == other.scalingValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(scalingFactor, scalingValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScalingFactor{scalingFactor=$scalingFactor, scalingValue=$scalingValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a unit amount */ + class UnitAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val pricingValue: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("pricing_value") + @ExcludeMissing + pricingValue: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(pricingValue, unitAmount, mutableMapOf()) + + /** + * Pricing value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun pricingValue(): String = pricingValue.getRequired("pricing_value") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [pricingValue]. + * + * Unlike [pricingValue], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pricing_value") + @ExcludeMissing + fun _pricingValue(): JsonField = pricingValue + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 [UnitAmount]. + * + * The following fields are required: + * ```kotlin + * .pricingValue() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [UnitAmount]. */ + class Builder internal constructor() { + + private var pricingValue: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(unitAmount: UnitAmount) = apply { + pricingValue = unitAmount.pricingValue + this.unitAmount = unitAmount.unitAmount + additionalProperties = unitAmount.additionalProperties.toMutableMap() + } + + /** Pricing value */ + fun pricingValue(pricingValue: String) = pricingValue(JsonField.of(pricingValue)) + + /** + * Sets [Builder.pricingValue] to an arbitrary JSON value. + * + * You should usually call [Builder.pricingValue] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun pricingValue(pricingValue: JsonField) = apply { + this.pricingValue = pricingValue + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UnitAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .pricingValue() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnitAmount = + UnitAmount( + checkRequired("pricingValue", pricingValue), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): UnitAmount = apply { + if (validated) { + return@apply + } + + pricingValue() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (pricingValue.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnitAmount && + pricingValue == other.pricingValue && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(pricingValue, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UnitAmount{pricingValue=$pricingValue, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedWithMeteredMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedWithMeteredMinimumConfig && + groupingKey == other.groupingKey && + minimumUnitAmount == other.minimumUnitAmount && + pricingKey == other.pricingKey && + scalingFactors == other.scalingFactors && + scalingKey == other.scalingKey && + unitAmounts == other.unitAmounts && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + minimumUnitAmount, + pricingKey, + scalingFactors, + scalingKey, + unitAmounts, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedWithMeteredMinimumConfig{additionalProperties=$additionalProperties}" + "GroupedWithMeteredMinimumConfig{groupingKey=$groupingKey, minimumUnitAmount=$minimumUnitAmount, pricingKey=$pricingKey, scalingFactors=$scalingFactors, scalingKey=$scalingKey, unitAmounts=$unitAmounts, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1334,7 +2098,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1342,175 +2106,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1603,12 +2198,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1620,12 +2213,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanGroupedWithMeteredMinimumPrice && cadence == other.cadence && groupedWithMeteredMinimumConfig == other.groupedWithMeteredMinimumConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanGroupedWithMeteredMinimumPrice && + cadence == other.cadence && + groupedWithMeteredMinimumConfig == other.groupedWithMeteredMinimumConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, groupedWithMeteredMinimumConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedWithMeteredMinimumConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedWithProratedMinimumPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedWithProratedMinimumPrice.kt index 9c0d45e81..366a7d409 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedWithProratedMinimumPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanGroupedWithProratedMinimumPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanGroupedWithProratedMinimumPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val groupedWithProratedMinimumConfig: JsonField, @@ -129,6 +120,8 @@ private constructor( fun cadence(): Cadence = cadence.getRequired("cadence") /** + * Configuration for grouped_with_prorated_minimum pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -144,6 +137,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -530,6 +525,7 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + /** Configuration for grouped_with_prorated_minimum pricing */ fun groupedWithProratedMinimumConfig( groupedWithProratedMinimumConfig: GroupedWithProratedMinimumConfig ) = groupedWithProratedMinimumConfig(JsonField.of(groupedWithProratedMinimumConfig)) @@ -556,6 +552,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1108,7 +1105,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1116,16 +1113,83 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_with_prorated_minimum pricing */ class GroupedWithProratedMinimumConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val minimum: JsonField, + private val unitRate: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("minimum") @ExcludeMissing minimum: JsonField = JsonMissing.of(), + @JsonProperty("unit_rate") + @ExcludeMissing + unitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, minimum, unitRate, mutableMapOf()) + + /** + * How to determine the groups that should each have a minimum + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The minimum amount to charge per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun minimum(): String = minimum.getRequired("minimum") + + /** + * The amount to charge per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitRate(): String = unitRate.getRequired("unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [minimum]. + * + * Unlike [minimum], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("minimum") @ExcludeMissing fun _minimum(): JsonField = minimum + + /** + * Returns the raw JSON value of [unitRate]. + * + * Unlike [unitRate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_rate") @ExcludeMissing fun _unitRate(): JsonField = unitRate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1134,6 +1198,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [GroupedWithProratedMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimum() + * .unitRate() + * ``` */ fun builder() = Builder() } @@ -1141,14 +1212,58 @@ private constructor( /** A builder for [GroupedWithProratedMinimumConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var minimum: JsonField? = null + private var unitRate: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedWithProratedMinimumConfig: GroupedWithProratedMinimumConfig) = apply { + groupingKey = groupedWithProratedMinimumConfig.groupingKey + minimum = groupedWithProratedMinimumConfig.minimum + unitRate = groupedWithProratedMinimumConfig.unitRate additionalProperties = groupedWithProratedMinimumConfig.additionalProperties.toMutableMap() } + /** How to determine the groups that should each have a minimum */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The minimum amount to charge per group */ + fun minimum(minimum: String) = minimum(JsonField.of(minimum)) + + /** + * Sets [Builder.minimum] to an arbitrary JSON value. + * + * You should usually call [Builder.minimum] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimum(minimum: JsonField) = apply { this.minimum = minimum } + + /** The amount to charge per unit */ + fun unitRate(unitRate: String) = unitRate(JsonField.of(unitRate)) + + /** + * Sets [Builder.unitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRate] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun unitRate(unitRate: JsonField) = apply { this.unitRate = unitRate } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1172,9 +1287,23 @@ private constructor( * Returns an immutable instance of [GroupedWithProratedMinimumConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimum() + * .unitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedWithProratedMinimumConfig = - GroupedWithProratedMinimumConfig(additionalProperties.toImmutable()) + GroupedWithProratedMinimumConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("minimum", minimum), + checkRequired("unitRate", unitRate), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1184,6 +1313,9 @@ private constructor( return@apply } + groupingKey() + minimum() + unitRate() validated = true } @@ -1202,26 +1334,33 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (minimum.asKnown() == null) 0 else 1) + + (if (unitRate.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedWithProratedMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedWithProratedMinimumConfig && + groupingKey == other.groupingKey && + minimum == other.minimum && + unitRate == other.unitRate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(groupingKey, minimum, unitRate, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedWithProratedMinimumConfig{additionalProperties=$additionalProperties}" + "GroupedWithProratedMinimumConfig{groupingKey=$groupingKey, minimum=$minimum, unitRate=$unitRate, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1334,7 +1473,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1342,175 +1481,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1603,12 +1573,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1620,12 +1588,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanGroupedWithProratedMinimumPrice && cadence == other.cadence && groupedWithProratedMinimumConfig == other.groupedWithProratedMinimumConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanGroupedWithProratedMinimumPrice && + cadence == other.cadence && + groupedWithProratedMinimumConfig == other.groupedWithProratedMinimumConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, groupedWithProratedMinimumConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedWithProratedMinimumConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMatrixPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMatrixPrice.kt index f68a5680a..e4bfc7ad3 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMatrixPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMatrixPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanMatrixPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,12 +127,16 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * Configuration for matrix pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ fun matrixConfig(): MatrixConfig = matrixConfig.getRequired("matrix_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -528,6 +523,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for matrix pricing */ fun matrixConfig(matrixConfig: MatrixConfig) = matrixConfig(JsonField.of(matrixConfig)) /** @@ -541,6 +537,7 @@ private constructor( this.matrixConfig = matrixConfig } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1093,7 +1090,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1101,6 +1098,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1213,7 +1211,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1221,175 +1219,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1482,12 +1311,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1499,12 +1326,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanMatrixPrice && cadence == other.cadence && itemId == other.itemId && matrixConfig == other.matrixConfig && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanMatrixPrice && + cadence == other.cadence && + itemId == other.itemId && + matrixConfig == other.matrixConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, matrixConfig, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + matrixConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMatrixWithAllocationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMatrixWithAllocationPrice.kt index c11a920b3..874f616fd 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMatrixWithAllocationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMatrixWithAllocationPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanMatrixWithAllocationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * Configuration for matrix_with_allocation pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +136,8 @@ private constructor( matrixWithAllocationConfig.getRequired("matrix_with_allocation_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -538,6 +533,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for matrix_with_allocation pricing */ fun matrixWithAllocationConfig(matrixWithAllocationConfig: MatrixWithAllocationConfig) = matrixWithAllocationConfig(JsonField.of(matrixWithAllocationConfig)) @@ -552,6 +548,7 @@ private constructor( matrixWithAllocationConfig: JsonField ) = apply { this.matrixWithAllocationConfig = matrixWithAllocationConfig } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1104,7 +1101,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1112,6 +1109,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1224,7 +1222,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1232,175 +1230,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1493,12 +1322,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1510,12 +1337,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanMatrixWithAllocationPrice && cadence == other.cadence && itemId == other.itemId && matrixWithAllocationConfig == other.matrixWithAllocationConfig && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanMatrixWithAllocationPrice && + cadence == other.cadence && + itemId == other.itemId && + matrixWithAllocationConfig == other.matrixWithAllocationConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, matrixWithAllocationConfig, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + matrixWithAllocationConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMatrixWithDisplayNamePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMatrixWithDisplayNamePrice.kt index d638f8e2a..6ab4c5193 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMatrixWithDisplayNamePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMatrixWithDisplayNamePrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanMatrixWithDisplayNamePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +128,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * Configuration for matrix_with_display_name pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +137,8 @@ private constructor( matrixWithDisplayNameConfig.getRequired("matrix_with_display_name_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -538,6 +534,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for matrix_with_display_name pricing */ fun matrixWithDisplayNameConfig(matrixWithDisplayNameConfig: MatrixWithDisplayNameConfig) = matrixWithDisplayNameConfig(JsonField.of(matrixWithDisplayNameConfig)) @@ -552,6 +549,7 @@ private constructor( matrixWithDisplayNameConfig: JsonField ) = apply { this.matrixWithDisplayNameConfig = matrixWithDisplayNameConfig } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1104,7 +1102,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1112,16 +1110,66 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for matrix_with_display_name pricing */ class MatrixWithDisplayNameConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val dimension: JsonField, + private val unitAmounts: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("dimension") + @ExcludeMissing + dimension: JsonField = JsonMissing.of(), + @JsonProperty("unit_amounts") + @ExcludeMissing + unitAmounts: JsonField> = JsonMissing.of(), + ) : this(dimension, unitAmounts, mutableMapOf()) + + /** + * Used to determine the unit rate + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dimension(): String = dimension.getRequired("dimension") + + /** + * Apply per unit pricing to each dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmounts(): List = unitAmounts.getRequired("unit_amounts") + + /** + * Returns the raw JSON value of [dimension]. + * + * Unlike [dimension], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("dimension") @ExcludeMissing fun _dimension(): JsonField = dimension + + /** + * Returns the raw JSON value of [unitAmounts]. + * + * Unlike [unitAmounts], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amounts") + @ExcludeMissing + fun _unitAmounts(): JsonField> = unitAmounts + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1130,6 +1178,12 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [MatrixWithDisplayNameConfig]. + * + * The following fields are required: + * ```kotlin + * .dimension() + * .unitAmounts() + * ``` */ fun builder() = Builder() } @@ -1137,13 +1191,55 @@ private constructor( /** A builder for [MatrixWithDisplayNameConfig]. */ class Builder internal constructor() { + private var dimension: JsonField? = null + private var unitAmounts: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(matrixWithDisplayNameConfig: MatrixWithDisplayNameConfig) = apply { + dimension = matrixWithDisplayNameConfig.dimension + unitAmounts = matrixWithDisplayNameConfig.unitAmounts.map { it.toMutableList() } additionalProperties = matrixWithDisplayNameConfig.additionalProperties.toMutableMap() } + /** Used to determine the unit rate */ + fun dimension(dimension: String) = dimension(JsonField.of(dimension)) + + /** + * Sets [Builder.dimension] to an arbitrary JSON value. + * + * You should usually call [Builder.dimension] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun dimension(dimension: JsonField) = apply { this.dimension = dimension } + + /** Apply per unit pricing to each dimension value */ + fun unitAmounts(unitAmounts: List) = unitAmounts(JsonField.of(unitAmounts)) + + /** + * Sets [Builder.unitAmounts] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmounts] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmounts(unitAmounts: JsonField>) = apply { + this.unitAmounts = unitAmounts.map { it.toMutableList() } + } + + /** + * Adds a single [UnitAmount] to [unitAmounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUnitAmount(unitAmount: UnitAmount) = apply { + unitAmounts = + (unitAmounts ?: JsonField.of(mutableListOf())).also { + checkKnown("unitAmounts", it).add(unitAmount) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1167,9 +1263,21 @@ private constructor( * Returns an immutable instance of [MatrixWithDisplayNameConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .dimension() + * .unitAmounts() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): MatrixWithDisplayNameConfig = - MatrixWithDisplayNameConfig(additionalProperties.toImmutable()) + MatrixWithDisplayNameConfig( + checkRequired("dimension", dimension), + checkRequired("unitAmounts", unitAmounts).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1179,6 +1287,8 @@ private constructor( return@apply } + dimension() + unitAmounts().forEach { it.validate() } validated = true } @@ -1197,26 +1307,295 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (dimension.asKnown() == null) 0 else 1) + + (unitAmounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a unit amount item */ + class UnitAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val dimensionValue: JsonField, + private val displayName: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("dimension_value") + @ExcludeMissing + dimensionValue: JsonField = JsonMissing.of(), + @JsonProperty("display_name") + @ExcludeMissing + displayName: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(dimensionValue, displayName, unitAmount, mutableMapOf()) + + /** + * The dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun dimensionValue(): String = dimensionValue.getRequired("dimension_value") + + /** + * Display name for this dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun displayName(): String = displayName.getRequired("display_name") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [dimensionValue]. + * + * Unlike [dimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("dimension_value") + @ExcludeMissing + fun _dimensionValue(): JsonField = dimensionValue + + /** + * Returns the raw JSON value of [displayName]. + * + * Unlike [displayName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("display_name") + @ExcludeMissing + fun _displayName(): JsonField = displayName + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 [UnitAmount]. + * + * The following fields are required: + * ```kotlin + * .dimensionValue() + * .displayName() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [UnitAmount]. */ + class Builder internal constructor() { + + private var dimensionValue: JsonField? = null + private var displayName: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(unitAmount: UnitAmount) = apply { + dimensionValue = unitAmount.dimensionValue + displayName = unitAmount.displayName + this.unitAmount = unitAmount.unitAmount + additionalProperties = unitAmount.additionalProperties.toMutableMap() + } + + /** The dimension value */ + fun dimensionValue(dimensionValue: String) = + dimensionValue(JsonField.of(dimensionValue)) + + /** + * Sets [Builder.dimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionValue] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun dimensionValue(dimensionValue: JsonField) = apply { + this.dimensionValue = dimensionValue + } + + /** Display name for this dimension value */ + fun displayName(displayName: String) = displayName(JsonField.of(displayName)) + + /** + * Sets [Builder.displayName] to an arbitrary JSON value. + * + * You should usually call [Builder.displayName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun displayName(displayName: JsonField) = apply { + this.displayName = displayName + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UnitAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .dimensionValue() + * .displayName() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnitAmount = + UnitAmount( + checkRequired("dimensionValue", dimensionValue), + checkRequired("displayName", displayName), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): UnitAmount = apply { + if (validated) { + return@apply + } + + dimensionValue() + displayName() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (dimensionValue.asKnown() == null) 0 else 1) + + (if (displayName.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnitAmount && + dimensionValue == other.dimensionValue && + displayName == other.displayName && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(dimensionValue, displayName, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UnitAmount{dimensionValue=$dimensionValue, displayName=$displayName, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MatrixWithDisplayNameConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MatrixWithDisplayNameConfig && + dimension == other.dimension && + unitAmounts == other.unitAmounts && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(dimension, unitAmounts, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "MatrixWithDisplayNameConfig{additionalProperties=$additionalProperties}" + "MatrixWithDisplayNameConfig{dimension=$dimension, unitAmounts=$unitAmounts, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1329,7 +1708,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1337,175 +1716,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1598,12 +1808,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1615,12 +1823,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanMatrixWithDisplayNamePrice && cadence == other.cadence && itemId == other.itemId && matrixWithDisplayNameConfig == other.matrixWithDisplayNameConfig && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanMatrixWithDisplayNamePrice && + cadence == other.cadence && + itemId == other.itemId && + matrixWithDisplayNameConfig == other.matrixWithDisplayNameConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, matrixWithDisplayNameConfig, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + matrixWithDisplayNameConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMaxGroupTieredPackagePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMaxGroupTieredPackagePrice.kt index 14349ec29..ee0b9bc4b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMaxGroupTieredPackagePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMaxGroupTieredPackagePrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanMaxGroupTieredPackagePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +128,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * Configuration for max_group_tiered_package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +137,8 @@ private constructor( maxGroupTieredPackageConfig.getRequired("max_group_tiered_package_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -538,6 +534,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for max_group_tiered_package pricing */ fun maxGroupTieredPackageConfig(maxGroupTieredPackageConfig: MaxGroupTieredPackageConfig) = maxGroupTieredPackageConfig(JsonField.of(maxGroupTieredPackageConfig)) @@ -552,6 +549,7 @@ private constructor( maxGroupTieredPackageConfig: JsonField ) = apply { this.maxGroupTieredPackageConfig = maxGroupTieredPackageConfig } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1104,7 +1102,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1112,16 +1110,85 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for max_group_tiered_package pricing */ class MaxGroupTieredPackageConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(groupingKey, packageSize, tiers, mutableMapOf()) + + /** + * The event property used to group before tiering the group with the highest value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing to the largest group after grouping with the provided key. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1130,6 +1197,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [MaxGroupTieredPackageConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1137,13 +1211,73 @@ private constructor( /** A builder for [MaxGroupTieredPackageConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(maxGroupTieredPackageConfig: MaxGroupTieredPackageConfig) = apply { + groupingKey = maxGroupTieredPackageConfig.groupingKey + packageSize = maxGroupTieredPackageConfig.packageSize + tiers = maxGroupTieredPackageConfig.tiers.map { it.toMutableList() } additionalProperties = maxGroupTieredPackageConfig.additionalProperties.toMutableMap() } + /** The event property used to group before tiering the group with the highest value */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** Apply tiered pricing to the largest group after grouping with the provided key. */ + 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) @@ -1167,9 +1301,23 @@ private constructor( * Returns an immutable instance of [MaxGroupTieredPackageConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): MaxGroupTieredPackageConfig = - MaxGroupTieredPackageConfig(additionalProperties.toImmutable()) + MaxGroupTieredPackageConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1179,6 +1327,9 @@ private constructor( return@apply } + groupingKey() + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -1197,26 +1348,252 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MaxGroupTieredPackageConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MaxGroupTieredPackageConfig && + groupingKey == other.groupingKey && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(groupingKey, packageSize, tiers, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "MaxGroupTieredPackageConfig{additionalProperties=$additionalProperties}" + "MaxGroupTieredPackageConfig{groupingKey=$groupingKey, packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1329,7 +1706,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1337,175 +1714,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1598,12 +1806,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1615,12 +1821,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanMaxGroupTieredPackagePrice && cadence == other.cadence && itemId == other.itemId && maxGroupTieredPackageConfig == other.maxGroupTieredPackageConfig && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanMaxGroupTieredPackagePrice && + cadence == other.cadence && + itemId == other.itemId && + maxGroupTieredPackageConfig == other.maxGroupTieredPackageConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, maxGroupTieredPackageConfig, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + maxGroupTieredPackageConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBulkBpsPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMinimumCompositePrice.kt similarity index 79% rename from orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBulkBpsPrice.kt rename to orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMinimumCompositePrice.kt index 518ea20f4..459349ce0 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBulkBpsPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanMinimumCompositePrice.kt @@ -6,32 +6,23 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects -class NewSubscriptionBulkBpsPrice +class NewPlanMinimumCompositePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val bulkBpsConfig: JsonField, private val cadence: JsonField, private val itemId: JsonField, + private val minimumConfig: JsonField, private val modelType: JsonField, private val name: JsonField, private val billableMetricId: JsonField, @@ -52,11 +43,11 @@ private constructor( @JsonCreator private constructor( - @JsonProperty("bulk_bps_config") - @ExcludeMissing - bulkBpsConfig: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), @JsonProperty("item_id") @ExcludeMissing itemId: JsonField = JsonMissing.of(), + @JsonProperty("minimum_config") + @ExcludeMissing + minimumConfig: JsonField = JsonMissing.of(), @JsonProperty("model_type") @ExcludeMissing modelType: JsonField = JsonMissing.of(), @@ -98,9 +89,9 @@ private constructor( @ExcludeMissing referenceId: JsonField = JsonMissing.of(), ) : this( - bulkBpsConfig, cadence, itemId, + minimumConfig, modelType, name, billableMetricId, @@ -120,28 +111,32 @@ private constructor( ) /** + * The cadence to bill for this price on. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun bulkBpsConfig(): BulkBpsConfig = bulkBpsConfig.getRequired("bulk_bps_config") + fun cadence(): Cadence = cadence.getRequired("cadence") /** - * The cadence to bill for this price on. + * The id of the item the price will be associated with. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun cadence(): Cadence = cadence.getRequired("cadence") + fun itemId(): String = itemId.getRequired("item_id") /** - * The id of the item the price will be associated with. + * Configuration for minimum pricing * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun itemId(): String = itemId.getRequired("item_id") + fun minimumConfig(): MinimumConfig = minimumConfig.getRequired("minimum_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -269,15 +264,6 @@ private constructor( */ fun referenceId(): String? = referenceId.getNullable("reference_id") - /** - * Returns the raw JSON value of [bulkBpsConfig]. - * - * Unlike [bulkBpsConfig], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("bulk_bps_config") - @ExcludeMissing - fun _bulkBpsConfig(): JsonField = bulkBpsConfig - /** * Returns the raw JSON value of [cadence]. * @@ -292,6 +278,15 @@ private constructor( */ @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + /** + * Returns the raw JSON value of [minimumConfig]. + * + * Unlike [minimumConfig], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("minimum_config") + @ExcludeMissing + fun _minimumConfig(): JsonField = minimumConfig + /** * Returns the raw JSON value of [modelType]. * @@ -444,13 +439,13 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [NewSubscriptionBulkBpsPrice]. + * Returns a mutable builder for constructing an instance of [NewPlanMinimumCompositePrice]. * * The following fields are required: * ```kotlin - * .bulkBpsConfig() * .cadence() * .itemId() + * .minimumConfig() * .modelType() * .name() * ``` @@ -458,12 +453,12 @@ private constructor( fun builder() = Builder() } - /** A builder for [NewSubscriptionBulkBpsPrice]. */ + /** A builder for [NewPlanMinimumCompositePrice]. */ class Builder internal constructor() { - private var bulkBpsConfig: JsonField? = null private var cadence: JsonField? = null private var itemId: JsonField? = null + private var minimumConfig: JsonField? = null private var modelType: JsonField? = null private var name: JsonField? = null private var billableMetricId: JsonField = JsonMissing.of() @@ -484,40 +479,27 @@ private constructor( private var referenceId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(newSubscriptionBulkBpsPrice: NewSubscriptionBulkBpsPrice) = apply { - bulkBpsConfig = newSubscriptionBulkBpsPrice.bulkBpsConfig - cadence = newSubscriptionBulkBpsPrice.cadence - itemId = newSubscriptionBulkBpsPrice.itemId - modelType = newSubscriptionBulkBpsPrice.modelType - name = newSubscriptionBulkBpsPrice.name - billableMetricId = newSubscriptionBulkBpsPrice.billableMetricId - billedInAdvance = newSubscriptionBulkBpsPrice.billedInAdvance - billingCycleConfiguration = newSubscriptionBulkBpsPrice.billingCycleConfiguration - conversionRate = newSubscriptionBulkBpsPrice.conversionRate - conversionRateConfig = newSubscriptionBulkBpsPrice.conversionRateConfig - currency = newSubscriptionBulkBpsPrice.currency + internal fun from(newPlanMinimumCompositePrice: NewPlanMinimumCompositePrice) = apply { + cadence = newPlanMinimumCompositePrice.cadence + itemId = newPlanMinimumCompositePrice.itemId + minimumConfig = newPlanMinimumCompositePrice.minimumConfig + modelType = newPlanMinimumCompositePrice.modelType + name = newPlanMinimumCompositePrice.name + billableMetricId = newPlanMinimumCompositePrice.billableMetricId + billedInAdvance = newPlanMinimumCompositePrice.billedInAdvance + billingCycleConfiguration = newPlanMinimumCompositePrice.billingCycleConfiguration + conversionRate = newPlanMinimumCompositePrice.conversionRate + conversionRateConfig = newPlanMinimumCompositePrice.conversionRateConfig + currency = newPlanMinimumCompositePrice.currency dimensionalPriceConfiguration = - newSubscriptionBulkBpsPrice.dimensionalPriceConfiguration - externalPriceId = newSubscriptionBulkBpsPrice.externalPriceId - fixedPriceQuantity = newSubscriptionBulkBpsPrice.fixedPriceQuantity - invoiceGroupingKey = newSubscriptionBulkBpsPrice.invoiceGroupingKey - invoicingCycleConfiguration = newSubscriptionBulkBpsPrice.invoicingCycleConfiguration - metadata = newSubscriptionBulkBpsPrice.metadata - referenceId = newSubscriptionBulkBpsPrice.referenceId - additionalProperties = newSubscriptionBulkBpsPrice.additionalProperties.toMutableMap() - } - - fun bulkBpsConfig(bulkBpsConfig: BulkBpsConfig) = bulkBpsConfig(JsonField.of(bulkBpsConfig)) - - /** - * Sets [Builder.bulkBpsConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.bulkBpsConfig] with a well-typed [BulkBpsConfig] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun bulkBpsConfig(bulkBpsConfig: JsonField) = apply { - this.bulkBpsConfig = bulkBpsConfig + newPlanMinimumCompositePrice.dimensionalPriceConfiguration + externalPriceId = newPlanMinimumCompositePrice.externalPriceId + fixedPriceQuantity = newPlanMinimumCompositePrice.fixedPriceQuantity + invoiceGroupingKey = newPlanMinimumCompositePrice.invoiceGroupingKey + invoicingCycleConfiguration = newPlanMinimumCompositePrice.invoicingCycleConfiguration + metadata = newPlanMinimumCompositePrice.metadata + referenceId = newPlanMinimumCompositePrice.referenceId + additionalProperties = newPlanMinimumCompositePrice.additionalProperties.toMutableMap() } /** The cadence to bill for this price on. */ @@ -542,6 +524,21 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for minimum pricing */ + fun minimumConfig(minimumConfig: MinimumConfig) = minimumConfig(JsonField.of(minimumConfig)) + + /** + * Sets [Builder.minimumConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumConfig] with a well-typed [MinimumConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimumConfig(minimumConfig: JsonField) = apply { + this.minimumConfig = minimumConfig + } + + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -853,26 +850,26 @@ private constructor( } /** - * Returns an immutable instance of [NewSubscriptionBulkBpsPrice]. + * Returns an immutable instance of [NewPlanMinimumCompositePrice]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```kotlin - * .bulkBpsConfig() * .cadence() * .itemId() + * .minimumConfig() * .modelType() * .name() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): NewSubscriptionBulkBpsPrice = - NewSubscriptionBulkBpsPrice( - checkRequired("bulkBpsConfig", bulkBpsConfig), + fun build(): NewPlanMinimumCompositePrice = + NewPlanMinimumCompositePrice( checkRequired("cadence", cadence), checkRequired("itemId", itemId), + checkRequired("minimumConfig", minimumConfig), checkRequired("modelType", modelType), checkRequired("name", name), billableMetricId, @@ -894,14 +891,14 @@ private constructor( private var validated: Boolean = false - fun validate(): NewSubscriptionBulkBpsPrice = apply { + fun validate(): NewPlanMinimumCompositePrice = apply { if (validated) { return@apply } - bulkBpsConfig().validate() cadence().validate() itemId() + minimumConfig().validate() modelType().validate() name() billableMetricId() @@ -934,9 +931,9 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - (bulkBpsConfig.asKnown()?.validity() ?: 0) + - (cadence.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + (if (itemId.asKnown() == null) 0 else 1) + + (minimumConfig.asKnown()?.validity() ?: 0) + (modelType.asKnown()?.validity() ?: 0) + (if (name.asKnown() == null) 0 else 1) + (if (billableMetricId.asKnown() == null) 0 else 1) + @@ -1094,7 +1091,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1102,6 +1099,213 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for minimum pricing */ + class MinimumConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val minimumAmount: JsonField, + private val prorated: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("prorated") + @ExcludeMissing + prorated: JsonField = JsonMissing.of(), + ) : this(minimumAmount, prorated, mutableMapOf()) + + /** + * The minimum amount to apply + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun minimumAmount(): String = minimumAmount.getRequired("minimum_amount") + + /** + * If true, subtotals from this price are prorated based on the service period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorated(): Boolean? = prorated.getNullable("prorated") + + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount + + /** + * Returns the raw JSON value of [prorated]. + * + * Unlike [prorated], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorated") @ExcludeMissing fun _prorated(): JsonField = prorated + + @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 [MinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [MinimumConfig]. */ + class Builder internal constructor() { + + private var minimumAmount: JsonField? = null + private var prorated: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(minimumConfig: MinimumConfig) = apply { + minimumAmount = minimumConfig.minimumAmount + prorated = minimumConfig.prorated + additionalProperties = minimumConfig.additionalProperties.toMutableMap() + } + + /** The minimum amount to apply */ + fun minimumAmount(minimumAmount: String) = minimumAmount(JsonField.of(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } + + /** If true, subtotals from this price are prorated based on the service period */ + fun prorated(prorated: Boolean) = prorated(JsonField.of(prorated)) + + /** + * Sets [Builder.prorated] to an arbitrary JSON value. + * + * You should usually call [Builder.prorated] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prorated(prorated: JsonField) = apply { this.prorated = prorated } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [MinimumConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MinimumConfig = + MinimumConfig( + checkRequired("minimumAmount", minimumAmount), + prorated, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MinimumConfig = apply { + if (validated) { + return@apply + } + + minimumAmount() + prorated() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (minimumAmount.asKnown() == null) 0 else 1) + + (if (prorated.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MinimumConfig && + minimumAmount == other.minimumAmount && + prorated == other.prorated && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(minimumAmount, prorated, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MinimumConfig{minimumAmount=$minimumAmount, prorated=$prorated, additionalProperties=$additionalProperties}" + } + + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1116,14 +1320,14 @@ private constructor( companion object { - val BULK_BPS = of("bulk_bps") + val MINIMUM = of("minimum") fun of(value: String) = ModelType(JsonField.of(value)) } /** An enum containing [ModelType]'s known values. */ enum class Known { - BULK_BPS + MINIMUM } /** @@ -1136,7 +1340,7 @@ private constructor( * - It was constructed with an arbitrary value using the [of] method. */ enum class Value { - BULK_BPS, + MINIMUM, /** * An enum member indicating that [ModelType] was instantiated with an unknown value. */ @@ -1152,7 +1356,7 @@ private constructor( */ fun value(): Value = when (this) { - BULK_BPS -> Value.BULK_BPS + MINIMUM -> Value.MINIMUM else -> Value._UNKNOWN } @@ -1166,7 +1370,7 @@ private constructor( */ fun known(): Known = when (this) { - BULK_BPS -> Known.BULK_BPS + MINIMUM -> Known.MINIMUM else -> throw OrbInvalidDataException("Unknown ModelType: $value") } @@ -1214,7 +1418,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1222,175 +1426,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1483,12 +1518,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1500,15 +1533,54 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionBulkBpsPrice && bulkBpsConfig == other.bulkBpsConfig && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanMinimumCompositePrice && + cadence == other.cadence && + itemId == other.itemId && + minimumConfig == other.minimumConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bulkBpsConfig, cadence, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + minimumConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "NewSubscriptionBulkBpsPrice{bulkBpsConfig=$bulkBpsConfig, cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + "NewPlanMinimumCompositePrice{cadence=$cadence, itemId=$itemId, minimumConfig=$minimumConfig, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanPackagePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanPackagePrice.kt index 7ddce003b..e068235e9 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanPackagePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanPackagePrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanPackagePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +143,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -528,6 +523,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -550,6 +546,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for package pricing */ fun packageConfig(packageConfig: PackageConfig) = packageConfig(JsonField.of(packageConfig)) /** @@ -1093,7 +1090,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1101,6 +1098,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1213,7 +1211,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1221,175 +1219,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1482,12 +1311,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1499,12 +1326,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanPackagePrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && packageConfig == other.packageConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanPackagePrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + packageConfig == other.packageConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, packageConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + packageConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanPackageWithAllocationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanPackageWithAllocationPrice.kt index 1d379d287..01b128cc4 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanPackageWithAllocationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanPackageWithAllocationPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanPackageWithAllocationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +143,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for package_with_allocation pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -538,6 +533,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -560,6 +556,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for package_with_allocation pricing */ fun packageWithAllocationConfig(packageWithAllocationConfig: PackageWithAllocationConfig) = packageWithAllocationConfig(JsonField.of(packageWithAllocationConfig)) @@ -1104,7 +1101,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1112,6 +1109,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1224,7 +1222,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1232,16 +1230,90 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for package_with_allocation pricing */ class PackageWithAllocationConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val allocation: JsonField, + private val packageAmount: JsonField, + private val packageSize: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("allocation") + @ExcludeMissing + allocation: JsonField = JsonMissing.of(), + @JsonProperty("package_amount") + @ExcludeMissing + packageAmount: JsonField = JsonMissing.of(), + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + ) : this(allocation, packageAmount, packageSize, mutableMapOf()) + + /** + * Usage allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun allocation(): String = allocation.getRequired("allocation") + + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageAmount(): String = packageAmount.getRequired("package_amount") + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Returns the raw JSON value of [allocation]. + * + * Unlike [allocation], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allocation") + @ExcludeMissing + fun _allocation(): JsonField = allocation + + /** + * Returns the raw JSON value of [packageAmount]. + * + * Unlike [packageAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("package_amount") + @ExcludeMissing + fun _packageAmount(): JsonField = packageAmount + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1250,6 +1322,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [PackageWithAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .packageAmount() + * .packageSize() + * ``` */ fun builder() = Builder() } @@ -1257,13 +1336,59 @@ private constructor( /** A builder for [PackageWithAllocationConfig]. */ class Builder internal constructor() { + private var allocation: JsonField? = null + private var packageAmount: JsonField? = null + private var packageSize: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(packageWithAllocationConfig: PackageWithAllocationConfig) = apply { + allocation = packageWithAllocationConfig.allocation + packageAmount = packageWithAllocationConfig.packageAmount + packageSize = packageWithAllocationConfig.packageSize additionalProperties = packageWithAllocationConfig.additionalProperties.toMutableMap() } + /** Usage allocation */ + fun allocation(allocation: String) = allocation(JsonField.of(allocation)) + + /** + * Sets [Builder.allocation] to an arbitrary JSON value. + * + * You should usually call [Builder.allocation] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun allocation(allocation: JsonField) = apply { this.allocation = allocation } + + /** Price per package */ + fun packageAmount(packageAmount: String) = packageAmount(JsonField.of(packageAmount)) + + /** + * Sets [Builder.packageAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.packageAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageAmount(packageAmount: JsonField) = apply { + this.packageAmount = packageAmount + } + + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1287,9 +1412,23 @@ private constructor( * Returns an immutable instance of [PackageWithAllocationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .packageAmount() + * .packageSize() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): PackageWithAllocationConfig = - PackageWithAllocationConfig(additionalProperties.toImmutable()) + PackageWithAllocationConfig( + checkRequired("allocation", allocation), + checkRequired("packageAmount", packageAmount), + checkRequired("packageSize", packageSize), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1299,6 +1438,9 @@ private constructor( return@apply } + allocation() + packageAmount() + packageSize() validated = true } @@ -1317,193 +1459,30 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (allocation.asKnown() == null) 0 else 1) + + (if (packageAmount.asKnown() == null) 0 else 1) + + (if (packageSize.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PackageWithAllocationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PackageWithAllocationConfig && + allocation == other.allocation && + packageAmount == other.packageAmount && + packageSize == other.packageSize && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(allocation, packageAmount, packageSize, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "PackageWithAllocationConfig{additionalProperties=$additionalProperties}" - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } + "PackageWithAllocationConfig{allocation=$allocation, packageAmount=$packageAmount, packageSize=$packageSize, additionalProperties=$additionalProperties}" } /** @@ -1598,12 +1577,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1615,12 +1592,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanPackageWithAllocationPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && packageWithAllocationConfig == other.packageWithAllocationConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanPackageWithAllocationPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + packageWithAllocationConfig == other.packageWithAllocationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, packageWithAllocationConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + packageWithAllocationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithTieredPricingPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithTieredPricingPrice.kt index 43854c725..90a7ba681 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithTieredPricingPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithTieredPricingPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanScalableMatrixWithTieredPricingPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -138,6 +130,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -152,6 +146,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for scalable_matrix_with_tiered_pricing pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -545,6 +541,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -567,6 +564,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for scalable_matrix_with_tiered_pricing pricing */ fun scalableMatrixWithTieredPricingConfig( scalableMatrixWithTieredPricingConfig: ScalableMatrixWithTieredPricingConfig ) = @@ -1120,7 +1118,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1128,6 +1126,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1240,7 +1239,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1248,16 +1247,110 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for scalable_matrix_with_tiered_pricing pricing */ class ScalableMatrixWithTieredPricingConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val firstDimension: JsonField, + private val matrixScalingFactors: JsonField>, + private val tiers: JsonField>, + private val secondDimension: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("first_dimension") + @ExcludeMissing + firstDimension: JsonField = JsonMissing.of(), + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + matrixScalingFactors: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + @JsonProperty("second_dimension") + @ExcludeMissing + secondDimension: JsonField = JsonMissing.of(), + ) : this(firstDimension, matrixScalingFactors, tiers, secondDimension, mutableMapOf()) + + /** + * Used for the scalable matrix first dimension + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun firstDimension(): String = firstDimension.getRequired("first_dimension") + + /** + * Apply a scaling factor to each dimension + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun matrixScalingFactors(): List = + matrixScalingFactors.getRequired("matrix_scaling_factors") + + /** + * Tier pricing structure + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Used for the scalable matrix second dimension (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimension(): String? = secondDimension.getNullable("second_dimension") + + /** + * Returns the raw JSON value of [firstDimension]. + * + * Unlike [firstDimension], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("first_dimension") + @ExcludeMissing + fun _firstDimension(): JsonField = firstDimension + + /** + * Returns the raw JSON value of [matrixScalingFactors]. + * + * Unlike [matrixScalingFactors], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + fun _matrixScalingFactors(): JsonField> = matrixScalingFactors + + /** + * 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 + + /** + * Returns the raw JSON value of [secondDimension]. + * + * Unlike [secondDimension], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("second_dimension") + @ExcludeMissing + fun _secondDimension(): JsonField = secondDimension + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1266,6 +1359,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [ScalableMatrixWithTieredPricingConfig]. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1273,15 +1373,110 @@ private constructor( /** A builder for [ScalableMatrixWithTieredPricingConfig]. */ class Builder internal constructor() { + private var firstDimension: JsonField? = null + private var matrixScalingFactors: JsonField>? = null + private var tiers: JsonField>? = null + private var secondDimension: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from( scalableMatrixWithTieredPricingConfig: ScalableMatrixWithTieredPricingConfig ) = apply { + firstDimension = scalableMatrixWithTieredPricingConfig.firstDimension + matrixScalingFactors = + scalableMatrixWithTieredPricingConfig.matrixScalingFactors.map { + it.toMutableList() + } + tiers = scalableMatrixWithTieredPricingConfig.tiers.map { it.toMutableList() } + secondDimension = scalableMatrixWithTieredPricingConfig.secondDimension additionalProperties = scalableMatrixWithTieredPricingConfig.additionalProperties.toMutableMap() } + /** Used for the scalable matrix first dimension */ + fun firstDimension(firstDimension: String) = + firstDimension(JsonField.of(firstDimension)) + + /** + * Sets [Builder.firstDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun firstDimension(firstDimension: JsonField) = apply { + this.firstDimension = firstDimension + } + + /** Apply a scaling factor to each dimension */ + fun matrixScalingFactors(matrixScalingFactors: List) = + matrixScalingFactors(JsonField.of(matrixScalingFactors)) + + /** + * Sets [Builder.matrixScalingFactors] to an arbitrary JSON value. + * + * You should usually call [Builder.matrixScalingFactors] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun matrixScalingFactors(matrixScalingFactors: JsonField>) = + apply { + this.matrixScalingFactors = matrixScalingFactors.map { it.toMutableList() } + } + + /** + * Adds a single [MatrixScalingFactor] to [matrixScalingFactors]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMatrixScalingFactor(matrixScalingFactor: MatrixScalingFactor) = apply { + matrixScalingFactors = + (matrixScalingFactors ?: JsonField.of(mutableListOf())).also { + checkKnown("matrixScalingFactors", it).add(matrixScalingFactor) + } + } + + /** Tier pricing structure */ + 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) + } + } + + /** Used for the scalable matrix second dimension (optional) */ + fun secondDimension(secondDimension: String?) = + secondDimension(JsonField.ofNullable(secondDimension)) + + /** + * Sets [Builder.secondDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun secondDimension(secondDimension: JsonField) = apply { + this.secondDimension = secondDimension + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1305,9 +1500,26 @@ private constructor( * Returns an immutable instance of [ScalableMatrixWithTieredPricingConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): ScalableMatrixWithTieredPricingConfig = - ScalableMatrixWithTieredPricingConfig(additionalProperties.toImmutable()) + ScalableMatrixWithTieredPricingConfig( + checkRequired("firstDimension", firstDimension), + checkRequired("matrixScalingFactors", matrixScalingFactors).map { + it.toImmutable() + }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + secondDimension, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1317,6 +1529,10 @@ private constructor( return@apply } + firstDimension() + matrixScalingFactors().forEach { it.validate() } + tiers().forEach { it.validate() } + secondDimension() validated = true } @@ -1335,193 +1551,527 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (firstDimension.asKnown() == null) 0 else 1) + + (matrixScalingFactors.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (secondDimension.asKnown() == null) 0 else 1) + + /** Configuration for a single matrix scaling factor */ + class MatrixScalingFactor + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val firstDimensionValue: JsonField, + private val scalingFactor: JsonField, + private val secondDimensionValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("first_dimension_value") + @ExcludeMissing + firstDimensionValue: JsonField = JsonMissing.of(), + @JsonProperty("scaling_factor") + @ExcludeMissing + scalingFactor: JsonField = JsonMissing.of(), + @JsonProperty("second_dimension_value") + @ExcludeMissing + secondDimensionValue: JsonField = JsonMissing.of(), + ) : this(firstDimensionValue, scalingFactor, secondDimensionValue, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * First dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun firstDimensionValue(): String = + firstDimensionValue.getRequired("first_dimension_value") - return /* spotless:off */ other is ScalableMatrixWithTieredPricingConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingFactor(): String = scalingFactor.getRequired("scaling_factor") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Second dimension value (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimensionValue(): String? = + secondDimensionValue.getNullable("second_dimension_value") - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [firstDimensionValue]. + * + * Unlike [firstDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("first_dimension_value") + @ExcludeMissing + fun _firstDimensionValue(): JsonField = firstDimensionValue - override fun toString() = - "ScalableMatrixWithTieredPricingConfig{additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [scalingFactor]. + * + * Unlike [scalingFactor], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_factor") + @ExcludeMissing + fun _scalingFactor(): JsonField = scalingFactor - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + /** + * Returns the raw JSON value of [secondDimensionValue]. + * + * Unlike [secondDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("second_dimension_value") + @ExcludeMissing + fun _secondDimensionValue(): JsonField = secondDimensionValue - fun unit(): UnitConversionRateConfig? = unit + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [MatrixScalingFactor]. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + */ + fun builder() = Builder() + } - fun isUnit(): Boolean = unit != null + /** A builder for [MatrixScalingFactor]. */ + class Builder internal constructor() { - fun isTiered(): Boolean = tiered != null + private var firstDimensionValue: JsonField? = null + private var scalingFactor: JsonField? = null + private var secondDimensionValue: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + internal fun from(matrixScalingFactor: MatrixScalingFactor) = apply { + firstDimensionValue = matrixScalingFactor.firstDimensionValue + scalingFactor = matrixScalingFactor.scalingFactor + secondDimensionValue = matrixScalingFactor.secondDimensionValue + additionalProperties = matrixScalingFactor.additionalProperties.toMutableMap() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** First dimension value */ + fun firstDimensionValue(firstDimensionValue: String) = + firstDimensionValue(JsonField.of(firstDimensionValue)) + + /** + * Sets [Builder.firstDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimensionValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun firstDimensionValue(firstDimensionValue: JsonField) = apply { + this.firstDimensionValue = firstDimensionValue + } - fun _json(): JsonValue? = _json + /** Scaling factor */ + fun scalingFactor(scalingFactor: String) = + scalingFactor(JsonField.of(scalingFactor)) + + /** + * Sets [Builder.scalingFactor] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactor] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun scalingFactor(scalingFactor: JsonField) = apply { + this.scalingFactor = scalingFactor + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + /** Second dimension value (optional) */ + fun secondDimensionValue(secondDimensionValue: String?) = + secondDimensionValue(JsonField.ofNullable(secondDimensionValue)) + + /** + * Sets [Builder.secondDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimensionValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun secondDimensionValue(secondDimensionValue: JsonField) = apply { + this.secondDimensionValue = secondDimensionValue + } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + /** + * Returns an immutable instance of [MatrixScalingFactor]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MatrixScalingFactor = + MatrixScalingFactor( + checkRequired("firstDimensionValue", firstDimensionValue), + checkRequired("scalingFactor", scalingFactor), + secondDimensionValue, + additionalProperties.toMutableMap(), + ) + } - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() + private var validated: Boolean = false - override fun unknown(json: JsonValue?) = 0 + fun validate(): MatrixScalingFactor = apply { + if (validated) { + return@apply } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + firstDimensionValue() + scalingFactor() + secondDimensionValue() + validated = true } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (firstDimensionValue.asKnown() == null) 0 else 1) + + (if (scalingFactor.asKnown() == null) 0 else 1) + + (if (secondDimensionValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + return other is MatrixScalingFactor && + firstDimensionValue == other.firstDimensionValue && + scalingFactor == other.scalingFactor && + secondDimensionValue == other.secondDimensionValue && + additionalProperties == other.additionalProperties } - companion object { + private val hashCode: Int by lazy { + Objects.hash( + firstDimensionValue, + scalingFactor, + secondDimensionValue, + additionalProperties, + ) + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + override fun hashCode(): Int = hashCode - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) + override fun toString() = + "MatrixScalingFactor{firstDimensionValue=$firstDimensionValue, scalingFactor=$scalingFactor, secondDimensionValue=$secondDimensionValue, additionalProperties=$additionalProperties}" } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { + /** Configuration for a single tier entry with business logic */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) - fun visitUnit(unit: UnitConversionRateConfig): T + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - fun visitTiered(tiered: TieredConversionRateConfig): T + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns the raw JSON value of [tierLowerBound]. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. * - * @throws OrbInvalidDataException in the default implementation. + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + /** A builder for [Tier]. */ + class Builder internal constructor() { - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - return ConversionRateConfig(_json = json) + 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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is ScalableMatrixWithTieredPricingConfig && + firstDimension == other.firstDimension && + matrixScalingFactors == other.matrixScalingFactors && + tiers == other.tiers && + secondDimension == other.secondDimension && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + firstDimension, + matrixScalingFactors, + tiers, + secondDimension, + additionalProperties, + ) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScalableMatrixWithTieredPricingConfig{firstDimension=$firstDimension, matrixScalingFactors=$matrixScalingFactors, tiers=$tiers, secondDimension=$secondDimension, additionalProperties=$additionalProperties}" } /** @@ -1616,12 +2166,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1633,12 +2181,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanScalableMatrixWithTieredPricingPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && scalableMatrixWithTieredPricingConfig == other.scalableMatrixWithTieredPricingConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanScalableMatrixWithTieredPricingPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + scalableMatrixWithTieredPricingConfig == other.scalableMatrixWithTieredPricingConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, scalableMatrixWithTieredPricingConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + scalableMatrixWithTieredPricingConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithUnitPricingPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithUnitPricingPrice.kt index f4f08764f..3c2e3374d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithUnitPricingPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithUnitPricingPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanScalableMatrixWithUnitPricingPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -137,6 +129,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -151,6 +145,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for scalable_matrix_with_unit_pricing pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -542,6 +538,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -564,6 +561,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for scalable_matrix_with_unit_pricing pricing */ fun scalableMatrixWithUnitPricingConfig( scalableMatrixWithUnitPricingConfig: ScalableMatrixWithUnitPricingConfig ) = scalableMatrixWithUnitPricingConfig(JsonField.of(scalableMatrixWithUnitPricingConfig)) @@ -1112,7 +1110,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1120,6 +1118,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1232,7 +1231,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1240,16 +1239,136 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for scalable_matrix_with_unit_pricing pricing */ class ScalableMatrixWithUnitPricingConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val firstDimension: JsonField, + private val matrixScalingFactors: JsonField>, + private val unitPrice: JsonField, + private val prorate: JsonField, + private val secondDimension: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("first_dimension") + @ExcludeMissing + firstDimension: JsonField = JsonMissing.of(), + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + matrixScalingFactors: JsonField> = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + @JsonProperty("prorate") @ExcludeMissing prorate: JsonField = JsonMissing.of(), + @JsonProperty("second_dimension") + @ExcludeMissing + secondDimension: JsonField = JsonMissing.of(), + ) : this( + firstDimension, + matrixScalingFactors, + unitPrice, + prorate, + secondDimension, + mutableMapOf(), + ) + + /** + * Used to determine the unit rate + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun firstDimension(): String = firstDimension.getRequired("first_dimension") + + /** + * Apply a scaling factor to each dimension + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun matrixScalingFactors(): List = + matrixScalingFactors.getRequired("matrix_scaling_factors") + + /** + * The final unit price to rate against the output of the matrix + * + * @throws OrbInvalidDataException if 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(): String = unitPrice.getRequired("unit_price") + + /** + * If true, the unit price will be prorated to the billing period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorate(): Boolean? = prorate.getNullable("prorate") + + /** + * Used to determine the unit rate (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimension(): String? = secondDimension.getNullable("second_dimension") + + /** + * Returns the raw JSON value of [firstDimension]. + * + * Unlike [firstDimension], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("first_dimension") + @ExcludeMissing + fun _firstDimension(): JsonField = firstDimension + + /** + * Returns the raw JSON value of [matrixScalingFactors]. + * + * Unlike [matrixScalingFactors], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + fun _matrixScalingFactors(): JsonField> = matrixScalingFactors + + /** + * 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 [prorate]. + * + * Unlike [prorate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorate") @ExcludeMissing fun _prorate(): JsonField = prorate + + /** + * Returns the raw JSON value of [secondDimension]. + * + * Unlike [secondDimension], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("second_dimension") + @ExcludeMissing + fun _secondDimension(): JsonField = secondDimension + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1258,6 +1377,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [ScalableMatrixWithUnitPricingConfig]. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .unitPrice() + * ``` */ fun builder() = Builder() } @@ -1265,15 +1391,117 @@ private constructor( /** A builder for [ScalableMatrixWithUnitPricingConfig]. */ class Builder internal constructor() { + private var firstDimension: JsonField? = null + private var matrixScalingFactors: JsonField>? = null + private var unitPrice: JsonField? = null + private var prorate: JsonField = JsonMissing.of() + private var secondDimension: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from( scalableMatrixWithUnitPricingConfig: ScalableMatrixWithUnitPricingConfig ) = apply { + firstDimension = scalableMatrixWithUnitPricingConfig.firstDimension + matrixScalingFactors = + scalableMatrixWithUnitPricingConfig.matrixScalingFactors.map { + it.toMutableList() + } + unitPrice = scalableMatrixWithUnitPricingConfig.unitPrice + prorate = scalableMatrixWithUnitPricingConfig.prorate + secondDimension = scalableMatrixWithUnitPricingConfig.secondDimension additionalProperties = scalableMatrixWithUnitPricingConfig.additionalProperties.toMutableMap() } + /** Used to determine the unit rate */ + fun firstDimension(firstDimension: String) = + firstDimension(JsonField.of(firstDimension)) + + /** + * Sets [Builder.firstDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun firstDimension(firstDimension: JsonField) = apply { + this.firstDimension = firstDimension + } + + /** Apply a scaling factor to each dimension */ + fun matrixScalingFactors(matrixScalingFactors: List) = + matrixScalingFactors(JsonField.of(matrixScalingFactors)) + + /** + * Sets [Builder.matrixScalingFactors] to an arbitrary JSON value. + * + * You should usually call [Builder.matrixScalingFactors] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun matrixScalingFactors(matrixScalingFactors: JsonField>) = + apply { + this.matrixScalingFactors = matrixScalingFactors.map { it.toMutableList() } + } + + /** + * Adds a single [MatrixScalingFactor] to [matrixScalingFactors]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMatrixScalingFactor(matrixScalingFactor: MatrixScalingFactor) = apply { + matrixScalingFactors = + (matrixScalingFactors ?: JsonField.of(mutableListOf())).also { + checkKnown("matrixScalingFactors", it).add(matrixScalingFactor) + } + } + + /** The final unit price to rate against the output of the matrix */ + fun unitPrice(unitPrice: String) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [String] 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 } + + /** If true, the unit price will be prorated to the billing period */ + fun prorate(prorate: Boolean?) = prorate(JsonField.ofNullable(prorate)) + + /** + * Alias for [Builder.prorate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun prorate(prorate: Boolean) = prorate(prorate as Boolean?) + + /** + * Sets [Builder.prorate] to an arbitrary JSON value. + * + * You should usually call [Builder.prorate] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prorate(prorate: JsonField) = apply { this.prorate = prorate } + + /** Used to determine the unit rate (optional) */ + fun secondDimension(secondDimension: String?) = + secondDimension(JsonField.ofNullable(secondDimension)) + + /** + * Sets [Builder.secondDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun secondDimension(secondDimension: JsonField) = apply { + this.secondDimension = secondDimension + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1297,9 +1525,27 @@ private constructor( * Returns an immutable instance of [ScalableMatrixWithUnitPricingConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .unitPrice() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): ScalableMatrixWithUnitPricingConfig = - ScalableMatrixWithUnitPricingConfig(additionalProperties.toImmutable()) + ScalableMatrixWithUnitPricingConfig( + checkRequired("firstDimension", firstDimension), + checkRequired("matrixScalingFactors", matrixScalingFactors).map { + it.toImmutable() + }, + checkRequired("unitPrice", unitPrice), + prorate, + secondDimension, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1309,6 +1555,11 @@ private constructor( return@apply } + firstDimension() + matrixScalingFactors().forEach { it.validate() } + unitPrice() + prorate() + secondDimension() validated = true } @@ -1327,193 +1578,311 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (firstDimension.asKnown() == null) 0 else 1) + + (matrixScalingFactors.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (unitPrice.asKnown() == null) 0 else 1) + + (if (prorate.asKnown() == null) 0 else 1) + + (if (secondDimension.asKnown() == null) 0 else 1) + + /** Configuration for a single matrix scaling factor */ + class MatrixScalingFactor + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val firstDimensionValue: JsonField, + private val scalingFactor: JsonField, + private val secondDimensionValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("first_dimension_value") + @ExcludeMissing + firstDimensionValue: JsonField = JsonMissing.of(), + @JsonProperty("scaling_factor") + @ExcludeMissing + scalingFactor: JsonField = JsonMissing.of(), + @JsonProperty("second_dimension_value") + @ExcludeMissing + secondDimensionValue: JsonField = JsonMissing.of(), + ) : this(firstDimensionValue, scalingFactor, secondDimensionValue, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * First dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun firstDimensionValue(): String = + firstDimensionValue.getRequired("first_dimension_value") - return /* spotless:off */ other is ScalableMatrixWithUnitPricingConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingFactor(): String = scalingFactor.getRequired("scaling_factor") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Second dimension value (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimensionValue(): String? = + secondDimensionValue.getNullable("second_dimension_value") - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [firstDimensionValue]. + * + * Unlike [firstDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("first_dimension_value") + @ExcludeMissing + fun _firstDimensionValue(): JsonField = firstDimensionValue - override fun toString() = - "ScalableMatrixWithUnitPricingConfig{additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [scalingFactor]. + * + * Unlike [scalingFactor], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_factor") + @ExcludeMissing + fun _scalingFactor(): JsonField = scalingFactor - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + /** + * Returns the raw JSON value of [secondDimensionValue]. + * + * Unlike [secondDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("second_dimension_value") + @ExcludeMissing + fun _secondDimensionValue(): JsonField = secondDimensionValue - fun unit(): UnitConversionRateConfig? = unit + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [MatrixScalingFactor]. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + */ + fun builder() = Builder() + } - fun isUnit(): Boolean = unit != null + /** A builder for [MatrixScalingFactor]. */ + class Builder internal constructor() { - fun isTiered(): Boolean = tiered != null + private var firstDimensionValue: JsonField? = null + private var scalingFactor: JsonField? = null + private var secondDimensionValue: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + internal fun from(matrixScalingFactor: MatrixScalingFactor) = apply { + firstDimensionValue = matrixScalingFactor.firstDimensionValue + scalingFactor = matrixScalingFactor.scalingFactor + secondDimensionValue = matrixScalingFactor.secondDimensionValue + additionalProperties = matrixScalingFactor.additionalProperties.toMutableMap() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** First dimension value */ + fun firstDimensionValue(firstDimensionValue: String) = + firstDimensionValue(JsonField.of(firstDimensionValue)) + + /** + * Sets [Builder.firstDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimensionValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun firstDimensionValue(firstDimensionValue: JsonField) = apply { + this.firstDimensionValue = firstDimensionValue + } - fun _json(): JsonValue? = _json + /** Scaling factor */ + fun scalingFactor(scalingFactor: String) = + scalingFactor(JsonField.of(scalingFactor)) + + /** + * Sets [Builder.scalingFactor] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactor] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun scalingFactor(scalingFactor: JsonField) = apply { + this.scalingFactor = scalingFactor + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + /** Second dimension value (optional) */ + fun secondDimensionValue(secondDimensionValue: String?) = + secondDimensionValue(JsonField.ofNullable(secondDimensionValue)) + + /** + * Sets [Builder.secondDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimensionValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun secondDimensionValue(secondDimensionValue: JsonField) = apply { + this.secondDimensionValue = secondDimensionValue + } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 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 [MatrixScalingFactor]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MatrixScalingFactor = + MatrixScalingFactor( + checkRequired("firstDimensionValue", firstDimensionValue), + checkRequired("scalingFactor", scalingFactor), + secondDimensionValue, + additionalProperties.toMutableMap(), + ) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + private var validated: Boolean = false - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun validate(): MatrixScalingFactor = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + firstDimensionValue() + scalingFactor() + secondDimensionValue() + validated = true } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + internal fun validity(): Int = + (if (firstDimensionValue.asKnown() == null) 0 else 1) + + (if (scalingFactor.asKnown() == null) 0 else 1) + + (if (secondDimensionValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MatrixScalingFactor && + firstDimensionValue == other.firstDimensionValue && + scalingFactor == other.scalingFactor && + secondDimensionValue == other.secondDimensionValue && + additionalProperties == other.additionalProperties } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + private val hashCode: Int by lazy { + Objects.hash( + firstDimensionValue, + scalingFactor, + secondDimensionValue, + additionalProperties, + ) + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + override fun hashCode(): Int = hashCode - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + override fun toString() = + "MatrixScalingFactor{firstDimensionValue=$firstDimensionValue, scalingFactor=$scalingFactor, secondDimensionValue=$secondDimensionValue, additionalProperties=$additionalProperties}" + } - return ConversionRateConfig(_json = json) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is ScalableMatrixWithUnitPricingConfig && + firstDimension == other.firstDimension && + matrixScalingFactors == other.matrixScalingFactors && + unitPrice == other.unitPrice && + prorate == other.prorate && + secondDimension == other.secondDimension && + additionalProperties == other.additionalProperties } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } + private val hashCode: Int by lazy { + Objects.hash( + firstDimension, + matrixScalingFactors, + unitPrice, + prorate, + secondDimension, + additionalProperties, + ) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScalableMatrixWithUnitPricingConfig{firstDimension=$firstDimension, matrixScalingFactors=$matrixScalingFactors, unitPrice=$unitPrice, prorate=$prorate, secondDimension=$secondDimension, additionalProperties=$additionalProperties}" } /** @@ -1608,12 +1977,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1625,12 +1992,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanScalableMatrixWithUnitPricingPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && scalableMatrixWithUnitPricingConfig == other.scalableMatrixWithUnitPricingConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanScalableMatrixWithUnitPricingPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + scalableMatrixWithUnitPricingConfig == other.scalableMatrixWithUnitPricingConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, scalableMatrixWithUnitPricingConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + scalableMatrixWithUnitPricingConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanThresholdTotalAmountPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanThresholdTotalAmountPrice.kt index 79b909ae6..5cac439fe 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanThresholdTotalAmountPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanThresholdTotalAmountPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanThresholdTotalAmountPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +128,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +144,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for threshold_total_amount pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -538,6 +534,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -560,6 +557,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for threshold_total_amount pricing */ fun thresholdTotalAmountConfig(thresholdTotalAmountConfig: ThresholdTotalAmountConfig) = thresholdTotalAmountConfig(JsonField.of(thresholdTotalAmountConfig)) @@ -1104,7 +1102,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1112,6 +1110,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1224,7 +1223,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1232,16 +1231,67 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for threshold_total_amount pricing */ class ThresholdTotalAmountConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val consumptionTable: JsonField>, + private val prorate: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("consumption_table") + @ExcludeMissing + consumptionTable: JsonField> = JsonMissing.of(), + @JsonProperty("prorate") @ExcludeMissing prorate: JsonField = JsonMissing.of(), + ) : this(consumptionTable, prorate, mutableMapOf()) + + /** + * When the quantity consumed passes a provided threshold, the configured total will be + * charged + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun consumptionTable(): List = + consumptionTable.getRequired("consumption_table") + + /** + * If true, the unit price will be prorated to the billing period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorate(): Boolean? = prorate.getNullable("prorate") + + /** + * Returns the raw JSON value of [consumptionTable]. + * + * Unlike [consumptionTable], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("consumption_table") + @ExcludeMissing + fun _consumptionTable(): JsonField> = consumptionTable + + /** + * Returns the raw JSON value of [prorate]. + * + * Unlike [prorate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorate") @ExcludeMissing fun _prorate(): JsonField = prorate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1250,6 +1300,11 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [ThresholdTotalAmountConfig]. + * + * The following fields are required: + * ```kotlin + * .consumptionTable() + * ``` */ fun builder() = Builder() } @@ -1257,13 +1312,67 @@ private constructor( /** A builder for [ThresholdTotalAmountConfig]. */ class Builder internal constructor() { + private var consumptionTable: JsonField>? = null + private var prorate: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(thresholdTotalAmountConfig: ThresholdTotalAmountConfig) = apply { + consumptionTable = + thresholdTotalAmountConfig.consumptionTable.map { it.toMutableList() } + prorate = thresholdTotalAmountConfig.prorate additionalProperties = thresholdTotalAmountConfig.additionalProperties.toMutableMap() } + /** + * When the quantity consumed passes a provided threshold, the configured total will be + * charged + */ + fun consumptionTable(consumptionTable: List) = + consumptionTable(JsonField.of(consumptionTable)) + + /** + * Sets [Builder.consumptionTable] to an arbitrary JSON value. + * + * You should usually call [Builder.consumptionTable] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun consumptionTable(consumptionTable: JsonField>) = apply { + this.consumptionTable = consumptionTable.map { it.toMutableList() } + } + + /** + * Adds a single [ConsumptionTable] to [Builder.consumptionTable]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addConsumptionTable(consumptionTable: ConsumptionTable) = apply { + this.consumptionTable = + (this.consumptionTable ?: JsonField.of(mutableListOf())).also { + checkKnown("consumptionTable", it).add(consumptionTable) + } + } + + /** If true, the unit price will be prorated to the billing period */ + fun prorate(prorate: Boolean?) = prorate(JsonField.ofNullable(prorate)) + + /** + * Alias for [Builder.prorate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun prorate(prorate: Boolean) = prorate(prorate as Boolean?) + + /** + * Sets [Builder.prorate] to an arbitrary JSON value. + * + * You should usually call [Builder.prorate] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prorate(prorate: JsonField) = apply { this.prorate = prorate } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1287,9 +1396,20 @@ private constructor( * Returns an immutable instance of [ThresholdTotalAmountConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .consumptionTable() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): ThresholdTotalAmountConfig = - ThresholdTotalAmountConfig(additionalProperties.toImmutable()) + ThresholdTotalAmountConfig( + checkRequired("consumptionTable", consumptionTable).map { it.toImmutable() }, + prorate, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1299,6 +1419,8 @@ private constructor( return@apply } + consumptionTable().forEach { it.validate() } + prorate() validated = true } @@ -1317,193 +1439,244 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (consumptionTable.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (prorate.asKnown() == null) 0 else 1) + + /** Configuration for a single threshold */ + class ConsumptionTable + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val threshold: JsonField, + private val totalAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("threshold") + @ExcludeMissing + threshold: JsonField = JsonMissing.of(), + @JsonProperty("total_amount") + @ExcludeMissing + totalAmount: JsonField = JsonMissing.of(), + ) : this(threshold, totalAmount, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Quantity threshold + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun threshold(): String = threshold.getRequired("threshold") - return /* spotless:off */ other is ThresholdTotalAmountConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Total amount for this threshold + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun totalAmount(): String = totalAmount.getRequired("total_amount") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Returns the raw JSON value of [threshold]. + * + * Unlike [threshold], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("threshold") + @ExcludeMissing + fun _threshold(): JsonField = threshold - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [totalAmount]. + * + * Unlike [totalAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("total_amount") + @ExcludeMissing + fun _totalAmount(): JsonField = totalAmount - override fun toString() = - "ThresholdTotalAmountConfig{additionalProperties=$additionalProperties}" - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ConsumptionTable]. + * + * The following fields are required: + * ```kotlin + * .threshold() + * .totalAmount() + * ``` + */ + fun builder() = Builder() + } - fun unit(): UnitConversionRateConfig? = unit + /** A builder for [ConsumptionTable]. */ + class Builder internal constructor() { - fun tiered(): TieredConversionRateConfig? = tiered + private var threshold: JsonField? = null + private var totalAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun isUnit(): Boolean = unit != null + internal fun from(consumptionTable: ConsumptionTable) = apply { + threshold = consumptionTable.threshold + totalAmount = consumptionTable.totalAmount + additionalProperties = consumptionTable.additionalProperties.toMutableMap() + } - fun isTiered(): Boolean = tiered != null + /** Quantity threshold */ + fun threshold(threshold: String) = threshold(JsonField.of(threshold)) + + /** + * Sets [Builder.threshold] to an arbitrary JSON value. + * + * You should usually call [Builder.threshold] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun threshold(threshold: JsonField) = apply { this.threshold = threshold } + + /** Total amount for this threshold */ + fun totalAmount(totalAmount: String) = totalAmount(JsonField.of(totalAmount)) + + /** + * Sets [Builder.totalAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.totalAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun totalAmount(totalAmount: JsonField) = apply { + this.totalAmount = totalAmount + } - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun _json(): JsonValue? = _json + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - private var validated: Boolean = false + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Returns an immutable instance of [ConsumptionTable]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .threshold() + * .totalAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ConsumptionTable = + ConsumptionTable( + checkRequired("threshold", threshold), + checkRequired("totalAmount", totalAmount), + additionalProperties.toMutableMap(), + ) } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } + private var validated: Boolean = false - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun validate(): ConsumptionTable = apply { + if (validated) { + return@apply } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + threshold() + totalAmount() + validated = true } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (threshold.asKnown() == null) 0 else 1) + + (if (totalAmount.asKnown() == null) 0 else 1) - override fun unknown(json: JsonValue?) = 0 + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + return other is ConsumptionTable && + threshold == other.threshold && + totalAmount == other.totalAmount && + additionalProperties == other.additionalProperties } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + private val hashCode: Int by lazy { + Objects.hash(threshold, totalAmount, additionalProperties) } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + override fun hashCode(): Int = hashCode - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) + override fun toString() = + "ConsumptionTable{threshold=$threshold, totalAmount=$totalAmount, additionalProperties=$additionalProperties}" } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - return ConversionRateConfig(_json = json) - } + return other is ThresholdTotalAmountConfig && + consumptionTable == other.consumptionTable && + prorate == other.prorate && + additionalProperties == other.additionalProperties } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } + private val hashCode: Int by lazy { + Objects.hash(consumptionTable, prorate, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThresholdTotalAmountConfig{consumptionTable=$consumptionTable, prorate=$prorate, additionalProperties=$additionalProperties}" } /** @@ -1598,12 +1771,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1615,12 +1786,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanThresholdTotalAmountPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && thresholdTotalAmountConfig == other.thresholdTotalAmountConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanThresholdTotalAmountPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + thresholdTotalAmountConfig == other.thresholdTotalAmountConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, thresholdTotalAmountConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + thresholdTotalAmountConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTierWithProrationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTierWithProrationPrice.kt deleted file mode 100644 index e782385d8..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTierWithProrationPrice.kt +++ /dev/null @@ -1,1623 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer -import com.withorb.api.core.Enum -import com.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow -import com.withorb.api.core.toImmutable -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class NewPlanTierWithProrationPrice -private constructor( - private val cadence: JsonField, - private val itemId: JsonField, - private val modelType: JsonField, - private val name: JsonField, - private val tieredWithProrationConfig: JsonField, - private val billableMetricId: JsonField, - private val billedInAdvance: JsonField, - private val billingCycleConfiguration: JsonField, - private val conversionRate: JsonField, - private val conversionRateConfig: JsonField, - private val currency: JsonField, - private val dimensionalPriceConfiguration: JsonField, - private val externalPriceId: JsonField, - private val fixedPriceQuantity: JsonField, - private val invoiceGroupingKey: JsonField, - private val invoicingCycleConfiguration: JsonField, - private val metadata: JsonField, - private val referenceId: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), - @JsonProperty("item_id") @ExcludeMissing itemId: JsonField = JsonMissing.of(), - @JsonProperty("model_type") - @ExcludeMissing - modelType: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("tiered_with_proration_config") - @ExcludeMissing - tieredWithProrationConfig: JsonField = JsonMissing.of(), - @JsonProperty("billable_metric_id") - @ExcludeMissing - billableMetricId: JsonField = JsonMissing.of(), - @JsonProperty("billed_in_advance") - @ExcludeMissing - billedInAdvance: JsonField = JsonMissing.of(), - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - billingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate") - @ExcludeMissing - conversionRate: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate_config") - @ExcludeMissing - conversionRateConfig: JsonField = JsonMissing.of(), - @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - dimensionalPriceConfiguration: JsonField = - JsonMissing.of(), - @JsonProperty("external_price_id") - @ExcludeMissing - externalPriceId: JsonField = JsonMissing.of(), - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - invoiceGroupingKey: JsonField = JsonMissing.of(), - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - invoicingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), - @JsonProperty("reference_id") - @ExcludeMissing - referenceId: JsonField = JsonMissing.of(), - ) : this( - cadence, - itemId, - modelType, - name, - tieredWithProrationConfig, - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - currency, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - referenceId, - mutableMapOf(), - ) - - /** - * The cadence to bill for this price on. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun cadence(): Cadence = cadence.getRequired("cadence") - - /** - * The id of the item the price will be associated with. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun itemId(): String = itemId.getRequired("item_id") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun modelType(): ModelType = modelType.getRequired("model_type") - - /** - * The name of the price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun name(): String = name.getRequired("name") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun tieredWithProrationConfig(): TieredWithProrationConfig = - tieredWithProrationConfig.getRequired("tiered_with_proration_config") - - /** - * The id of the billable metric for the price. Only needed if the price is usage-based. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is true, - * and in-arrears if this is false. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - - /** - * For custom cadence: specifies the duration of the billing period in days or months. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billingCycleConfiguration(): NewBillingCycleConfiguration? = - billingCycleConfiguration.getNullable("billing_cycle_configuration") - - /** - * The per unit conversion rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - - /** - * The configuration for the rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRateConfig(): ConversionRateConfig? = - conversionRateConfig.getNullable("conversion_rate_config") - - /** - * An ISO 4217 currency string, or custom pricing unit identifier, in which this price is - * billed. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun currency(): String? = currency.getNullable("currency") - - /** - * For dimensional price: specifies a price group and dimension values - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = - dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - - /** - * An alias for the price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - - /** - * If the Price represents a fixed cost, this represents the quantity of units applied. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") - - /** - * The property used to group this price on an invoice - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoiceGroupingKey(): String? = invoiceGroupingKey.getNullable("invoice_grouping_key") - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = - invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun metadata(): Metadata? = metadata.getNullable("metadata") - - /** - * A transient ID that can be used to reference this price when adding adjustments in the same - * API call. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun referenceId(): String? = referenceId.getNullable("reference_id") - - /** - * Returns the raw JSON value of [cadence]. - * - * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence - - /** - * Returns the raw JSON value of [itemId]. - * - * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - - /** - * Returns the raw JSON value of [modelType]. - * - * Unlike [modelType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonField = modelType - - /** - * 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 [tieredWithProrationConfig]. - * - * Unlike [tieredWithProrationConfig], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("tiered_with_proration_config") - @ExcludeMissing - fun _tieredWithProrationConfig(): JsonField = - tieredWithProrationConfig - - /** - * Returns the raw JSON value of [billableMetricId]. - * - * Unlike [billableMetricId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("billable_metric_id") - @ExcludeMissing - fun _billableMetricId(): JsonField = billableMetricId - - /** - * Returns the raw JSON value of [billedInAdvance]. - * - * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("billed_in_advance") - @ExcludeMissing - fun _billedInAdvance(): JsonField = billedInAdvance - - /** - * Returns the raw JSON value of [billingCycleConfiguration]. - * - * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - fun _billingCycleConfiguration(): JsonField = - billingCycleConfiguration - - /** - * Returns the raw JSON value of [conversionRate]. - * - * Unlike [conversionRate], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("conversion_rate") - @ExcludeMissing - fun _conversionRate(): JsonField = conversionRate - - /** - * Returns the raw JSON value of [conversionRateConfig]. - * - * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("conversion_rate_config") - @ExcludeMissing - fun _conversionRateConfig(): JsonField = conversionRateConfig - - /** - * Returns the raw JSON value of [currency]. - * - * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency - - /** - * Returns the raw JSON value of [dimensionalPriceConfiguration]. - * - * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - fun _dimensionalPriceConfiguration(): JsonField = - dimensionalPriceConfiguration - - /** - * Returns the raw JSON value of [externalPriceId]. - * - * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("external_price_id") - @ExcludeMissing - fun _externalPriceId(): JsonField = externalPriceId - - /** - * Returns the raw JSON value of [fixedPriceQuantity]. - * - * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - - /** - * Returns the raw JSON value of [invoiceGroupingKey]. - * - * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - - /** - * Returns the raw JSON value of [invoicingCycleConfiguration]. - * - * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - fun _invoicingCycleConfiguration(): JsonField = - invoicingCycleConfiguration - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - - /** - * Returns the raw JSON value of [referenceId]. - * - * Unlike [referenceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("reference_id") - @ExcludeMissing - fun _referenceId(): JsonField = referenceId - - @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 - * [NewPlanTierWithProrationPrice]. - * - * The following fields are required: - * ```kotlin - * .cadence() - * .itemId() - * .modelType() - * .name() - * .tieredWithProrationConfig() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [NewPlanTierWithProrationPrice]. */ - class Builder internal constructor() { - - private var cadence: JsonField? = null - private var itemId: JsonField? = null - private var modelType: JsonField? = null - private var name: JsonField? = null - private var tieredWithProrationConfig: JsonField? = null - private var billableMetricId: JsonField = JsonMissing.of() - private var billedInAdvance: JsonField = JsonMissing.of() - private var billingCycleConfiguration: JsonField = - JsonMissing.of() - private var conversionRate: JsonField = JsonMissing.of() - private var conversionRateConfig: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var dimensionalPriceConfiguration: JsonField = - JsonMissing.of() - private var externalPriceId: JsonField = JsonMissing.of() - private var fixedPriceQuantity: JsonField = JsonMissing.of() - private var invoiceGroupingKey: JsonField = JsonMissing.of() - private var invoicingCycleConfiguration: JsonField = - JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var referenceId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(newPlanTierWithProrationPrice: NewPlanTierWithProrationPrice) = apply { - cadence = newPlanTierWithProrationPrice.cadence - itemId = newPlanTierWithProrationPrice.itemId - modelType = newPlanTierWithProrationPrice.modelType - name = newPlanTierWithProrationPrice.name - tieredWithProrationConfig = newPlanTierWithProrationPrice.tieredWithProrationConfig - billableMetricId = newPlanTierWithProrationPrice.billableMetricId - billedInAdvance = newPlanTierWithProrationPrice.billedInAdvance - billingCycleConfiguration = newPlanTierWithProrationPrice.billingCycleConfiguration - conversionRate = newPlanTierWithProrationPrice.conversionRate - conversionRateConfig = newPlanTierWithProrationPrice.conversionRateConfig - currency = newPlanTierWithProrationPrice.currency - dimensionalPriceConfiguration = - newPlanTierWithProrationPrice.dimensionalPriceConfiguration - externalPriceId = newPlanTierWithProrationPrice.externalPriceId - fixedPriceQuantity = newPlanTierWithProrationPrice.fixedPriceQuantity - invoiceGroupingKey = newPlanTierWithProrationPrice.invoiceGroupingKey - invoicingCycleConfiguration = newPlanTierWithProrationPrice.invoicingCycleConfiguration - metadata = newPlanTierWithProrationPrice.metadata - referenceId = newPlanTierWithProrationPrice.referenceId - additionalProperties = newPlanTierWithProrationPrice.additionalProperties.toMutableMap() - } - - /** The cadence to bill for this price on. */ - fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) - - /** - * Sets [Builder.cadence] to an arbitrary JSON value. - * - * You should usually call [Builder.cadence] with a well-typed [Cadence] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun cadence(cadence: JsonField) = apply { this.cadence = cadence } - - /** The id of the item the price will be associated with. */ - fun itemId(itemId: String) = itemId(JsonField.of(itemId)) - - /** - * Sets [Builder.itemId] to an arbitrary JSON value. - * - * You should usually call [Builder.itemId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun itemId(itemId: JsonField) = apply { this.itemId = itemId } - - fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) - - /** - * Sets [Builder.modelType] to an arbitrary JSON value. - * - * You should usually call [Builder.modelType] with a well-typed [ModelType] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun modelType(modelType: JsonField) = apply { this.modelType = modelType } - - /** The name of the price. */ - 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 tieredWithProrationConfig(tieredWithProrationConfig: TieredWithProrationConfig) = - tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) - - /** - * Sets [Builder.tieredWithProrationConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.tieredWithProrationConfig] with a well-typed - * [TieredWithProrationConfig] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. - */ - fun tieredWithProrationConfig( - tieredWithProrationConfig: JsonField - ) = apply { this.tieredWithProrationConfig = tieredWithProrationConfig } - - /** The id of the billable metric for the price. Only needed if the price is usage-based. */ - fun billableMetricId(billableMetricId: String?) = - billableMetricId(JsonField.ofNullable(billableMetricId)) - - /** - * Sets [Builder.billableMetricId] to an arbitrary JSON value. - * - * You should usually call [Builder.billableMetricId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billableMetricId(billableMetricId: JsonField) = apply { - this.billableMetricId = billableMetricId - } - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is - * true, and in-arrears if this is false. - */ - fun billedInAdvance(billedInAdvance: Boolean?) = - billedInAdvance(JsonField.ofNullable(billedInAdvance)) - - /** - * Alias for [Builder.billedInAdvance]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun billedInAdvance(billedInAdvance: Boolean) = billedInAdvance(billedInAdvance as Boolean?) - - /** - * Sets [Builder.billedInAdvance] to an arbitrary JSON value. - * - * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billedInAdvance(billedInAdvance: JsonField) = apply { - this.billedInAdvance = billedInAdvance - } - - /** For custom cadence: specifies the duration of the billing period in days or months. */ - fun billingCycleConfiguration(billingCycleConfiguration: NewBillingCycleConfiguration?) = - billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) - - /** - * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.billingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun billingCycleConfiguration( - billingCycleConfiguration: JsonField - ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } - - /** The per unit conversion rate of the price currency to the invoicing currency. */ - fun conversionRate(conversionRate: Double?) = - conversionRate(JsonField.ofNullable(conversionRate)) - - /** - * Alias for [Builder.conversionRate]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun conversionRate(conversionRate: Double) = conversionRate(conversionRate as Double?) - - /** - * Sets [Builder.conversionRate] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRate] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun conversionRate(conversionRate: JsonField) = apply { - this.conversionRate = conversionRate - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = - conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) - - /** - * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRateConfig] with a well-typed - * [ConversionRateConfig] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun conversionRateConfig(conversionRateConfig: JsonField) = apply { - this.conversionRateConfig = conversionRateConfig - } - - /** Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofUnit(unit)`. */ - fun conversionRateConfig(unit: UnitConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofUnit(unit)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * UnitConversionRateConfig.builder() - * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - * .unitConfig(unitConfig) - * .build() - * ``` - */ - fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = - conversionRateConfig( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig(unitConfig) - .build() - ) - - /** - * Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofTiered(tiered)`. - */ - fun conversionRateConfig(tiered: TieredConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * TieredConversionRateConfig.builder() - * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - * .tieredConfig(tieredConfig) - * .build() - * ``` - */ - fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = - conversionRateConfig( - TieredConversionRateConfig.builder() - .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - .tieredConfig(tieredConfig) - .build() - ) - - /** - * An ISO 4217 currency string, or custom pricing unit identifier, in which this price is - * billed. - */ - fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) - - /** - * Sets [Builder.currency] to an arbitrary JSON value. - * - * You should usually call [Builder.currency] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun currency(currency: JsonField) = apply { this.currency = currency } - - /** For dimensional price: specifies a price group and dimension values */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? - ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) - - /** - * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed - * [NewDimensionalPriceConfiguration] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: JsonField - ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } - - /** An alias for the price. */ - fun externalPriceId(externalPriceId: String?) = - externalPriceId(JsonField.ofNullable(externalPriceId)) - - /** - * Sets [Builder.externalPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.externalPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun externalPriceId(externalPriceId: JsonField) = apply { - this.externalPriceId = externalPriceId - } - - /** If the Price represents a fixed cost, this represents the quantity of units applied. */ - fun fixedPriceQuantity(fixedPriceQuantity: Double?) = - fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) - - /** - * Alias for [Builder.fixedPriceQuantity]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun fixedPriceQuantity(fixedPriceQuantity: Double) = - fixedPriceQuantity(fixedPriceQuantity as Double?) - - /** - * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. - * - * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { - this.fixedPriceQuantity = fixedPriceQuantity - } - - /** The property used to group this price on an invoice */ - fun invoiceGroupingKey(invoiceGroupingKey: String?) = - invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) - - /** - * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceGroupingKey] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { - this.invoiceGroupingKey = invoiceGroupingKey - } - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: NewBillingCycleConfiguration? - ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) - - /** - * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: JsonField - ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by - * setting the value to `null`, and the entire metadata mapping can be cleared by setting - * `metadata` to `null`. - */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - /** - * A transient ID that can be used to reference this price when adding adjustments in the - * same API call. - */ - fun referenceId(referenceId: String?) = referenceId(JsonField.ofNullable(referenceId)) - - /** - * Sets [Builder.referenceId] to an arbitrary JSON value. - * - * You should usually call [Builder.referenceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun referenceId(referenceId: JsonField) = apply { this.referenceId = referenceId } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [NewPlanTierWithProrationPrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .cadence() - * .itemId() - * .modelType() - * .name() - * .tieredWithProrationConfig() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): NewPlanTierWithProrationPrice = - NewPlanTierWithProrationPrice( - checkRequired("cadence", cadence), - checkRequired("itemId", itemId), - checkRequired("modelType", modelType), - checkRequired("name", name), - checkRequired("tieredWithProrationConfig", tieredWithProrationConfig), - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - currency, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - referenceId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): NewPlanTierWithProrationPrice = apply { - if (validated) { - return@apply - } - - cadence().validate() - itemId() - modelType().validate() - name() - tieredWithProrationConfig().validate() - billableMetricId() - billedInAdvance() - billingCycleConfiguration()?.validate() - conversionRate() - conversionRateConfig()?.validate() - currency() - dimensionalPriceConfiguration()?.validate() - externalPriceId() - fixedPriceQuantity() - invoiceGroupingKey() - invoicingCycleConfiguration()?.validate() - metadata()?.validate() - referenceId() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (cadence.asKnown()?.validity() ?: 0) + - (if (itemId.asKnown() == null) 0 else 1) + - (modelType.asKnown()?.validity() ?: 0) + - (if (name.asKnown() == null) 0 else 1) + - (tieredWithProrationConfig.asKnown()?.validity() ?: 0) + - (if (billableMetricId.asKnown() == null) 0 else 1) + - (if (billedInAdvance.asKnown() == null) 0 else 1) + - (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (if (conversionRate.asKnown() == null) 0 else 1) + - (conversionRateConfig.asKnown()?.validity() ?: 0) + - (if (currency.asKnown() == null) 0 else 1) + - (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + - (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + - (metadata.asKnown()?.validity() ?: 0) + - (if (referenceId.asKnown() == null) 0 else 1) - - /** The cadence to bill for this price on. */ - class Cadence @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 { - - val ANNUAL = of("annual") - - val SEMI_ANNUAL = of("semi_annual") - - val MONTHLY = of("monthly") - - val QUARTERLY = of("quarterly") - - val ONE_TIME = of("one_time") - - val CUSTOM = of("custom") - - fun of(value: String) = Cadence(JsonField.of(value)) - } - - /** An enum containing [Cadence]'s known values. */ - enum class Known { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - } - - /** - * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Cadence] 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 { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - /** An enum member indicating that [Cadence] 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) { - ANNUAL -> Value.ANNUAL - SEMI_ANNUAL -> Value.SEMI_ANNUAL - MONTHLY -> Value.MONTHLY - QUARTERLY -> Value.QUARTERLY - ONE_TIME -> Value.ONE_TIME - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - ANNUAL -> Known.ANNUAL - SEMI_ANNUAL -> Known.SEMI_ANNUAL - MONTHLY -> Known.MONTHLY - QUARTERLY -> Known.QUARTERLY - ONE_TIME -> Known.ONE_TIME - CUSTOM -> Known.CUSTOM - else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): Cadence = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class ModelType @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 { - - val TIERED_WITH_PRORATION = of("tiered_with_proration") - - fun of(value: String) = ModelType(JsonField.of(value)) - } - - /** An enum containing [ModelType]'s known values. */ - enum class Known { - TIERED_WITH_PRORATION - } - - /** - * An enum containing [ModelType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [ModelType] 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 { - TIERED_WITH_PRORATION, - /** - * An enum member indicating that [ModelType] 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) { - TIERED_WITH_PRORATION -> Value.TIERED_WITH_PRORATION - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - TIERED_WITH_PRORATION -> Known.TIERED_WITH_PRORATION - else -> throw OrbInvalidDataException("Unknown ModelType: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): ModelType = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class TieredWithProrationConfig - @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 - * [TieredWithProrationConfig]. - */ - fun builder() = Builder() - } - - /** A builder for [TieredWithProrationConfig]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = apply { - additionalProperties = tieredWithProrationConfig.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 [TieredWithProrationConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): TieredWithProrationConfig = - TieredWithProrationConfig(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): TieredWithProrationConfig = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TieredWithProrationConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "TieredWithProrationConfig{additionalProperties=$additionalProperties}" - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - */ - class Metadata - @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 [Metadata]. */ - fun builder() = Builder() - } - - /** A builder for [Metadata]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.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 [Metadata]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is NewPlanTierWithProrationPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredWithProrationConfig == other.tieredWithProrationConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, tieredWithProrationConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "NewPlanTierWithProrationPrice{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, tieredWithProrationConfig=$tieredWithProrationConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredBpsPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredBpsPrice.kt deleted file mode 100644 index edca5a4dc..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredBpsPrice.kt +++ /dev/null @@ -1,1514 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer -import com.withorb.api.core.Enum -import com.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow -import com.withorb.api.core.toImmutable -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class NewPlanTieredBpsPrice -private constructor( - private val cadence: JsonField, - private val itemId: JsonField, - private val modelType: JsonField, - private val name: JsonField, - private val tieredBpsConfig: JsonField, - private val billableMetricId: JsonField, - private val billedInAdvance: JsonField, - private val billingCycleConfiguration: JsonField, - private val conversionRate: JsonField, - private val conversionRateConfig: JsonField, - private val currency: JsonField, - private val dimensionalPriceConfiguration: JsonField, - private val externalPriceId: JsonField, - private val fixedPriceQuantity: JsonField, - private val invoiceGroupingKey: JsonField, - private val invoicingCycleConfiguration: JsonField, - private val metadata: JsonField, - private val referenceId: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), - @JsonProperty("item_id") @ExcludeMissing itemId: JsonField = JsonMissing.of(), - @JsonProperty("model_type") - @ExcludeMissing - modelType: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("tiered_bps_config") - @ExcludeMissing - tieredBpsConfig: JsonField = JsonMissing.of(), - @JsonProperty("billable_metric_id") - @ExcludeMissing - billableMetricId: JsonField = JsonMissing.of(), - @JsonProperty("billed_in_advance") - @ExcludeMissing - billedInAdvance: JsonField = JsonMissing.of(), - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - billingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate") - @ExcludeMissing - conversionRate: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate_config") - @ExcludeMissing - conversionRateConfig: JsonField = JsonMissing.of(), - @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - dimensionalPriceConfiguration: JsonField = - JsonMissing.of(), - @JsonProperty("external_price_id") - @ExcludeMissing - externalPriceId: JsonField = JsonMissing.of(), - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - invoiceGroupingKey: JsonField = JsonMissing.of(), - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - invoicingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), - @JsonProperty("reference_id") - @ExcludeMissing - referenceId: JsonField = JsonMissing.of(), - ) : this( - cadence, - itemId, - modelType, - name, - tieredBpsConfig, - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - currency, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - referenceId, - mutableMapOf(), - ) - - /** - * The cadence to bill for this price on. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun cadence(): Cadence = cadence.getRequired("cadence") - - /** - * The id of the item the price will be associated with. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun itemId(): String = itemId.getRequired("item_id") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun modelType(): ModelType = modelType.getRequired("model_type") - - /** - * The name of the price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun name(): String = name.getRequired("name") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun tieredBpsConfig(): TieredBpsConfig = tieredBpsConfig.getRequired("tiered_bps_config") - - /** - * The id of the billable metric for the price. Only needed if the price is usage-based. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is true, - * and in-arrears if this is false. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - - /** - * For custom cadence: specifies the duration of the billing period in days or months. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billingCycleConfiguration(): NewBillingCycleConfiguration? = - billingCycleConfiguration.getNullable("billing_cycle_configuration") - - /** - * The per unit conversion rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - - /** - * The configuration for the rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRateConfig(): ConversionRateConfig? = - conversionRateConfig.getNullable("conversion_rate_config") - - /** - * An ISO 4217 currency string, or custom pricing unit identifier, in which this price is - * billed. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun currency(): String? = currency.getNullable("currency") - - /** - * For dimensional price: specifies a price group and dimension values - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = - dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - - /** - * An alias for the price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - - /** - * If the Price represents a fixed cost, this represents the quantity of units applied. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") - - /** - * The property used to group this price on an invoice - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoiceGroupingKey(): String? = invoiceGroupingKey.getNullable("invoice_grouping_key") - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = - invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun metadata(): Metadata? = metadata.getNullable("metadata") - - /** - * A transient ID that can be used to reference this price when adding adjustments in the same - * API call. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun referenceId(): String? = referenceId.getNullable("reference_id") - - /** - * Returns the raw JSON value of [cadence]. - * - * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence - - /** - * Returns the raw JSON value of [itemId]. - * - * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - - /** - * Returns the raw JSON value of [modelType]. - * - * Unlike [modelType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonField = modelType - - /** - * 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 [tieredBpsConfig]. - * - * Unlike [tieredBpsConfig], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("tiered_bps_config") - @ExcludeMissing - fun _tieredBpsConfig(): JsonField = tieredBpsConfig - - /** - * Returns the raw JSON value of [billableMetricId]. - * - * Unlike [billableMetricId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("billable_metric_id") - @ExcludeMissing - fun _billableMetricId(): JsonField = billableMetricId - - /** - * Returns the raw JSON value of [billedInAdvance]. - * - * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("billed_in_advance") - @ExcludeMissing - fun _billedInAdvance(): JsonField = billedInAdvance - - /** - * Returns the raw JSON value of [billingCycleConfiguration]. - * - * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - fun _billingCycleConfiguration(): JsonField = - billingCycleConfiguration - - /** - * Returns the raw JSON value of [conversionRate]. - * - * Unlike [conversionRate], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("conversion_rate") - @ExcludeMissing - fun _conversionRate(): JsonField = conversionRate - - /** - * Returns the raw JSON value of [conversionRateConfig]. - * - * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("conversion_rate_config") - @ExcludeMissing - fun _conversionRateConfig(): JsonField = conversionRateConfig - - /** - * Returns the raw JSON value of [currency]. - * - * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency - - /** - * Returns the raw JSON value of [dimensionalPriceConfiguration]. - * - * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - fun _dimensionalPriceConfiguration(): JsonField = - dimensionalPriceConfiguration - - /** - * Returns the raw JSON value of [externalPriceId]. - * - * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("external_price_id") - @ExcludeMissing - fun _externalPriceId(): JsonField = externalPriceId - - /** - * Returns the raw JSON value of [fixedPriceQuantity]. - * - * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - - /** - * Returns the raw JSON value of [invoiceGroupingKey]. - * - * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - - /** - * Returns the raw JSON value of [invoicingCycleConfiguration]. - * - * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - fun _invoicingCycleConfiguration(): JsonField = - invoicingCycleConfiguration - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - - /** - * Returns the raw JSON value of [referenceId]. - * - * Unlike [referenceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("reference_id") - @ExcludeMissing - fun _referenceId(): JsonField = referenceId - - @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 [NewPlanTieredBpsPrice]. - * - * The following fields are required: - * ```kotlin - * .cadence() - * .itemId() - * .modelType() - * .name() - * .tieredBpsConfig() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [NewPlanTieredBpsPrice]. */ - class Builder internal constructor() { - - private var cadence: JsonField? = null - private var itemId: JsonField? = null - private var modelType: JsonField? = null - private var name: JsonField? = null - private var tieredBpsConfig: JsonField? = null - private var billableMetricId: JsonField = JsonMissing.of() - private var billedInAdvance: JsonField = JsonMissing.of() - private var billingCycleConfiguration: JsonField = - JsonMissing.of() - private var conversionRate: JsonField = JsonMissing.of() - private var conversionRateConfig: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var dimensionalPriceConfiguration: JsonField = - JsonMissing.of() - private var externalPriceId: JsonField = JsonMissing.of() - private var fixedPriceQuantity: JsonField = JsonMissing.of() - private var invoiceGroupingKey: JsonField = JsonMissing.of() - private var invoicingCycleConfiguration: JsonField = - JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var referenceId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(newPlanTieredBpsPrice: NewPlanTieredBpsPrice) = apply { - cadence = newPlanTieredBpsPrice.cadence - itemId = newPlanTieredBpsPrice.itemId - modelType = newPlanTieredBpsPrice.modelType - name = newPlanTieredBpsPrice.name - tieredBpsConfig = newPlanTieredBpsPrice.tieredBpsConfig - billableMetricId = newPlanTieredBpsPrice.billableMetricId - billedInAdvance = newPlanTieredBpsPrice.billedInAdvance - billingCycleConfiguration = newPlanTieredBpsPrice.billingCycleConfiguration - conversionRate = newPlanTieredBpsPrice.conversionRate - conversionRateConfig = newPlanTieredBpsPrice.conversionRateConfig - currency = newPlanTieredBpsPrice.currency - dimensionalPriceConfiguration = newPlanTieredBpsPrice.dimensionalPriceConfiguration - externalPriceId = newPlanTieredBpsPrice.externalPriceId - fixedPriceQuantity = newPlanTieredBpsPrice.fixedPriceQuantity - invoiceGroupingKey = newPlanTieredBpsPrice.invoiceGroupingKey - invoicingCycleConfiguration = newPlanTieredBpsPrice.invoicingCycleConfiguration - metadata = newPlanTieredBpsPrice.metadata - referenceId = newPlanTieredBpsPrice.referenceId - additionalProperties = newPlanTieredBpsPrice.additionalProperties.toMutableMap() - } - - /** The cadence to bill for this price on. */ - fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) - - /** - * Sets [Builder.cadence] to an arbitrary JSON value. - * - * You should usually call [Builder.cadence] with a well-typed [Cadence] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun cadence(cadence: JsonField) = apply { this.cadence = cadence } - - /** The id of the item the price will be associated with. */ - fun itemId(itemId: String) = itemId(JsonField.of(itemId)) - - /** - * Sets [Builder.itemId] to an arbitrary JSON value. - * - * You should usually call [Builder.itemId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun itemId(itemId: JsonField) = apply { this.itemId = itemId } - - fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) - - /** - * Sets [Builder.modelType] to an arbitrary JSON value. - * - * You should usually call [Builder.modelType] with a well-typed [ModelType] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun modelType(modelType: JsonField) = apply { this.modelType = modelType } - - /** The name of the price. */ - 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 tieredBpsConfig(tieredBpsConfig: TieredBpsConfig) = - tieredBpsConfig(JsonField.of(tieredBpsConfig)) - - /** - * Sets [Builder.tieredBpsConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.tieredBpsConfig] with a well-typed [TieredBpsConfig] - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun tieredBpsConfig(tieredBpsConfig: JsonField) = apply { - this.tieredBpsConfig = tieredBpsConfig - } - - /** The id of the billable metric for the price. Only needed if the price is usage-based. */ - fun billableMetricId(billableMetricId: String?) = - billableMetricId(JsonField.ofNullable(billableMetricId)) - - /** - * Sets [Builder.billableMetricId] to an arbitrary JSON value. - * - * You should usually call [Builder.billableMetricId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billableMetricId(billableMetricId: JsonField) = apply { - this.billableMetricId = billableMetricId - } - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is - * true, and in-arrears if this is false. - */ - fun billedInAdvance(billedInAdvance: Boolean?) = - billedInAdvance(JsonField.ofNullable(billedInAdvance)) - - /** - * Alias for [Builder.billedInAdvance]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun billedInAdvance(billedInAdvance: Boolean) = billedInAdvance(billedInAdvance as Boolean?) - - /** - * Sets [Builder.billedInAdvance] to an arbitrary JSON value. - * - * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billedInAdvance(billedInAdvance: JsonField) = apply { - this.billedInAdvance = billedInAdvance - } - - /** For custom cadence: specifies the duration of the billing period in days or months. */ - fun billingCycleConfiguration(billingCycleConfiguration: NewBillingCycleConfiguration?) = - billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) - - /** - * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.billingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun billingCycleConfiguration( - billingCycleConfiguration: JsonField - ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } - - /** The per unit conversion rate of the price currency to the invoicing currency. */ - fun conversionRate(conversionRate: Double?) = - conversionRate(JsonField.ofNullable(conversionRate)) - - /** - * Alias for [Builder.conversionRate]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun conversionRate(conversionRate: Double) = conversionRate(conversionRate as Double?) - - /** - * Sets [Builder.conversionRate] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRate] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun conversionRate(conversionRate: JsonField) = apply { - this.conversionRate = conversionRate - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = - conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) - - /** - * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRateConfig] with a well-typed - * [ConversionRateConfig] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun conversionRateConfig(conversionRateConfig: JsonField) = apply { - this.conversionRateConfig = conversionRateConfig - } - - /** Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofUnit(unit)`. */ - fun conversionRateConfig(unit: UnitConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofUnit(unit)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * UnitConversionRateConfig.builder() - * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - * .unitConfig(unitConfig) - * .build() - * ``` - */ - fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = - conversionRateConfig( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig(unitConfig) - .build() - ) - - /** - * Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofTiered(tiered)`. - */ - fun conversionRateConfig(tiered: TieredConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * TieredConversionRateConfig.builder() - * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - * .tieredConfig(tieredConfig) - * .build() - * ``` - */ - fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = - conversionRateConfig( - TieredConversionRateConfig.builder() - .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - .tieredConfig(tieredConfig) - .build() - ) - - /** - * An ISO 4217 currency string, or custom pricing unit identifier, in which this price is - * billed. - */ - fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) - - /** - * Sets [Builder.currency] to an arbitrary JSON value. - * - * You should usually call [Builder.currency] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun currency(currency: JsonField) = apply { this.currency = currency } - - /** For dimensional price: specifies a price group and dimension values */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? - ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) - - /** - * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed - * [NewDimensionalPriceConfiguration] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: JsonField - ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } - - /** An alias for the price. */ - fun externalPriceId(externalPriceId: String?) = - externalPriceId(JsonField.ofNullable(externalPriceId)) - - /** - * Sets [Builder.externalPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.externalPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun externalPriceId(externalPriceId: JsonField) = apply { - this.externalPriceId = externalPriceId - } - - /** If the Price represents a fixed cost, this represents the quantity of units applied. */ - fun fixedPriceQuantity(fixedPriceQuantity: Double?) = - fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) - - /** - * Alias for [Builder.fixedPriceQuantity]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun fixedPriceQuantity(fixedPriceQuantity: Double) = - fixedPriceQuantity(fixedPriceQuantity as Double?) - - /** - * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. - * - * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { - this.fixedPriceQuantity = fixedPriceQuantity - } - - /** The property used to group this price on an invoice */ - fun invoiceGroupingKey(invoiceGroupingKey: String?) = - invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) - - /** - * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceGroupingKey] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { - this.invoiceGroupingKey = invoiceGroupingKey - } - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: NewBillingCycleConfiguration? - ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) - - /** - * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: JsonField - ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by - * setting the value to `null`, and the entire metadata mapping can be cleared by setting - * `metadata` to `null`. - */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - /** - * A transient ID that can be used to reference this price when adding adjustments in the - * same API call. - */ - fun referenceId(referenceId: String?) = referenceId(JsonField.ofNullable(referenceId)) - - /** - * Sets [Builder.referenceId] to an arbitrary JSON value. - * - * You should usually call [Builder.referenceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun referenceId(referenceId: JsonField) = apply { this.referenceId = referenceId } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [NewPlanTieredBpsPrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .cadence() - * .itemId() - * .modelType() - * .name() - * .tieredBpsConfig() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): NewPlanTieredBpsPrice = - NewPlanTieredBpsPrice( - checkRequired("cadence", cadence), - checkRequired("itemId", itemId), - checkRequired("modelType", modelType), - checkRequired("name", name), - checkRequired("tieredBpsConfig", tieredBpsConfig), - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - currency, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - referenceId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): NewPlanTieredBpsPrice = apply { - if (validated) { - return@apply - } - - cadence().validate() - itemId() - modelType().validate() - name() - tieredBpsConfig().validate() - billableMetricId() - billedInAdvance() - billingCycleConfiguration()?.validate() - conversionRate() - conversionRateConfig()?.validate() - currency() - dimensionalPriceConfiguration()?.validate() - externalPriceId() - fixedPriceQuantity() - invoiceGroupingKey() - invoicingCycleConfiguration()?.validate() - metadata()?.validate() - referenceId() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (cadence.asKnown()?.validity() ?: 0) + - (if (itemId.asKnown() == null) 0 else 1) + - (modelType.asKnown()?.validity() ?: 0) + - (if (name.asKnown() == null) 0 else 1) + - (tieredBpsConfig.asKnown()?.validity() ?: 0) + - (if (billableMetricId.asKnown() == null) 0 else 1) + - (if (billedInAdvance.asKnown() == null) 0 else 1) + - (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (if (conversionRate.asKnown() == null) 0 else 1) + - (conversionRateConfig.asKnown()?.validity() ?: 0) + - (if (currency.asKnown() == null) 0 else 1) + - (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + - (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + - (metadata.asKnown()?.validity() ?: 0) + - (if (referenceId.asKnown() == null) 0 else 1) - - /** The cadence to bill for this price on. */ - class Cadence @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 { - - val ANNUAL = of("annual") - - val SEMI_ANNUAL = of("semi_annual") - - val MONTHLY = of("monthly") - - val QUARTERLY = of("quarterly") - - val ONE_TIME = of("one_time") - - val CUSTOM = of("custom") - - fun of(value: String) = Cadence(JsonField.of(value)) - } - - /** An enum containing [Cadence]'s known values. */ - enum class Known { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - } - - /** - * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Cadence] 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 { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - /** An enum member indicating that [Cadence] 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) { - ANNUAL -> Value.ANNUAL - SEMI_ANNUAL -> Value.SEMI_ANNUAL - MONTHLY -> Value.MONTHLY - QUARTERLY -> Value.QUARTERLY - ONE_TIME -> Value.ONE_TIME - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - ANNUAL -> Known.ANNUAL - SEMI_ANNUAL -> Known.SEMI_ANNUAL - MONTHLY -> Known.MONTHLY - QUARTERLY -> Known.QUARTERLY - ONE_TIME -> Known.ONE_TIME - CUSTOM -> Known.CUSTOM - else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): Cadence = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class ModelType @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 { - - val TIERED_BPS = of("tiered_bps") - - fun of(value: String) = ModelType(JsonField.of(value)) - } - - /** An enum containing [ModelType]'s known values. */ - enum class Known { - TIERED_BPS - } - - /** - * An enum containing [ModelType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [ModelType] 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 { - TIERED_BPS, - /** - * An enum member indicating that [ModelType] 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) { - TIERED_BPS -> Value.TIERED_BPS - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - TIERED_BPS -> Known.TIERED_BPS - else -> throw OrbInvalidDataException("Unknown ModelType: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): ModelType = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - */ - class Metadata - @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 [Metadata]. */ - fun builder() = Builder() - } - - /** A builder for [Metadata]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.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 [Metadata]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is NewPlanTieredBpsPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredBpsConfig == other.tieredBpsConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, tieredBpsConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "NewPlanTieredBpsPrice{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, tieredBpsConfig=$tieredBpsConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredPackagePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredPackagePrice.kt index 413f6a1b9..c02e0bbb8 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredPackagePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredPackagePrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanTieredPackagePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +128,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +144,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for tiered_package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -530,6 +526,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -552,6 +549,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for tiered_package pricing */ fun tieredPackageConfig(tieredPackageConfig: TieredPackageConfig) = tieredPackageConfig(JsonField.of(tieredPackageConfig)) @@ -1096,7 +1094,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1104,6 +1102,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1216,7 +1215,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1224,34 +1223,142 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for tiered_package pricing */ class TieredPackageConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(packageSize, tiers, mutableMapOf()) + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. The tier bounds are defined based on the total + * quantity rather than the number of packages, so they must be multiples of the package + * size. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) companion object { - /** Returns a mutable builder for constructing an instance of [TieredPackageConfig]. */ + /** + * Returns a mutable builder for constructing an instance of [TieredPackageConfig]. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` + */ fun builder() = Builder() } /** A builder for [TieredPackageConfig]. */ class Builder internal constructor() { + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(tieredPackageConfig: TieredPackageConfig) = apply { + packageSize = tieredPackageConfig.packageSize + tiers = tieredPackageConfig.tiers.map { it.toMutableList() } additionalProperties = tieredPackageConfig.additionalProperties.toMutableMap() } + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. The tier bounds are defined based on the total + * quantity rather than the number of packages, so they must be multiples of the package + * size. + */ + 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) @@ -1275,9 +1382,21 @@ private constructor( * Returns an immutable instance of [TieredPackageConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): TieredPackageConfig = - TieredPackageConfig(additionalProperties.toImmutable()) + TieredPackageConfig( + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1287,6 +1406,8 @@ private constructor( return@apply } + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -1305,192 +1426,240 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier with business logic */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val perUnit: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("per_unit") + @ExcludeMissing + perUnit: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(perUnit, tierLowerBound, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnit(): String = perUnit.getRequired("per_unit") - return /* spotless:off */ other is TieredPackageConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Returns the raw JSON value of [perUnit]. + * + * Unlike [perUnit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("per_unit") @ExcludeMissing fun _perUnit(): JsonField = perUnit - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound - override fun toString() = "TieredPackageConfig{additionalProperties=$additionalProperties}" - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + @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: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + */ + fun builder() = Builder() + } - fun unit(): UnitConversionRateConfig? = unit + /** A builder for [Tier]. */ + class Builder internal constructor() { - fun tiered(): TieredConversionRateConfig? = tiered + private var perUnit: JsonField? = null + private var tierLowerBound: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun isUnit(): Boolean = unit != null + internal fun from(tier: Tier) = apply { + perUnit = tier.perUnit + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } - fun isTiered(): Boolean = tiered != null + /** Price per package */ + fun perUnit(perUnit: String) = perUnit(JsonField.of(perUnit)) + + /** + * Sets [Builder.perUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnit] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun perUnit(perUnit: JsonField) = apply { this.perUnit = perUnit } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun _json(): JsonValue? = _json + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - private var validated: Boolean = false + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Returns an immutable instance of [Tier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("perUnit", perUnit), + checkRequired("tierLowerBound", tierLowerBound), + additionalProperties.toMutableMap(), + ) } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } + private var validated: Boolean = false - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun validate(): Tier = apply { + if (validated) { + return@apply } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + perUnit() + tierLowerBound() + validated = true } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (perUnit.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) - override fun unknown(json: JsonValue?) = 0 + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + return other is Tier && + perUnit == other.perUnit && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + private val hashCode: Int by lazy { + Objects.hash(perUnit, tierLowerBound, additionalProperties) } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + override fun hashCode(): Int = hashCode - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) + override fun toString() = + "Tier{perUnit=$perUnit, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + return other is TieredPackageConfig && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + private val hashCode: Int by lazy { Objects.hash(packageSize, tiers, additionalProperties) } - return ConversionRateConfig(_json = json) - } - } + override fun hashCode(): Int = hashCode - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } + override fun toString() = + "TieredPackageConfig{packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } /** @@ -1585,12 +1754,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1602,12 +1769,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanTieredPackagePrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredPackageConfig == other.tieredPackageConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanTieredPackagePrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredPackageConfig == other.tieredPackageConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, tieredPackageConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredPackageConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredPackageWithMinimumPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredPackageWithMinimumPrice.kt index fd381ddb0..be4505a9c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredPackageWithMinimumPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredPackageWithMinimumPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanTieredPackageWithMinimumPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -137,6 +129,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -151,6 +145,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for tiered_package_with_minimum pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -541,6 +537,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -563,6 +560,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for tiered_package_with_minimum pricing */ fun tieredPackageWithMinimumConfig( tieredPackageWithMinimumConfig: TieredPackageWithMinimumConfig ) = tieredPackageWithMinimumConfig(JsonField.of(tieredPackageWithMinimumConfig)) @@ -1108,7 +1106,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1116,6 +1114,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1228,7 +1227,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1236,16 +1235,65 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for tiered_package_with_minimum pricing */ class TieredPackageWithMinimumConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(packageSize, tiers, mutableMapOf()) + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): Double = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1254,6 +1302,12 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [TieredPackageWithMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1261,14 +1315,61 @@ private constructor( /** A builder for [TieredPackageWithMinimumConfig]. */ class Builder internal constructor() { + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(tieredPackageWithMinimumConfig: TieredPackageWithMinimumConfig) = apply { + packageSize = tieredPackageWithMinimumConfig.packageSize + tiers = tieredPackageWithMinimumConfig.tiers.map { it.toMutableList() } additionalProperties = tieredPackageWithMinimumConfig.additionalProperties.toMutableMap() } + /** Package size */ + fun packageSize(packageSize: Double) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + */ + 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) @@ -1292,9 +1393,21 @@ private constructor( * Returns an immutable instance of [TieredPackageWithMinimumConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): TieredPackageWithMinimumConfig = - TieredPackageWithMinimumConfig(additionalProperties.toImmutable()) + TieredPackageWithMinimumConfig( + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1304,6 +1417,8 @@ private constructor( return@apply } + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -1322,193 +1437,286 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val minimumAmount: JsonField, + private val perUnit: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("per_unit") + @ExcludeMissing + perUnit: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(minimumAmount, perUnit, tierLowerBound, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TieredPackageWithMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Minimum amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun minimumAmount(): String = minimumAmount.getRequired("minimum_amount") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnit(): String = perUnit.getRequired("per_unit") - override fun hashCode(): Int = hashCode + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - override fun toString() = - "TieredPackageWithMinimumConfig{additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + /** + * Returns the raw JSON value of [perUnit]. + * + * Unlike [perUnit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("per_unit") @ExcludeMissing fun _perUnit(): JsonField = perUnit - fun unit(): UnitConversionRateConfig? = unit + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun isUnit(): Boolean = unit != null + @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: + * ```kotlin + * .minimumAmount() + * .perUnit() + * .tierLowerBound() + * ``` + */ + fun builder() = Builder() + } - fun isTiered(): Boolean = tiered != null + /** A builder for [Tier]. */ + class Builder internal constructor() { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + private var minimumAmount: JsonField? = null + private var perUnit: JsonField? = null + private var tierLowerBound: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + internal fun from(tier: Tier) = apply { + minimumAmount = tier.minimumAmount + perUnit = tier.perUnit + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } - fun _json(): JsonValue? = _json + /** Minimum amount */ + fun minimumAmount(minimumAmount: String) = + minimumAmount(JsonField.of(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + /** Price per package */ + fun perUnit(perUnit: String) = perUnit(JsonField.of(perUnit)) + + /** + * Sets [Builder.perUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnit] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun perUnit(perUnit: JsonField) = apply { this.perUnit = perUnit } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 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 [Tier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * .perUnit() + * .tierLowerBound() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("minimumAmount", minimumAmount), + checkRequired("perUnit", perUnit), + checkRequired("tierLowerBound", tierLowerBound), + additionalProperties.toMutableMap(), + ) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + private var validated: Boolean = false - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun validate(): Tier = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + minimumAmount() + perUnit() + tierLowerBound() + validated = true } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } + internal fun validity(): Int = + (if (minimumAmount.asKnown() == null) 0 else 1) + + (if (perUnit.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + return other is Tier && + minimumAmount == other.minimumAmount && + perUnit == other.perUnit && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + private val hashCode: Int by lazy { + Objects.hash(minimumAmount, perUnit, tierLowerBound, additionalProperties) + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + override fun hashCode(): Int = hashCode - return ConversionRateConfig(_json = json) - } + override fun toString() = + "Tier{minimumAmount=$minimumAmount, perUnit=$perUnit, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is TieredPackageWithMinimumConfig && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties } + + private val hashCode: Int by lazy { Objects.hash(packageSize, tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredPackageWithMinimumConfig{packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } /** @@ -1603,12 +1811,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1620,12 +1826,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanTieredPackageWithMinimumPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredPackageWithMinimumConfig == other.tieredPackageWithMinimumConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanTieredPackageWithMinimumPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredPackageWithMinimumConfig == other.tieredPackageWithMinimumConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, tieredPackageWithMinimumConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredPackageWithMinimumConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredPrice.kt index 61f5e5388..579e9ce80 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanTieredPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +143,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for tiered pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -528,6 +523,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -550,6 +546,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for tiered pricing */ fun tieredConfig(tieredConfig: TieredConfig) = tieredConfig(JsonField.of(tieredConfig)) /** @@ -1093,7 +1090,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1101,6 +1098,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1213,7 +1211,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1221,175 +1219,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1482,12 +1311,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1499,12 +1326,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanTieredPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredConfig == other.tieredConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanTieredPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredConfig == other.tieredConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, tieredConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredWithMinimumPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredWithMinimumPrice.kt index 6b129bc02..a36fcb093 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredWithMinimumPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanTieredWithMinimumPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanTieredWithMinimumPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +128,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +144,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for tiered_with_minimum pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -532,6 +528,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -554,6 +551,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for tiered_with_minimum pricing */ fun tieredWithMinimumConfig(tieredWithMinimumConfig: TieredWithMinimumConfig) = tieredWithMinimumConfig(JsonField.of(tieredWithMinimumConfig)) @@ -1099,7 +1097,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1107,6 +1105,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1219,7 +1218,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1227,16 +1226,84 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for tiered_with_minimum pricing */ class TieredWithMinimumConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val tiers: JsonField>, + private val hideZeroAmountTiers: JsonField, + private val prorate: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + @JsonProperty("hide_zero_amount_tiers") + @ExcludeMissing + hideZeroAmountTiers: JsonField = JsonMissing.of(), + @JsonProperty("prorate") @ExcludeMissing prorate: JsonField = JsonMissing.of(), + ) : this(tiers, hideZeroAmountTiers, prorate, mutableMapOf()) + + /** + * Tiered pricing with a minimum amount dependent on the volume tier. Tiers are defined + * using exclusive lower bounds. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * If true, tiers with an accrued amount of 0 will not be included in the rating. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun hideZeroAmountTiers(): Boolean? = + hideZeroAmountTiers.getNullable("hide_zero_amount_tiers") + + /** + * If true, the unit price will be prorated to the billing period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorate(): Boolean? = prorate.getNullable("prorate") + + /** + * 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 + + /** + * Returns the raw JSON value of [hideZeroAmountTiers]. + * + * Unlike [hideZeroAmountTiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("hide_zero_amount_tiers") + @ExcludeMissing + fun _hideZeroAmountTiers(): JsonField = hideZeroAmountTiers + + /** + * Returns the raw JSON value of [prorate]. + * + * Unlike [prorate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorate") @ExcludeMissing fun _prorate(): JsonField = prorate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1244,6 +1311,11 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [TieredWithMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1251,12 +1323,74 @@ private constructor( /** A builder for [TieredWithMinimumConfig]. */ class Builder internal constructor() { + private var tiers: JsonField>? = null + private var hideZeroAmountTiers: JsonField = JsonMissing.of() + private var prorate: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(tieredWithMinimumConfig: TieredWithMinimumConfig) = apply { + tiers = tieredWithMinimumConfig.tiers.map { it.toMutableList() } + hideZeroAmountTiers = tieredWithMinimumConfig.hideZeroAmountTiers + prorate = tieredWithMinimumConfig.prorate additionalProperties = tieredWithMinimumConfig.additionalProperties.toMutableMap() } + /** + * Tiered pricing with a minimum amount dependent on the volume tier. Tiers are defined + * using exclusive lower bounds. + */ + 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) + } + } + + /** If true, tiers with an accrued amount of 0 will not be included in the rating. */ + fun hideZeroAmountTiers(hideZeroAmountTiers: Boolean) = + hideZeroAmountTiers(JsonField.of(hideZeroAmountTiers)) + + /** + * Sets [Builder.hideZeroAmountTiers] to an arbitrary JSON value. + * + * You should usually call [Builder.hideZeroAmountTiers] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun hideZeroAmountTiers(hideZeroAmountTiers: JsonField) = apply { + this.hideZeroAmountTiers = hideZeroAmountTiers + } + + /** If true, the unit price will be prorated to the billing period */ + fun prorate(prorate: Boolean) = prorate(JsonField.of(prorate)) + + /** + * Sets [Builder.prorate] to an arbitrary JSON value. + * + * You should usually call [Builder.prorate] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prorate(prorate: JsonField) = apply { this.prorate = prorate } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1280,9 +1414,21 @@ private constructor( * Returns an immutable instance of [TieredWithMinimumConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): TieredWithMinimumConfig = - TieredWithMinimumConfig(additionalProperties.toImmutable()) + TieredWithMinimumConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + hideZeroAmountTiers, + prorate, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1292,6 +1438,9 @@ private constructor( return@apply } + tiers().forEach { it.validate() } + hideZeroAmountTiers() + prorate() validated = true } @@ -1310,193 +1459,295 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (hideZeroAmountTiers.asKnown() == null) 0 else 1) + + (if (prorate.asKnown() == null) 0 else 1) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val minimumAmount: JsonField, + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(minimumAmount, tierLowerBound, unitAmount, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Minimum amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun minimumAmount(): String = minimumAmount.getRequired("minimum_amount") - return /* spotless:off */ other is TieredWithMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount - override fun toString() = - "TieredWithMinimumConfig{additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount - fun unit(): UnitConversionRateConfig? = unit + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @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: + * ```kotlin + * .minimumAmount() + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - fun isUnit(): Boolean = unit != null + /** A builder for [Tier]. */ + class Builder internal constructor() { - fun isTiered(): Boolean = tiered != null + private var minimumAmount: JsonField? = null + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + internal fun from(tier: Tier) = apply { + minimumAmount = tier.minimumAmount + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** Minimum amount */ + fun minimumAmount(minimumAmount: String) = + minimumAmount(JsonField.of(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } - fun _json(): JsonValue? = _json + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - override fun unknown(json: JsonValue?) = 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 [Tier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("minimumAmount", minimumAmount), + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + private var validated: Boolean = false - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun validate(): Tier = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + minimumAmount() + tierLowerBound() + unitAmount() + validated = true } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + internal fun validity(): Int = + (if (minimumAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + minimumAmount == other.minimumAmount && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + private val hashCode: Int by lazy { + Objects.hash(minimumAmount, tierLowerBound, unitAmount, additionalProperties) + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + override fun hashCode(): Int = hashCode - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + override fun toString() = + "Tier{minimumAmount=$minimumAmount, tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } - return ConversionRateConfig(_json = json) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is TieredWithMinimumConfig && + tiers == other.tiers && + hideZeroAmountTiers == other.hideZeroAmountTiers && + prorate == other.prorate && + additionalProperties == other.additionalProperties } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } + private val hashCode: Int by lazy { + Objects.hash(tiers, hideZeroAmountTiers, prorate, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithMinimumConfig{tiers=$tiers, hideZeroAmountTiers=$hideZeroAmountTiers, prorate=$prorate, additionalProperties=$additionalProperties}" } /** @@ -1591,12 +1842,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1608,12 +1857,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanTieredWithMinimumPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredWithMinimumConfig == other.tieredWithMinimumConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanTieredWithMinimumPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredWithMinimumConfig == other.tieredWithMinimumConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, tieredWithMinimumConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredWithMinimumConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanUnitPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanUnitPrice.kt index c6482b259..670c157ef 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanUnitPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanUnitPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanUnitPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +143,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for unit pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -528,6 +523,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -550,6 +546,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for unit pricing */ fun unitConfig(unitConfig: UnitConfig) = unitConfig(JsonField.of(unitConfig)) /** @@ -1091,7 +1088,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1099,6 +1096,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1211,7 +1209,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1219,175 +1217,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1480,12 +1309,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1497,12 +1324,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanUnitPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && unitConfig == other.unitConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanUnitPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + unitConfig == other.unitConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, unitConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + unitConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanUnitWithPercentPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanUnitWithPercentPrice.kt index e6fbc8c88..2f83db737 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanUnitWithPercentPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanUnitWithPercentPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanUnitWithPercentPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +143,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for unit_with_percent pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -531,6 +526,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -553,6 +549,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for unit_with_percent pricing */ fun unitWithPercentConfig(unitWithPercentConfig: UnitWithPercentConfig) = unitWithPercentConfig(JsonField.of(unitWithPercentConfig)) @@ -1097,7 +1094,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1105,6 +1102,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1217,7 +1215,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1225,16 +1223,64 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for unit_with_percent pricing */ class UnitWithPercentConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val percent: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("percent") @ExcludeMissing percent: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(percent, unitAmount, mutableMapOf()) + + /** + * What percent, out of 100, of the calculated total to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun percent(): String = percent.getRequired("percent") + + /** + * Rate per unit of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("percent") @ExcludeMissing fun _percent(): JsonField = percent + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1242,6 +1288,12 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [UnitWithPercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * .unitAmount() + * ``` */ fun builder() = Builder() } @@ -1249,12 +1301,40 @@ private constructor( /** A builder for [UnitWithPercentConfig]. */ class Builder internal constructor() { + private var percent: JsonField? = null + private var unitAmount: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(unitWithPercentConfig: UnitWithPercentConfig) = apply { + percent = unitWithPercentConfig.percent + unitAmount = unitWithPercentConfig.unitAmount additionalProperties = unitWithPercentConfig.additionalProperties.toMutableMap() } + /** What percent, out of 100, of the calculated total to charge */ + fun percent(percent: String) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + /** Rate per unit of usage */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { this.unitAmount = unitAmount } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1278,9 +1358,21 @@ private constructor( * Returns an immutable instance of [UnitWithPercentConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): UnitWithPercentConfig = - UnitWithPercentConfig(additionalProperties.toImmutable()) + UnitWithPercentConfig( + checkRequired("percent", percent), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1290,6 +1382,8 @@ private constructor( return@apply } + percent() + unitAmount() validated = true } @@ -1308,193 +1402,27 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (percent.asKnown() == null) 0 else 1) + (if (unitAmount.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is UnitWithPercentConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UnitWithPercentConfig && + percent == other.percent && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(percent, unitAmount, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "UnitWithPercentConfig{additionalProperties=$additionalProperties}" - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } + "UnitWithPercentConfig{percent=$percent, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" } /** @@ -1589,12 +1517,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1606,12 +1532,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanUnitWithPercentPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && unitWithPercentConfig == other.unitWithPercentConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanUnitWithPercentPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + unitWithPercentConfig == other.unitWithPercentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, unitWithPercentConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + unitWithPercentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanUnitWithProrationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanUnitWithProrationPrice.kt index 172894d71..ed0113c20 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanUnitWithProrationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanUnitWithProrationPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewPlanUnitWithProrationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +143,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for unit_with_proration pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -532,6 +527,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -554,6 +550,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for unit_with_proration pricing */ fun unitWithProrationConfig(unitWithProrationConfig: UnitWithProrationConfig) = unitWithProrationConfig(JsonField.of(unitWithProrationConfig)) @@ -1099,7 +1096,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1107,6 +1104,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1219,7 +1217,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1227,16 +1225,47 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for unit_with_proration pricing */ class UnitWithProrationConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of() + ) : this(unitAmount, mutableMapOf()) + + /** + * Rate per unit of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1244,6 +1273,11 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [UnitWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .unitAmount() + * ``` */ fun builder() = Builder() } @@ -1251,12 +1285,26 @@ private constructor( /** A builder for [UnitWithProrationConfig]. */ class Builder internal constructor() { + private var unitAmount: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(unitWithProrationConfig: UnitWithProrationConfig) = apply { + unitAmount = unitWithProrationConfig.unitAmount additionalProperties = unitWithProrationConfig.additionalProperties.toMutableMap() } + /** Rate per unit of usage */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { this.unitAmount = unitAmount } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1280,9 +1328,19 @@ private constructor( * Returns an immutable instance of [UnitWithProrationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): UnitWithProrationConfig = - UnitWithProrationConfig(additionalProperties.toImmutable()) + UnitWithProrationConfig( + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1292,6 +1350,7 @@ private constructor( return@apply } + unitAmount() validated = true } @@ -1309,194 +1368,24 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + internal fun validity(): Int = (if (unitAmount.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is UnitWithProrationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UnitWithProrationConfig && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { Objects.hash(unitAmount, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "UnitWithProrationConfig{additionalProperties=$additionalProperties}" - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } + "UnitWithProrationConfig{unitAmount=$unitAmount, additionalProperties=$additionalProperties}" } /** @@ -1591,12 +1480,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1608,12 +1495,51 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanUnitWithProrationPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && unitWithProrationConfig == other.unitWithProrationConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewPlanUnitWithProrationPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + unitWithProrationConfig == other.unitWithProrationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, unitWithProrationConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + unitWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewReportingConfiguration.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewReportingConfiguration.kt index 930dc6867..e91776826 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewReportingConfiguration.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewReportingConfiguration.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class NewReportingConfiguration +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val exempt: JsonField, private val additionalProperties: MutableMap, @@ -154,12 +155,12 @@ private constructor( return true } - return /* spotless:off */ other is NewReportingConfiguration && exempt == other.exempt && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewReportingConfiguration && + exempt == other.exempt && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(exempt, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSphereConfiguration.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSphereConfiguration.kt index 35d237880..deedc3f48 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSphereConfiguration.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSphereConfiguration.kt @@ -17,9 +17,11 @@ import java.util.Collections import java.util.Objects class NewSphereConfiguration +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val taxExempt: JsonField, private val taxProvider: JsonField, + private val automaticTaxEnabled: JsonField, private val additionalProperties: MutableMap, ) { @@ -31,7 +33,10 @@ private constructor( @JsonProperty("tax_provider") @ExcludeMissing taxProvider: JsonField = JsonMissing.of(), - ) : this(taxExempt, taxProvider, mutableMapOf()) + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + automaticTaxEnabled: JsonField = JsonMissing.of(), + ) : this(taxExempt, taxProvider, automaticTaxEnabled, mutableMapOf()) /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -45,6 +50,15 @@ private constructor( */ fun taxProvider(): TaxProvider = taxProvider.getRequired("tax_provider") + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun automaticTaxEnabled(): Boolean? = automaticTaxEnabled.getNullable("automatic_tax_enabled") + /** * Returns the raw JSON value of [taxExempt]. * @@ -61,6 +75,16 @@ private constructor( @ExcludeMissing fun _taxProvider(): JsonField = taxProvider + /** + * Returns the raw JSON value of [automaticTaxEnabled]. + * + * Unlike [automaticTaxEnabled], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + fun _automaticTaxEnabled(): JsonField = automaticTaxEnabled + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -92,11 +116,13 @@ private constructor( private var taxExempt: JsonField? = null private var taxProvider: JsonField? = null + private var automaticTaxEnabled: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(newSphereConfiguration: NewSphereConfiguration) = apply { taxExempt = newSphereConfiguration.taxExempt taxProvider = newSphereConfiguration.taxProvider + automaticTaxEnabled = newSphereConfiguration.automaticTaxEnabled additionalProperties = newSphereConfiguration.additionalProperties.toMutableMap() } @@ -124,6 +150,32 @@ private constructor( this.taxProvider = taxProvider } + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean?) = + automaticTaxEnabled(JsonField.ofNullable(automaticTaxEnabled)) + + /** + * Alias for [Builder.automaticTaxEnabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean) = + automaticTaxEnabled(automaticTaxEnabled as Boolean?) + + /** + * Sets [Builder.automaticTaxEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticTaxEnabled] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: JsonField) = apply { + this.automaticTaxEnabled = automaticTaxEnabled + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -160,6 +212,7 @@ private constructor( NewSphereConfiguration( checkRequired("taxExempt", taxExempt), checkRequired("taxProvider", taxProvider), + automaticTaxEnabled, additionalProperties.toMutableMap(), ) } @@ -173,6 +226,7 @@ private constructor( taxExempt() taxProvider().validate() + automaticTaxEnabled() validated = true } @@ -190,7 +244,9 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - (if (taxExempt.asKnown() == null) 0 else 1) + (taxProvider.asKnown()?.validity() ?: 0) + (if (taxExempt.asKnown() == null) 0 else 1) + + (taxProvider.asKnown()?.validity() ?: 0) + + (if (automaticTaxEnabled.asKnown() == null) 0 else 1) class TaxProvider @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -305,7 +361,7 @@ private constructor( return true } - return /* spotless:off */ other is TaxProvider && value == other.value /* spotless:on */ + return other is TaxProvider && value == other.value } override fun hashCode() = value.hashCode() @@ -318,15 +374,19 @@ private constructor( return true } - return /* spotless:off */ other is NewSphereConfiguration && taxExempt == other.taxExempt && taxProvider == other.taxProvider && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSphereConfiguration && + taxExempt == other.taxExempt && + taxProvider == other.taxProvider && + automaticTaxEnabled == other.automaticTaxEnabled && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(taxExempt, taxProvider, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(taxExempt, taxProvider, automaticTaxEnabled, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "NewSphereConfiguration{taxExempt=$taxExempt, taxProvider=$taxProvider, additionalProperties=$additionalProperties}" + "NewSphereConfiguration{taxExempt=$taxExempt, taxProvider=$taxProvider, automaticTaxEnabled=$automaticTaxEnabled, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBpsPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBpsPrice.kt deleted file mode 100644 index 125217d4d..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBpsPrice.kt +++ /dev/null @@ -1,1509 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer -import com.withorb.api.core.Enum -import com.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow -import com.withorb.api.core.toImmutable -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class NewSubscriptionBpsPrice -private constructor( - private val bpsConfig: JsonField, - private val cadence: JsonField, - private val itemId: JsonField, - private val modelType: JsonField, - private val name: JsonField, - private val billableMetricId: JsonField, - private val billedInAdvance: JsonField, - private val billingCycleConfiguration: JsonField, - private val conversionRate: JsonField, - private val conversionRateConfig: JsonField, - private val currency: JsonField, - private val dimensionalPriceConfiguration: JsonField, - private val externalPriceId: JsonField, - private val fixedPriceQuantity: JsonField, - private val invoiceGroupingKey: JsonField, - private val invoicingCycleConfiguration: JsonField, - private val metadata: JsonField, - private val referenceId: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("bps_config") - @ExcludeMissing - bpsConfig: JsonField = JsonMissing.of(), - @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), - @JsonProperty("item_id") @ExcludeMissing itemId: JsonField = JsonMissing.of(), - @JsonProperty("model_type") - @ExcludeMissing - modelType: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("billable_metric_id") - @ExcludeMissing - billableMetricId: JsonField = JsonMissing.of(), - @JsonProperty("billed_in_advance") - @ExcludeMissing - billedInAdvance: JsonField = JsonMissing.of(), - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - billingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate") - @ExcludeMissing - conversionRate: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate_config") - @ExcludeMissing - conversionRateConfig: JsonField = JsonMissing.of(), - @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - dimensionalPriceConfiguration: JsonField = - JsonMissing.of(), - @JsonProperty("external_price_id") - @ExcludeMissing - externalPriceId: JsonField = JsonMissing.of(), - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - invoiceGroupingKey: JsonField = JsonMissing.of(), - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - invoicingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), - @JsonProperty("reference_id") - @ExcludeMissing - referenceId: JsonField = JsonMissing.of(), - ) : this( - bpsConfig, - cadence, - itemId, - modelType, - name, - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - currency, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - referenceId, - mutableMapOf(), - ) - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun bpsConfig(): BpsConfig = bpsConfig.getRequired("bps_config") - - /** - * The cadence to bill for this price on. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun cadence(): Cadence = cadence.getRequired("cadence") - - /** - * The id of the item the price will be associated with. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun itemId(): String = itemId.getRequired("item_id") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun modelType(): ModelType = modelType.getRequired("model_type") - - /** - * The name of the price. - * - * @throws OrbInvalidDataException if 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") - - /** - * The id of the billable metric for the price. Only needed if the price is usage-based. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is true, - * and in-arrears if this is false. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - - /** - * For custom cadence: specifies the duration of the billing period in days or months. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billingCycleConfiguration(): NewBillingCycleConfiguration? = - billingCycleConfiguration.getNullable("billing_cycle_configuration") - - /** - * The per unit conversion rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - - /** - * The configuration for the rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRateConfig(): ConversionRateConfig? = - conversionRateConfig.getNullable("conversion_rate_config") - - /** - * An ISO 4217 currency string, or custom pricing unit identifier, in which this price is - * billed. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun currency(): String? = currency.getNullable("currency") - - /** - * For dimensional price: specifies a price group and dimension values - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = - dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - - /** - * An alias for the price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - - /** - * If the Price represents a fixed cost, this represents the quantity of units applied. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") - - /** - * The property used to group this price on an invoice - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoiceGroupingKey(): String? = invoiceGroupingKey.getNullable("invoice_grouping_key") - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = - invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun metadata(): Metadata? = metadata.getNullable("metadata") - - /** - * A transient ID that can be used to reference this price when adding adjustments in the same - * API call. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun referenceId(): String? = referenceId.getNullable("reference_id") - - /** - * Returns the raw JSON value of [bpsConfig]. - * - * Unlike [bpsConfig], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("bps_config") @ExcludeMissing fun _bpsConfig(): JsonField = bpsConfig - - /** - * Returns the raw JSON value of [cadence]. - * - * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence - - /** - * Returns the raw JSON value of [itemId]. - * - * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - - /** - * Returns the raw JSON value of [modelType]. - * - * Unlike [modelType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonField = modelType - - /** - * 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 [billableMetricId]. - * - * Unlike [billableMetricId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("billable_metric_id") - @ExcludeMissing - fun _billableMetricId(): JsonField = billableMetricId - - /** - * Returns the raw JSON value of [billedInAdvance]. - * - * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("billed_in_advance") - @ExcludeMissing - fun _billedInAdvance(): JsonField = billedInAdvance - - /** - * Returns the raw JSON value of [billingCycleConfiguration]. - * - * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - fun _billingCycleConfiguration(): JsonField = - billingCycleConfiguration - - /** - * Returns the raw JSON value of [conversionRate]. - * - * Unlike [conversionRate], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("conversion_rate") - @ExcludeMissing - fun _conversionRate(): JsonField = conversionRate - - /** - * Returns the raw JSON value of [conversionRateConfig]. - * - * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("conversion_rate_config") - @ExcludeMissing - fun _conversionRateConfig(): JsonField = conversionRateConfig - - /** - * Returns the raw JSON value of [currency]. - * - * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency - - /** - * Returns the raw JSON value of [dimensionalPriceConfiguration]. - * - * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - fun _dimensionalPriceConfiguration(): JsonField = - dimensionalPriceConfiguration - - /** - * Returns the raw JSON value of [externalPriceId]. - * - * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("external_price_id") - @ExcludeMissing - fun _externalPriceId(): JsonField = externalPriceId - - /** - * Returns the raw JSON value of [fixedPriceQuantity]. - * - * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - - /** - * Returns the raw JSON value of [invoiceGroupingKey]. - * - * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - - /** - * Returns the raw JSON value of [invoicingCycleConfiguration]. - * - * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - fun _invoicingCycleConfiguration(): JsonField = - invoicingCycleConfiguration - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - - /** - * Returns the raw JSON value of [referenceId]. - * - * Unlike [referenceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("reference_id") - @ExcludeMissing - fun _referenceId(): JsonField = referenceId - - @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 [NewSubscriptionBpsPrice]. - * - * The following fields are required: - * ```kotlin - * .bpsConfig() - * .cadence() - * .itemId() - * .modelType() - * .name() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [NewSubscriptionBpsPrice]. */ - class Builder internal constructor() { - - private var bpsConfig: JsonField? = null - private var cadence: JsonField? = null - private var itemId: JsonField? = null - private var modelType: JsonField? = null - private var name: JsonField? = null - private var billableMetricId: JsonField = JsonMissing.of() - private var billedInAdvance: JsonField = JsonMissing.of() - private var billingCycleConfiguration: JsonField = - JsonMissing.of() - private var conversionRate: JsonField = JsonMissing.of() - private var conversionRateConfig: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var dimensionalPriceConfiguration: JsonField = - JsonMissing.of() - private var externalPriceId: JsonField = JsonMissing.of() - private var fixedPriceQuantity: JsonField = JsonMissing.of() - private var invoiceGroupingKey: JsonField = JsonMissing.of() - private var invoicingCycleConfiguration: JsonField = - JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var referenceId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(newSubscriptionBpsPrice: NewSubscriptionBpsPrice) = apply { - bpsConfig = newSubscriptionBpsPrice.bpsConfig - cadence = newSubscriptionBpsPrice.cadence - itemId = newSubscriptionBpsPrice.itemId - modelType = newSubscriptionBpsPrice.modelType - name = newSubscriptionBpsPrice.name - billableMetricId = newSubscriptionBpsPrice.billableMetricId - billedInAdvance = newSubscriptionBpsPrice.billedInAdvance - billingCycleConfiguration = newSubscriptionBpsPrice.billingCycleConfiguration - conversionRate = newSubscriptionBpsPrice.conversionRate - conversionRateConfig = newSubscriptionBpsPrice.conversionRateConfig - currency = newSubscriptionBpsPrice.currency - dimensionalPriceConfiguration = newSubscriptionBpsPrice.dimensionalPriceConfiguration - externalPriceId = newSubscriptionBpsPrice.externalPriceId - fixedPriceQuantity = newSubscriptionBpsPrice.fixedPriceQuantity - invoiceGroupingKey = newSubscriptionBpsPrice.invoiceGroupingKey - invoicingCycleConfiguration = newSubscriptionBpsPrice.invoicingCycleConfiguration - metadata = newSubscriptionBpsPrice.metadata - referenceId = newSubscriptionBpsPrice.referenceId - additionalProperties = newSubscriptionBpsPrice.additionalProperties.toMutableMap() - } - - fun bpsConfig(bpsConfig: BpsConfig) = bpsConfig(JsonField.of(bpsConfig)) - - /** - * Sets [Builder.bpsConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.bpsConfig] with a well-typed [BpsConfig] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun bpsConfig(bpsConfig: JsonField) = apply { this.bpsConfig = bpsConfig } - - /** The cadence to bill for this price on. */ - fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) - - /** - * Sets [Builder.cadence] to an arbitrary JSON value. - * - * You should usually call [Builder.cadence] with a well-typed [Cadence] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun cadence(cadence: JsonField) = apply { this.cadence = cadence } - - /** The id of the item the price will be associated with. */ - fun itemId(itemId: String) = itemId(JsonField.of(itemId)) - - /** - * Sets [Builder.itemId] to an arbitrary JSON value. - * - * You should usually call [Builder.itemId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun itemId(itemId: JsonField) = apply { this.itemId = itemId } - - fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) - - /** - * Sets [Builder.modelType] to an arbitrary JSON value. - * - * You should usually call [Builder.modelType] with a well-typed [ModelType] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun modelType(modelType: JsonField) = apply { this.modelType = modelType } - - /** The name of the price. */ - 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 id of the billable metric for the price. Only needed if the price is usage-based. */ - fun billableMetricId(billableMetricId: String?) = - billableMetricId(JsonField.ofNullable(billableMetricId)) - - /** - * Sets [Builder.billableMetricId] to an arbitrary JSON value. - * - * You should usually call [Builder.billableMetricId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billableMetricId(billableMetricId: JsonField) = apply { - this.billableMetricId = billableMetricId - } - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is - * true, and in-arrears if this is false. - */ - fun billedInAdvance(billedInAdvance: Boolean?) = - billedInAdvance(JsonField.ofNullable(billedInAdvance)) - - /** - * Alias for [Builder.billedInAdvance]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun billedInAdvance(billedInAdvance: Boolean) = billedInAdvance(billedInAdvance as Boolean?) - - /** - * Sets [Builder.billedInAdvance] to an arbitrary JSON value. - * - * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billedInAdvance(billedInAdvance: JsonField) = apply { - this.billedInAdvance = billedInAdvance - } - - /** For custom cadence: specifies the duration of the billing period in days or months. */ - fun billingCycleConfiguration(billingCycleConfiguration: NewBillingCycleConfiguration?) = - billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) - - /** - * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.billingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun billingCycleConfiguration( - billingCycleConfiguration: JsonField - ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } - - /** The per unit conversion rate of the price currency to the invoicing currency. */ - fun conversionRate(conversionRate: Double?) = - conversionRate(JsonField.ofNullable(conversionRate)) - - /** - * Alias for [Builder.conversionRate]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun conversionRate(conversionRate: Double) = conversionRate(conversionRate as Double?) - - /** - * Sets [Builder.conversionRate] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRate] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun conversionRate(conversionRate: JsonField) = apply { - this.conversionRate = conversionRate - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = - conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) - - /** - * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRateConfig] with a well-typed - * [ConversionRateConfig] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun conversionRateConfig(conversionRateConfig: JsonField) = apply { - this.conversionRateConfig = conversionRateConfig - } - - /** Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofUnit(unit)`. */ - fun conversionRateConfig(unit: UnitConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofUnit(unit)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * UnitConversionRateConfig.builder() - * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - * .unitConfig(unitConfig) - * .build() - * ``` - */ - fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = - conversionRateConfig( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig(unitConfig) - .build() - ) - - /** - * Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofTiered(tiered)`. - */ - fun conversionRateConfig(tiered: TieredConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * TieredConversionRateConfig.builder() - * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - * .tieredConfig(tieredConfig) - * .build() - * ``` - */ - fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = - conversionRateConfig( - TieredConversionRateConfig.builder() - .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - .tieredConfig(tieredConfig) - .build() - ) - - /** - * An ISO 4217 currency string, or custom pricing unit identifier, in which this price is - * billed. - */ - fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) - - /** - * Sets [Builder.currency] to an arbitrary JSON value. - * - * You should usually call [Builder.currency] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun currency(currency: JsonField) = apply { this.currency = currency } - - /** For dimensional price: specifies a price group and dimension values */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? - ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) - - /** - * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed - * [NewDimensionalPriceConfiguration] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: JsonField - ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } - - /** An alias for the price. */ - fun externalPriceId(externalPriceId: String?) = - externalPriceId(JsonField.ofNullable(externalPriceId)) - - /** - * Sets [Builder.externalPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.externalPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun externalPriceId(externalPriceId: JsonField) = apply { - this.externalPriceId = externalPriceId - } - - /** If the Price represents a fixed cost, this represents the quantity of units applied. */ - fun fixedPriceQuantity(fixedPriceQuantity: Double?) = - fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) - - /** - * Alias for [Builder.fixedPriceQuantity]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun fixedPriceQuantity(fixedPriceQuantity: Double) = - fixedPriceQuantity(fixedPriceQuantity as Double?) - - /** - * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. - * - * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { - this.fixedPriceQuantity = fixedPriceQuantity - } - - /** The property used to group this price on an invoice */ - fun invoiceGroupingKey(invoiceGroupingKey: String?) = - invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) - - /** - * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceGroupingKey] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { - this.invoiceGroupingKey = invoiceGroupingKey - } - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: NewBillingCycleConfiguration? - ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) - - /** - * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: JsonField - ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by - * setting the value to `null`, and the entire metadata mapping can be cleared by setting - * `metadata` to `null`. - */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - /** - * A transient ID that can be used to reference this price when adding adjustments in the - * same API call. - */ - fun referenceId(referenceId: String?) = referenceId(JsonField.ofNullable(referenceId)) - - /** - * Sets [Builder.referenceId] to an arbitrary JSON value. - * - * You should usually call [Builder.referenceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun referenceId(referenceId: JsonField) = apply { this.referenceId = referenceId } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [NewSubscriptionBpsPrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .bpsConfig() - * .cadence() - * .itemId() - * .modelType() - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): NewSubscriptionBpsPrice = - NewSubscriptionBpsPrice( - checkRequired("bpsConfig", bpsConfig), - checkRequired("cadence", cadence), - checkRequired("itemId", itemId), - checkRequired("modelType", modelType), - checkRequired("name", name), - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - currency, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - referenceId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): NewSubscriptionBpsPrice = apply { - if (validated) { - return@apply - } - - bpsConfig().validate() - cadence().validate() - itemId() - modelType().validate() - name() - billableMetricId() - billedInAdvance() - billingCycleConfiguration()?.validate() - conversionRate() - conversionRateConfig()?.validate() - currency() - dimensionalPriceConfiguration()?.validate() - externalPriceId() - fixedPriceQuantity() - invoiceGroupingKey() - invoicingCycleConfiguration()?.validate() - metadata()?.validate() - referenceId() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (bpsConfig.asKnown()?.validity() ?: 0) + - (cadence.asKnown()?.validity() ?: 0) + - (if (itemId.asKnown() == null) 0 else 1) + - (modelType.asKnown()?.validity() ?: 0) + - (if (name.asKnown() == null) 0 else 1) + - (if (billableMetricId.asKnown() == null) 0 else 1) + - (if (billedInAdvance.asKnown() == null) 0 else 1) + - (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (if (conversionRate.asKnown() == null) 0 else 1) + - (conversionRateConfig.asKnown()?.validity() ?: 0) + - (if (currency.asKnown() == null) 0 else 1) + - (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + - (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + - (metadata.asKnown()?.validity() ?: 0) + - (if (referenceId.asKnown() == null) 0 else 1) - - /** The cadence to bill for this price on. */ - class Cadence @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 { - - val ANNUAL = of("annual") - - val SEMI_ANNUAL = of("semi_annual") - - val MONTHLY = of("monthly") - - val QUARTERLY = of("quarterly") - - val ONE_TIME = of("one_time") - - val CUSTOM = of("custom") - - fun of(value: String) = Cadence(JsonField.of(value)) - } - - /** An enum containing [Cadence]'s known values. */ - enum class Known { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - } - - /** - * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Cadence] 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 { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - /** An enum member indicating that [Cadence] 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) { - ANNUAL -> Value.ANNUAL - SEMI_ANNUAL -> Value.SEMI_ANNUAL - MONTHLY -> Value.MONTHLY - QUARTERLY -> Value.QUARTERLY - ONE_TIME -> Value.ONE_TIME - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - ANNUAL -> Known.ANNUAL - SEMI_ANNUAL -> Known.SEMI_ANNUAL - MONTHLY -> Known.MONTHLY - QUARTERLY -> Known.QUARTERLY - ONE_TIME -> Known.ONE_TIME - CUSTOM -> Known.CUSTOM - else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): Cadence = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class ModelType @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 { - - val BPS = of("bps") - - fun of(value: String) = ModelType(JsonField.of(value)) - } - - /** An enum containing [ModelType]'s known values. */ - enum class Known { - BPS - } - - /** - * An enum containing [ModelType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [ModelType] 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 { - BPS, - /** - * An enum member indicating that [ModelType] 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) { - BPS -> Value.BPS - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - BPS -> Known.BPS - else -> throw OrbInvalidDataException("Unknown ModelType: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): ModelType = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - */ - class Metadata - @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 [Metadata]. */ - fun builder() = Builder() - } - - /** A builder for [Metadata]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.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 [Metadata]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is NewSubscriptionBpsPrice && bpsConfig == other.bpsConfig && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bpsConfig, cadence, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "NewSubscriptionBpsPrice{bpsConfig=$bpsConfig, cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBulkPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBulkPrice.kt index 4fa9b17b0..444fd4b50 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBulkPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBulkPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionBulkPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val bulkConfig: JsonField, private val cadence: JsonField, @@ -120,6 +111,8 @@ private constructor( ) /** + * Configuration for bulk pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -142,6 +135,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -506,6 +501,7 @@ private constructor( additionalProperties = newSubscriptionBulkPrice.additionalProperties.toMutableMap() } + /** Configuration for bulk pricing */ fun bulkConfig(bulkConfig: BulkConfig) = bulkConfig(JsonField.of(bulkConfig)) /** @@ -539,6 +535,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1091,7 +1088,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1099,6 +1096,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1211,7 +1209,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1219,175 +1217,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1480,12 +1309,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1497,12 +1324,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionBulkPrice && bulkConfig == other.bulkConfig && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionBulkPrice && + bulkConfig == other.bulkConfig && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bulkConfig, cadence, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + bulkConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBulkWithProrationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBulkWithProrationPrice.kt index fddea7912..5d5d26545 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBulkWithProrationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionBulkWithProrationPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionBulkWithProrationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val bulkWithProrationConfig: JsonField, private val cadence: JsonField, @@ -120,6 +112,8 @@ private constructor( ) /** + * Configuration for bulk_with_proration pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +137,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -515,6 +511,7 @@ private constructor( newSubscriptionBulkWithProrationPrice.additionalProperties.toMutableMap() } + /** Configuration for bulk_with_proration pricing */ fun bulkWithProrationConfig(bulkWithProrationConfig: BulkWithProrationConfig) = bulkWithProrationConfig(JsonField.of(bulkWithProrationConfig)) @@ -552,6 +549,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -963,16 +961,43 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (if (referenceId.asKnown() == null) 0 else 1) + /** Configuration for bulk_with_proration pricing */ class BulkWithProrationConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -980,6 +1005,11 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [BulkWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` */ fun builder() = Builder() } @@ -987,12 +1017,40 @@ private constructor( /** A builder for [BulkWithProrationConfig]. */ class Builder internal constructor() { + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(bulkWithProrationConfig: BulkWithProrationConfig) = apply { + tiers = bulkWithProrationConfig.tiers.map { it.toMutableList() } additionalProperties = bulkWithProrationConfig.additionalProperties.toMutableMap() } + /** Bulk tiers for rating based on total usage volume */ + 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) @@ -1016,9 +1074,19 @@ private constructor( * Returns an immutable instance of [BulkWithProrationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): BulkWithProrationConfig = - BulkWithProrationConfig(additionalProperties.toImmutable()) + BulkWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1028,6 +1096,7 @@ private constructor( return@apply } + tiers().forEach { it.validate() } validated = true } @@ -1045,25 +1114,240 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + internal fun validity(): Int = (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single bulk pricing tier with proration */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Cost per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun tierLowerBound(): String? = tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Cost per unit */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is BulkWithProrationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BulkWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "BulkWithProrationConfig{additionalProperties=$additionalProperties}" + "BulkWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" } /** The cadence to bill for this price on. */ @@ -1207,7 +1491,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1215,6 +1499,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1327,7 +1612,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1335,175 +1620,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1596,12 +1712,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1613,12 +1727,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionBulkWithProrationPrice && bulkWithProrationConfig == other.bulkWithProrationConfig && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionBulkWithProrationPrice && + bulkWithProrationConfig == other.bulkWithProrationConfig && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bulkWithProrationConfig, cadence, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + bulkWithProrationConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionCumulativeGroupedBulkPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionCumulativeGroupedBulkPrice.kt index 02a96c175..5e6c7823d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionCumulativeGroupedBulkPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionCumulativeGroupedBulkPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionCumulativeGroupedBulkPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val cumulativeGroupedBulkConfig: JsonField, @@ -128,6 +120,8 @@ private constructor( fun cadence(): Cadence = cadence.getRequired("cadence") /** + * Configuration for cumulative_grouped_bulk pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +137,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -528,6 +524,7 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + /** Configuration for cumulative_grouped_bulk pricing */ fun cumulativeGroupedBulkConfig(cumulativeGroupedBulkConfig: CumulativeGroupedBulkConfig) = cumulativeGroupedBulkConfig(JsonField.of(cumulativeGroupedBulkConfig)) @@ -553,6 +550,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1105,7 +1103,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1113,16 +1111,66 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for cumulative_grouped_bulk pricing */ class CumulativeGroupedBulkConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val dimensionValues: JsonField>, + private val group: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("dimension_values") + @ExcludeMissing + dimensionValues: JsonField> = JsonMissing.of(), + @JsonProperty("group") @ExcludeMissing group: JsonField = JsonMissing.of(), + ) : this(dimensionValues, group, mutableMapOf()) + + /** + * Each tier lower bound must have the same group of values. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dimensionValues(): List = + dimensionValues.getRequired("dimension_values") + + /** + * Grouping key name + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun group(): String = group.getRequired("group") + + /** + * Returns the raw JSON value of [dimensionValues]. + * + * Unlike [dimensionValues], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dimension_values") + @ExcludeMissing + fun _dimensionValues(): JsonField> = dimensionValues + + /** + * Returns the raw JSON value of [group]. + * + * Unlike [group], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("group") @ExcludeMissing fun _group(): JsonField = group + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1131,6 +1179,12 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [CumulativeGroupedBulkConfig]. + * + * The following fields are required: + * ```kotlin + * .dimensionValues() + * .group() + * ``` */ fun builder() = Builder() } @@ -1138,13 +1192,57 @@ private constructor( /** A builder for [CumulativeGroupedBulkConfig]. */ class Builder internal constructor() { + private var dimensionValues: JsonField>? = null + private var group: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(cumulativeGroupedBulkConfig: CumulativeGroupedBulkConfig) = apply { + dimensionValues = + cumulativeGroupedBulkConfig.dimensionValues.map { it.toMutableList() } + group = cumulativeGroupedBulkConfig.group additionalProperties = cumulativeGroupedBulkConfig.additionalProperties.toMutableMap() } + /** Each tier lower bound must have the same group of values. */ + fun dimensionValues(dimensionValues: List) = + dimensionValues(JsonField.of(dimensionValues)) + + /** + * Sets [Builder.dimensionValues] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionValues] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun dimensionValues(dimensionValues: JsonField>) = apply { + this.dimensionValues = dimensionValues.map { it.toMutableList() } + } + + /** + * Adds a single [DimensionValue] to [dimensionValues]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDimensionValue(dimensionValue: DimensionValue) = apply { + dimensionValues = + (dimensionValues ?: JsonField.of(mutableListOf())).also { + checkKnown("dimensionValues", it).add(dimensionValue) + } + } + + /** Grouping key name */ + fun group(group: String) = group(JsonField.of(group)) + + /** + * Sets [Builder.group] to an arbitrary JSON value. + * + * You should usually call [Builder.group] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun group(group: JsonField) = apply { this.group = group } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1168,9 +1266,21 @@ private constructor( * Returns an immutable instance of [CumulativeGroupedBulkConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .dimensionValues() + * .group() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): CumulativeGroupedBulkConfig = - CumulativeGroupedBulkConfig(additionalProperties.toImmutable()) + CumulativeGroupedBulkConfig( + checkRequired("dimensionValues", dimensionValues).map { it.toImmutable() }, + checkRequired("group", group), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1180,6 +1290,8 @@ private constructor( return@apply } + dimensionValues().forEach { it.validate() } + group() validated = true } @@ -1198,26 +1310,295 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (dimensionValues.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (group.asKnown() == null) 0 else 1) + + /** Configuration for a dimension value entry */ + class DimensionValue + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(groupingKey, tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Grouping key value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Unit amount for this combination + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 [DimensionValue]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [DimensionValue]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(dimensionValue: DimensionValue) = apply { + groupingKey = dimensionValue.groupingKey + tierLowerBound = dimensionValue.tierLowerBound + unitAmount = dimensionValue.unitAmount + additionalProperties = dimensionValue.additionalProperties.toMutableMap() + } + + /** Grouping key value */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Unit amount for this combination */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [DimensionValue]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DimensionValue = + DimensionValue( + checkRequired("groupingKey", groupingKey), + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): DimensionValue = apply { + if (validated) { + return@apply + } + + groupingKey() + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DimensionValue && + groupingKey == other.groupingKey && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(groupingKey, tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DimensionValue{groupingKey=$groupingKey, tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is CumulativeGroupedBulkConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CumulativeGroupedBulkConfig && + dimensionValues == other.dimensionValues && + group == other.group && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(dimensionValues, group, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "CumulativeGroupedBulkConfig{additionalProperties=$additionalProperties}" + "CumulativeGroupedBulkConfig{dimensionValues=$dimensionValues, group=$group, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1330,7 +1711,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1338,175 +1719,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1599,12 +1811,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1616,12 +1826,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionCumulativeGroupedBulkPrice && cadence == other.cadence && cumulativeGroupedBulkConfig == other.cumulativeGroupedBulkConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionCumulativeGroupedBulkPrice && + cadence == other.cadence && + cumulativeGroupedBulkConfig == other.cumulativeGroupedBulkConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, cumulativeGroupedBulkConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedBulkConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedAllocationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedAllocationPrice.kt index d8bc0308f..1376a2207 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedAllocationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedAllocationPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionGroupedAllocationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val groupedAllocationConfig: JsonField, @@ -128,6 +119,8 @@ private constructor( fun cadence(): Cadence = cadence.getRequired("cadence") /** + * Configuration for grouped_allocation pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +136,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -526,6 +521,7 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + /** Configuration for grouped_allocation pricing */ fun groupedAllocationConfig(groupedAllocationConfig: GroupedAllocationConfig) = groupedAllocationConfig(JsonField.of(groupedAllocationConfig)) @@ -552,6 +548,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1104,7 +1101,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1112,16 +1109,90 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_allocation pricing */ class GroupedAllocationConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val allocation: JsonField, + private val groupingKey: JsonField, + private val overageUnitRate: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("allocation") + @ExcludeMissing + allocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("overage_unit_rate") + @ExcludeMissing + overageUnitRate: JsonField = JsonMissing.of(), + ) : this(allocation, groupingKey, overageUnitRate, mutableMapOf()) + + /** + * Usage allocation per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun allocation(): String = allocation.getRequired("allocation") + + /** + * How to determine the groups that should each be allocated some quantity + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Unit rate for post-allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun overageUnitRate(): String = overageUnitRate.getRequired("overage_unit_rate") + + /** + * Returns the raw JSON value of [allocation]. + * + * Unlike [allocation], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allocation") + @ExcludeMissing + fun _allocation(): JsonField = allocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [overageUnitRate]. + * + * Unlike [overageUnitRate], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("overage_unit_rate") + @ExcludeMissing + fun _overageUnitRate(): JsonField = overageUnitRate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1129,6 +1200,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [GroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .groupingKey() + * .overageUnitRate() + * ``` */ fun builder() = Builder() } @@ -1136,12 +1214,59 @@ private constructor( /** A builder for [GroupedAllocationConfig]. */ class Builder internal constructor() { + private var allocation: JsonField? = null + private var groupingKey: JsonField? = null + private var overageUnitRate: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedAllocationConfig: GroupedAllocationConfig) = apply { + allocation = groupedAllocationConfig.allocation + groupingKey = groupedAllocationConfig.groupingKey + overageUnitRate = groupedAllocationConfig.overageUnitRate additionalProperties = groupedAllocationConfig.additionalProperties.toMutableMap() } + /** Usage allocation per group */ + fun allocation(allocation: String) = allocation(JsonField.of(allocation)) + + /** + * Sets [Builder.allocation] to an arbitrary JSON value. + * + * You should usually call [Builder.allocation] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun allocation(allocation: JsonField) = apply { this.allocation = allocation } + + /** How to determine the groups that should each be allocated some quantity */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Unit rate for post-allocation */ + fun overageUnitRate(overageUnitRate: String) = + overageUnitRate(JsonField.of(overageUnitRate)) + + /** + * Sets [Builder.overageUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.overageUnitRate] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun overageUnitRate(overageUnitRate: JsonField) = apply { + this.overageUnitRate = overageUnitRate + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1165,9 +1290,23 @@ private constructor( * Returns an immutable instance of [GroupedAllocationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .groupingKey() + * .overageUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedAllocationConfig = - GroupedAllocationConfig(additionalProperties.toImmutable()) + GroupedAllocationConfig( + checkRequired("allocation", allocation), + checkRequired("groupingKey", groupingKey), + checkRequired("overageUnitRate", overageUnitRate), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1177,6 +1316,9 @@ private constructor( return@apply } + allocation() + groupingKey() + overageUnitRate() validated = true } @@ -1195,26 +1337,33 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (allocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (overageUnitRate.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedAllocationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedAllocationConfig && + allocation == other.allocation && + groupingKey == other.groupingKey && + overageUnitRate == other.overageUnitRate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(allocation, groupingKey, overageUnitRate, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedAllocationConfig{additionalProperties=$additionalProperties}" + "GroupedAllocationConfig{allocation=$allocation, groupingKey=$groupingKey, overageUnitRate=$overageUnitRate, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1327,7 +1476,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1335,175 +1484,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1596,12 +1576,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1613,12 +1591,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionGroupedAllocationPrice && cadence == other.cadence && groupedAllocationConfig == other.groupedAllocationConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionGroupedAllocationPrice && + cadence == other.cadence && + groupedAllocationConfig == other.groupedAllocationConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, groupedAllocationConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPackagePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPackagePrice.kt index 55b9cd6cf..b89fb3b05 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPackagePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPackagePrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionGroupedTieredPackagePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val groupedTieredPackageConfig: JsonField, @@ -128,6 +120,8 @@ private constructor( fun cadence(): Cadence = cadence.getRequired("cadence") /** + * Configuration for grouped_tiered_package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +137,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -528,6 +524,7 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + /** Configuration for grouped_tiered_package pricing */ fun groupedTieredPackageConfig(groupedTieredPackageConfig: GroupedTieredPackageConfig) = groupedTieredPackageConfig(JsonField.of(groupedTieredPackageConfig)) @@ -553,6 +550,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1105,7 +1103,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1113,16 +1111,86 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_tiered_package pricing */ class GroupedTieredPackageConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(groupingKey, packageSize, tiers, mutableMapOf()) + + /** + * The event property used to group before tiering + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1131,6 +1199,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [GroupedTieredPackageConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1138,13 +1213,76 @@ private constructor( /** A builder for [GroupedTieredPackageConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedTieredPackageConfig: GroupedTieredPackageConfig) = apply { + groupingKey = groupedTieredPackageConfig.groupingKey + packageSize = groupedTieredPackageConfig.packageSize + tiers = groupedTieredPackageConfig.tiers.map { it.toMutableList() } additionalProperties = groupedTieredPackageConfig.additionalProperties.toMutableMap() } + /** The event property used to group before tiering */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + */ + 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) @@ -1168,9 +1306,23 @@ private constructor( * Returns an immutable instance of [GroupedTieredPackageConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedTieredPackageConfig = - GroupedTieredPackageConfig(additionalProperties.toImmutable()) + GroupedTieredPackageConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1180,6 +1332,9 @@ private constructor( return@apply } + groupingKey() + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -1198,26 +1353,247 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val perUnit: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("per_unit") + @ExcludeMissing + perUnit: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(perUnit, tierLowerBound, mutableMapOf()) + + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnit(): String = perUnit.getRequired("per_unit") + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Returns the raw JSON value of [perUnit]. + * + * Unlike [perUnit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("per_unit") @ExcludeMissing fun _perUnit(): JsonField = perUnit + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var perUnit: JsonField? = null + private var tierLowerBound: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + perUnit = tier.perUnit + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Price per package */ + fun perUnit(perUnit: String) = perUnit(JsonField.of(perUnit)) + + /** + * Sets [Builder.perUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnit] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun perUnit(perUnit: JsonField) = apply { this.perUnit = perUnit } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("perUnit", perUnit), + checkRequired("tierLowerBound", tierLowerBound), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + perUnit() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (perUnit.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + perUnit == other.perUnit && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(perUnit, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{perUnit=$perUnit, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedTieredPackageConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedTieredPackageConfig && + groupingKey == other.groupingKey && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(groupingKey, packageSize, tiers, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedTieredPackageConfig{additionalProperties=$additionalProperties}" + "GroupedTieredPackageConfig{groupingKey=$groupingKey, packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1330,7 +1706,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1338,175 +1714,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1599,12 +1806,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1616,12 +1821,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionGroupedTieredPackagePrice && cadence == other.cadence && groupedTieredPackageConfig == other.groupedTieredPackageConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionGroupedTieredPackagePrice && + cadence == other.cadence && + groupedTieredPackageConfig == other.groupedTieredPackageConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, groupedTieredPackageConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedTieredPackageConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPrice.kt index da2ae3613..58474f9e3 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionGroupedTieredPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val groupedTieredConfig: JsonField, @@ -128,6 +120,8 @@ private constructor( fun cadence(): Cadence = cadence.getRequired("cadence") /** + * Configuration for grouped_tiered pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +137,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -525,6 +521,7 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + /** Configuration for grouped_tiered pricing */ fun groupedTieredConfig(groupedTieredConfig: GroupedTieredConfig) = groupedTieredConfig(JsonField.of(groupedTieredConfig)) @@ -550,6 +547,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1102,7 +1100,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1110,34 +1108,136 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_tiered pricing */ class GroupedTieredConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(groupingKey, tiers, mutableMapOf()) + + /** + * The billable metric property used to group before tiering + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Apply tiered pricing to each segment generated after grouping with the provided key + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) companion object { - /** Returns a mutable builder for constructing an instance of [GroupedTieredConfig]. */ + /** + * Returns a mutable builder for constructing an instance of [GroupedTieredConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tiers() + * ``` + */ fun builder() = Builder() } /** A builder for [GroupedTieredConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedTieredConfig: GroupedTieredConfig) = apply { + groupingKey = groupedTieredConfig.groupingKey + tiers = groupedTieredConfig.tiers.map { it.toMutableList() } additionalProperties = groupedTieredConfig.additionalProperties.toMutableMap() } + /** The billable metric property used to group before tiering */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** + * Apply tiered pricing to each segment generated after grouping with the provided key + */ + 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) @@ -1161,9 +1261,21 @@ private constructor( * Returns an immutable instance of [GroupedTieredConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedTieredConfig = - GroupedTieredConfig(additionalProperties.toImmutable()) + GroupedTieredConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1173,6 +1285,8 @@ private constructor( return@apply } + groupingKey() + tiers().forEach { it.validate() } validated = true } @@ -1191,25 +1305,248 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedTieredConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedTieredConfig && + groupingKey == other.groupingKey && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { Objects.hash(groupingKey, tiers, additionalProperties) } override fun hashCode(): Int = hashCode - override fun toString() = "GroupedTieredConfig{additionalProperties=$additionalProperties}" + override fun toString() = + "GroupedTieredConfig{groupingKey=$groupingKey, tiers=$tiers, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1322,7 +1659,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1330,175 +1667,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1591,12 +1759,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1608,12 +1774,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionGroupedTieredPrice && cadence == other.cadence && groupedTieredConfig == other.groupedTieredConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionGroupedTieredPrice && + cadence == other.cadence && + groupedTieredConfig == other.groupedTieredConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, groupedTieredConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedTieredConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithMeteredMinimumPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithMeteredMinimumPrice.kt index a48c6e80c..218580f21 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithMeteredMinimumPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithMeteredMinimumPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionGroupedWithMeteredMinimumPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val groupedWithMeteredMinimumConfig: JsonField, @@ -129,6 +121,8 @@ private constructor( fun cadence(): Cadence = cadence.getRequired("cadence") /** + * Configuration for grouped_with_metered_minimum pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -144,6 +138,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -532,6 +528,7 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + /** Configuration for grouped_with_metered_minimum pricing */ fun groupedWithMeteredMinimumConfig( groupedWithMeteredMinimumConfig: GroupedWithMeteredMinimumConfig ) = groupedWithMeteredMinimumConfig(JsonField.of(groupedWithMeteredMinimumConfig)) @@ -558,6 +555,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1110,7 +1108,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1118,16 +1116,163 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_with_metered_minimum pricing */ class GroupedWithMeteredMinimumConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val minimumUnitAmount: JsonField, + private val pricingKey: JsonField, + private val scalingFactors: JsonField>, + private val scalingKey: JsonField, + private val unitAmounts: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("minimum_unit_amount") + @ExcludeMissing + minimumUnitAmount: JsonField = JsonMissing.of(), + @JsonProperty("pricing_key") + @ExcludeMissing + pricingKey: JsonField = JsonMissing.of(), + @JsonProperty("scaling_factors") + @ExcludeMissing + scalingFactors: JsonField> = JsonMissing.of(), + @JsonProperty("scaling_key") + @ExcludeMissing + scalingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amounts") + @ExcludeMissing + unitAmounts: JsonField> = JsonMissing.of(), + ) : this( + groupingKey, + minimumUnitAmount, + pricingKey, + scalingFactors, + scalingKey, + unitAmounts, + mutableMapOf(), + ) + + /** + * Used to partition the usage into groups. The minimum amount is applied to each group. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The minimum amount to charge per group per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun minimumUnitAmount(): String = minimumUnitAmount.getRequired("minimum_unit_amount") + + /** + * Used to determine the unit rate + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun pricingKey(): String = pricingKey.getRequired("pricing_key") + + /** + * Scale the unit rates by the scaling factor. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun scalingFactors(): List = scalingFactors.getRequired("scaling_factors") + + /** + * Used to determine the unit rate scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun scalingKey(): String = scalingKey.getRequired("scaling_key") + + /** + * Apply per unit pricing to each pricing value. The minimum amount is applied any unmatched + * usage. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmounts(): List = unitAmounts.getRequired("unit_amounts") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [minimumUnitAmount]. + * + * Unlike [minimumUnitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_unit_amount") + @ExcludeMissing + fun _minimumUnitAmount(): JsonField = minimumUnitAmount + + /** + * Returns the raw JSON value of [pricingKey]. + * + * Unlike [pricingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("pricing_key") + @ExcludeMissing + fun _pricingKey(): JsonField = pricingKey + + /** + * Returns the raw JSON value of [scalingFactors]. + * + * Unlike [scalingFactors], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_factors") + @ExcludeMissing + fun _scalingFactors(): JsonField> = scalingFactors + + /** + * Returns the raw JSON value of [scalingKey]. + * + * Unlike [scalingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("scaling_key") + @ExcludeMissing + fun _scalingKey(): JsonField = scalingKey + + /** + * Returns the raw JSON value of [unitAmounts]. + * + * Unlike [unitAmounts], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amounts") + @ExcludeMissing + fun _unitAmounts(): JsonField> = unitAmounts + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1136,6 +1281,16 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [GroupedWithMeteredMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimumUnitAmount() + * .pricingKey() + * .scalingFactors() + * .scalingKey() + * .unitAmounts() + * ``` */ fun builder() = Builder() } @@ -1143,14 +1298,139 @@ private constructor( /** A builder for [GroupedWithMeteredMinimumConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var minimumUnitAmount: JsonField? = null + private var pricingKey: JsonField? = null + private var scalingFactors: JsonField>? = null + private var scalingKey: JsonField? = null + private var unitAmounts: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedWithMeteredMinimumConfig: GroupedWithMeteredMinimumConfig) = apply { + groupingKey = groupedWithMeteredMinimumConfig.groupingKey + minimumUnitAmount = groupedWithMeteredMinimumConfig.minimumUnitAmount + pricingKey = groupedWithMeteredMinimumConfig.pricingKey + scalingFactors = + groupedWithMeteredMinimumConfig.scalingFactors.map { it.toMutableList() } + scalingKey = groupedWithMeteredMinimumConfig.scalingKey + unitAmounts = + groupedWithMeteredMinimumConfig.unitAmounts.map { it.toMutableList() } additionalProperties = groupedWithMeteredMinimumConfig.additionalProperties.toMutableMap() } + /** + * Used to partition the usage into groups. The minimum amount is applied to each group. + */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The minimum amount to charge per group per unit */ + fun minimumUnitAmount(minimumUnitAmount: String) = + minimumUnitAmount(JsonField.of(minimumUnitAmount)) + + /** + * Sets [Builder.minimumUnitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumUnitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimumUnitAmount(minimumUnitAmount: JsonField) = apply { + this.minimumUnitAmount = minimumUnitAmount + } + + /** Used to determine the unit rate */ + fun pricingKey(pricingKey: String) = pricingKey(JsonField.of(pricingKey)) + + /** + * Sets [Builder.pricingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.pricingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun pricingKey(pricingKey: JsonField) = apply { this.pricingKey = pricingKey } + + /** Scale the unit rates by the scaling factor. */ + fun scalingFactors(scalingFactors: List) = + scalingFactors(JsonField.of(scalingFactors)) + + /** + * Sets [Builder.scalingFactors] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactors] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun scalingFactors(scalingFactors: JsonField>) = apply { + this.scalingFactors = scalingFactors.map { it.toMutableList() } + } + + /** + * Adds a single [ScalingFactor] to [scalingFactors]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addScalingFactor(scalingFactor: ScalingFactor) = apply { + scalingFactors = + (scalingFactors ?: JsonField.of(mutableListOf())).also { + checkKnown("scalingFactors", it).add(scalingFactor) + } + } + + /** Used to determine the unit rate scaling factor */ + fun scalingKey(scalingKey: String) = scalingKey(JsonField.of(scalingKey)) + + /** + * Sets [Builder.scalingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun scalingKey(scalingKey: JsonField) = apply { this.scalingKey = scalingKey } + + /** + * Apply per unit pricing to each pricing value. The minimum amount is applied any + * unmatched usage. + */ + fun unitAmounts(unitAmounts: List) = unitAmounts(JsonField.of(unitAmounts)) + + /** + * Sets [Builder.unitAmounts] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmounts] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmounts(unitAmounts: JsonField>) = apply { + this.unitAmounts = unitAmounts.map { it.toMutableList() } + } + + /** + * Adds a single [UnitAmount] to [unitAmounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUnitAmount(unitAmount: UnitAmount) = apply { + unitAmounts = + (unitAmounts ?: JsonField.of(mutableListOf())).also { + checkKnown("unitAmounts", it).add(unitAmount) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1174,9 +1454,29 @@ private constructor( * Returns an immutable instance of [GroupedWithMeteredMinimumConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimumUnitAmount() + * .pricingKey() + * .scalingFactors() + * .scalingKey() + * .unitAmounts() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedWithMeteredMinimumConfig = - GroupedWithMeteredMinimumConfig(additionalProperties.toImmutable()) + GroupedWithMeteredMinimumConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("minimumUnitAmount", minimumUnitAmount), + checkRequired("pricingKey", pricingKey), + checkRequired("scalingFactors", scalingFactors).map { it.toImmutable() }, + checkRequired("scalingKey", scalingKey), + checkRequired("unitAmounts", unitAmounts).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1186,6 +1486,12 @@ private constructor( return@apply } + groupingKey() + minimumUnitAmount() + pricingKey() + scalingFactors().forEach { it.validate() } + scalingKey() + unitAmounts().forEach { it.validate() } validated = true } @@ -1204,26 +1510,484 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (minimumUnitAmount.asKnown() == null) 0 else 1) + + (if (pricingKey.asKnown() == null) 0 else 1) + + (scalingFactors.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (scalingKey.asKnown() == null) 0 else 1) + + (unitAmounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a scaling factor */ + class ScalingFactor + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val scalingFactor: JsonField, + private val scalingValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("scaling_factor") + @ExcludeMissing + scalingFactor: JsonField = JsonMissing.of(), + @JsonProperty("scaling_value") + @ExcludeMissing + scalingValue: JsonField = JsonMissing.of(), + ) : this(scalingFactor, scalingValue, mutableMapOf()) + + /** + * Scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingFactor(): String = scalingFactor.getRequired("scaling_factor") + + /** + * Scaling value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingValue(): String = scalingValue.getRequired("scaling_value") + + /** + * Returns the raw JSON value of [scalingFactor]. + * + * Unlike [scalingFactor], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_factor") + @ExcludeMissing + fun _scalingFactor(): JsonField = scalingFactor + + /** + * Returns the raw JSON value of [scalingValue]. + * + * Unlike [scalingValue], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_value") + @ExcludeMissing + fun _scalingValue(): JsonField = scalingValue + + @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 [ScalingFactor]. + * + * The following fields are required: + * ```kotlin + * .scalingFactor() + * .scalingValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ScalingFactor]. */ + class Builder internal constructor() { + + private var scalingFactor: JsonField? = null + private var scalingValue: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(scalingFactor: ScalingFactor) = apply { + this.scalingFactor = scalingFactor.scalingFactor + scalingValue = scalingFactor.scalingValue + additionalProperties = scalingFactor.additionalProperties.toMutableMap() + } + + /** Scaling factor */ + fun scalingFactor(scalingFactor: String) = + scalingFactor(JsonField.of(scalingFactor)) + + /** + * Sets [Builder.scalingFactor] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactor] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun scalingFactor(scalingFactor: JsonField) = apply { + this.scalingFactor = scalingFactor + } + + /** Scaling value */ + fun scalingValue(scalingValue: String) = scalingValue(JsonField.of(scalingValue)) + + /** + * Sets [Builder.scalingValue] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingValue] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun scalingValue(scalingValue: JsonField) = apply { + this.scalingValue = scalingValue + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ScalingFactor]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .scalingFactor() + * .scalingValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ScalingFactor = + ScalingFactor( + checkRequired("scalingFactor", scalingFactor), + checkRequired("scalingValue", scalingValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ScalingFactor = apply { + if (validated) { + return@apply + } + + scalingFactor() + scalingValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (scalingFactor.asKnown() == null) 0 else 1) + + (if (scalingValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ScalingFactor && + scalingFactor == other.scalingFactor && + scalingValue == other.scalingValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(scalingFactor, scalingValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScalingFactor{scalingFactor=$scalingFactor, scalingValue=$scalingValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a unit amount */ + class UnitAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val pricingValue: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("pricing_value") + @ExcludeMissing + pricingValue: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(pricingValue, unitAmount, mutableMapOf()) + + /** + * Pricing value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun pricingValue(): String = pricingValue.getRequired("pricing_value") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [pricingValue]. + * + * Unlike [pricingValue], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pricing_value") + @ExcludeMissing + fun _pricingValue(): JsonField = pricingValue + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 [UnitAmount]. + * + * The following fields are required: + * ```kotlin + * .pricingValue() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [UnitAmount]. */ + class Builder internal constructor() { + + private var pricingValue: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(unitAmount: UnitAmount) = apply { + pricingValue = unitAmount.pricingValue + this.unitAmount = unitAmount.unitAmount + additionalProperties = unitAmount.additionalProperties.toMutableMap() + } + + /** Pricing value */ + fun pricingValue(pricingValue: String) = pricingValue(JsonField.of(pricingValue)) + + /** + * Sets [Builder.pricingValue] to an arbitrary JSON value. + * + * You should usually call [Builder.pricingValue] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun pricingValue(pricingValue: JsonField) = apply { + this.pricingValue = pricingValue + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UnitAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .pricingValue() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnitAmount = + UnitAmount( + checkRequired("pricingValue", pricingValue), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): UnitAmount = apply { + if (validated) { + return@apply + } + + pricingValue() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (pricingValue.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnitAmount && + pricingValue == other.pricingValue && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(pricingValue, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UnitAmount{pricingValue=$pricingValue, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedWithMeteredMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedWithMeteredMinimumConfig && + groupingKey == other.groupingKey && + minimumUnitAmount == other.minimumUnitAmount && + pricingKey == other.pricingKey && + scalingFactors == other.scalingFactors && + scalingKey == other.scalingKey && + unitAmounts == other.unitAmounts && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + minimumUnitAmount, + pricingKey, + scalingFactors, + scalingKey, + unitAmounts, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedWithMeteredMinimumConfig{additionalProperties=$additionalProperties}" + "GroupedWithMeteredMinimumConfig{groupingKey=$groupingKey, minimumUnitAmount=$minimumUnitAmount, pricingKey=$pricingKey, scalingFactors=$scalingFactors, scalingKey=$scalingKey, unitAmounts=$unitAmounts, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1336,7 +2100,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1344,175 +2108,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1605,12 +2200,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1622,12 +2215,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionGroupedWithMeteredMinimumPrice && cadence == other.cadence && groupedWithMeteredMinimumConfig == other.groupedWithMeteredMinimumConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionGroupedWithMeteredMinimumPrice && + cadence == other.cadence && + groupedWithMeteredMinimumConfig == other.groupedWithMeteredMinimumConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, groupedWithMeteredMinimumConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedWithMeteredMinimumConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithProratedMinimumPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithProratedMinimumPrice.kt index f436c3d88..61a7ad018 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithProratedMinimumPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithProratedMinimumPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionGroupedWithProratedMinimumPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val groupedWithProratedMinimumConfig: JsonField, @@ -129,6 +120,8 @@ private constructor( fun cadence(): Cadence = cadence.getRequired("cadence") /** + * Configuration for grouped_with_prorated_minimum pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -144,6 +137,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -532,6 +527,7 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + /** Configuration for grouped_with_prorated_minimum pricing */ fun groupedWithProratedMinimumConfig( groupedWithProratedMinimumConfig: GroupedWithProratedMinimumConfig ) = groupedWithProratedMinimumConfig(JsonField.of(groupedWithProratedMinimumConfig)) @@ -558,6 +554,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1110,7 +1107,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1118,16 +1115,83 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for grouped_with_prorated_minimum pricing */ class GroupedWithProratedMinimumConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val minimum: JsonField, + private val unitRate: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("minimum") @ExcludeMissing minimum: JsonField = JsonMissing.of(), + @JsonProperty("unit_rate") + @ExcludeMissing + unitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, minimum, unitRate, mutableMapOf()) + + /** + * How to determine the groups that should each have a minimum + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The minimum amount to charge per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun minimum(): String = minimum.getRequired("minimum") + + /** + * The amount to charge per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitRate(): String = unitRate.getRequired("unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [minimum]. + * + * Unlike [minimum], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("minimum") @ExcludeMissing fun _minimum(): JsonField = minimum + + /** + * Returns the raw JSON value of [unitRate]. + * + * Unlike [unitRate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_rate") @ExcludeMissing fun _unitRate(): JsonField = unitRate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1136,6 +1200,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [GroupedWithProratedMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimum() + * .unitRate() + * ``` */ fun builder() = Builder() } @@ -1143,14 +1214,58 @@ private constructor( /** A builder for [GroupedWithProratedMinimumConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var minimum: JsonField? = null + private var unitRate: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(groupedWithProratedMinimumConfig: GroupedWithProratedMinimumConfig) = apply { + groupingKey = groupedWithProratedMinimumConfig.groupingKey + minimum = groupedWithProratedMinimumConfig.minimum + unitRate = groupedWithProratedMinimumConfig.unitRate additionalProperties = groupedWithProratedMinimumConfig.additionalProperties.toMutableMap() } + /** How to determine the groups that should each have a minimum */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The minimum amount to charge per group */ + fun minimum(minimum: String) = minimum(JsonField.of(minimum)) + + /** + * Sets [Builder.minimum] to an arbitrary JSON value. + * + * You should usually call [Builder.minimum] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimum(minimum: JsonField) = apply { this.minimum = minimum } + + /** The amount to charge per unit */ + fun unitRate(unitRate: String) = unitRate(JsonField.of(unitRate)) + + /** + * Sets [Builder.unitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRate] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun unitRate(unitRate: JsonField) = apply { this.unitRate = unitRate } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1174,9 +1289,23 @@ private constructor( * Returns an immutable instance of [GroupedWithProratedMinimumConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimum() + * .unitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): GroupedWithProratedMinimumConfig = - GroupedWithProratedMinimumConfig(additionalProperties.toImmutable()) + GroupedWithProratedMinimumConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("minimum", minimum), + checkRequired("unitRate", unitRate), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1186,6 +1315,9 @@ private constructor( return@apply } + groupingKey() + minimum() + unitRate() validated = true } @@ -1204,26 +1336,33 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (minimum.asKnown() == null) 0 else 1) + + (if (unitRate.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedWithProratedMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedWithProratedMinimumConfig && + groupingKey == other.groupingKey && + minimum == other.minimum && + unitRate == other.unitRate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(groupingKey, minimum, unitRate, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedWithProratedMinimumConfig{additionalProperties=$additionalProperties}" + "GroupedWithProratedMinimumConfig{groupingKey=$groupingKey, minimum=$minimum, unitRate=$unitRate, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1336,7 +1475,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1344,175 +1483,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1605,12 +1575,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1622,12 +1590,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionGroupedWithProratedMinimumPrice && cadence == other.cadence && groupedWithProratedMinimumConfig == other.groupedWithProratedMinimumConfig && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionGroupedWithProratedMinimumPrice && + cadence == other.cadence && + groupedWithProratedMinimumConfig == other.groupedWithProratedMinimumConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, groupedWithProratedMinimumConfig, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedWithProratedMinimumConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMatrixPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMatrixPrice.kt index c16e7160e..1d22f90f4 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMatrixPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMatrixPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionMatrixPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,12 +127,16 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * Configuration for matrix pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ fun matrixConfig(): MatrixConfig = matrixConfig.getRequired("matrix_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -528,6 +523,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for matrix pricing */ fun matrixConfig(matrixConfig: MatrixConfig) = matrixConfig(JsonField.of(matrixConfig)) /** @@ -541,6 +537,7 @@ private constructor( this.matrixConfig = matrixConfig } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1093,7 +1090,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1101,6 +1098,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1213,7 +1211,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1221,175 +1219,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1482,12 +1311,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1499,12 +1326,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionMatrixPrice && cadence == other.cadence && itemId == other.itemId && matrixConfig == other.matrixConfig && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionMatrixPrice && + cadence == other.cadence && + itemId == other.itemId && + matrixConfig == other.matrixConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, matrixConfig, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + matrixConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithAllocationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithAllocationPrice.kt index 82577468e..f15a1c497 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithAllocationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithAllocationPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionMatrixWithAllocationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * Configuration for matrix_with_allocation pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +136,8 @@ private constructor( matrixWithAllocationConfig.getRequired("matrix_with_allocation_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -539,6 +534,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for matrix_with_allocation pricing */ fun matrixWithAllocationConfig(matrixWithAllocationConfig: MatrixWithAllocationConfig) = matrixWithAllocationConfig(JsonField.of(matrixWithAllocationConfig)) @@ -553,6 +549,7 @@ private constructor( matrixWithAllocationConfig: JsonField ) = apply { this.matrixWithAllocationConfig = matrixWithAllocationConfig } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1105,7 +1102,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1113,6 +1110,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1225,7 +1223,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1233,175 +1231,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1494,12 +1323,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1511,12 +1338,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionMatrixWithAllocationPrice && cadence == other.cadence && itemId == other.itemId && matrixWithAllocationConfig == other.matrixWithAllocationConfig && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionMatrixWithAllocationPrice && + cadence == other.cadence && + itemId == other.itemId && + matrixWithAllocationConfig == other.matrixWithAllocationConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, matrixWithAllocationConfig, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + matrixWithAllocationConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithDisplayNamePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithDisplayNamePrice.kt index 54bb66c10..9ab1f5275 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithDisplayNamePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithDisplayNamePrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionMatrixWithDisplayNamePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +128,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * Configuration for matrix_with_display_name pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +137,8 @@ private constructor( matrixWithDisplayNameConfig.getRequired("matrix_with_display_name_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -539,6 +535,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for matrix_with_display_name pricing */ fun matrixWithDisplayNameConfig(matrixWithDisplayNameConfig: MatrixWithDisplayNameConfig) = matrixWithDisplayNameConfig(JsonField.of(matrixWithDisplayNameConfig)) @@ -553,6 +550,7 @@ private constructor( matrixWithDisplayNameConfig: JsonField ) = apply { this.matrixWithDisplayNameConfig = matrixWithDisplayNameConfig } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1105,7 +1103,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1113,16 +1111,66 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for matrix_with_display_name pricing */ class MatrixWithDisplayNameConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val dimension: JsonField, + private val unitAmounts: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("dimension") + @ExcludeMissing + dimension: JsonField = JsonMissing.of(), + @JsonProperty("unit_amounts") + @ExcludeMissing + unitAmounts: JsonField> = JsonMissing.of(), + ) : this(dimension, unitAmounts, mutableMapOf()) + + /** + * Used to determine the unit rate + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dimension(): String = dimension.getRequired("dimension") + + /** + * Apply per unit pricing to each dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmounts(): List = unitAmounts.getRequired("unit_amounts") + + /** + * Returns the raw JSON value of [dimension]. + * + * Unlike [dimension], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("dimension") @ExcludeMissing fun _dimension(): JsonField = dimension + + /** + * Returns the raw JSON value of [unitAmounts]. + * + * Unlike [unitAmounts], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amounts") + @ExcludeMissing + fun _unitAmounts(): JsonField> = unitAmounts + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1131,6 +1179,12 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [MatrixWithDisplayNameConfig]. + * + * The following fields are required: + * ```kotlin + * .dimension() + * .unitAmounts() + * ``` */ fun builder() = Builder() } @@ -1138,13 +1192,55 @@ private constructor( /** A builder for [MatrixWithDisplayNameConfig]. */ class Builder internal constructor() { + private var dimension: JsonField? = null + private var unitAmounts: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(matrixWithDisplayNameConfig: MatrixWithDisplayNameConfig) = apply { + dimension = matrixWithDisplayNameConfig.dimension + unitAmounts = matrixWithDisplayNameConfig.unitAmounts.map { it.toMutableList() } additionalProperties = matrixWithDisplayNameConfig.additionalProperties.toMutableMap() } + /** Used to determine the unit rate */ + fun dimension(dimension: String) = dimension(JsonField.of(dimension)) + + /** + * Sets [Builder.dimension] to an arbitrary JSON value. + * + * You should usually call [Builder.dimension] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun dimension(dimension: JsonField) = apply { this.dimension = dimension } + + /** Apply per unit pricing to each dimension value */ + fun unitAmounts(unitAmounts: List) = unitAmounts(JsonField.of(unitAmounts)) + + /** + * Sets [Builder.unitAmounts] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmounts] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmounts(unitAmounts: JsonField>) = apply { + this.unitAmounts = unitAmounts.map { it.toMutableList() } + } + + /** + * Adds a single [UnitAmount] to [unitAmounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUnitAmount(unitAmount: UnitAmount) = apply { + unitAmounts = + (unitAmounts ?: JsonField.of(mutableListOf())).also { + checkKnown("unitAmounts", it).add(unitAmount) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1168,9 +1264,21 @@ private constructor( * Returns an immutable instance of [MatrixWithDisplayNameConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .dimension() + * .unitAmounts() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): MatrixWithDisplayNameConfig = - MatrixWithDisplayNameConfig(additionalProperties.toImmutable()) + MatrixWithDisplayNameConfig( + checkRequired("dimension", dimension), + checkRequired("unitAmounts", unitAmounts).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1180,6 +1288,8 @@ private constructor( return@apply } + dimension() + unitAmounts().forEach { it.validate() } validated = true } @@ -1198,26 +1308,295 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (dimension.asKnown() == null) 0 else 1) + + (unitAmounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a unit amount item */ + class UnitAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val dimensionValue: JsonField, + private val displayName: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("dimension_value") + @ExcludeMissing + dimensionValue: JsonField = JsonMissing.of(), + @JsonProperty("display_name") + @ExcludeMissing + displayName: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(dimensionValue, displayName, unitAmount, mutableMapOf()) + + /** + * The dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun dimensionValue(): String = dimensionValue.getRequired("dimension_value") + + /** + * Display name for this dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun displayName(): String = displayName.getRequired("display_name") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [dimensionValue]. + * + * Unlike [dimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("dimension_value") + @ExcludeMissing + fun _dimensionValue(): JsonField = dimensionValue + + /** + * Returns the raw JSON value of [displayName]. + * + * Unlike [displayName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("display_name") + @ExcludeMissing + fun _displayName(): JsonField = displayName + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 [UnitAmount]. + * + * The following fields are required: + * ```kotlin + * .dimensionValue() + * .displayName() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [UnitAmount]. */ + class Builder internal constructor() { + + private var dimensionValue: JsonField? = null + private var displayName: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(unitAmount: UnitAmount) = apply { + dimensionValue = unitAmount.dimensionValue + displayName = unitAmount.displayName + this.unitAmount = unitAmount.unitAmount + additionalProperties = unitAmount.additionalProperties.toMutableMap() + } + + /** The dimension value */ + fun dimensionValue(dimensionValue: String) = + dimensionValue(JsonField.of(dimensionValue)) + + /** + * Sets [Builder.dimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionValue] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun dimensionValue(dimensionValue: JsonField) = apply { + this.dimensionValue = dimensionValue + } + + /** Display name for this dimension value */ + fun displayName(displayName: String) = displayName(JsonField.of(displayName)) + + /** + * Sets [Builder.displayName] to an arbitrary JSON value. + * + * You should usually call [Builder.displayName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun displayName(displayName: JsonField) = apply { + this.displayName = displayName + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UnitAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .dimensionValue() + * .displayName() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnitAmount = + UnitAmount( + checkRequired("dimensionValue", dimensionValue), + checkRequired("displayName", displayName), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): UnitAmount = apply { + if (validated) { + return@apply + } + + dimensionValue() + displayName() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (dimensionValue.asKnown() == null) 0 else 1) + + (if (displayName.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnitAmount && + dimensionValue == other.dimensionValue && + displayName == other.displayName && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(dimensionValue, displayName, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UnitAmount{dimensionValue=$dimensionValue, displayName=$displayName, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MatrixWithDisplayNameConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MatrixWithDisplayNameConfig && + dimension == other.dimension && + unitAmounts == other.unitAmounts && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(dimension, unitAmounts, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "MatrixWithDisplayNameConfig{additionalProperties=$additionalProperties}" + "MatrixWithDisplayNameConfig{dimension=$dimension, unitAmounts=$unitAmounts, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1330,7 +1709,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1338,175 +1717,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1599,12 +1809,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1616,12 +1824,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionMatrixWithDisplayNamePrice && cadence == other.cadence && itemId == other.itemId && matrixWithDisplayNameConfig == other.matrixWithDisplayNameConfig && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionMatrixWithDisplayNamePrice && + cadence == other.cadence && + itemId == other.itemId && + matrixWithDisplayNameConfig == other.matrixWithDisplayNameConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, matrixWithDisplayNameConfig, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + matrixWithDisplayNameConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMaxGroupTieredPackagePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMaxGroupTieredPackagePrice.kt index a0d371c4e..d0ed2ee87 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMaxGroupTieredPackagePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMaxGroupTieredPackagePrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionMaxGroupTieredPackagePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +128,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * Configuration for max_group_tiered_package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -143,6 +137,8 @@ private constructor( maxGroupTieredPackageConfig.getRequired("max_group_tiered_package_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -539,6 +535,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for max_group_tiered_package pricing */ fun maxGroupTieredPackageConfig(maxGroupTieredPackageConfig: MaxGroupTieredPackageConfig) = maxGroupTieredPackageConfig(JsonField.of(maxGroupTieredPackageConfig)) @@ -553,6 +550,7 @@ private constructor( maxGroupTieredPackageConfig: JsonField ) = apply { this.maxGroupTieredPackageConfig = maxGroupTieredPackageConfig } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -1105,7 +1103,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1113,16 +1111,85 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for max_group_tiered_package pricing */ class MaxGroupTieredPackageConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(groupingKey, packageSize, tiers, mutableMapOf()) + + /** + * The event property used to group before tiering the group with the highest value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing to the largest group after grouping with the provided key. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1131,6 +1198,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [MaxGroupTieredPackageConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1138,13 +1212,73 @@ private constructor( /** A builder for [MaxGroupTieredPackageConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(maxGroupTieredPackageConfig: MaxGroupTieredPackageConfig) = apply { + groupingKey = maxGroupTieredPackageConfig.groupingKey + packageSize = maxGroupTieredPackageConfig.packageSize + tiers = maxGroupTieredPackageConfig.tiers.map { it.toMutableList() } additionalProperties = maxGroupTieredPackageConfig.additionalProperties.toMutableMap() } + /** The event property used to group before tiering the group with the highest value */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** Apply tiered pricing to the largest group after grouping with the provided key. */ + 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) @@ -1168,9 +1302,23 @@ private constructor( * Returns an immutable instance of [MaxGroupTieredPackageConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): MaxGroupTieredPackageConfig = - MaxGroupTieredPackageConfig(additionalProperties.toImmutable()) + MaxGroupTieredPackageConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1180,6 +1328,9 @@ private constructor( return@apply } + groupingKey() + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -1198,26 +1349,252 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MaxGroupTieredPackageConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MaxGroupTieredPackageConfig && + groupingKey == other.groupingKey && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(groupingKey, packageSize, tiers, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "MaxGroupTieredPackageConfig{additionalProperties=$additionalProperties}" + "MaxGroupTieredPackageConfig{groupingKey=$groupingKey, packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1330,7 +1707,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1338,175 +1715,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1599,12 +1807,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1616,12 +1822,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionMaxGroupTieredPackagePrice && cadence == other.cadence && itemId == other.itemId && maxGroupTieredPackageConfig == other.maxGroupTieredPackageConfig && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionMaxGroupTieredPackagePrice && + cadence == other.cadence && + itemId == other.itemId && + maxGroupTieredPackageConfig == other.maxGroupTieredPackageConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, maxGroupTieredPackageConfig, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + maxGroupTieredPackageConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBulkBpsPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMinimumCompositePrice.kt similarity index 79% rename from orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBulkBpsPrice.kt rename to orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMinimumCompositePrice.kt index 8ae0a3c71..a769ead59 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewPlanBulkBpsPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionMinimumCompositePrice.kt @@ -6,32 +6,23 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects -class NewPlanBulkBpsPrice +class NewSubscriptionMinimumCompositePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val bulkBpsConfig: JsonField, private val cadence: JsonField, private val itemId: JsonField, + private val minimumConfig: JsonField, private val modelType: JsonField, private val name: JsonField, private val billableMetricId: JsonField, @@ -52,11 +43,11 @@ private constructor( @JsonCreator private constructor( - @JsonProperty("bulk_bps_config") - @ExcludeMissing - bulkBpsConfig: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), @JsonProperty("item_id") @ExcludeMissing itemId: JsonField = JsonMissing.of(), + @JsonProperty("minimum_config") + @ExcludeMissing + minimumConfig: JsonField = JsonMissing.of(), @JsonProperty("model_type") @ExcludeMissing modelType: JsonField = JsonMissing.of(), @@ -98,9 +89,9 @@ private constructor( @ExcludeMissing referenceId: JsonField = JsonMissing.of(), ) : this( - bulkBpsConfig, cadence, itemId, + minimumConfig, modelType, name, billableMetricId, @@ -120,28 +111,32 @@ private constructor( ) /** + * The cadence to bill for this price on. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun bulkBpsConfig(): BulkBpsConfig = bulkBpsConfig.getRequired("bulk_bps_config") + fun cadence(): Cadence = cadence.getRequired("cadence") /** - * The cadence to bill for this price on. + * The id of the item the price will be associated with. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun cadence(): Cadence = cadence.getRequired("cadence") + fun itemId(): String = itemId.getRequired("item_id") /** - * The id of the item the price will be associated with. + * Configuration for minimum pricing * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun itemId(): String = itemId.getRequired("item_id") + fun minimumConfig(): MinimumConfig = minimumConfig.getRequired("minimum_config") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -269,15 +264,6 @@ private constructor( */ fun referenceId(): String? = referenceId.getNullable("reference_id") - /** - * Returns the raw JSON value of [bulkBpsConfig]. - * - * Unlike [bulkBpsConfig], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("bulk_bps_config") - @ExcludeMissing - fun _bulkBpsConfig(): JsonField = bulkBpsConfig - /** * Returns the raw JSON value of [cadence]. * @@ -292,6 +278,15 @@ private constructor( */ @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + /** + * Returns the raw JSON value of [minimumConfig]. + * + * Unlike [minimumConfig], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("minimum_config") + @ExcludeMissing + fun _minimumConfig(): JsonField = minimumConfig + /** * Returns the raw JSON value of [modelType]. * @@ -444,13 +439,14 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [NewPlanBulkBpsPrice]. + * Returns a mutable builder for constructing an instance of + * [NewSubscriptionMinimumCompositePrice]. * * The following fields are required: * ```kotlin - * .bulkBpsConfig() * .cadence() * .itemId() + * .minimumConfig() * .modelType() * .name() * ``` @@ -458,12 +454,12 @@ private constructor( fun builder() = Builder() } - /** A builder for [NewPlanBulkBpsPrice]. */ + /** A builder for [NewSubscriptionMinimumCompositePrice]. */ class Builder internal constructor() { - private var bulkBpsConfig: JsonField? = null private var cadence: JsonField? = null private var itemId: JsonField? = null + private var minimumConfig: JsonField? = null private var modelType: JsonField? = null private var name: JsonField? = null private var billableMetricId: JsonField = JsonMissing.of() @@ -484,39 +480,32 @@ private constructor( private var referenceId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(newPlanBulkBpsPrice: NewPlanBulkBpsPrice) = apply { - bulkBpsConfig = newPlanBulkBpsPrice.bulkBpsConfig - cadence = newPlanBulkBpsPrice.cadence - itemId = newPlanBulkBpsPrice.itemId - modelType = newPlanBulkBpsPrice.modelType - name = newPlanBulkBpsPrice.name - billableMetricId = newPlanBulkBpsPrice.billableMetricId - billedInAdvance = newPlanBulkBpsPrice.billedInAdvance - billingCycleConfiguration = newPlanBulkBpsPrice.billingCycleConfiguration - conversionRate = newPlanBulkBpsPrice.conversionRate - conversionRateConfig = newPlanBulkBpsPrice.conversionRateConfig - currency = newPlanBulkBpsPrice.currency - dimensionalPriceConfiguration = newPlanBulkBpsPrice.dimensionalPriceConfiguration - externalPriceId = newPlanBulkBpsPrice.externalPriceId - fixedPriceQuantity = newPlanBulkBpsPrice.fixedPriceQuantity - invoiceGroupingKey = newPlanBulkBpsPrice.invoiceGroupingKey - invoicingCycleConfiguration = newPlanBulkBpsPrice.invoicingCycleConfiguration - metadata = newPlanBulkBpsPrice.metadata - referenceId = newPlanBulkBpsPrice.referenceId - additionalProperties = newPlanBulkBpsPrice.additionalProperties.toMutableMap() - } - - fun bulkBpsConfig(bulkBpsConfig: BulkBpsConfig) = bulkBpsConfig(JsonField.of(bulkBpsConfig)) - - /** - * Sets [Builder.bulkBpsConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.bulkBpsConfig] with a well-typed [BulkBpsConfig] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun bulkBpsConfig(bulkBpsConfig: JsonField) = apply { - this.bulkBpsConfig = bulkBpsConfig + internal fun from( + newSubscriptionMinimumCompositePrice: NewSubscriptionMinimumCompositePrice + ) = apply { + cadence = newSubscriptionMinimumCompositePrice.cadence + itemId = newSubscriptionMinimumCompositePrice.itemId + minimumConfig = newSubscriptionMinimumCompositePrice.minimumConfig + modelType = newSubscriptionMinimumCompositePrice.modelType + name = newSubscriptionMinimumCompositePrice.name + billableMetricId = newSubscriptionMinimumCompositePrice.billableMetricId + billedInAdvance = newSubscriptionMinimumCompositePrice.billedInAdvance + billingCycleConfiguration = + newSubscriptionMinimumCompositePrice.billingCycleConfiguration + conversionRate = newSubscriptionMinimumCompositePrice.conversionRate + conversionRateConfig = newSubscriptionMinimumCompositePrice.conversionRateConfig + currency = newSubscriptionMinimumCompositePrice.currency + dimensionalPriceConfiguration = + newSubscriptionMinimumCompositePrice.dimensionalPriceConfiguration + externalPriceId = newSubscriptionMinimumCompositePrice.externalPriceId + fixedPriceQuantity = newSubscriptionMinimumCompositePrice.fixedPriceQuantity + invoiceGroupingKey = newSubscriptionMinimumCompositePrice.invoiceGroupingKey + invoicingCycleConfiguration = + newSubscriptionMinimumCompositePrice.invoicingCycleConfiguration + metadata = newSubscriptionMinimumCompositePrice.metadata + referenceId = newSubscriptionMinimumCompositePrice.referenceId + additionalProperties = + newSubscriptionMinimumCompositePrice.additionalProperties.toMutableMap() } /** The cadence to bill for this price on. */ @@ -541,6 +530,21 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** Configuration for minimum pricing */ + fun minimumConfig(minimumConfig: MinimumConfig) = minimumConfig(JsonField.of(minimumConfig)) + + /** + * Sets [Builder.minimumConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumConfig] with a well-typed [MinimumConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimumConfig(minimumConfig: JsonField) = apply { + this.minimumConfig = minimumConfig + } + + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -852,26 +856,26 @@ private constructor( } /** - * Returns an immutable instance of [NewPlanBulkBpsPrice]. + * Returns an immutable instance of [NewSubscriptionMinimumCompositePrice]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```kotlin - * .bulkBpsConfig() * .cadence() * .itemId() + * .minimumConfig() * .modelType() * .name() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): NewPlanBulkBpsPrice = - NewPlanBulkBpsPrice( - checkRequired("bulkBpsConfig", bulkBpsConfig), + fun build(): NewSubscriptionMinimumCompositePrice = + NewSubscriptionMinimumCompositePrice( checkRequired("cadence", cadence), checkRequired("itemId", itemId), + checkRequired("minimumConfig", minimumConfig), checkRequired("modelType", modelType), checkRequired("name", name), billableMetricId, @@ -893,14 +897,14 @@ private constructor( private var validated: Boolean = false - fun validate(): NewPlanBulkBpsPrice = apply { + fun validate(): NewSubscriptionMinimumCompositePrice = apply { if (validated) { return@apply } - bulkBpsConfig().validate() cadence().validate() itemId() + minimumConfig().validate() modelType().validate() name() billableMetricId() @@ -933,9 +937,9 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - (bulkBpsConfig.asKnown()?.validity() ?: 0) + - (cadence.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + (if (itemId.asKnown() == null) 0 else 1) + + (minimumConfig.asKnown()?.validity() ?: 0) + (modelType.asKnown()?.validity() ?: 0) + (if (name.asKnown() == null) 0 else 1) + (if (billableMetricId.asKnown() == null) 0 else 1) + @@ -1093,7 +1097,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1101,6 +1105,213 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for minimum pricing */ + class MinimumConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val minimumAmount: JsonField, + private val prorated: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("prorated") + @ExcludeMissing + prorated: JsonField = JsonMissing.of(), + ) : this(minimumAmount, prorated, mutableMapOf()) + + /** + * The minimum amount to apply + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun minimumAmount(): String = minimumAmount.getRequired("minimum_amount") + + /** + * If true, subtotals from this price are prorated based on the service period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorated(): Boolean? = prorated.getNullable("prorated") + + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount + + /** + * Returns the raw JSON value of [prorated]. + * + * Unlike [prorated], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorated") @ExcludeMissing fun _prorated(): JsonField = prorated + + @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 [MinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [MinimumConfig]. */ + class Builder internal constructor() { + + private var minimumAmount: JsonField? = null + private var prorated: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(minimumConfig: MinimumConfig) = apply { + minimumAmount = minimumConfig.minimumAmount + prorated = minimumConfig.prorated + additionalProperties = minimumConfig.additionalProperties.toMutableMap() + } + + /** The minimum amount to apply */ + fun minimumAmount(minimumAmount: String) = minimumAmount(JsonField.of(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } + + /** If true, subtotals from this price are prorated based on the service period */ + fun prorated(prorated: Boolean) = prorated(JsonField.of(prorated)) + + /** + * Sets [Builder.prorated] to an arbitrary JSON value. + * + * You should usually call [Builder.prorated] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prorated(prorated: JsonField) = apply { this.prorated = prorated } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [MinimumConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MinimumConfig = + MinimumConfig( + checkRequired("minimumAmount", minimumAmount), + prorated, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MinimumConfig = apply { + if (validated) { + return@apply + } + + minimumAmount() + prorated() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (minimumAmount.asKnown() == null) 0 else 1) + + (if (prorated.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MinimumConfig && + minimumAmount == other.minimumAmount && + prorated == other.prorated && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(minimumAmount, prorated, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MinimumConfig{minimumAmount=$minimumAmount, prorated=$prorated, additionalProperties=$additionalProperties}" + } + + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1115,14 +1326,14 @@ private constructor( companion object { - val BULK_BPS = of("bulk_bps") + val MINIMUM = of("minimum") fun of(value: String) = ModelType(JsonField.of(value)) } /** An enum containing [ModelType]'s known values. */ enum class Known { - BULK_BPS + MINIMUM } /** @@ -1135,7 +1346,7 @@ private constructor( * - It was constructed with an arbitrary value using the [of] method. */ enum class Value { - BULK_BPS, + MINIMUM, /** * An enum member indicating that [ModelType] was instantiated with an unknown value. */ @@ -1151,7 +1362,7 @@ private constructor( */ fun value(): Value = when (this) { - BULK_BPS -> Value.BULK_BPS + MINIMUM -> Value.MINIMUM else -> Value._UNKNOWN } @@ -1165,7 +1376,7 @@ private constructor( */ fun known(): Known = when (this) { - BULK_BPS -> Known.BULK_BPS + MINIMUM -> Known.MINIMUM else -> throw OrbInvalidDataException("Unknown ModelType: $value") } @@ -1213,7 +1424,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1221,175 +1432,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1482,12 +1524,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1499,15 +1539,54 @@ private constructor( return true } - return /* spotless:off */ other is NewPlanBulkBpsPrice && bulkBpsConfig == other.bulkBpsConfig && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionMinimumCompositePrice && + cadence == other.cadence && + itemId == other.itemId && + minimumConfig == other.minimumConfig && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bulkBpsConfig, cadence, itemId, modelType, name, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + minimumConfig, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "NewPlanBulkBpsPrice{bulkBpsConfig=$bulkBpsConfig, cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + "NewSubscriptionMinimumCompositePrice{cadence=$cadence, itemId=$itemId, minimumConfig=$minimumConfig, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionPackagePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionPackagePrice.kt index 00ee6e275..4692905c4 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionPackagePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionPackagePrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionPackagePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +143,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -529,6 +524,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -551,6 +547,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for package pricing */ fun packageConfig(packageConfig: PackageConfig) = packageConfig(JsonField.of(packageConfig)) /** @@ -1094,7 +1091,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1102,6 +1099,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1214,7 +1212,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1222,175 +1220,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1483,12 +1312,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1500,12 +1327,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionPackagePrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && packageConfig == other.packageConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionPackagePrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + packageConfig == other.packageConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, packageConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + packageConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionPackageWithAllocationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionPackageWithAllocationPrice.kt index 8a41dd903..38aba0da0 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionPackageWithAllocationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionPackageWithAllocationPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionPackageWithAllocationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +143,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for package_with_allocation pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -539,6 +534,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -561,6 +557,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for package_with_allocation pricing */ fun packageWithAllocationConfig(packageWithAllocationConfig: PackageWithAllocationConfig) = packageWithAllocationConfig(JsonField.of(packageWithAllocationConfig)) @@ -1105,7 +1102,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1113,6 +1110,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1225,7 +1223,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1233,16 +1231,90 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for package_with_allocation pricing */ class PackageWithAllocationConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val allocation: JsonField, + private val packageAmount: JsonField, + private val packageSize: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("allocation") + @ExcludeMissing + allocation: JsonField = JsonMissing.of(), + @JsonProperty("package_amount") + @ExcludeMissing + packageAmount: JsonField = JsonMissing.of(), + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + ) : this(allocation, packageAmount, packageSize, mutableMapOf()) + + /** + * Usage allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun allocation(): String = allocation.getRequired("allocation") + + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageAmount(): String = packageAmount.getRequired("package_amount") + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Returns the raw JSON value of [allocation]. + * + * Unlike [allocation], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allocation") + @ExcludeMissing + fun _allocation(): JsonField = allocation + + /** + * Returns the raw JSON value of [packageAmount]. + * + * Unlike [packageAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("package_amount") + @ExcludeMissing + fun _packageAmount(): JsonField = packageAmount + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1251,6 +1323,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [PackageWithAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .packageAmount() + * .packageSize() + * ``` */ fun builder() = Builder() } @@ -1258,13 +1337,59 @@ private constructor( /** A builder for [PackageWithAllocationConfig]. */ class Builder internal constructor() { + private var allocation: JsonField? = null + private var packageAmount: JsonField? = null + private var packageSize: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(packageWithAllocationConfig: PackageWithAllocationConfig) = apply { + allocation = packageWithAllocationConfig.allocation + packageAmount = packageWithAllocationConfig.packageAmount + packageSize = packageWithAllocationConfig.packageSize additionalProperties = packageWithAllocationConfig.additionalProperties.toMutableMap() } + /** Usage allocation */ + fun allocation(allocation: String) = allocation(JsonField.of(allocation)) + + /** + * Sets [Builder.allocation] to an arbitrary JSON value. + * + * You should usually call [Builder.allocation] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun allocation(allocation: JsonField) = apply { this.allocation = allocation } + + /** Price per package */ + fun packageAmount(packageAmount: String) = packageAmount(JsonField.of(packageAmount)) + + /** + * Sets [Builder.packageAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.packageAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageAmount(packageAmount: JsonField) = apply { + this.packageAmount = packageAmount + } + + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1288,9 +1413,23 @@ private constructor( * Returns an immutable instance of [PackageWithAllocationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .packageAmount() + * .packageSize() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): PackageWithAllocationConfig = - PackageWithAllocationConfig(additionalProperties.toImmutable()) + PackageWithAllocationConfig( + checkRequired("allocation", allocation), + checkRequired("packageAmount", packageAmount), + checkRequired("packageSize", packageSize), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1300,6 +1439,9 @@ private constructor( return@apply } + allocation() + packageAmount() + packageSize() validated = true } @@ -1318,193 +1460,30 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (allocation.asKnown() == null) 0 else 1) + + (if (packageAmount.asKnown() == null) 0 else 1) + + (if (packageSize.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PackageWithAllocationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PackageWithAllocationConfig && + allocation == other.allocation && + packageAmount == other.packageAmount && + packageSize == other.packageSize && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(allocation, packageAmount, packageSize, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "PackageWithAllocationConfig{additionalProperties=$additionalProperties}" - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } + "PackageWithAllocationConfig{allocation=$allocation, packageAmount=$packageAmount, packageSize=$packageSize, additionalProperties=$additionalProperties}" } /** @@ -1599,12 +1578,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1616,12 +1593,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionPackageWithAllocationPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && packageWithAllocationConfig == other.packageWithAllocationConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionPackageWithAllocationPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + packageWithAllocationConfig == other.packageWithAllocationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, packageWithAllocationConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + packageWithAllocationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithTieredPricingPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithTieredPricingPrice.kt index 345dc9ffc..6330dac3d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithTieredPricingPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithTieredPricingPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionScalableMatrixWithTieredPricingPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -138,6 +130,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -152,6 +146,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for scalable_matrix_with_tiered_pricing pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -551,6 +547,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -573,6 +570,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for scalable_matrix_with_tiered_pricing pricing */ fun scalableMatrixWithTieredPricingConfig( scalableMatrixWithTieredPricingConfig: ScalableMatrixWithTieredPricingConfig ) = @@ -1126,7 +1124,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1134,6 +1132,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1246,7 +1245,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1254,16 +1253,110 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for scalable_matrix_with_tiered_pricing pricing */ class ScalableMatrixWithTieredPricingConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val firstDimension: JsonField, + private val matrixScalingFactors: JsonField>, + private val tiers: JsonField>, + private val secondDimension: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("first_dimension") + @ExcludeMissing + firstDimension: JsonField = JsonMissing.of(), + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + matrixScalingFactors: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + @JsonProperty("second_dimension") + @ExcludeMissing + secondDimension: JsonField = JsonMissing.of(), + ) : this(firstDimension, matrixScalingFactors, tiers, secondDimension, mutableMapOf()) + + /** + * Used for the scalable matrix first dimension + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun firstDimension(): String = firstDimension.getRequired("first_dimension") + + /** + * Apply a scaling factor to each dimension + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun matrixScalingFactors(): List = + matrixScalingFactors.getRequired("matrix_scaling_factors") + + /** + * Tier pricing structure + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Used for the scalable matrix second dimension (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimension(): String? = secondDimension.getNullable("second_dimension") + + /** + * Returns the raw JSON value of [firstDimension]. + * + * Unlike [firstDimension], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("first_dimension") + @ExcludeMissing + fun _firstDimension(): JsonField = firstDimension + + /** + * Returns the raw JSON value of [matrixScalingFactors]. + * + * Unlike [matrixScalingFactors], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + fun _matrixScalingFactors(): JsonField> = matrixScalingFactors + + /** + * 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 + + /** + * Returns the raw JSON value of [secondDimension]. + * + * Unlike [secondDimension], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("second_dimension") + @ExcludeMissing + fun _secondDimension(): JsonField = secondDimension + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1272,6 +1365,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [ScalableMatrixWithTieredPricingConfig]. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1279,15 +1379,110 @@ private constructor( /** A builder for [ScalableMatrixWithTieredPricingConfig]. */ class Builder internal constructor() { + private var firstDimension: JsonField? = null + private var matrixScalingFactors: JsonField>? = null + private var tiers: JsonField>? = null + private var secondDimension: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from( scalableMatrixWithTieredPricingConfig: ScalableMatrixWithTieredPricingConfig ) = apply { + firstDimension = scalableMatrixWithTieredPricingConfig.firstDimension + matrixScalingFactors = + scalableMatrixWithTieredPricingConfig.matrixScalingFactors.map { + it.toMutableList() + } + tiers = scalableMatrixWithTieredPricingConfig.tiers.map { it.toMutableList() } + secondDimension = scalableMatrixWithTieredPricingConfig.secondDimension additionalProperties = scalableMatrixWithTieredPricingConfig.additionalProperties.toMutableMap() } + /** Used for the scalable matrix first dimension */ + fun firstDimension(firstDimension: String) = + firstDimension(JsonField.of(firstDimension)) + + /** + * Sets [Builder.firstDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun firstDimension(firstDimension: JsonField) = apply { + this.firstDimension = firstDimension + } + + /** Apply a scaling factor to each dimension */ + fun matrixScalingFactors(matrixScalingFactors: List) = + matrixScalingFactors(JsonField.of(matrixScalingFactors)) + + /** + * Sets [Builder.matrixScalingFactors] to an arbitrary JSON value. + * + * You should usually call [Builder.matrixScalingFactors] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun matrixScalingFactors(matrixScalingFactors: JsonField>) = + apply { + this.matrixScalingFactors = matrixScalingFactors.map { it.toMutableList() } + } + + /** + * Adds a single [MatrixScalingFactor] to [matrixScalingFactors]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMatrixScalingFactor(matrixScalingFactor: MatrixScalingFactor) = apply { + matrixScalingFactors = + (matrixScalingFactors ?: JsonField.of(mutableListOf())).also { + checkKnown("matrixScalingFactors", it).add(matrixScalingFactor) + } + } + + /** Tier pricing structure */ + 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) + } + } + + /** Used for the scalable matrix second dimension (optional) */ + fun secondDimension(secondDimension: String?) = + secondDimension(JsonField.ofNullable(secondDimension)) + + /** + * Sets [Builder.secondDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun secondDimension(secondDimension: JsonField) = apply { + this.secondDimension = secondDimension + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1311,9 +1506,26 @@ private constructor( * Returns an immutable instance of [ScalableMatrixWithTieredPricingConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): ScalableMatrixWithTieredPricingConfig = - ScalableMatrixWithTieredPricingConfig(additionalProperties.toImmutable()) + ScalableMatrixWithTieredPricingConfig( + checkRequired("firstDimension", firstDimension), + checkRequired("matrixScalingFactors", matrixScalingFactors).map { + it.toImmutable() + }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + secondDimension, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1323,6 +1535,10 @@ private constructor( return@apply } + firstDimension() + matrixScalingFactors().forEach { it.validate() } + tiers().forEach { it.validate() } + secondDimension() validated = true } @@ -1341,193 +1557,527 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (firstDimension.asKnown() == null) 0 else 1) + + (matrixScalingFactors.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (secondDimension.asKnown() == null) 0 else 1) + + /** Configuration for a single matrix scaling factor */ + class MatrixScalingFactor + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val firstDimensionValue: JsonField, + private val scalingFactor: JsonField, + private val secondDimensionValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("first_dimension_value") + @ExcludeMissing + firstDimensionValue: JsonField = JsonMissing.of(), + @JsonProperty("scaling_factor") + @ExcludeMissing + scalingFactor: JsonField = JsonMissing.of(), + @JsonProperty("second_dimension_value") + @ExcludeMissing + secondDimensionValue: JsonField = JsonMissing.of(), + ) : this(firstDimensionValue, scalingFactor, secondDimensionValue, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * First dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun firstDimensionValue(): String = + firstDimensionValue.getRequired("first_dimension_value") - return /* spotless:off */ other is ScalableMatrixWithTieredPricingConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingFactor(): String = scalingFactor.getRequired("scaling_factor") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Second dimension value (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimensionValue(): String? = + secondDimensionValue.getNullable("second_dimension_value") - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [firstDimensionValue]. + * + * Unlike [firstDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("first_dimension_value") + @ExcludeMissing + fun _firstDimensionValue(): JsonField = firstDimensionValue - override fun toString() = - "ScalableMatrixWithTieredPricingConfig{additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [scalingFactor]. + * + * Unlike [scalingFactor], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_factor") + @ExcludeMissing + fun _scalingFactor(): JsonField = scalingFactor - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + /** + * Returns the raw JSON value of [secondDimensionValue]. + * + * Unlike [secondDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("second_dimension_value") + @ExcludeMissing + fun _secondDimensionValue(): JsonField = secondDimensionValue - fun unit(): UnitConversionRateConfig? = unit + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [MatrixScalingFactor]. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + */ + fun builder() = Builder() + } - fun isUnit(): Boolean = unit != null + /** A builder for [MatrixScalingFactor]. */ + class Builder internal constructor() { - fun isTiered(): Boolean = tiered != null + private var firstDimensionValue: JsonField? = null + private var scalingFactor: JsonField? = null + private var secondDimensionValue: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + internal fun from(matrixScalingFactor: MatrixScalingFactor) = apply { + firstDimensionValue = matrixScalingFactor.firstDimensionValue + scalingFactor = matrixScalingFactor.scalingFactor + secondDimensionValue = matrixScalingFactor.secondDimensionValue + additionalProperties = matrixScalingFactor.additionalProperties.toMutableMap() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** First dimension value */ + fun firstDimensionValue(firstDimensionValue: String) = + firstDimensionValue(JsonField.of(firstDimensionValue)) + + /** + * Sets [Builder.firstDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimensionValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun firstDimensionValue(firstDimensionValue: JsonField) = apply { + this.firstDimensionValue = firstDimensionValue + } - fun _json(): JsonValue? = _json + /** Scaling factor */ + fun scalingFactor(scalingFactor: String) = + scalingFactor(JsonField.of(scalingFactor)) + + /** + * Sets [Builder.scalingFactor] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactor] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun scalingFactor(scalingFactor: JsonField) = apply { + this.scalingFactor = scalingFactor + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + /** Second dimension value (optional) */ + fun secondDimensionValue(secondDimensionValue: String?) = + secondDimensionValue(JsonField.ofNullable(secondDimensionValue)) + + /** + * Sets [Builder.secondDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimensionValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun secondDimensionValue(secondDimensionValue: JsonField) = apply { + this.secondDimensionValue = secondDimensionValue + } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + /** + * Returns an immutable instance of [MatrixScalingFactor]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MatrixScalingFactor = + MatrixScalingFactor( + checkRequired("firstDimensionValue", firstDimensionValue), + checkRequired("scalingFactor", scalingFactor), + secondDimensionValue, + additionalProperties.toMutableMap(), + ) + } - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() + private var validated: Boolean = false - override fun unknown(json: JsonValue?) = 0 + fun validate(): MatrixScalingFactor = apply { + if (validated) { + return@apply } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + firstDimensionValue() + scalingFactor() + secondDimensionValue() + validated = true } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (firstDimensionValue.asKnown() == null) 0 else 1) + + (if (scalingFactor.asKnown() == null) 0 else 1) + + (if (secondDimensionValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + return other is MatrixScalingFactor && + firstDimensionValue == other.firstDimensionValue && + scalingFactor == other.scalingFactor && + secondDimensionValue == other.secondDimensionValue && + additionalProperties == other.additionalProperties } - companion object { + private val hashCode: Int by lazy { + Objects.hash( + firstDimensionValue, + scalingFactor, + secondDimensionValue, + additionalProperties, + ) + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + override fun hashCode(): Int = hashCode - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) + override fun toString() = + "MatrixScalingFactor{firstDimensionValue=$firstDimensionValue, scalingFactor=$scalingFactor, secondDimensionValue=$secondDimensionValue, additionalProperties=$additionalProperties}" } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { + /** Configuration for a single tier entry with business logic */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) - fun visitUnit(unit: UnitConversionRateConfig): T + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - fun visitTiered(tiered: TieredConversionRateConfig): T + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns the raw JSON value of [tierLowerBound]. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. * - * @throws OrbInvalidDataException in the default implementation. + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + /** A builder for [Tier]. */ + class Builder internal constructor() { - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - return ConversionRateConfig(_json = json) + 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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is ScalableMatrixWithTieredPricingConfig && + firstDimension == other.firstDimension && + matrixScalingFactors == other.matrixScalingFactors && + tiers == other.tiers && + secondDimension == other.secondDimension && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + firstDimension, + matrixScalingFactors, + tiers, + secondDimension, + additionalProperties, + ) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScalableMatrixWithTieredPricingConfig{firstDimension=$firstDimension, matrixScalingFactors=$matrixScalingFactors, tiers=$tiers, secondDimension=$secondDimension, additionalProperties=$additionalProperties}" } /** @@ -1622,12 +2172,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1639,12 +2187,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionScalableMatrixWithTieredPricingPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && scalableMatrixWithTieredPricingConfig == other.scalableMatrixWithTieredPricingConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionScalableMatrixWithTieredPricingPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + scalableMatrixWithTieredPricingConfig == other.scalableMatrixWithTieredPricingConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, scalableMatrixWithTieredPricingConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + scalableMatrixWithTieredPricingConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithUnitPricingPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithUnitPricingPrice.kt index 151d8647e..96db4f2f1 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithUnitPricingPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithUnitPricingPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionScalableMatrixWithUnitPricingPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -137,6 +129,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -151,6 +145,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for scalable_matrix_with_unit_pricing pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -548,6 +544,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -570,6 +567,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for scalable_matrix_with_unit_pricing pricing */ fun scalableMatrixWithUnitPricingConfig( scalableMatrixWithUnitPricingConfig: ScalableMatrixWithUnitPricingConfig ) = scalableMatrixWithUnitPricingConfig(JsonField.of(scalableMatrixWithUnitPricingConfig)) @@ -1118,7 +1116,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1126,6 +1124,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1238,7 +1237,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1246,16 +1245,136 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for scalable_matrix_with_unit_pricing pricing */ class ScalableMatrixWithUnitPricingConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val firstDimension: JsonField, + private val matrixScalingFactors: JsonField>, + private val unitPrice: JsonField, + private val prorate: JsonField, + private val secondDimension: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("first_dimension") + @ExcludeMissing + firstDimension: JsonField = JsonMissing.of(), + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + matrixScalingFactors: JsonField> = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + @JsonProperty("prorate") @ExcludeMissing prorate: JsonField = JsonMissing.of(), + @JsonProperty("second_dimension") + @ExcludeMissing + secondDimension: JsonField = JsonMissing.of(), + ) : this( + firstDimension, + matrixScalingFactors, + unitPrice, + prorate, + secondDimension, + mutableMapOf(), + ) + + /** + * Used to determine the unit rate + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun firstDimension(): String = firstDimension.getRequired("first_dimension") + + /** + * Apply a scaling factor to each dimension + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun matrixScalingFactors(): List = + matrixScalingFactors.getRequired("matrix_scaling_factors") + + /** + * The final unit price to rate against the output of the matrix + * + * @throws OrbInvalidDataException if 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(): String = unitPrice.getRequired("unit_price") + + /** + * If true, the unit price will be prorated to the billing period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorate(): Boolean? = prorate.getNullable("prorate") + + /** + * Used to determine the unit rate (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimension(): String? = secondDimension.getNullable("second_dimension") + + /** + * Returns the raw JSON value of [firstDimension]. + * + * Unlike [firstDimension], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("first_dimension") + @ExcludeMissing + fun _firstDimension(): JsonField = firstDimension + + /** + * Returns the raw JSON value of [matrixScalingFactors]. + * + * Unlike [matrixScalingFactors], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + fun _matrixScalingFactors(): JsonField> = matrixScalingFactors + + /** + * 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 [prorate]. + * + * Unlike [prorate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorate") @ExcludeMissing fun _prorate(): JsonField = prorate + + /** + * Returns the raw JSON value of [secondDimension]. + * + * Unlike [secondDimension], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("second_dimension") + @ExcludeMissing + fun _secondDimension(): JsonField = secondDimension + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1264,6 +1383,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [ScalableMatrixWithUnitPricingConfig]. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .unitPrice() + * ``` */ fun builder() = Builder() } @@ -1271,15 +1397,117 @@ private constructor( /** A builder for [ScalableMatrixWithUnitPricingConfig]. */ class Builder internal constructor() { + private var firstDimension: JsonField? = null + private var matrixScalingFactors: JsonField>? = null + private var unitPrice: JsonField? = null + private var prorate: JsonField = JsonMissing.of() + private var secondDimension: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from( scalableMatrixWithUnitPricingConfig: ScalableMatrixWithUnitPricingConfig ) = apply { + firstDimension = scalableMatrixWithUnitPricingConfig.firstDimension + matrixScalingFactors = + scalableMatrixWithUnitPricingConfig.matrixScalingFactors.map { + it.toMutableList() + } + unitPrice = scalableMatrixWithUnitPricingConfig.unitPrice + prorate = scalableMatrixWithUnitPricingConfig.prorate + secondDimension = scalableMatrixWithUnitPricingConfig.secondDimension additionalProperties = scalableMatrixWithUnitPricingConfig.additionalProperties.toMutableMap() } + /** Used to determine the unit rate */ + fun firstDimension(firstDimension: String) = + firstDimension(JsonField.of(firstDimension)) + + /** + * Sets [Builder.firstDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun firstDimension(firstDimension: JsonField) = apply { + this.firstDimension = firstDimension + } + + /** Apply a scaling factor to each dimension */ + fun matrixScalingFactors(matrixScalingFactors: List) = + matrixScalingFactors(JsonField.of(matrixScalingFactors)) + + /** + * Sets [Builder.matrixScalingFactors] to an arbitrary JSON value. + * + * You should usually call [Builder.matrixScalingFactors] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun matrixScalingFactors(matrixScalingFactors: JsonField>) = + apply { + this.matrixScalingFactors = matrixScalingFactors.map { it.toMutableList() } + } + + /** + * Adds a single [MatrixScalingFactor] to [matrixScalingFactors]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMatrixScalingFactor(matrixScalingFactor: MatrixScalingFactor) = apply { + matrixScalingFactors = + (matrixScalingFactors ?: JsonField.of(mutableListOf())).also { + checkKnown("matrixScalingFactors", it).add(matrixScalingFactor) + } + } + + /** The final unit price to rate against the output of the matrix */ + fun unitPrice(unitPrice: String) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [String] 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 } + + /** If true, the unit price will be prorated to the billing period */ + fun prorate(prorate: Boolean?) = prorate(JsonField.ofNullable(prorate)) + + /** + * Alias for [Builder.prorate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun prorate(prorate: Boolean) = prorate(prorate as Boolean?) + + /** + * Sets [Builder.prorate] to an arbitrary JSON value. + * + * You should usually call [Builder.prorate] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prorate(prorate: JsonField) = apply { this.prorate = prorate } + + /** Used to determine the unit rate (optional) */ + fun secondDimension(secondDimension: String?) = + secondDimension(JsonField.ofNullable(secondDimension)) + + /** + * Sets [Builder.secondDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun secondDimension(secondDimension: JsonField) = apply { + this.secondDimension = secondDimension + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1303,9 +1531,27 @@ private constructor( * Returns an immutable instance of [ScalableMatrixWithUnitPricingConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .unitPrice() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): ScalableMatrixWithUnitPricingConfig = - ScalableMatrixWithUnitPricingConfig(additionalProperties.toImmutable()) + ScalableMatrixWithUnitPricingConfig( + checkRequired("firstDimension", firstDimension), + checkRequired("matrixScalingFactors", matrixScalingFactors).map { + it.toImmutable() + }, + checkRequired("unitPrice", unitPrice), + prorate, + secondDimension, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1315,6 +1561,11 @@ private constructor( return@apply } + firstDimension() + matrixScalingFactors().forEach { it.validate() } + unitPrice() + prorate() + secondDimension() validated = true } @@ -1333,193 +1584,311 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (firstDimension.asKnown() == null) 0 else 1) + + (matrixScalingFactors.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (unitPrice.asKnown() == null) 0 else 1) + + (if (prorate.asKnown() == null) 0 else 1) + + (if (secondDimension.asKnown() == null) 0 else 1) + + /** Configuration for a single matrix scaling factor */ + class MatrixScalingFactor + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val firstDimensionValue: JsonField, + private val scalingFactor: JsonField, + private val secondDimensionValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("first_dimension_value") + @ExcludeMissing + firstDimensionValue: JsonField = JsonMissing.of(), + @JsonProperty("scaling_factor") + @ExcludeMissing + scalingFactor: JsonField = JsonMissing.of(), + @JsonProperty("second_dimension_value") + @ExcludeMissing + secondDimensionValue: JsonField = JsonMissing.of(), + ) : this(firstDimensionValue, scalingFactor, secondDimensionValue, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * First dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun firstDimensionValue(): String = + firstDimensionValue.getRequired("first_dimension_value") - return /* spotless:off */ other is ScalableMatrixWithUnitPricingConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingFactor(): String = scalingFactor.getRequired("scaling_factor") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Second dimension value (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimensionValue(): String? = + secondDimensionValue.getNullable("second_dimension_value") - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [firstDimensionValue]. + * + * Unlike [firstDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("first_dimension_value") + @ExcludeMissing + fun _firstDimensionValue(): JsonField = firstDimensionValue - override fun toString() = - "ScalableMatrixWithUnitPricingConfig{additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [scalingFactor]. + * + * Unlike [scalingFactor], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("scaling_factor") + @ExcludeMissing + fun _scalingFactor(): JsonField = scalingFactor - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + /** + * Returns the raw JSON value of [secondDimensionValue]. + * + * Unlike [secondDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("second_dimension_value") + @ExcludeMissing + fun _secondDimensionValue(): JsonField = secondDimensionValue - fun unit(): UnitConversionRateConfig? = unit + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [MatrixScalingFactor]. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + */ + fun builder() = Builder() + } - fun isUnit(): Boolean = unit != null + /** A builder for [MatrixScalingFactor]. */ + class Builder internal constructor() { - fun isTiered(): Boolean = tiered != null + private var firstDimensionValue: JsonField? = null + private var scalingFactor: JsonField? = null + private var secondDimensionValue: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + internal fun from(matrixScalingFactor: MatrixScalingFactor) = apply { + firstDimensionValue = matrixScalingFactor.firstDimensionValue + scalingFactor = matrixScalingFactor.scalingFactor + secondDimensionValue = matrixScalingFactor.secondDimensionValue + additionalProperties = matrixScalingFactor.additionalProperties.toMutableMap() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** First dimension value */ + fun firstDimensionValue(firstDimensionValue: String) = + firstDimensionValue(JsonField.of(firstDimensionValue)) + + /** + * Sets [Builder.firstDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimensionValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun firstDimensionValue(firstDimensionValue: JsonField) = apply { + this.firstDimensionValue = firstDimensionValue + } - fun _json(): JsonValue? = _json + /** Scaling factor */ + fun scalingFactor(scalingFactor: String) = + scalingFactor(JsonField.of(scalingFactor)) + + /** + * Sets [Builder.scalingFactor] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactor] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun scalingFactor(scalingFactor: JsonField) = apply { + this.scalingFactor = scalingFactor + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + /** Second dimension value (optional) */ + fun secondDimensionValue(secondDimensionValue: String?) = + secondDimensionValue(JsonField.ofNullable(secondDimensionValue)) + + /** + * Sets [Builder.secondDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimensionValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun secondDimensionValue(secondDimensionValue: JsonField) = apply { + this.secondDimensionValue = secondDimensionValue + } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 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 [MatrixScalingFactor]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MatrixScalingFactor = + MatrixScalingFactor( + checkRequired("firstDimensionValue", firstDimensionValue), + checkRequired("scalingFactor", scalingFactor), + secondDimensionValue, + additionalProperties.toMutableMap(), + ) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + private var validated: Boolean = false - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun validate(): MatrixScalingFactor = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + firstDimensionValue() + scalingFactor() + secondDimensionValue() + validated = true } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + internal fun validity(): Int = + (if (firstDimensionValue.asKnown() == null) 0 else 1) + + (if (scalingFactor.asKnown() == null) 0 else 1) + + (if (secondDimensionValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MatrixScalingFactor && + firstDimensionValue == other.firstDimensionValue && + scalingFactor == other.scalingFactor && + secondDimensionValue == other.secondDimensionValue && + additionalProperties == other.additionalProperties } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + private val hashCode: Int by lazy { + Objects.hash( + firstDimensionValue, + scalingFactor, + secondDimensionValue, + additionalProperties, + ) + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + override fun hashCode(): Int = hashCode - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + override fun toString() = + "MatrixScalingFactor{firstDimensionValue=$firstDimensionValue, scalingFactor=$scalingFactor, secondDimensionValue=$secondDimensionValue, additionalProperties=$additionalProperties}" + } - return ConversionRateConfig(_json = json) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is ScalableMatrixWithUnitPricingConfig && + firstDimension == other.firstDimension && + matrixScalingFactors == other.matrixScalingFactors && + unitPrice == other.unitPrice && + prorate == other.prorate && + secondDimension == other.secondDimension && + additionalProperties == other.additionalProperties } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } + private val hashCode: Int by lazy { + Objects.hash( + firstDimension, + matrixScalingFactors, + unitPrice, + prorate, + secondDimension, + additionalProperties, + ) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScalableMatrixWithUnitPricingConfig{firstDimension=$firstDimension, matrixScalingFactors=$matrixScalingFactors, unitPrice=$unitPrice, prorate=$prorate, secondDimension=$secondDimension, additionalProperties=$additionalProperties}" } /** @@ -1614,12 +1983,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1631,12 +1998,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionScalableMatrixWithUnitPricingPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && scalableMatrixWithUnitPricingConfig == other.scalableMatrixWithUnitPricingConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionScalableMatrixWithUnitPricingPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + scalableMatrixWithUnitPricingConfig == other.scalableMatrixWithUnitPricingConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, scalableMatrixWithUnitPricingConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + scalableMatrixWithUnitPricingConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionThresholdTotalAmountPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionThresholdTotalAmountPrice.kt index 13b71260b..ee5d55cfa 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionThresholdTotalAmountPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionThresholdTotalAmountPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionThresholdTotalAmountPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +128,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +144,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for threshold_total_amount pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -539,6 +535,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -561,6 +558,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for threshold_total_amount pricing */ fun thresholdTotalAmountConfig(thresholdTotalAmountConfig: ThresholdTotalAmountConfig) = thresholdTotalAmountConfig(JsonField.of(thresholdTotalAmountConfig)) @@ -1105,7 +1103,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1113,6 +1111,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1225,7 +1224,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1233,16 +1232,67 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for threshold_total_amount pricing */ class ThresholdTotalAmountConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val consumptionTable: JsonField>, + private val prorate: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("consumption_table") + @ExcludeMissing + consumptionTable: JsonField> = JsonMissing.of(), + @JsonProperty("prorate") @ExcludeMissing prorate: JsonField = JsonMissing.of(), + ) : this(consumptionTable, prorate, mutableMapOf()) + + /** + * When the quantity consumed passes a provided threshold, the configured total will be + * charged + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun consumptionTable(): List = + consumptionTable.getRequired("consumption_table") + + /** + * If true, the unit price will be prorated to the billing period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorate(): Boolean? = prorate.getNullable("prorate") + + /** + * Returns the raw JSON value of [consumptionTable]. + * + * Unlike [consumptionTable], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("consumption_table") + @ExcludeMissing + fun _consumptionTable(): JsonField> = consumptionTable + + /** + * Returns the raw JSON value of [prorate]. + * + * Unlike [prorate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorate") @ExcludeMissing fun _prorate(): JsonField = prorate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1251,6 +1301,11 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [ThresholdTotalAmountConfig]. + * + * The following fields are required: + * ```kotlin + * .consumptionTable() + * ``` */ fun builder() = Builder() } @@ -1258,13 +1313,67 @@ private constructor( /** A builder for [ThresholdTotalAmountConfig]. */ class Builder internal constructor() { + private var consumptionTable: JsonField>? = null + private var prorate: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(thresholdTotalAmountConfig: ThresholdTotalAmountConfig) = apply { + consumptionTable = + thresholdTotalAmountConfig.consumptionTable.map { it.toMutableList() } + prorate = thresholdTotalAmountConfig.prorate additionalProperties = thresholdTotalAmountConfig.additionalProperties.toMutableMap() } + /** + * When the quantity consumed passes a provided threshold, the configured total will be + * charged + */ + fun consumptionTable(consumptionTable: List) = + consumptionTable(JsonField.of(consumptionTable)) + + /** + * Sets [Builder.consumptionTable] to an arbitrary JSON value. + * + * You should usually call [Builder.consumptionTable] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun consumptionTable(consumptionTable: JsonField>) = apply { + this.consumptionTable = consumptionTable.map { it.toMutableList() } + } + + /** + * Adds a single [ConsumptionTable] to [Builder.consumptionTable]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addConsumptionTable(consumptionTable: ConsumptionTable) = apply { + this.consumptionTable = + (this.consumptionTable ?: JsonField.of(mutableListOf())).also { + checkKnown("consumptionTable", it).add(consumptionTable) + } + } + + /** If true, the unit price will be prorated to the billing period */ + fun prorate(prorate: Boolean?) = prorate(JsonField.ofNullable(prorate)) + + /** + * Alias for [Builder.prorate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun prorate(prorate: Boolean) = prorate(prorate as Boolean?) + + /** + * Sets [Builder.prorate] to an arbitrary JSON value. + * + * You should usually call [Builder.prorate] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prorate(prorate: JsonField) = apply { this.prorate = prorate } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1288,9 +1397,20 @@ private constructor( * Returns an immutable instance of [ThresholdTotalAmountConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .consumptionTable() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): ThresholdTotalAmountConfig = - ThresholdTotalAmountConfig(additionalProperties.toImmutable()) + ThresholdTotalAmountConfig( + checkRequired("consumptionTable", consumptionTable).map { it.toImmutable() }, + prorate, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1300,6 +1420,8 @@ private constructor( return@apply } + consumptionTable().forEach { it.validate() } + prorate() validated = true } @@ -1318,193 +1440,244 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (consumptionTable.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (prorate.asKnown() == null) 0 else 1) + + /** Configuration for a single threshold */ + class ConsumptionTable + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val threshold: JsonField, + private val totalAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("threshold") + @ExcludeMissing + threshold: JsonField = JsonMissing.of(), + @JsonProperty("total_amount") + @ExcludeMissing + totalAmount: JsonField = JsonMissing.of(), + ) : this(threshold, totalAmount, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Quantity threshold + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun threshold(): String = threshold.getRequired("threshold") - return /* spotless:off */ other is ThresholdTotalAmountConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Total amount for this threshold + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun totalAmount(): String = totalAmount.getRequired("total_amount") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Returns the raw JSON value of [threshold]. + * + * Unlike [threshold], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("threshold") + @ExcludeMissing + fun _threshold(): JsonField = threshold - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [totalAmount]. + * + * Unlike [totalAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("total_amount") + @ExcludeMissing + fun _totalAmount(): JsonField = totalAmount - override fun toString() = - "ThresholdTotalAmountConfig{additionalProperties=$additionalProperties}" - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ConsumptionTable]. + * + * The following fields are required: + * ```kotlin + * .threshold() + * .totalAmount() + * ``` + */ + fun builder() = Builder() + } - fun unit(): UnitConversionRateConfig? = unit + /** A builder for [ConsumptionTable]. */ + class Builder internal constructor() { - fun tiered(): TieredConversionRateConfig? = tiered + private var threshold: JsonField? = null + private var totalAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun isUnit(): Boolean = unit != null + internal fun from(consumptionTable: ConsumptionTable) = apply { + threshold = consumptionTable.threshold + totalAmount = consumptionTable.totalAmount + additionalProperties = consumptionTable.additionalProperties.toMutableMap() + } - fun isTiered(): Boolean = tiered != null + /** Quantity threshold */ + fun threshold(threshold: String) = threshold(JsonField.of(threshold)) + + /** + * Sets [Builder.threshold] to an arbitrary JSON value. + * + * You should usually call [Builder.threshold] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun threshold(threshold: JsonField) = apply { this.threshold = threshold } + + /** Total amount for this threshold */ + fun totalAmount(totalAmount: String) = totalAmount(JsonField.of(totalAmount)) + + /** + * Sets [Builder.totalAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.totalAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun totalAmount(totalAmount: JsonField) = apply { + this.totalAmount = totalAmount + } - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun _json(): JsonValue? = _json + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - private var validated: Boolean = false + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Returns an immutable instance of [ConsumptionTable]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .threshold() + * .totalAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ConsumptionTable = + ConsumptionTable( + checkRequired("threshold", threshold), + checkRequired("totalAmount", totalAmount), + additionalProperties.toMutableMap(), + ) } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } + private var validated: Boolean = false - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun validate(): ConsumptionTable = apply { + if (validated) { + return@apply } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + threshold() + totalAmount() + validated = true } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (threshold.asKnown() == null) 0 else 1) + + (if (totalAmount.asKnown() == null) 0 else 1) - override fun unknown(json: JsonValue?) = 0 + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + return other is ConsumptionTable && + threshold == other.threshold && + totalAmount == other.totalAmount && + additionalProperties == other.additionalProperties } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + private val hashCode: Int by lazy { + Objects.hash(threshold, totalAmount, additionalProperties) } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + override fun hashCode(): Int = hashCode - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) + override fun toString() = + "ConsumptionTable{threshold=$threshold, totalAmount=$totalAmount, additionalProperties=$additionalProperties}" } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - return ConversionRateConfig(_json = json) - } + return other is ThresholdTotalAmountConfig && + consumptionTable == other.consumptionTable && + prorate == other.prorate && + additionalProperties == other.additionalProperties } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } + private val hashCode: Int by lazy { + Objects.hash(consumptionTable, prorate, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThresholdTotalAmountConfig{consumptionTable=$consumptionTable, prorate=$prorate, additionalProperties=$additionalProperties}" } /** @@ -1599,12 +1772,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1616,12 +1787,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionThresholdTotalAmountPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && thresholdTotalAmountConfig == other.thresholdTotalAmountConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionThresholdTotalAmountPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + thresholdTotalAmountConfig == other.thresholdTotalAmountConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, thresholdTotalAmountConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + thresholdTotalAmountConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTierWithProrationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTierWithProrationPrice.kt deleted file mode 100644 index 80b5ce661..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTierWithProrationPrice.kt +++ /dev/null @@ -1,1629 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer -import com.withorb.api.core.Enum -import com.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow -import com.withorb.api.core.toImmutable -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class NewSubscriptionTierWithProrationPrice -private constructor( - private val cadence: JsonField, - private val itemId: JsonField, - private val modelType: JsonField, - private val name: JsonField, - private val tieredWithProrationConfig: JsonField, - private val billableMetricId: JsonField, - private val billedInAdvance: JsonField, - private val billingCycleConfiguration: JsonField, - private val conversionRate: JsonField, - private val conversionRateConfig: JsonField, - private val currency: JsonField, - private val dimensionalPriceConfiguration: JsonField, - private val externalPriceId: JsonField, - private val fixedPriceQuantity: JsonField, - private val invoiceGroupingKey: JsonField, - private val invoicingCycleConfiguration: JsonField, - private val metadata: JsonField, - private val referenceId: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), - @JsonProperty("item_id") @ExcludeMissing itemId: JsonField = JsonMissing.of(), - @JsonProperty("model_type") - @ExcludeMissing - modelType: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("tiered_with_proration_config") - @ExcludeMissing - tieredWithProrationConfig: JsonField = JsonMissing.of(), - @JsonProperty("billable_metric_id") - @ExcludeMissing - billableMetricId: JsonField = JsonMissing.of(), - @JsonProperty("billed_in_advance") - @ExcludeMissing - billedInAdvance: JsonField = JsonMissing.of(), - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - billingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate") - @ExcludeMissing - conversionRate: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate_config") - @ExcludeMissing - conversionRateConfig: JsonField = JsonMissing.of(), - @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - dimensionalPriceConfiguration: JsonField = - JsonMissing.of(), - @JsonProperty("external_price_id") - @ExcludeMissing - externalPriceId: JsonField = JsonMissing.of(), - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - invoiceGroupingKey: JsonField = JsonMissing.of(), - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - invoicingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), - @JsonProperty("reference_id") - @ExcludeMissing - referenceId: JsonField = JsonMissing.of(), - ) : this( - cadence, - itemId, - modelType, - name, - tieredWithProrationConfig, - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - currency, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - referenceId, - mutableMapOf(), - ) - - /** - * The cadence to bill for this price on. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun cadence(): Cadence = cadence.getRequired("cadence") - - /** - * The id of the item the price will be associated with. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun itemId(): String = itemId.getRequired("item_id") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun modelType(): ModelType = modelType.getRequired("model_type") - - /** - * The name of the price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun name(): String = name.getRequired("name") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun tieredWithProrationConfig(): TieredWithProrationConfig = - tieredWithProrationConfig.getRequired("tiered_with_proration_config") - - /** - * The id of the billable metric for the price. Only needed if the price is usage-based. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is true, - * and in-arrears if this is false. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - - /** - * For custom cadence: specifies the duration of the billing period in days or months. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billingCycleConfiguration(): NewBillingCycleConfiguration? = - billingCycleConfiguration.getNullable("billing_cycle_configuration") - - /** - * The per unit conversion rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - - /** - * The configuration for the rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRateConfig(): ConversionRateConfig? = - conversionRateConfig.getNullable("conversion_rate_config") - - /** - * An ISO 4217 currency string, or custom pricing unit identifier, in which this price is - * billed. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun currency(): String? = currency.getNullable("currency") - - /** - * For dimensional price: specifies a price group and dimension values - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = - dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - - /** - * An alias for the price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - - /** - * If the Price represents a fixed cost, this represents the quantity of units applied. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") - - /** - * The property used to group this price on an invoice - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoiceGroupingKey(): String? = invoiceGroupingKey.getNullable("invoice_grouping_key") - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = - invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun metadata(): Metadata? = metadata.getNullable("metadata") - - /** - * A transient ID that can be used to reference this price when adding adjustments in the same - * API call. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun referenceId(): String? = referenceId.getNullable("reference_id") - - /** - * Returns the raw JSON value of [cadence]. - * - * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence - - /** - * Returns the raw JSON value of [itemId]. - * - * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - - /** - * Returns the raw JSON value of [modelType]. - * - * Unlike [modelType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonField = modelType - - /** - * 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 [tieredWithProrationConfig]. - * - * Unlike [tieredWithProrationConfig], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("tiered_with_proration_config") - @ExcludeMissing - fun _tieredWithProrationConfig(): JsonField = - tieredWithProrationConfig - - /** - * Returns the raw JSON value of [billableMetricId]. - * - * Unlike [billableMetricId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("billable_metric_id") - @ExcludeMissing - fun _billableMetricId(): JsonField = billableMetricId - - /** - * Returns the raw JSON value of [billedInAdvance]. - * - * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("billed_in_advance") - @ExcludeMissing - fun _billedInAdvance(): JsonField = billedInAdvance - - /** - * Returns the raw JSON value of [billingCycleConfiguration]. - * - * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - fun _billingCycleConfiguration(): JsonField = - billingCycleConfiguration - - /** - * Returns the raw JSON value of [conversionRate]. - * - * Unlike [conversionRate], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("conversion_rate") - @ExcludeMissing - fun _conversionRate(): JsonField = conversionRate - - /** - * Returns the raw JSON value of [conversionRateConfig]. - * - * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("conversion_rate_config") - @ExcludeMissing - fun _conversionRateConfig(): JsonField = conversionRateConfig - - /** - * Returns the raw JSON value of [currency]. - * - * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency - - /** - * Returns the raw JSON value of [dimensionalPriceConfiguration]. - * - * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - fun _dimensionalPriceConfiguration(): JsonField = - dimensionalPriceConfiguration - - /** - * Returns the raw JSON value of [externalPriceId]. - * - * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("external_price_id") - @ExcludeMissing - fun _externalPriceId(): JsonField = externalPriceId - - /** - * Returns the raw JSON value of [fixedPriceQuantity]. - * - * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - - /** - * Returns the raw JSON value of [invoiceGroupingKey]. - * - * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - - /** - * Returns the raw JSON value of [invoicingCycleConfiguration]. - * - * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - fun _invoicingCycleConfiguration(): JsonField = - invoicingCycleConfiguration - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - - /** - * Returns the raw JSON value of [referenceId]. - * - * Unlike [referenceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("reference_id") - @ExcludeMissing - fun _referenceId(): JsonField = referenceId - - @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 - * [NewSubscriptionTierWithProrationPrice]. - * - * The following fields are required: - * ```kotlin - * .cadence() - * .itemId() - * .modelType() - * .name() - * .tieredWithProrationConfig() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [NewSubscriptionTierWithProrationPrice]. */ - class Builder internal constructor() { - - private var cadence: JsonField? = null - private var itemId: JsonField? = null - private var modelType: JsonField? = null - private var name: JsonField? = null - private var tieredWithProrationConfig: JsonField? = null - private var billableMetricId: JsonField = JsonMissing.of() - private var billedInAdvance: JsonField = JsonMissing.of() - private var billingCycleConfiguration: JsonField = - JsonMissing.of() - private var conversionRate: JsonField = JsonMissing.of() - private var conversionRateConfig: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var dimensionalPriceConfiguration: JsonField = - JsonMissing.of() - private var externalPriceId: JsonField = JsonMissing.of() - private var fixedPriceQuantity: JsonField = JsonMissing.of() - private var invoiceGroupingKey: JsonField = JsonMissing.of() - private var invoicingCycleConfiguration: JsonField = - JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var referenceId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from( - newSubscriptionTierWithProrationPrice: NewSubscriptionTierWithProrationPrice - ) = apply { - cadence = newSubscriptionTierWithProrationPrice.cadence - itemId = newSubscriptionTierWithProrationPrice.itemId - modelType = newSubscriptionTierWithProrationPrice.modelType - name = newSubscriptionTierWithProrationPrice.name - tieredWithProrationConfig = - newSubscriptionTierWithProrationPrice.tieredWithProrationConfig - billableMetricId = newSubscriptionTierWithProrationPrice.billableMetricId - billedInAdvance = newSubscriptionTierWithProrationPrice.billedInAdvance - billingCycleConfiguration = - newSubscriptionTierWithProrationPrice.billingCycleConfiguration - conversionRate = newSubscriptionTierWithProrationPrice.conversionRate - conversionRateConfig = newSubscriptionTierWithProrationPrice.conversionRateConfig - currency = newSubscriptionTierWithProrationPrice.currency - dimensionalPriceConfiguration = - newSubscriptionTierWithProrationPrice.dimensionalPriceConfiguration - externalPriceId = newSubscriptionTierWithProrationPrice.externalPriceId - fixedPriceQuantity = newSubscriptionTierWithProrationPrice.fixedPriceQuantity - invoiceGroupingKey = newSubscriptionTierWithProrationPrice.invoiceGroupingKey - invoicingCycleConfiguration = - newSubscriptionTierWithProrationPrice.invoicingCycleConfiguration - metadata = newSubscriptionTierWithProrationPrice.metadata - referenceId = newSubscriptionTierWithProrationPrice.referenceId - additionalProperties = - newSubscriptionTierWithProrationPrice.additionalProperties.toMutableMap() - } - - /** The cadence to bill for this price on. */ - fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) - - /** - * Sets [Builder.cadence] to an arbitrary JSON value. - * - * You should usually call [Builder.cadence] with a well-typed [Cadence] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun cadence(cadence: JsonField) = apply { this.cadence = cadence } - - /** The id of the item the price will be associated with. */ - fun itemId(itemId: String) = itemId(JsonField.of(itemId)) - - /** - * Sets [Builder.itemId] to an arbitrary JSON value. - * - * You should usually call [Builder.itemId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun itemId(itemId: JsonField) = apply { this.itemId = itemId } - - fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) - - /** - * Sets [Builder.modelType] to an arbitrary JSON value. - * - * You should usually call [Builder.modelType] with a well-typed [ModelType] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun modelType(modelType: JsonField) = apply { this.modelType = modelType } - - /** The name of the price. */ - 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 tieredWithProrationConfig(tieredWithProrationConfig: TieredWithProrationConfig) = - tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) - - /** - * Sets [Builder.tieredWithProrationConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.tieredWithProrationConfig] with a well-typed - * [TieredWithProrationConfig] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. - */ - fun tieredWithProrationConfig( - tieredWithProrationConfig: JsonField - ) = apply { this.tieredWithProrationConfig = tieredWithProrationConfig } - - /** The id of the billable metric for the price. Only needed if the price is usage-based. */ - fun billableMetricId(billableMetricId: String?) = - billableMetricId(JsonField.ofNullable(billableMetricId)) - - /** - * Sets [Builder.billableMetricId] to an arbitrary JSON value. - * - * You should usually call [Builder.billableMetricId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billableMetricId(billableMetricId: JsonField) = apply { - this.billableMetricId = billableMetricId - } - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is - * true, and in-arrears if this is false. - */ - fun billedInAdvance(billedInAdvance: Boolean?) = - billedInAdvance(JsonField.ofNullable(billedInAdvance)) - - /** - * Alias for [Builder.billedInAdvance]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun billedInAdvance(billedInAdvance: Boolean) = billedInAdvance(billedInAdvance as Boolean?) - - /** - * Sets [Builder.billedInAdvance] to an arbitrary JSON value. - * - * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billedInAdvance(billedInAdvance: JsonField) = apply { - this.billedInAdvance = billedInAdvance - } - - /** For custom cadence: specifies the duration of the billing period in days or months. */ - fun billingCycleConfiguration(billingCycleConfiguration: NewBillingCycleConfiguration?) = - billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) - - /** - * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.billingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun billingCycleConfiguration( - billingCycleConfiguration: JsonField - ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } - - /** The per unit conversion rate of the price currency to the invoicing currency. */ - fun conversionRate(conversionRate: Double?) = - conversionRate(JsonField.ofNullable(conversionRate)) - - /** - * Alias for [Builder.conversionRate]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun conversionRate(conversionRate: Double) = conversionRate(conversionRate as Double?) - - /** - * Sets [Builder.conversionRate] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRate] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun conversionRate(conversionRate: JsonField) = apply { - this.conversionRate = conversionRate - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = - conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) - - /** - * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRateConfig] with a well-typed - * [ConversionRateConfig] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun conversionRateConfig(conversionRateConfig: JsonField) = apply { - this.conversionRateConfig = conversionRateConfig - } - - /** Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofUnit(unit)`. */ - fun conversionRateConfig(unit: UnitConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofUnit(unit)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * UnitConversionRateConfig.builder() - * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - * .unitConfig(unitConfig) - * .build() - * ``` - */ - fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = - conversionRateConfig( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig(unitConfig) - .build() - ) - - /** - * Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofTiered(tiered)`. - */ - fun conversionRateConfig(tiered: TieredConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * TieredConversionRateConfig.builder() - * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - * .tieredConfig(tieredConfig) - * .build() - * ``` - */ - fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = - conversionRateConfig( - TieredConversionRateConfig.builder() - .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - .tieredConfig(tieredConfig) - .build() - ) - - /** - * An ISO 4217 currency string, or custom pricing unit identifier, in which this price is - * billed. - */ - fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) - - /** - * Sets [Builder.currency] to an arbitrary JSON value. - * - * You should usually call [Builder.currency] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun currency(currency: JsonField) = apply { this.currency = currency } - - /** For dimensional price: specifies a price group and dimension values */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? - ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) - - /** - * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed - * [NewDimensionalPriceConfiguration] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: JsonField - ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } - - /** An alias for the price. */ - fun externalPriceId(externalPriceId: String?) = - externalPriceId(JsonField.ofNullable(externalPriceId)) - - /** - * Sets [Builder.externalPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.externalPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun externalPriceId(externalPriceId: JsonField) = apply { - this.externalPriceId = externalPriceId - } - - /** If the Price represents a fixed cost, this represents the quantity of units applied. */ - fun fixedPriceQuantity(fixedPriceQuantity: Double?) = - fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) - - /** - * Alias for [Builder.fixedPriceQuantity]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun fixedPriceQuantity(fixedPriceQuantity: Double) = - fixedPriceQuantity(fixedPriceQuantity as Double?) - - /** - * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. - * - * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { - this.fixedPriceQuantity = fixedPriceQuantity - } - - /** The property used to group this price on an invoice */ - fun invoiceGroupingKey(invoiceGroupingKey: String?) = - invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) - - /** - * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceGroupingKey] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { - this.invoiceGroupingKey = invoiceGroupingKey - } - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: NewBillingCycleConfiguration? - ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) - - /** - * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: JsonField - ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by - * setting the value to `null`, and the entire metadata mapping can be cleared by setting - * `metadata` to `null`. - */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - /** - * A transient ID that can be used to reference this price when adding adjustments in the - * same API call. - */ - fun referenceId(referenceId: String?) = referenceId(JsonField.ofNullable(referenceId)) - - /** - * Sets [Builder.referenceId] to an arbitrary JSON value. - * - * You should usually call [Builder.referenceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun referenceId(referenceId: JsonField) = apply { this.referenceId = referenceId } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [NewSubscriptionTierWithProrationPrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .cadence() - * .itemId() - * .modelType() - * .name() - * .tieredWithProrationConfig() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): NewSubscriptionTierWithProrationPrice = - NewSubscriptionTierWithProrationPrice( - checkRequired("cadence", cadence), - checkRequired("itemId", itemId), - checkRequired("modelType", modelType), - checkRequired("name", name), - checkRequired("tieredWithProrationConfig", tieredWithProrationConfig), - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - currency, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - referenceId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): NewSubscriptionTierWithProrationPrice = apply { - if (validated) { - return@apply - } - - cadence().validate() - itemId() - modelType().validate() - name() - tieredWithProrationConfig().validate() - billableMetricId() - billedInAdvance() - billingCycleConfiguration()?.validate() - conversionRate() - conversionRateConfig()?.validate() - currency() - dimensionalPriceConfiguration()?.validate() - externalPriceId() - fixedPriceQuantity() - invoiceGroupingKey() - invoicingCycleConfiguration()?.validate() - metadata()?.validate() - referenceId() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (cadence.asKnown()?.validity() ?: 0) + - (if (itemId.asKnown() == null) 0 else 1) + - (modelType.asKnown()?.validity() ?: 0) + - (if (name.asKnown() == null) 0 else 1) + - (tieredWithProrationConfig.asKnown()?.validity() ?: 0) + - (if (billableMetricId.asKnown() == null) 0 else 1) + - (if (billedInAdvance.asKnown() == null) 0 else 1) + - (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (if (conversionRate.asKnown() == null) 0 else 1) + - (conversionRateConfig.asKnown()?.validity() ?: 0) + - (if (currency.asKnown() == null) 0 else 1) + - (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + - (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + - (metadata.asKnown()?.validity() ?: 0) + - (if (referenceId.asKnown() == null) 0 else 1) - - /** The cadence to bill for this price on. */ - class Cadence @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 { - - val ANNUAL = of("annual") - - val SEMI_ANNUAL = of("semi_annual") - - val MONTHLY = of("monthly") - - val QUARTERLY = of("quarterly") - - val ONE_TIME = of("one_time") - - val CUSTOM = of("custom") - - fun of(value: String) = Cadence(JsonField.of(value)) - } - - /** An enum containing [Cadence]'s known values. */ - enum class Known { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - } - - /** - * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Cadence] 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 { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - /** An enum member indicating that [Cadence] 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) { - ANNUAL -> Value.ANNUAL - SEMI_ANNUAL -> Value.SEMI_ANNUAL - MONTHLY -> Value.MONTHLY - QUARTERLY -> Value.QUARTERLY - ONE_TIME -> Value.ONE_TIME - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - ANNUAL -> Known.ANNUAL - SEMI_ANNUAL -> Known.SEMI_ANNUAL - MONTHLY -> Known.MONTHLY - QUARTERLY -> Known.QUARTERLY - ONE_TIME -> Known.ONE_TIME - CUSTOM -> Known.CUSTOM - else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): Cadence = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class ModelType @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 { - - val TIERED_WITH_PRORATION = of("tiered_with_proration") - - fun of(value: String) = ModelType(JsonField.of(value)) - } - - /** An enum containing [ModelType]'s known values. */ - enum class Known { - TIERED_WITH_PRORATION - } - - /** - * An enum containing [ModelType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [ModelType] 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 { - TIERED_WITH_PRORATION, - /** - * An enum member indicating that [ModelType] 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) { - TIERED_WITH_PRORATION -> Value.TIERED_WITH_PRORATION - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - TIERED_WITH_PRORATION -> Known.TIERED_WITH_PRORATION - else -> throw OrbInvalidDataException("Unknown ModelType: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): ModelType = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class TieredWithProrationConfig - @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 - * [TieredWithProrationConfig]. - */ - fun builder() = Builder() - } - - /** A builder for [TieredWithProrationConfig]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = apply { - additionalProperties = tieredWithProrationConfig.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 [TieredWithProrationConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): TieredWithProrationConfig = - TieredWithProrationConfig(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): TieredWithProrationConfig = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TieredWithProrationConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "TieredWithProrationConfig{additionalProperties=$additionalProperties}" - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - */ - class Metadata - @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 [Metadata]. */ - fun builder() = Builder() - } - - /** A builder for [Metadata]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.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 [Metadata]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is NewSubscriptionTierWithProrationPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredWithProrationConfig == other.tieredWithProrationConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, tieredWithProrationConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "NewSubscriptionTierWithProrationPrice{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, tieredWithProrationConfig=$tieredWithProrationConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredBpsPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredBpsPrice.kt deleted file mode 100644 index 6bec4f3e7..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredBpsPrice.kt +++ /dev/null @@ -1,1516 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer -import com.withorb.api.core.Enum -import com.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow -import com.withorb.api.core.toImmutable -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class NewSubscriptionTieredBpsPrice -private constructor( - private val cadence: JsonField, - private val itemId: JsonField, - private val modelType: JsonField, - private val name: JsonField, - private val tieredBpsConfig: JsonField, - private val billableMetricId: JsonField, - private val billedInAdvance: JsonField, - private val billingCycleConfiguration: JsonField, - private val conversionRate: JsonField, - private val conversionRateConfig: JsonField, - private val currency: JsonField, - private val dimensionalPriceConfiguration: JsonField, - private val externalPriceId: JsonField, - private val fixedPriceQuantity: JsonField, - private val invoiceGroupingKey: JsonField, - private val invoicingCycleConfiguration: JsonField, - private val metadata: JsonField, - private val referenceId: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), - @JsonProperty("item_id") @ExcludeMissing itemId: JsonField = JsonMissing.of(), - @JsonProperty("model_type") - @ExcludeMissing - modelType: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("tiered_bps_config") - @ExcludeMissing - tieredBpsConfig: JsonField = JsonMissing.of(), - @JsonProperty("billable_metric_id") - @ExcludeMissing - billableMetricId: JsonField = JsonMissing.of(), - @JsonProperty("billed_in_advance") - @ExcludeMissing - billedInAdvance: JsonField = JsonMissing.of(), - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - billingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate") - @ExcludeMissing - conversionRate: JsonField = JsonMissing.of(), - @JsonProperty("conversion_rate_config") - @ExcludeMissing - conversionRateConfig: JsonField = JsonMissing.of(), - @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - dimensionalPriceConfiguration: JsonField = - JsonMissing.of(), - @JsonProperty("external_price_id") - @ExcludeMissing - externalPriceId: JsonField = JsonMissing.of(), - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - invoiceGroupingKey: JsonField = JsonMissing.of(), - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - invoicingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), - @JsonProperty("reference_id") - @ExcludeMissing - referenceId: JsonField = JsonMissing.of(), - ) : this( - cadence, - itemId, - modelType, - name, - tieredBpsConfig, - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - currency, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - referenceId, - mutableMapOf(), - ) - - /** - * The cadence to bill for this price on. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun cadence(): Cadence = cadence.getRequired("cadence") - - /** - * The id of the item the price will be associated with. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun itemId(): String = itemId.getRequired("item_id") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun modelType(): ModelType = modelType.getRequired("model_type") - - /** - * The name of the price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun name(): String = name.getRequired("name") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun tieredBpsConfig(): TieredBpsConfig = tieredBpsConfig.getRequired("tiered_bps_config") - - /** - * The id of the billable metric for the price. Only needed if the price is usage-based. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is true, - * and in-arrears if this is false. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - - /** - * For custom cadence: specifies the duration of the billing period in days or months. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun billingCycleConfiguration(): NewBillingCycleConfiguration? = - billingCycleConfiguration.getNullable("billing_cycle_configuration") - - /** - * The per unit conversion rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - - /** - * The configuration for the rate of the price currency to the invoicing currency. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun conversionRateConfig(): ConversionRateConfig? = - conversionRateConfig.getNullable("conversion_rate_config") - - /** - * An ISO 4217 currency string, or custom pricing unit identifier, in which this price is - * billed. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun currency(): String? = currency.getNullable("currency") - - /** - * For dimensional price: specifies a price group and dimension values - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = - dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - - /** - * An alias for the price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - - /** - * If the Price represents a fixed cost, this represents the quantity of units applied. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") - - /** - * The property used to group this price on an invoice - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoiceGroupingKey(): String? = invoiceGroupingKey.getNullable("invoice_grouping_key") - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = - invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun metadata(): Metadata? = metadata.getNullable("metadata") - - /** - * A transient ID that can be used to reference this price when adding adjustments in the same - * API call. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun referenceId(): String? = referenceId.getNullable("reference_id") - - /** - * Returns the raw JSON value of [cadence]. - * - * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence - - /** - * Returns the raw JSON value of [itemId]. - * - * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - - /** - * Returns the raw JSON value of [modelType]. - * - * Unlike [modelType], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonField = modelType - - /** - * 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 [tieredBpsConfig]. - * - * Unlike [tieredBpsConfig], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("tiered_bps_config") - @ExcludeMissing - fun _tieredBpsConfig(): JsonField = tieredBpsConfig - - /** - * Returns the raw JSON value of [billableMetricId]. - * - * Unlike [billableMetricId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("billable_metric_id") - @ExcludeMissing - fun _billableMetricId(): JsonField = billableMetricId - - /** - * Returns the raw JSON value of [billedInAdvance]. - * - * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("billed_in_advance") - @ExcludeMissing - fun _billedInAdvance(): JsonField = billedInAdvance - - /** - * Returns the raw JSON value of [billingCycleConfiguration]. - * - * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("billing_cycle_configuration") - @ExcludeMissing - fun _billingCycleConfiguration(): JsonField = - billingCycleConfiguration - - /** - * Returns the raw JSON value of [conversionRate]. - * - * Unlike [conversionRate], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("conversion_rate") - @ExcludeMissing - fun _conversionRate(): JsonField = conversionRate - - /** - * Returns the raw JSON value of [conversionRateConfig]. - * - * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("conversion_rate_config") - @ExcludeMissing - fun _conversionRateConfig(): JsonField = conversionRateConfig - - /** - * Returns the raw JSON value of [currency]. - * - * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency - - /** - * Returns the raw JSON value of [dimensionalPriceConfiguration]. - * - * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("dimensional_price_configuration") - @ExcludeMissing - fun _dimensionalPriceConfiguration(): JsonField = - dimensionalPriceConfiguration - - /** - * Returns the raw JSON value of [externalPriceId]. - * - * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("external_price_id") - @ExcludeMissing - fun _externalPriceId(): JsonField = externalPriceId - - /** - * Returns the raw JSON value of [fixedPriceQuantity]. - * - * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - - /** - * Returns the raw JSON value of [invoiceGroupingKey]. - * - * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("invoice_grouping_key") - @ExcludeMissing - fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - - /** - * Returns the raw JSON value of [invoicingCycleConfiguration]. - * - * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("invoicing_cycle_configuration") - @ExcludeMissing - fun _invoicingCycleConfiguration(): JsonField = - invoicingCycleConfiguration - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - - /** - * Returns the raw JSON value of [referenceId]. - * - * Unlike [referenceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("reference_id") - @ExcludeMissing - fun _referenceId(): JsonField = referenceId - - @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 - * [NewSubscriptionTieredBpsPrice]. - * - * The following fields are required: - * ```kotlin - * .cadence() - * .itemId() - * .modelType() - * .name() - * .tieredBpsConfig() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [NewSubscriptionTieredBpsPrice]. */ - class Builder internal constructor() { - - private var cadence: JsonField? = null - private var itemId: JsonField? = null - private var modelType: JsonField? = null - private var name: JsonField? = null - private var tieredBpsConfig: JsonField? = null - private var billableMetricId: JsonField = JsonMissing.of() - private var billedInAdvance: JsonField = JsonMissing.of() - private var billingCycleConfiguration: JsonField = - JsonMissing.of() - private var conversionRate: JsonField = JsonMissing.of() - private var conversionRateConfig: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var dimensionalPriceConfiguration: JsonField = - JsonMissing.of() - private var externalPriceId: JsonField = JsonMissing.of() - private var fixedPriceQuantity: JsonField = JsonMissing.of() - private var invoiceGroupingKey: JsonField = JsonMissing.of() - private var invoicingCycleConfiguration: JsonField = - JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() - private var referenceId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(newSubscriptionTieredBpsPrice: NewSubscriptionTieredBpsPrice) = apply { - cadence = newSubscriptionTieredBpsPrice.cadence - itemId = newSubscriptionTieredBpsPrice.itemId - modelType = newSubscriptionTieredBpsPrice.modelType - name = newSubscriptionTieredBpsPrice.name - tieredBpsConfig = newSubscriptionTieredBpsPrice.tieredBpsConfig - billableMetricId = newSubscriptionTieredBpsPrice.billableMetricId - billedInAdvance = newSubscriptionTieredBpsPrice.billedInAdvance - billingCycleConfiguration = newSubscriptionTieredBpsPrice.billingCycleConfiguration - conversionRate = newSubscriptionTieredBpsPrice.conversionRate - conversionRateConfig = newSubscriptionTieredBpsPrice.conversionRateConfig - currency = newSubscriptionTieredBpsPrice.currency - dimensionalPriceConfiguration = - newSubscriptionTieredBpsPrice.dimensionalPriceConfiguration - externalPriceId = newSubscriptionTieredBpsPrice.externalPriceId - fixedPriceQuantity = newSubscriptionTieredBpsPrice.fixedPriceQuantity - invoiceGroupingKey = newSubscriptionTieredBpsPrice.invoiceGroupingKey - invoicingCycleConfiguration = newSubscriptionTieredBpsPrice.invoicingCycleConfiguration - metadata = newSubscriptionTieredBpsPrice.metadata - referenceId = newSubscriptionTieredBpsPrice.referenceId - additionalProperties = newSubscriptionTieredBpsPrice.additionalProperties.toMutableMap() - } - - /** The cadence to bill for this price on. */ - fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) - - /** - * Sets [Builder.cadence] to an arbitrary JSON value. - * - * You should usually call [Builder.cadence] with a well-typed [Cadence] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun cadence(cadence: JsonField) = apply { this.cadence = cadence } - - /** The id of the item the price will be associated with. */ - fun itemId(itemId: String) = itemId(JsonField.of(itemId)) - - /** - * Sets [Builder.itemId] to an arbitrary JSON value. - * - * You should usually call [Builder.itemId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun itemId(itemId: JsonField) = apply { this.itemId = itemId } - - fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) - - /** - * Sets [Builder.modelType] to an arbitrary JSON value. - * - * You should usually call [Builder.modelType] with a well-typed [ModelType] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun modelType(modelType: JsonField) = apply { this.modelType = modelType } - - /** The name of the price. */ - 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 tieredBpsConfig(tieredBpsConfig: TieredBpsConfig) = - tieredBpsConfig(JsonField.of(tieredBpsConfig)) - - /** - * Sets [Builder.tieredBpsConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.tieredBpsConfig] with a well-typed [TieredBpsConfig] - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun tieredBpsConfig(tieredBpsConfig: JsonField) = apply { - this.tieredBpsConfig = tieredBpsConfig - } - - /** The id of the billable metric for the price. Only needed if the price is usage-based. */ - fun billableMetricId(billableMetricId: String?) = - billableMetricId(JsonField.ofNullable(billableMetricId)) - - /** - * Sets [Builder.billableMetricId] to an arbitrary JSON value. - * - * You should usually call [Builder.billableMetricId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billableMetricId(billableMetricId: JsonField) = apply { - this.billableMetricId = billableMetricId - } - - /** - * If the Price represents a fixed cost, the price will be billed in-advance if this is - * true, and in-arrears if this is false. - */ - fun billedInAdvance(billedInAdvance: Boolean?) = - billedInAdvance(JsonField.ofNullable(billedInAdvance)) - - /** - * Alias for [Builder.billedInAdvance]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun billedInAdvance(billedInAdvance: Boolean) = billedInAdvance(billedInAdvance as Boolean?) - - /** - * Sets [Builder.billedInAdvance] to an arbitrary JSON value. - * - * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun billedInAdvance(billedInAdvance: JsonField) = apply { - this.billedInAdvance = billedInAdvance - } - - /** For custom cadence: specifies the duration of the billing period in days or months. */ - fun billingCycleConfiguration(billingCycleConfiguration: NewBillingCycleConfiguration?) = - billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) - - /** - * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.billingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun billingCycleConfiguration( - billingCycleConfiguration: JsonField - ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } - - /** The per unit conversion rate of the price currency to the invoicing currency. */ - fun conversionRate(conversionRate: Double?) = - conversionRate(JsonField.ofNullable(conversionRate)) - - /** - * Alias for [Builder.conversionRate]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun conversionRate(conversionRate: Double) = conversionRate(conversionRate as Double?) - - /** - * Sets [Builder.conversionRate] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRate] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun conversionRate(conversionRate: JsonField) = apply { - this.conversionRate = conversionRate - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = - conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) - - /** - * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.conversionRateConfig] with a well-typed - * [ConversionRateConfig] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun conversionRateConfig(conversionRateConfig: JsonField) = apply { - this.conversionRateConfig = conversionRateConfig - } - - /** Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofUnit(unit)`. */ - fun conversionRateConfig(unit: UnitConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofUnit(unit)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * UnitConversionRateConfig.builder() - * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - * .unitConfig(unitConfig) - * .build() - * ``` - */ - fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = - conversionRateConfig( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig(unitConfig) - .build() - ) - - /** - * Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofTiered(tiered)`. - */ - fun conversionRateConfig(tiered: TieredConversionRateConfig) = - conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) - - /** - * Alias for calling [conversionRateConfig] with the following: - * ```kotlin - * TieredConversionRateConfig.builder() - * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - * .tieredConfig(tieredConfig) - * .build() - * ``` - */ - fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = - conversionRateConfig( - TieredConversionRateConfig.builder() - .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) - .tieredConfig(tieredConfig) - .build() - ) - - /** - * An ISO 4217 currency string, or custom pricing unit identifier, in which this price is - * billed. - */ - fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) - - /** - * Sets [Builder.currency] to an arbitrary JSON value. - * - * You should usually call [Builder.currency] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun currency(currency: JsonField) = apply { this.currency = currency } - - /** For dimensional price: specifies a price group and dimension values */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? - ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) - - /** - * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed - * [NewDimensionalPriceConfiguration] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. - */ - fun dimensionalPriceConfiguration( - dimensionalPriceConfiguration: JsonField - ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } - - /** An alias for the price. */ - fun externalPriceId(externalPriceId: String?) = - externalPriceId(JsonField.ofNullable(externalPriceId)) - - /** - * Sets [Builder.externalPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.externalPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun externalPriceId(externalPriceId: JsonField) = apply { - this.externalPriceId = externalPriceId - } - - /** If the Price represents a fixed cost, this represents the quantity of units applied. */ - fun fixedPriceQuantity(fixedPriceQuantity: Double?) = - fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) - - /** - * Alias for [Builder.fixedPriceQuantity]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun fixedPriceQuantity(fixedPriceQuantity: Double) = - fixedPriceQuantity(fixedPriceQuantity as Double?) - - /** - * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. - * - * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { - this.fixedPriceQuantity = fixedPriceQuantity - } - - /** The property used to group this price on an invoice */ - fun invoiceGroupingKey(invoiceGroupingKey: String?) = - invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) - - /** - * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. - * - * You should usually call [Builder.invoiceGroupingKey] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { - this.invoiceGroupingKey = invoiceGroupingKey - } - - /** - * Within each billing cycle, specifies the cadence at which invoices are produced. If - * unspecified, a single invoice is produced per billing cycle. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: NewBillingCycleConfiguration? - ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) - - /** - * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. - * - * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed - * [NewBillingCycleConfiguration] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun invoicingCycleConfiguration( - invoicingCycleConfiguration: JsonField - ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by - * setting the value to `null`, and the entire metadata mapping can be cleared by setting - * `metadata` to `null`. - */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - /** - * A transient ID that can be used to reference this price when adding adjustments in the - * same API call. - */ - fun referenceId(referenceId: String?) = referenceId(JsonField.ofNullable(referenceId)) - - /** - * Sets [Builder.referenceId] to an arbitrary JSON value. - * - * You should usually call [Builder.referenceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun referenceId(referenceId: JsonField) = apply { this.referenceId = referenceId } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [NewSubscriptionTieredBpsPrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .cadence() - * .itemId() - * .modelType() - * .name() - * .tieredBpsConfig() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): NewSubscriptionTieredBpsPrice = - NewSubscriptionTieredBpsPrice( - checkRequired("cadence", cadence), - checkRequired("itemId", itemId), - checkRequired("modelType", modelType), - checkRequired("name", name), - checkRequired("tieredBpsConfig", tieredBpsConfig), - billableMetricId, - billedInAdvance, - billingCycleConfiguration, - conversionRate, - conversionRateConfig, - currency, - dimensionalPriceConfiguration, - externalPriceId, - fixedPriceQuantity, - invoiceGroupingKey, - invoicingCycleConfiguration, - metadata, - referenceId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): NewSubscriptionTieredBpsPrice = apply { - if (validated) { - return@apply - } - - cadence().validate() - itemId() - modelType().validate() - name() - tieredBpsConfig().validate() - billableMetricId() - billedInAdvance() - billingCycleConfiguration()?.validate() - conversionRate() - conversionRateConfig()?.validate() - currency() - dimensionalPriceConfiguration()?.validate() - externalPriceId() - fixedPriceQuantity() - invoiceGroupingKey() - invoicingCycleConfiguration()?.validate() - metadata()?.validate() - referenceId() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (cadence.asKnown()?.validity() ?: 0) + - (if (itemId.asKnown() == null) 0 else 1) + - (modelType.asKnown()?.validity() ?: 0) + - (if (name.asKnown() == null) 0 else 1) + - (tieredBpsConfig.asKnown()?.validity() ?: 0) + - (if (billableMetricId.asKnown() == null) 0 else 1) + - (if (billedInAdvance.asKnown() == null) 0 else 1) + - (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (if (conversionRate.asKnown() == null) 0 else 1) + - (conversionRateConfig.asKnown()?.validity() ?: 0) + - (if (currency.asKnown() == null) 0 else 1) + - (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + - (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + - (metadata.asKnown()?.validity() ?: 0) + - (if (referenceId.asKnown() == null) 0 else 1) - - /** The cadence to bill for this price on. */ - class Cadence @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 { - - val ANNUAL = of("annual") - - val SEMI_ANNUAL = of("semi_annual") - - val MONTHLY = of("monthly") - - val QUARTERLY = of("quarterly") - - val ONE_TIME = of("one_time") - - val CUSTOM = of("custom") - - fun of(value: String) = Cadence(JsonField.of(value)) - } - - /** An enum containing [Cadence]'s known values. */ - enum class Known { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - } - - /** - * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Cadence] 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 { - ANNUAL, - SEMI_ANNUAL, - MONTHLY, - QUARTERLY, - ONE_TIME, - CUSTOM, - /** An enum member indicating that [Cadence] 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) { - ANNUAL -> Value.ANNUAL - SEMI_ANNUAL -> Value.SEMI_ANNUAL - MONTHLY -> Value.MONTHLY - QUARTERLY -> Value.QUARTERLY - ONE_TIME -> Value.ONE_TIME - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - ANNUAL -> Known.ANNUAL - SEMI_ANNUAL -> Known.SEMI_ANNUAL - MONTHLY -> Known.MONTHLY - QUARTERLY -> Known.QUARTERLY - ONE_TIME -> Known.ONE_TIME - CUSTOM -> Known.CUSTOM - else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): Cadence = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class ModelType @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 { - - val TIERED_BPS = of("tiered_bps") - - fun of(value: String) = ModelType(JsonField.of(value)) - } - - /** An enum containing [ModelType]'s known values. */ - enum class Known { - TIERED_BPS - } - - /** - * An enum containing [ModelType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [ModelType] 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 { - TIERED_BPS, - /** - * An enum member indicating that [ModelType] 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) { - TIERED_BPS -> Value.TIERED_BPS - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - TIERED_BPS -> Known.TIERED_BPS - else -> throw OrbInvalidDataException("Unknown ModelType: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): ModelType = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - */ - class Metadata - @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 [Metadata]. */ - fun builder() = Builder() - } - - /** A builder for [Metadata]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.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 [Metadata]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): Metadata = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is NewSubscriptionTieredBpsPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredBpsConfig == other.tieredBpsConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, tieredBpsConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "NewSubscriptionTieredBpsPrice{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, tieredBpsConfig=$tieredBpsConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredPackagePrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredPackagePrice.kt index b5c4640cc..471edb763 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredPackagePrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredPackagePrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionTieredPackagePrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +128,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +144,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for tiered_package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -536,6 +532,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -558,6 +555,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for tiered_package pricing */ fun tieredPackageConfig(tieredPackageConfig: TieredPackageConfig) = tieredPackageConfig(JsonField.of(tieredPackageConfig)) @@ -1102,7 +1100,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1110,6 +1108,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1222,7 +1221,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1230,34 +1229,142 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for tiered_package pricing */ class TieredPackageConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(packageSize, tiers, mutableMapOf()) + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. The tier bounds are defined based on the total + * quantity rather than the number of packages, so they must be multiples of the package + * size. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) companion object { - /** Returns a mutable builder for constructing an instance of [TieredPackageConfig]. */ + /** + * Returns a mutable builder for constructing an instance of [TieredPackageConfig]. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` + */ fun builder() = Builder() } /** A builder for [TieredPackageConfig]. */ class Builder internal constructor() { + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(tieredPackageConfig: TieredPackageConfig) = apply { + packageSize = tieredPackageConfig.packageSize + tiers = tieredPackageConfig.tiers.map { it.toMutableList() } additionalProperties = tieredPackageConfig.additionalProperties.toMutableMap() } + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. The tier bounds are defined based on the total + * quantity rather than the number of packages, so they must be multiples of the package + * size. + */ + 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) @@ -1281,9 +1388,21 @@ private constructor( * Returns an immutable instance of [TieredPackageConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): TieredPackageConfig = - TieredPackageConfig(additionalProperties.toImmutable()) + TieredPackageConfig( + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1293,6 +1412,8 @@ private constructor( return@apply } + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -1311,192 +1432,240 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier with business logic */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val perUnit: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("per_unit") + @ExcludeMissing + perUnit: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(perUnit, tierLowerBound, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnit(): String = perUnit.getRequired("per_unit") - return /* spotless:off */ other is TieredPackageConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Returns the raw JSON value of [perUnit]. + * + * Unlike [perUnit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("per_unit") @ExcludeMissing fun _perUnit(): JsonField = perUnit - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound - override fun toString() = "TieredPackageConfig{additionalProperties=$additionalProperties}" - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + @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: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + */ + fun builder() = Builder() + } - fun unit(): UnitConversionRateConfig? = unit + /** A builder for [Tier]. */ + class Builder internal constructor() { - fun tiered(): TieredConversionRateConfig? = tiered + private var perUnit: JsonField? = null + private var tierLowerBound: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun isUnit(): Boolean = unit != null + internal fun from(tier: Tier) = apply { + perUnit = tier.perUnit + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } - fun isTiered(): Boolean = tiered != null + /** Price per package */ + fun perUnit(perUnit: String) = perUnit(JsonField.of(perUnit)) + + /** + * Sets [Builder.perUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnit] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun perUnit(perUnit: JsonField) = apply { this.perUnit = perUnit } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun _json(): JsonValue? = _json + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - private var validated: Boolean = false + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Returns an immutable instance of [Tier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("perUnit", perUnit), + checkRequired("tierLowerBound", tierLowerBound), + additionalProperties.toMutableMap(), + ) } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } + private var validated: Boolean = false - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun validate(): Tier = apply { + if (validated) { + return@apply } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + perUnit() + tierLowerBound() + validated = true } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (perUnit.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) - override fun unknown(json: JsonValue?) = 0 + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + return other is Tier && + perUnit == other.perUnit && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + private val hashCode: Int by lazy { + Objects.hash(perUnit, tierLowerBound, additionalProperties) } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + override fun hashCode(): Int = hashCode - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) + override fun toString() = + "Tier{perUnit=$perUnit, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + return other is TieredPackageConfig && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + private val hashCode: Int by lazy { Objects.hash(packageSize, tiers, additionalProperties) } - return ConversionRateConfig(_json = json) - } - } + override fun hashCode(): Int = hashCode - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } + override fun toString() = + "TieredPackageConfig{packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } /** @@ -1591,12 +1760,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1608,12 +1775,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionTieredPackagePrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredPackageConfig == other.tieredPackageConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionTieredPackagePrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredPackageConfig == other.tieredPackageConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, tieredPackageConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredPackageConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredPackageWithMinimumPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredPackageWithMinimumPrice.kt index 45e1564bb..304afa795 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredPackageWithMinimumPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredPackageWithMinimumPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionTieredPackageWithMinimumPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -137,6 +129,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -151,6 +145,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for tiered_package_with_minimum pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -542,6 +538,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -564,6 +561,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for tiered_package_with_minimum pricing */ fun tieredPackageWithMinimumConfig( tieredPackageWithMinimumConfig: TieredPackageWithMinimumConfig ) = tieredPackageWithMinimumConfig(JsonField.of(tieredPackageWithMinimumConfig)) @@ -1109,7 +1107,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1117,6 +1115,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1229,7 +1228,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1237,16 +1236,65 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for tiered_package_with_minimum pricing */ class TieredPackageWithMinimumConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + ) : this(packageSize, tiers, mutableMapOf()) + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageSize(): Double = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1255,6 +1303,12 @@ private constructor( /** * Returns a mutable builder for constructing an instance of * [TieredPackageWithMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1262,14 +1316,61 @@ private constructor( /** A builder for [TieredPackageWithMinimumConfig]. */ class Builder internal constructor() { + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(tieredPackageWithMinimumConfig: TieredPackageWithMinimumConfig) = apply { + packageSize = tieredPackageWithMinimumConfig.packageSize + tiers = tieredPackageWithMinimumConfig.tiers.map { it.toMutableList() } additionalProperties = tieredPackageWithMinimumConfig.additionalProperties.toMutableMap() } + /** Package size */ + fun packageSize(packageSize: Double) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + */ + 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) @@ -1293,9 +1394,21 @@ private constructor( * Returns an immutable instance of [TieredPackageWithMinimumConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): TieredPackageWithMinimumConfig = - TieredPackageWithMinimumConfig(additionalProperties.toImmutable()) + TieredPackageWithMinimumConfig( + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1305,6 +1418,8 @@ private constructor( return@apply } + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -1323,193 +1438,286 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val minimumAmount: JsonField, + private val perUnit: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("per_unit") + @ExcludeMissing + perUnit: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(minimumAmount, perUnit, tierLowerBound, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TieredPackageWithMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Minimum amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun minimumAmount(): String = minimumAmount.getRequired("minimum_amount") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnit(): String = perUnit.getRequired("per_unit") - override fun hashCode(): Int = hashCode + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - override fun toString() = - "TieredPackageWithMinimumConfig{additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + /** + * Returns the raw JSON value of [perUnit]. + * + * Unlike [perUnit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("per_unit") @ExcludeMissing fun _perUnit(): JsonField = perUnit - fun unit(): UnitConversionRateConfig? = unit + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun isUnit(): Boolean = unit != null + @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: + * ```kotlin + * .minimumAmount() + * .perUnit() + * .tierLowerBound() + * ``` + */ + fun builder() = Builder() + } - fun isTiered(): Boolean = tiered != null + /** A builder for [Tier]. */ + class Builder internal constructor() { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + private var minimumAmount: JsonField? = null + private var perUnit: JsonField? = null + private var tierLowerBound: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + internal fun from(tier: Tier) = apply { + minimumAmount = tier.minimumAmount + perUnit = tier.perUnit + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } - fun _json(): JsonValue? = _json + /** Minimum amount */ + fun minimumAmount(minimumAmount: String) = + minimumAmount(JsonField.of(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + /** Price per package */ + fun perUnit(perUnit: String) = perUnit(JsonField.of(perUnit)) + + /** + * Sets [Builder.perUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnit] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun perUnit(perUnit: JsonField) = apply { this.perUnit = perUnit } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 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 [Tier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * .perUnit() + * .tierLowerBound() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("minimumAmount", minimumAmount), + checkRequired("perUnit", perUnit), + checkRequired("tierLowerBound", tierLowerBound), + additionalProperties.toMutableMap(), + ) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + private var validated: Boolean = false - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun validate(): Tier = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + minimumAmount() + perUnit() + tierLowerBound() + validated = true } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } + internal fun validity(): Int = + (if (minimumAmount.asKnown() == null) 0 else 1) + + (if (perUnit.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + return other is Tier && + minimumAmount == other.minimumAmount && + perUnit == other.perUnit && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + private val hashCode: Int by lazy { + Objects.hash(minimumAmount, perUnit, tierLowerBound, additionalProperties) + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + override fun hashCode(): Int = hashCode - return ConversionRateConfig(_json = json) - } + override fun toString() = + "Tier{minimumAmount=$minimumAmount, perUnit=$perUnit, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is TieredPackageWithMinimumConfig && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties } + + private val hashCode: Int by lazy { Objects.hash(packageSize, tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredPackageWithMinimumConfig{packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } /** @@ -1604,12 +1812,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1621,12 +1827,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionTieredPackageWithMinimumPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredPackageWithMinimumConfig == other.tieredPackageWithMinimumConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionTieredPackageWithMinimumPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredPackageWithMinimumConfig == other.tieredPackageWithMinimumConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, tieredPackageWithMinimumConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredPackageWithMinimumConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredPrice.kt index 414480efc..aad8a711d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionTieredPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +143,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for tiered pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -528,6 +523,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -550,6 +546,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for tiered pricing */ fun tieredConfig(tieredConfig: TieredConfig) = tieredConfig(JsonField.of(tieredConfig)) /** @@ -1093,7 +1090,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1101,6 +1098,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1213,7 +1211,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1221,175 +1219,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1482,12 +1311,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1499,12 +1326,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionTieredPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredConfig == other.tieredConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionTieredPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredConfig == other.tieredConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, tieredConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredWithMinimumPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredWithMinimumPrice.kt index 702371998..2067c6d3f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredWithMinimumPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionTieredWithMinimumPrice.kt @@ -6,28 +6,20 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionTieredWithMinimumPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +128,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +144,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for tiered_with_minimum pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -537,6 +533,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -559,6 +556,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for tiered_with_minimum pricing */ fun tieredWithMinimumConfig(tieredWithMinimumConfig: TieredWithMinimumConfig) = tieredWithMinimumConfig(JsonField.of(tieredWithMinimumConfig)) @@ -1104,7 +1102,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1112,6 +1110,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1224,7 +1223,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1232,16 +1231,84 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for tiered_with_minimum pricing */ class TieredWithMinimumConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val tiers: JsonField>, + private val hideZeroAmountTiers: JsonField, + private val prorate: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + @JsonProperty("hide_zero_amount_tiers") + @ExcludeMissing + hideZeroAmountTiers: JsonField = JsonMissing.of(), + @JsonProperty("prorate") @ExcludeMissing prorate: JsonField = JsonMissing.of(), + ) : this(tiers, hideZeroAmountTiers, prorate, mutableMapOf()) + + /** + * Tiered pricing with a minimum amount dependent on the volume tier. Tiers are defined + * using exclusive lower bounds. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * If true, tiers with an accrued amount of 0 will not be included in the rating. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun hideZeroAmountTiers(): Boolean? = + hideZeroAmountTiers.getNullable("hide_zero_amount_tiers") + + /** + * If true, the unit price will be prorated to the billing period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorate(): Boolean? = prorate.getNullable("prorate") + + /** + * 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 + + /** + * Returns the raw JSON value of [hideZeroAmountTiers]. + * + * Unlike [hideZeroAmountTiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("hide_zero_amount_tiers") + @ExcludeMissing + fun _hideZeroAmountTiers(): JsonField = hideZeroAmountTiers + + /** + * Returns the raw JSON value of [prorate]. + * + * Unlike [prorate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorate") @ExcludeMissing fun _prorate(): JsonField = prorate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1249,6 +1316,11 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [TieredWithMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` */ fun builder() = Builder() } @@ -1256,12 +1328,74 @@ private constructor( /** A builder for [TieredWithMinimumConfig]. */ class Builder internal constructor() { + private var tiers: JsonField>? = null + private var hideZeroAmountTiers: JsonField = JsonMissing.of() + private var prorate: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(tieredWithMinimumConfig: TieredWithMinimumConfig) = apply { + tiers = tieredWithMinimumConfig.tiers.map { it.toMutableList() } + hideZeroAmountTiers = tieredWithMinimumConfig.hideZeroAmountTiers + prorate = tieredWithMinimumConfig.prorate additionalProperties = tieredWithMinimumConfig.additionalProperties.toMutableMap() } + /** + * Tiered pricing with a minimum amount dependent on the volume tier. Tiers are defined + * using exclusive lower bounds. + */ + 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) + } + } + + /** If true, tiers with an accrued amount of 0 will not be included in the rating. */ + fun hideZeroAmountTiers(hideZeroAmountTiers: Boolean) = + hideZeroAmountTiers(JsonField.of(hideZeroAmountTiers)) + + /** + * Sets [Builder.hideZeroAmountTiers] to an arbitrary JSON value. + * + * You should usually call [Builder.hideZeroAmountTiers] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun hideZeroAmountTiers(hideZeroAmountTiers: JsonField) = apply { + this.hideZeroAmountTiers = hideZeroAmountTiers + } + + /** If true, the unit price will be prorated to the billing period */ + fun prorate(prorate: Boolean) = prorate(JsonField.of(prorate)) + + /** + * Sets [Builder.prorate] to an arbitrary JSON value. + * + * You should usually call [Builder.prorate] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prorate(prorate: JsonField) = apply { this.prorate = prorate } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1285,9 +1419,21 @@ private constructor( * Returns an immutable instance of [TieredWithMinimumConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): TieredWithMinimumConfig = - TieredWithMinimumConfig(additionalProperties.toImmutable()) + TieredWithMinimumConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + hideZeroAmountTiers, + prorate, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1297,6 +1443,9 @@ private constructor( return@apply } + tiers().forEach { it.validate() } + hideZeroAmountTiers() + prorate() validated = true } @@ -1315,193 +1464,295 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (hideZeroAmountTiers.asKnown() == null) 0 else 1) + + (if (prorate.asKnown() == null) 0 else 1) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val minimumAmount: JsonField, + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(minimumAmount, tierLowerBound, unitAmount, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Minimum amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun minimumAmount(): String = minimumAmount.getRequired("minimum_amount") - return /* spotless:off */ other is TieredWithMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount - override fun toString() = - "TieredWithMinimumConfig{additionalProperties=$additionalProperties}" - } + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount - fun unit(): UnitConversionRateConfig? = unit + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @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: + * ```kotlin + * .minimumAmount() + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - fun isUnit(): Boolean = unit != null + /** A builder for [Tier]. */ + class Builder internal constructor() { - fun isTiered(): Boolean = tiered != null + private var minimumAmount: JsonField? = null + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + internal fun from(tier: Tier) = apply { + minimumAmount = tier.minimumAmount + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** Minimum amount */ + fun minimumAmount(minimumAmount: String) = + minimumAmount(JsonField.of(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } - fun _json(): JsonValue? = _json + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - override fun unknown(json: JsonValue?) = 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 [Tier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("minimumAmount", minimumAmount), + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + private var validated: Boolean = false - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun validate(): Tier = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + minimumAmount() + tierLowerBound() + unitAmount() + validated = true } - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + internal fun validity(): Int = + (if (minimumAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + minimumAmount == other.minimumAmount && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + private val hashCode: Int by lazy { + Objects.hash(minimumAmount, tierLowerBound, unitAmount, additionalProperties) + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() + override fun hashCode(): Int = hashCode - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + override fun toString() = + "Tier{minimumAmount=$minimumAmount, tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } - return ConversionRateConfig(_json = json) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is TieredWithMinimumConfig && + tiers == other.tiers && + hideZeroAmountTiers == other.hideZeroAmountTiers && + prorate == other.prorate && + additionalProperties == other.additionalProperties } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } + private val hashCode: Int by lazy { + Objects.hash(tiers, hideZeroAmountTiers, prorate, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithMinimumConfig{tiers=$tiers, hideZeroAmountTiers=$hideZeroAmountTiers, prorate=$prorate, additionalProperties=$additionalProperties}" } /** @@ -1596,12 +1847,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1613,12 +1862,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionTieredWithMinimumPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && tieredWithMinimumConfig == other.tieredWithMinimumConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionTieredWithMinimumPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredWithMinimumConfig == other.tieredWithMinimumConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, tieredWithMinimumConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredWithMinimumConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionUnitPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionUnitPrice.kt index 840dacf40..74787c1d4 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionUnitPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionUnitPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionUnitPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +143,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for unit pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -528,6 +523,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -550,6 +546,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for unit pricing */ fun unitConfig(unitConfig: UnitConfig) = unitConfig(JsonField.of(unitConfig)) /** @@ -1091,7 +1088,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1099,6 +1096,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1211,7 +1209,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1219,175 +1217,6 @@ private constructor( override fun toString() = value.toString() } - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - /** * User-specified key/value pairs for the resource. Individual keys can be removed by setting * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to @@ -1480,12 +1309,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1497,12 +1324,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionUnitPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && unitConfig == other.unitConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionUnitPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + unitConfig == other.unitConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, unitConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + unitConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionUnitWithPercentPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionUnitWithPercentPrice.kt index 3a8818bae..7c407f78f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionUnitWithPercentPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionUnitWithPercentPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionUnitWithPercentPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +143,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for unit_with_percent pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -537,6 +532,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -559,6 +555,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for unit_with_percent pricing */ fun unitWithPercentConfig(unitWithPercentConfig: UnitWithPercentConfig) = unitWithPercentConfig(JsonField.of(unitWithPercentConfig)) @@ -1103,7 +1100,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1111,6 +1108,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1223,7 +1221,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1231,16 +1229,64 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for unit_with_percent pricing */ class UnitWithPercentConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val percent: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("percent") @ExcludeMissing percent: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(percent, unitAmount, mutableMapOf()) + + /** + * What percent, out of 100, of the calculated total to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun percent(): String = percent.getRequired("percent") + + /** + * Rate per unit of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("percent") @ExcludeMissing fun _percent(): JsonField = percent + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1248,6 +1294,12 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [UnitWithPercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * .unitAmount() + * ``` */ fun builder() = Builder() } @@ -1255,12 +1307,40 @@ private constructor( /** A builder for [UnitWithPercentConfig]. */ class Builder internal constructor() { + private var percent: JsonField? = null + private var unitAmount: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(unitWithPercentConfig: UnitWithPercentConfig) = apply { + percent = unitWithPercentConfig.percent + unitAmount = unitWithPercentConfig.unitAmount additionalProperties = unitWithPercentConfig.additionalProperties.toMutableMap() } + /** What percent, out of 100, of the calculated total to charge */ + fun percent(percent: String) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + /** Rate per unit of usage */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { this.unitAmount = unitAmount } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1284,9 +1364,21 @@ private constructor( * Returns an immutable instance of [UnitWithPercentConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): UnitWithPercentConfig = - UnitWithPercentConfig(additionalProperties.toImmutable()) + UnitWithPercentConfig( + checkRequired("percent", percent), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1296,6 +1388,8 @@ private constructor( return@apply } + percent() + unitAmount() validated = true } @@ -1314,193 +1408,27 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (percent.asKnown() == null) 0 else 1) + (if (unitAmount.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is UnitWithPercentConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UnitWithPercentConfig && + percent == other.percent && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(percent, unitAmount, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "UnitWithPercentConfig{additionalProperties=$additionalProperties}" - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } + "UnitWithPercentConfig{percent=$percent, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" } /** @@ -1595,12 +1523,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1612,12 +1538,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionUnitWithPercentPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && unitWithPercentConfig == other.unitWithPercentConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionUnitWithPercentPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + unitWithPercentConfig == other.unitWithPercentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, unitWithPercentConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + unitWithPercentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionUnitWithProrationPrice.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionUnitWithProrationPrice.kt index a2de6191f..3ef3b34ae 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionUnitWithProrationPrice.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewSubscriptionUnitWithProrationPrice.kt @@ -6,28 +6,19 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.ObjectCodec -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.annotation.JsonSerialize -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.BaseDeserializer -import com.withorb.api.core.BaseSerializer import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.checkRequired -import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects class NewSubscriptionUnitWithProrationPrice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cadence: JsonField, private val itemId: JsonField, @@ -136,6 +127,8 @@ private constructor( fun itemId(): String = itemId.getRequired("item_id") /** + * The pricing model type + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -150,6 +143,8 @@ private constructor( fun name(): String = name.getRequired("name") /** + * Configuration for unit_with_proration pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ @@ -537,6 +532,7 @@ private constructor( */ fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + /** The pricing model type */ fun modelType(modelType: ModelType) = modelType(JsonField.of(modelType)) /** @@ -559,6 +555,7 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for unit_with_proration pricing */ fun unitWithProrationConfig(unitWithProrationConfig: UnitWithProrationConfig) = unitWithProrationConfig(JsonField.of(unitWithProrationConfig)) @@ -1104,7 +1101,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -1112,6 +1109,7 @@ private constructor( override fun toString() = value.toString() } + /** The pricing model type */ class ModelType @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -1224,7 +1222,7 @@ private constructor( return true } - return /* spotless:off */ other is ModelType && value == other.value /* spotless:on */ + return other is ModelType && value == other.value } override fun hashCode() = value.hashCode() @@ -1232,16 +1230,47 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for unit_with_proration pricing */ class UnitWithProrationConfig - @JsonCreator + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of() + ) : this(unitAmount, mutableMapOf()) + + /** + * Rate per unit of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -1249,6 +1278,11 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [UnitWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .unitAmount() + * ``` */ fun builder() = Builder() } @@ -1256,12 +1290,26 @@ private constructor( /** A builder for [UnitWithProrationConfig]. */ class Builder internal constructor() { + private var unitAmount: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() internal fun from(unitWithProrationConfig: UnitWithProrationConfig) = apply { + unitAmount = unitWithProrationConfig.unitAmount additionalProperties = unitWithProrationConfig.additionalProperties.toMutableMap() } + /** Rate per unit of usage */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { this.unitAmount = unitAmount } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1285,9 +1333,19 @@ private constructor( * Returns an immutable instance of [UnitWithProrationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): UnitWithProrationConfig = - UnitWithProrationConfig(additionalProperties.toImmutable()) + UnitWithProrationConfig( + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1297,6 +1355,7 @@ private constructor( return@apply } + unitAmount() validated = true } @@ -1314,194 +1373,24 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + internal fun validity(): Int = (if (unitAmount.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is UnitWithProrationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UnitWithProrationConfig && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { Objects.hash(unitAmount, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "UnitWithProrationConfig{additionalProperties=$additionalProperties}" - } - - /** The configuration for the rate of the price currency to the invoicing currency. */ - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { - - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() - - override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ - - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - - companion object { - - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a value of - * type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the SDK - * is on an older version than the API, then the API may respond with new variants that - * the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } - - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } - - return ConversionRateConfig(_json = json) - } - } - - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } + "UnitWithProrationConfig{unitAmount=$unitAmount, additionalProperties=$additionalProperties}" } /** @@ -1596,12 +1485,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1613,12 +1500,51 @@ private constructor( return true } - return /* spotless:off */ other is NewSubscriptionUnitWithProrationPrice && cadence == other.cadence && itemId == other.itemId && modelType == other.modelType && name == other.name && unitWithProrationConfig == other.unitWithProrationConfig && billableMetricId == other.billableMetricId && billedInAdvance == other.billedInAdvance && billingCycleConfiguration == other.billingCycleConfiguration && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && currency == other.currency && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoiceGroupingKey == other.invoiceGroupingKey && invoicingCycleConfiguration == other.invoicingCycleConfiguration && metadata == other.metadata && referenceId == other.referenceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewSubscriptionUnitWithProrationPrice && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + unitWithProrationConfig == other.unitWithProrationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cadence, itemId, modelType, name, unitWithProrationConfig, billableMetricId, billedInAdvance, billingCycleConfiguration, conversionRate, conversionRateConfig, currency, dimensionalPriceConfiguration, externalPriceId, fixedPriceQuantity, invoiceGroupingKey, invoicingCycleConfiguration, metadata, referenceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + unitWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewTaxJarConfiguration.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewTaxJarConfiguration.kt index 9dfceac00..ca782cabd 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewTaxJarConfiguration.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewTaxJarConfiguration.kt @@ -17,9 +17,11 @@ import java.util.Collections import java.util.Objects class NewTaxJarConfiguration +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val taxExempt: JsonField, private val taxProvider: JsonField, + private val automaticTaxEnabled: JsonField, private val additionalProperties: MutableMap, ) { @@ -31,7 +33,10 @@ private constructor( @JsonProperty("tax_provider") @ExcludeMissing taxProvider: JsonField = JsonMissing.of(), - ) : this(taxExempt, taxProvider, mutableMapOf()) + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + automaticTaxEnabled: JsonField = JsonMissing.of(), + ) : this(taxExempt, taxProvider, automaticTaxEnabled, mutableMapOf()) /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -45,6 +50,15 @@ private constructor( */ fun taxProvider(): TaxProvider = taxProvider.getRequired("tax_provider") + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun automaticTaxEnabled(): Boolean? = automaticTaxEnabled.getNullable("automatic_tax_enabled") + /** * Returns the raw JSON value of [taxExempt]. * @@ -61,6 +75,16 @@ private constructor( @ExcludeMissing fun _taxProvider(): JsonField = taxProvider + /** + * Returns the raw JSON value of [automaticTaxEnabled]. + * + * Unlike [automaticTaxEnabled], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("automatic_tax_enabled") + @ExcludeMissing + fun _automaticTaxEnabled(): JsonField = automaticTaxEnabled + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -92,11 +116,13 @@ private constructor( private var taxExempt: JsonField? = null private var taxProvider: JsonField? = null + private var automaticTaxEnabled: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(newTaxJarConfiguration: NewTaxJarConfiguration) = apply { taxExempt = newTaxJarConfiguration.taxExempt taxProvider = newTaxJarConfiguration.taxProvider + automaticTaxEnabled = newTaxJarConfiguration.automaticTaxEnabled additionalProperties = newTaxJarConfiguration.additionalProperties.toMutableMap() } @@ -124,6 +150,32 @@ private constructor( this.taxProvider = taxProvider } + /** + * Whether to automatically calculate tax for this customer. When null, inherits from + * account-level setting. When true or false, overrides the account setting. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean?) = + automaticTaxEnabled(JsonField.ofNullable(automaticTaxEnabled)) + + /** + * Alias for [Builder.automaticTaxEnabled]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun automaticTaxEnabled(automaticTaxEnabled: Boolean) = + automaticTaxEnabled(automaticTaxEnabled as Boolean?) + + /** + * Sets [Builder.automaticTaxEnabled] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticTaxEnabled] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun automaticTaxEnabled(automaticTaxEnabled: JsonField) = apply { + this.automaticTaxEnabled = automaticTaxEnabled + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -160,6 +212,7 @@ private constructor( NewTaxJarConfiguration( checkRequired("taxExempt", taxExempt), checkRequired("taxProvider", taxProvider), + automaticTaxEnabled, additionalProperties.toMutableMap(), ) } @@ -173,6 +226,7 @@ private constructor( taxExempt() taxProvider().validate() + automaticTaxEnabled() validated = true } @@ -190,7 +244,9 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - (if (taxExempt.asKnown() == null) 0 else 1) + (taxProvider.asKnown()?.validity() ?: 0) + (if (taxExempt.asKnown() == null) 0 else 1) + + (taxProvider.asKnown()?.validity() ?: 0) + + (if (automaticTaxEnabled.asKnown() == null) 0 else 1) class TaxProvider @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -305,7 +361,7 @@ private constructor( return true } - return /* spotless:off */ other is TaxProvider && value == other.value /* spotless:on */ + return other is TaxProvider && value == other.value } override fun hashCode() = value.hashCode() @@ -318,15 +374,19 @@ private constructor( return true } - return /* spotless:off */ other is NewTaxJarConfiguration && taxExempt == other.taxExempt && taxProvider == other.taxProvider && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewTaxJarConfiguration && + taxExempt == other.taxExempt && + taxProvider == other.taxProvider && + automaticTaxEnabled == other.automaticTaxEnabled && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(taxExempt, taxProvider, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(taxExempt, taxProvider, automaticTaxEnabled, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "NewTaxJarConfiguration{taxExempt=$taxExempt, taxProvider=$taxProvider, additionalProperties=$additionalProperties}" + "NewTaxJarConfiguration{taxExempt=$taxExempt, taxProvider=$taxProvider, automaticTaxEnabled=$automaticTaxEnabled, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewUsageDiscount.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewUsageDiscount.kt index 9e4cc672f..0d01c188f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewUsageDiscount.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/NewUsageDiscount.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class NewUsageDiscount +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val adjustmentType: JsonField, private val usageDiscount: JsonField, @@ -26,7 +27,7 @@ private constructor( private val appliesToItemIds: JsonField>, private val appliesToPriceIds: JsonField>, private val currency: JsonField, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val priceType: JsonField, private val additionalProperties: MutableMap, @@ -52,7 +53,7 @@ private constructor( @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -122,7 +123,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). */ - fun filters(): List? = filters.getNullable("filters") + fun filters(): List? = filters.getNullable("filters") /** * When false, this adjustment will be applied to a single price. Otherwise, it will be applied @@ -200,9 +201,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -255,7 +254,7 @@ private constructor( private var appliesToItemIds: JsonField>? = null private var appliesToPriceIds: JsonField>? = null private var currency: JsonField = JsonMissing.of() - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField = JsonMissing.of() private var priceType: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -381,25 +380,25 @@ private constructor( fun currency(currency: JsonField) = apply { this.currency = currency } /** A list of filters that determine which prices this adjustment will apply to. */ - fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -639,7 +638,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -758,7 +757,7 @@ private constructor( return true } - return /* spotless:off */ other is AppliesToAll && value == other.value /* spotless:on */ + return other is AppliesToAll && value == other.value } override fun hashCode() = value.hashCode() @@ -766,6 +765,534 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + /** If set, only prices of the specified type will have the adjustment applied. */ class PriceType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -903,7 +1430,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -916,12 +1443,33 @@ private constructor( return true } - return /* spotless:off */ other is NewUsageDiscount && adjustmentType == other.adjustmentType && usageDiscount == other.usageDiscount && appliesToAll == other.appliesToAll && appliesToItemIds == other.appliesToItemIds && appliesToPriceIds == other.appliesToPriceIds && currency == other.currency && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && priceType == other.priceType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is NewUsageDiscount && + adjustmentType == other.adjustmentType && + usageDiscount == other.usageDiscount && + appliesToAll == other.appliesToAll && + appliesToItemIds == other.appliesToItemIds && + appliesToPriceIds == other.appliesToPriceIds && + currency == other.currency && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + priceType == other.priceType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustmentType, usageDiscount, appliesToAll, appliesToItemIds, appliesToPriceIds, currency, filters, isInvoiceLevel, priceType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + adjustmentType, + usageDiscount, + appliesToAll, + appliesToItemIds, + appliesToPriceIds, + currency, + filters, + isInvoiceLevel, + priceType, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/OtherSubLineItem.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/OtherSubLineItem.kt index 250397b06..fe8a7b58f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/OtherSubLineItem.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/OtherSubLineItem.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class OtherSubLineItem +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val grouping: JsonField, @@ -397,7 +398,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -410,12 +411,18 @@ private constructor( return true } - return /* spotless:off */ other is OtherSubLineItem && amount == other.amount && grouping == other.grouping && name == other.name && quantity == other.quantity && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is OtherSubLineItem && + amount == other.amount && + grouping == other.grouping && + name == other.name && + quantity == other.quantity && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, grouping, name, quantity, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(amount, grouping, name, quantity, type, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PackageConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PackageConfig.kt index 057b6f074..abcf97778 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PackageConfig.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PackageConfig.kt @@ -15,7 +15,9 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects +/** Configuration for package pricing */ class PackageConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val packageAmount: JsonField, private val packageSize: JsonField, @@ -207,12 +209,15 @@ private constructor( return true } - return /* spotless:off */ other is PackageConfig && packageAmount == other.packageAmount && packageSize == other.packageSize && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PackageConfig && + packageAmount == other.packageAmount && + packageSize == other.packageSize && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(packageAmount, packageSize, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(packageAmount, packageSize, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PaginationMetadata.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PaginationMetadata.kt index 5f538e0f6..19445fdb2 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PaginationMetadata.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PaginationMetadata.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class PaginationMetadata +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val hasMore: JsonField, private val nextCursor: JsonField, @@ -189,12 +190,13 @@ private constructor( return true } - return /* spotless:off */ other is PaginationMetadata && hasMore == other.hasMore && nextCursor == other.nextCursor && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PaginationMetadata && + hasMore == other.hasMore && + nextCursor == other.nextCursor && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(hasMore, nextCursor, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PerPriceCost.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PerPriceCost.kt index dcaf60afa..bb91d35d3 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PerPriceCost.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PerPriceCost.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class PerPriceCost +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val price: JsonField, private val priceId: JsonField, @@ -168,28 +169,23 @@ private constructor( fun price(price: JsonField) = apply { this.price = price } /** Alias for calling [price] with `Price.ofUnit(unit)`. */ - fun price(unit: Price.Unit) = price(Price.ofUnit(unit)) - - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: Price.Package) = price(Price.ofPackage(package_)) - - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: Price.Matrix) = price(Price.ofMatrix(matrix)) + fun price(unit: Price.UnitPrice) = price(Price.ofUnit(unit)) /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ fun price(tiered: Price.Tiered) = price(Price.ofTiered(tiered)) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: Price.TieredBps) = price(Price.ofTieredBps(tieredBps)) + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: Price.Bulk) = price(Price.ofBulk(bulk)) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: Price.Bps) = price(Price.ofBps(bps)) + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: Price.BulkBps) = price(Price.ofBulkBps(bulkBps)) + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: Price.Package) = price(Price.ofPackage(package_)) - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: Price.Bulk) = price(Price.ofBulk(bulk)) + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: Price.Matrix) = price(Price.ofMatrix(matrix)) /** Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. */ fun price(thresholdTotalAmount: Price.ThresholdTotalAmount) = @@ -198,13 +194,13 @@ private constructor( /** Alias for calling [price] with `Price.ofTieredPackage(tieredPackage)`. */ fun price(tieredPackage: Price.TieredPackage) = price(Price.ofTieredPackage(tieredPackage)) - /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: Price.GroupedTiered) = price(Price.ofGroupedTiered(groupedTiered)) - /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ fun price(tieredWithMinimum: Price.TieredWithMinimum) = price(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: Price.GroupedTiered) = price(Price.ofGroupedTiered(groupedTiered)) + /** * Alias for calling [price] with * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. @@ -238,6 +234,10 @@ private constructor( fun price(groupedAllocation: Price.GroupedAllocation) = price(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: Price.BulkWithProration) = + price(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [price] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -252,16 +252,19 @@ private constructor( fun price(groupedWithMeteredMinimum: Price.GroupedWithMeteredMinimum) = price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** * Alias for calling [price] with `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. */ fun price(matrixWithDisplayName: Price.MatrixWithDisplayName) = price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: Price.BulkWithProration) = - price(Price.ofBulkWithProration(bulkWithProration)) - /** Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. */ fun price(groupedTieredPackage: Price.GroupedTieredPackage) = price(Price.ofGroupedTieredPackage(groupedTieredPackage)) @@ -294,10 +297,19 @@ private constructor( /** * Alias for calling [price] with - * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. */ - fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = - price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: Price.Minimum) = price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) /** The price the cost is associated with */ fun priceId(priceId: String) = priceId(JsonField.of(priceId)) @@ -435,12 +447,18 @@ private constructor( return true } - return /* spotless:off */ other is PerPriceCost && price == other.price && priceId == other.priceId && subtotal == other.subtotal && total == other.total && quantity == other.quantity && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PerPriceCost && + price == other.price && + priceId == other.priceId && + subtotal == other.subtotal && + total == other.total && + quantity == other.quantity && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(price, priceId, subtotal, total, quantity, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(price, priceId, subtotal, total, quantity, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PercentageDiscount.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PercentageDiscount.kt index b3814b637..89aab9b6c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PercentageDiscount.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PercentageDiscount.kt @@ -19,11 +19,12 @@ import java.util.Collections import java.util.Objects class PercentageDiscount +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val discountType: JsonField, private val percentageDiscount: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val reason: JsonField, private val additionalProperties: MutableMap, ) { @@ -41,7 +42,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("reason") @ExcludeMissing reason: JsonField = JsonMissing.of(), ) : this(discountType, percentageDiscount, appliesToPriceIds, filters, reason, mutableMapOf()) @@ -74,7 +75,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). */ - fun filters(): List? = filters.getNullable("filters") + fun filters(): List? = filters.getNullable("filters") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server @@ -116,9 +117,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [reason]. @@ -159,7 +158,7 @@ private constructor( private var discountType: JsonField? = null private var percentageDiscount: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var reason: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -231,25 +230,25 @@ private constructor( } /** The filters that determine which prices to apply this discount to. */ - fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -457,7 +456,7 @@ private constructor( return true } - return /* spotless:off */ other is DiscountType && value == other.value /* spotless:on */ + return other is DiscountType && value == other.value } override fun hashCode() = value.hashCode() @@ -465,17 +464,558 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PercentageDiscount && discountType == other.discountType && percentageDiscount == other.percentageDiscount && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && reason == other.reason && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PercentageDiscount && + discountType == other.discountType && + percentageDiscount == other.percentageDiscount && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + reason == other.reason && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(discountType, percentageDiscount, appliesToPriceIds, filters, reason, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + discountType, + percentageDiscount, + appliesToPriceIds, + filters, + reason, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PercentageDiscountInterval.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PercentageDiscountInterval.kt index 4e2da7a8d..4a488d7a0 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PercentageDiscountInterval.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PercentageDiscountInterval.kt @@ -20,11 +20,12 @@ import java.util.Collections import java.util.Objects class PercentageDiscountInterval +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val appliesToPriceIntervalIds: JsonField>, private val discountType: JsonField, private val endDate: JsonField, - private val filters: JsonField>, + private val filters: JsonField>, private val percentageDiscount: JsonField, private val startDate: JsonField, private val additionalProperties: MutableMap, @@ -43,7 +44,7 @@ private constructor( endDate: JsonField = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("percentage_discount") @ExcludeMissing percentageDiscount: JsonField = JsonMissing.of(), @@ -89,7 +90,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** * Only available if discount_type is `percentage`.This is a number between 0 and 1. @@ -138,9 +139,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [percentageDiscount]. @@ -197,7 +196,7 @@ private constructor( private var appliesToPriceIntervalIds: JsonField>? = null private var discountType: JsonField? = null private var endDate: JsonField? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var percentageDiscount: JsonField? = null private var startDate: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -266,25 +265,25 @@ private constructor( fun endDate(endDate: JsonField) = apply { this.endDate = endDate } /** The filters that determine which prices this discount interval applies to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -518,7 +517,7 @@ private constructor( return true } - return /* spotless:off */ other is DiscountType && value == other.value /* spotless:on */ + return other is DiscountType && value == other.value } override fun hashCode() = value.hashCode() @@ -526,17 +525,560 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PercentageDiscountInterval && appliesToPriceIntervalIds == other.appliesToPriceIntervalIds && discountType == other.discountType && endDate == other.endDate && filters == other.filters && percentageDiscount == other.percentageDiscount && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PercentageDiscountInterval && + appliesToPriceIntervalIds == other.appliesToPriceIntervalIds && + discountType == other.discountType && + endDate == other.endDate && + filters == other.filters && + percentageDiscount == other.percentageDiscount && + startDate == other.startDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(appliesToPriceIntervalIds, discountType, endDate, filters, percentageDiscount, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + appliesToPriceIntervalIds, + discountType, + endDate, + filters, + percentageDiscount, + startDate, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Plan.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Plan.kt index b927fa4ca..84130f377 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Plan.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Plan.kt @@ -35,6 +35,7 @@ import java.util.Objects * configure prices in the [Price resource](/reference/price). */ class Plan +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustments: JsonField>, @@ -155,19 +156,22 @@ private constructor( fun adjustments(): List = adjustments.getRequired("adjustments") /** + * Legacy field representing the parent plan if the current plan is a 'child plan', overriding + * prices from the parent. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). */ - fun basePlan(): BasePlan? = basePlan.getNullable("base_plan") + @Deprecated("deprecated") fun basePlan(): BasePlan? = basePlan.getNullable("base_plan") /** - * The parent plan id if the given plan was created by overriding one or more of the parent's - * prices + * Legacy field representing the parent plan ID if the current plan is a 'child plan', + * overriding prices from the parent. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). */ - fun basePlanId(): String? = basePlanId.getNullable("base_plan_id") + @Deprecated("deprecated") fun basePlanId(): String? = basePlanId.getNullable("base_plan_id") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -335,14 +339,20 @@ private constructor( * * Unlike [basePlan], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("base_plan") @ExcludeMissing fun _basePlan(): JsonField = basePlan + @Deprecated("deprecated") + @JsonProperty("base_plan") + @ExcludeMissing + fun _basePlan(): JsonField = basePlan /** * Returns the raw JSON value of [basePlanId]. * * Unlike [basePlanId], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("base_plan_id") @ExcludeMissing fun _basePlanId(): JsonField = basePlanId + @Deprecated("deprecated") + @JsonProperty("base_plan_id") + @ExcludeMissing + fun _basePlanId(): JsonField = basePlanId /** * Returns the raw JSON value of [createdAt]. @@ -683,6 +693,11 @@ private constructor( fun addAdjustment(maximum: PlanPhaseMaximumAdjustment) = addAdjustment(Adjustment.ofMaximum(maximum)) + /** + * Legacy field representing the parent plan if the current plan is a 'child plan', + * overriding prices from the parent. + */ + @Deprecated("deprecated") fun basePlan(basePlan: BasePlan?) = basePlan(JsonField.ofNullable(basePlan)) /** @@ -692,12 +707,14 @@ private constructor( * This method is primarily for setting the field to an undocumented or not yet supported * value. */ + @Deprecated("deprecated") fun basePlan(basePlan: JsonField) = apply { this.basePlan = basePlan } /** - * The parent plan id if the given plan was created by overriding one or more of the - * parent's prices + * Legacy field representing the parent plan ID if the current plan is a 'child plan', + * overriding prices from the parent. */ + @Deprecated("deprecated") fun basePlanId(basePlanId: String?) = basePlanId(JsonField.ofNullable(basePlanId)) /** @@ -707,6 +724,7 @@ private constructor( * This method is primarily for setting the field to an undocumented or not yet supported * value. */ + @Deprecated("deprecated") fun basePlanId(basePlanId: JsonField) = apply { this.basePlanId = basePlanId } fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) @@ -1043,28 +1061,23 @@ private constructor( } /** Alias for calling [addPrice] with `Price.ofUnit(unit)`. */ - fun addPrice(unit: Price.Unit) = addPrice(Price.ofUnit(unit)) - - /** Alias for calling [addPrice] with `Price.ofPackage(package_)`. */ - fun addPrice(package_: Price.Package) = addPrice(Price.ofPackage(package_)) - - /** Alias for calling [addPrice] with `Price.ofMatrix(matrix)`. */ - fun addPrice(matrix: Price.Matrix) = addPrice(Price.ofMatrix(matrix)) + fun addPrice(unit: Price.UnitPrice) = addPrice(Price.ofUnit(unit)) /** Alias for calling [addPrice] with `Price.ofTiered(tiered)`. */ fun addPrice(tiered: Price.Tiered) = addPrice(Price.ofTiered(tiered)) - /** Alias for calling [addPrice] with `Price.ofTieredBps(tieredBps)`. */ - fun addPrice(tieredBps: Price.TieredBps) = addPrice(Price.ofTieredBps(tieredBps)) + /** Alias for calling [addPrice] with `Price.ofBulk(bulk)`. */ + fun addPrice(bulk: Price.Bulk) = addPrice(Price.ofBulk(bulk)) - /** Alias for calling [addPrice] with `Price.ofBps(bps)`. */ - fun addPrice(bps: Price.Bps) = addPrice(Price.ofBps(bps)) + /** Alias for calling [addPrice] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun addPrice(bulkWithFilters: Price.BulkWithFilters) = + addPrice(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [addPrice] with `Price.ofBulkBps(bulkBps)`. */ - fun addPrice(bulkBps: Price.BulkBps) = addPrice(Price.ofBulkBps(bulkBps)) + /** Alias for calling [addPrice] with `Price.ofPackage(package_)`. */ + fun addPrice(package_: Price.Package) = addPrice(Price.ofPackage(package_)) - /** Alias for calling [addPrice] with `Price.ofBulk(bulk)`. */ - fun addPrice(bulk: Price.Bulk) = addPrice(Price.ofBulk(bulk)) + /** Alias for calling [addPrice] with `Price.ofMatrix(matrix)`. */ + fun addPrice(matrix: Price.Matrix) = addPrice(Price.ofMatrix(matrix)) /** * Alias for calling [addPrice] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. @@ -1076,14 +1089,14 @@ private constructor( fun addPrice(tieredPackage: Price.TieredPackage) = addPrice(Price.ofTieredPackage(tieredPackage)) - /** Alias for calling [addPrice] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun addPrice(groupedTiered: Price.GroupedTiered) = - addPrice(Price.ofGroupedTiered(groupedTiered)) - /** Alias for calling [addPrice] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ fun addPrice(tieredWithMinimum: Price.TieredWithMinimum) = addPrice(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** Alias for calling [addPrice] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun addPrice(groupedTiered: Price.GroupedTiered) = + addPrice(Price.ofGroupedTiered(groupedTiered)) + /** * Alias for calling [addPrice] with * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. @@ -1119,6 +1132,10 @@ private constructor( fun addPrice(groupedAllocation: Price.GroupedAllocation) = addPrice(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [addPrice] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun addPrice(bulkWithProration: Price.BulkWithProration) = + addPrice(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [addPrice] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -1133,16 +1150,19 @@ private constructor( fun addPrice(groupedWithMeteredMinimum: Price.GroupedWithMeteredMinimum) = addPrice(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [addPrice] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun addPrice(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + addPrice(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** * Alias for calling [addPrice] with `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. */ fun addPrice(matrixWithDisplayName: Price.MatrixWithDisplayName) = addPrice(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [addPrice] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun addPrice(bulkWithProration: Price.BulkWithProration) = - addPrice(Price.ofBulkWithProration(bulkWithProration)) - /** * Alias for calling [addPrice] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. */ @@ -1177,10 +1197,19 @@ private constructor( /** * Alias for calling [addPrice] with - * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. */ - fun addPrice(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = - addPrice(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + fun addPrice(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + addPrice(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [addPrice] with `Price.ofMinimum(minimum)`. */ + fun addPrice(minimum: Price.Minimum) = addPrice(Price.ofMinimum(minimum)) + + /** Alias for calling [addPrice] with `Price.ofPercent(percent)`. */ + fun addPrice(percent: Price.Percent) = addPrice(Price.ofPercent(percent)) + + /** Alias for calling [addPrice] with `Price.ofEventOutput(eventOutput)`. */ + fun addPrice(eventOutput: Price.EventOutput) = addPrice(Price.ofEventOutput(eventOutput)) fun product(product: Product) = product(JsonField.of(product)) @@ -1522,10 +1551,16 @@ private constructor( return true } - return /* spotless:off */ other is Adjustment && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && percentageDiscount == other.percentageDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ + return other is Adjustment && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + percentageDiscount == other.percentageDiscount && + minimum == other.minimum && + maximum == other.maximum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(usageDiscount, amountDiscount, percentageDiscount, minimum, maximum) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(usageDiscount, amountDiscount, percentageDiscount, minimum, maximum) override fun toString(): String = when { @@ -1654,7 +1689,13 @@ private constructor( } } + /** + * Legacy field representing the parent plan if the current plan is a 'child plan', overriding + * prices from the parent. + */ + @Deprecated("deprecated") class BasePlan + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val externalPlanId: JsonField, @@ -1879,12 +1920,16 @@ private constructor( return true } - return /* spotless:off */ other is BasePlan && id == other.id && externalPlanId == other.externalPlanId && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BasePlan && + id == other.id && + externalPlanId == other.externalPlanId && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, externalPlanId, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, externalPlanId, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1984,12 +2029,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1997,6 +2040,7 @@ private constructor( } class PlanPhase + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val description: JsonField, @@ -2728,7 +2772,7 @@ private constructor( return true } - return /* spotless:off */ other is DurationUnit && value == other.value /* spotless:on */ + return other is DurationUnit && value == other.value } override fun hashCode() = value.hashCode() @@ -2741,12 +2785,37 @@ private constructor( return true } - return /* spotless:off */ other is PlanPhase && id == other.id && description == other.description && discount == other.discount && duration == other.duration && durationUnit == other.durationUnit && maximum == other.maximum && maximumAmount == other.maximumAmount && minimum == other.minimum && minimumAmount == other.minimumAmount && name == other.name && order == other.order && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PlanPhase && + id == other.id && + description == other.description && + discount == other.discount && + duration == other.duration && + durationUnit == other.durationUnit && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + name == other.name && + order == other.order && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, description, discount, duration, durationUnit, maximum, maximumAmount, minimum, minimumAmount, name, order, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + description, + discount, + duration, + durationUnit, + maximum, + maximumAmount, + minimum, + minimumAmount, + name, + order, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2755,6 +2824,7 @@ private constructor( } class Product + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val createdAt: JsonField, @@ -2968,12 +3038,16 @@ private constructor( return true } - return /* spotless:off */ other is Product && id == other.id && createdAt == other.createdAt && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Product && + id == other.id && + createdAt == other.createdAt && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, createdAt, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, createdAt, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3103,7 +3177,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -3112,6 +3186,7 @@ private constructor( } class TrialConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val trialPeriod: JsonField, private val trialPeriodUnit: JsonField, @@ -3416,7 +3491,7 @@ private constructor( return true } - return /* spotless:off */ other is TrialPeriodUnit && value == other.value /* spotless:on */ + return other is TrialPeriodUnit && value == other.value } override fun hashCode() = value.hashCode() @@ -3429,12 +3504,15 @@ private constructor( return true } - return /* spotless:off */ other is TrialConfig && trialPeriod == other.trialPeriod && trialPeriodUnit == other.trialPeriodUnit && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TrialConfig && + trialPeriod == other.trialPeriod && + trialPeriodUnit == other.trialPeriodUnit && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(trialPeriod, trialPeriodUnit, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(trialPeriod, trialPeriodUnit, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3447,12 +3525,63 @@ private constructor( return true } - return /* spotless:off */ other is Plan && id == other.id && adjustments == other.adjustments && basePlan == other.basePlan && basePlanId == other.basePlanId && createdAt == other.createdAt && currency == other.currency && defaultInvoiceMemo == other.defaultInvoiceMemo && description == other.description && discount == other.discount && externalPlanId == other.externalPlanId && invoicingCurrency == other.invoicingCurrency && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && name == other.name && netTerms == other.netTerms && planPhases == other.planPhases && prices == other.prices && product == other.product && status == other.status && trialConfig == other.trialConfig && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Plan && + id == other.id && + adjustments == other.adjustments && + basePlan == other.basePlan && + basePlanId == other.basePlanId && + createdAt == other.createdAt && + currency == other.currency && + defaultInvoiceMemo == other.defaultInvoiceMemo && + description == other.description && + discount == other.discount && + externalPlanId == other.externalPlanId && + invoicingCurrency == other.invoicingCurrency && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + name == other.name && + netTerms == other.netTerms && + planPhases == other.planPhases && + prices == other.prices && + product == other.product && + status == other.status && + trialConfig == other.trialConfig && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustments, basePlan, basePlanId, createdAt, currency, defaultInvoiceMemo, description, discount, externalPlanId, invoicingCurrency, maximum, maximumAmount, metadata, minimum, minimumAmount, name, netTerms, planPhases, prices, product, status, trialConfig, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustments, + basePlan, + basePlanId, + createdAt, + currency, + defaultInvoiceMemo, + description, + discount, + externalPlanId, + invoicingCurrency, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + name, + netTerms, + planPhases, + prices, + product, + status, + trialConfig, + version, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanCreateParams.kt index 0c947274b..47704fef5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanCreateParams.kt @@ -558,6 +558,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val currency: JsonField, private val name: JsonField, @@ -1125,12 +1126,35 @@ private constructor( return true } - return /* spotless:off */ other is Body && currency == other.currency && name == other.name && prices == other.prices && adjustments == other.adjustments && defaultInvoiceMemo == other.defaultInvoiceMemo && externalPlanId == other.externalPlanId && metadata == other.metadata && netTerms == other.netTerms && planPhases == other.planPhases && status == other.status && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + currency == other.currency && + name == other.name && + prices == other.prices && + adjustments == other.adjustments && + defaultInvoiceMemo == other.defaultInvoiceMemo && + externalPlanId == other.externalPlanId && + metadata == other.metadata && + netTerms == other.netTerms && + planPhases == other.planPhases && + status == other.status && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(currency, name, prices, adjustments, defaultInvoiceMemo, externalPlanId, metadata, netTerms, planPhases, status, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + currency, + name, + prices, + adjustments, + defaultInvoiceMemo, + externalPlanId, + metadata, + netTerms, + planPhases, + status, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1139,6 +1163,7 @@ private constructor( } class Price + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val allocationPrice: JsonField, private val planPhaseOrder: JsonField, @@ -1174,7 +1199,7 @@ private constructor( fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") /** - * The price to add to the plan + * New plan price request body params. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1278,7 +1303,7 @@ private constructor( this.planPhaseOrder = planPhaseOrder } - /** The price to add to the plan */ + /** New plan price request body params. */ fun price(price: InnerPrice?) = price(JsonField.ofNullable(price)) /** @@ -1293,26 +1318,21 @@ private constructor( /** Alias for calling [price] with `InnerPrice.ofUnit(unit)`. */ fun price(unit: NewPlanUnitPrice) = price(InnerPrice.ofUnit(unit)) - /** Alias for calling [price] with `InnerPrice.ofPackage(package_)`. */ - fun price(package_: NewPlanPackagePrice) = price(InnerPrice.ofPackage(package_)) - - /** Alias for calling [price] with `InnerPrice.ofMatrix(matrix)`. */ - fun price(matrix: NewPlanMatrixPrice) = price(InnerPrice.ofMatrix(matrix)) - /** Alias for calling [price] with `InnerPrice.ofTiered(tiered)`. */ fun price(tiered: NewPlanTieredPrice) = price(InnerPrice.ofTiered(tiered)) - /** Alias for calling [price] with `InnerPrice.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: NewPlanTieredBpsPrice) = price(InnerPrice.ofTieredBps(tieredBps)) + /** Alias for calling [price] with `InnerPrice.ofBulk(bulk)`. */ + fun price(bulk: NewPlanBulkPrice) = price(InnerPrice.ofBulk(bulk)) - /** Alias for calling [price] with `InnerPrice.ofBps(bps)`. */ - fun price(bps: NewPlanBpsPrice) = price(InnerPrice.ofBps(bps)) + /** Alias for calling [price] with `InnerPrice.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: InnerPrice.BulkWithFilters) = + price(InnerPrice.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [price] with `InnerPrice.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: NewPlanBulkBpsPrice) = price(InnerPrice.ofBulkBps(bulkBps)) + /** Alias for calling [price] with `InnerPrice.ofPackage(package_)`. */ + fun price(package_: NewPlanPackagePrice) = price(InnerPrice.ofPackage(package_)) - /** Alias for calling [price] with `InnerPrice.ofBulk(bulk)`. */ - fun price(bulk: NewPlanBulkPrice) = price(InnerPrice.ofBulk(bulk)) + /** Alias for calling [price] with `InnerPrice.ofMatrix(matrix)`. */ + fun price(matrix: NewPlanMatrixPrice) = price(InnerPrice.ofMatrix(matrix)) /** * Alias for calling [price] with @@ -1331,9 +1351,16 @@ private constructor( fun price(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = price(InnerPrice.ofTieredWithMinimum(tieredWithMinimum)) - /** Alias for calling [price] with `InnerPrice.ofUnitWithPercent(unitWithPercent)`. */ - fun price(unitWithPercent: NewPlanUnitWithPercentPrice) = - price(InnerPrice.ofUnitWithPercent(unitWithPercent)) + /** Alias for calling [price] with `InnerPrice.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: NewPlanGroupedTieredPrice) = + price(InnerPrice.ofGroupedTiered(groupedTiered)) + + /** + * Alias for calling [price] with + * `InnerPrice.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + */ + fun price(tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice) = + price(InnerPrice.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) /** * Alias for calling [price] with @@ -1342,11 +1369,22 @@ private constructor( fun price(packageWithAllocation: NewPlanPackageWithAllocationPrice) = price(InnerPrice.ofPackageWithAllocation(packageWithAllocation)) + /** Alias for calling [price] with `InnerPrice.ofUnitWithPercent(unitWithPercent)`. */ + fun price(unitWithPercent: NewPlanUnitWithPercentPrice) = + price(InnerPrice.ofUnitWithPercent(unitWithPercent)) + + /** + * Alias for calling [price] with + * `InnerPrice.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun price(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = + price(InnerPrice.ofMatrixWithAllocation(matrixWithAllocation)) + /** * Alias for calling [price] with * `InnerPrice.ofTieredWithProration(tieredWithProration)`. */ - fun price(tieredWithProration: NewPlanTierWithProrationPrice) = + fun price(tieredWithProration: InnerPrice.TieredWithProration) = price(InnerPrice.ofTieredWithProration(tieredWithProration)) /** @@ -1361,6 +1399,12 @@ private constructor( fun price(groupedAllocation: NewPlanGroupedAllocationPrice) = price(InnerPrice.ofGroupedAllocation(groupedAllocation)) + /** + * Alias for calling [price] with `InnerPrice.ofBulkWithProration(bulkWithProration)`. + */ + fun price(bulkWithProration: NewPlanBulkWithProrationPrice) = + price(InnerPrice.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [price] with * `InnerPrice.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -1377,16 +1421,17 @@ private constructor( /** * Alias for calling [price] with - * `InnerPrice.ofMatrixWithDisplayName(matrixWithDisplayName)`. + * `InnerPrice.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. */ - fun price(matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice) = - price(InnerPrice.ofMatrixWithDisplayName(matrixWithDisplayName)) + fun price(groupedWithMinMaxThresholds: InnerPrice.GroupedWithMinMaxThresholds) = + price(InnerPrice.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) /** - * Alias for calling [price] with `InnerPrice.ofBulkWithProration(bulkWithProration)`. + * Alias for calling [price] with + * `InnerPrice.ofMatrixWithDisplayName(matrixWithDisplayName)`. */ - fun price(bulkWithProration: NewPlanBulkWithProrationPrice) = - price(InnerPrice.ofBulkWithProration(bulkWithProration)) + fun price(matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice) = + price(InnerPrice.ofMatrixWithDisplayName(matrixWithDisplayName)) /** * Alias for calling [price] with @@ -1426,21 +1471,20 @@ private constructor( /** * Alias for calling [price] with - * `InnerPrice.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + * `InnerPrice.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. */ - fun price(tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice) = - price(InnerPrice.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + fun price(cumulativeGroupedAllocation: InnerPrice.CumulativeGroupedAllocation) = + price(InnerPrice.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) - /** - * Alias for calling [price] with - * `InnerPrice.ofMatrixWithAllocation(matrixWithAllocation)`. - */ - fun price(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = - price(InnerPrice.ofMatrixWithAllocation(matrixWithAllocation)) + /** Alias for calling [price] with `InnerPrice.ofMinimum(minimum)`. */ + fun price(minimum: NewPlanMinimumCompositePrice) = price(InnerPrice.ofMinimum(minimum)) - /** Alias for calling [price] with `InnerPrice.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: NewPlanGroupedTieredPrice) = - price(InnerPrice.ofGroupedTiered(groupedTiered)) + /** Alias for calling [price] with `InnerPrice.ofPercent(percent)`. */ + fun price(percent: InnerPrice.Percent) = price(InnerPrice.ofPercent(percent)) + + /** Alias for calling [price] with `InnerPrice.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: InnerPrice.EventOutput) = + price(InnerPrice.ofEventOutput(eventOutput)) fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -1502,31 +1546,33 @@ private constructor( (if (planPhaseOrder.asKnown() == null) 0 else 1) + (price.asKnown()?.validity() ?: 0) - /** The price to add to the plan */ + /** New plan price request body params. */ @JsonDeserialize(using = InnerPrice.Deserializer::class) @JsonSerialize(using = InnerPrice.Serializer::class) class InnerPrice private constructor( private val unit: NewPlanUnitPrice? = null, - private val package_: NewPlanPackagePrice? = null, - private val matrix: NewPlanMatrixPrice? = null, private val tiered: NewPlanTieredPrice? = null, - private val tieredBps: NewPlanTieredBpsPrice? = null, - private val bps: NewPlanBpsPrice? = null, - private val bulkBps: NewPlanBulkBpsPrice? = null, private val bulk: NewPlanBulkPrice? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: NewPlanPackagePrice? = null, + private val matrix: NewPlanMatrixPrice? = null, private val thresholdTotalAmount: NewPlanThresholdTotalAmountPrice? = null, private val tieredPackage: NewPlanTieredPackagePrice? = null, private val tieredWithMinimum: NewPlanTieredWithMinimumPrice? = null, - private val unitWithPercent: NewPlanUnitWithPercentPrice? = null, + private val groupedTiered: NewPlanGroupedTieredPrice? = null, + private val tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice? = null, private val packageWithAllocation: NewPlanPackageWithAllocationPrice? = null, - private val tieredWithProration: NewPlanTierWithProrationPrice? = null, + private val unitWithPercent: NewPlanUnitWithPercentPrice? = null, + private val matrixWithAllocation: NewPlanMatrixWithAllocationPrice? = null, + private val tieredWithProration: TieredWithProration? = null, private val unitWithProration: NewPlanUnitWithProrationPrice? = null, private val groupedAllocation: NewPlanGroupedAllocationPrice? = null, + private val bulkWithProration: NewPlanBulkWithProrationPrice? = null, private val groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice? = null, private val groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice? = null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, private val matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice? = null, - private val bulkWithProration: NewPlanBulkWithProrationPrice? = null, private val groupedTieredPackage: NewPlanGroupedTieredPackagePrice? = null, private val maxGroupTieredPackage: NewPlanMaxGroupTieredPackagePrice? = null, private val scalableMatrixWithUnitPricing: NewPlanScalableMatrixWithUnitPricingPrice? = @@ -1535,27 +1581,24 @@ private constructor( NewPlanScalableMatrixWithTieredPricingPrice? = null, private val cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice? = null, - private val tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice? = null, - private val matrixWithAllocation: NewPlanMatrixWithAllocationPrice? = null, - private val groupedTiered: NewPlanGroupedTieredPrice? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: NewPlanMinimumCompositePrice? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, private val _json: JsonValue? = null, ) { fun unit(): NewPlanUnitPrice? = unit - fun package_(): NewPlanPackagePrice? = package_ - - fun matrix(): NewPlanMatrixPrice? = matrix - fun tiered(): NewPlanTieredPrice? = tiered - fun tieredBps(): NewPlanTieredBpsPrice? = tieredBps + fun bulk(): NewPlanBulkPrice? = bulk - fun bps(): NewPlanBpsPrice? = bps + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters - fun bulkBps(): NewPlanBulkBpsPrice? = bulkBps + fun package_(): NewPlanPackagePrice? = package_ - fun bulk(): NewPlanBulkPrice? = bulk + fun matrix(): NewPlanMatrixPrice? = matrix fun thresholdTotalAmount(): NewPlanThresholdTotalAmountPrice? = thresholdTotalAmount @@ -1563,25 +1606,35 @@ private constructor( fun tieredWithMinimum(): NewPlanTieredWithMinimumPrice? = tieredWithMinimum - fun unitWithPercent(): NewPlanUnitWithPercentPrice? = unitWithPercent + fun groupedTiered(): NewPlanGroupedTieredPrice? = groupedTiered + + fun tieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice? = + tieredPackageWithMinimum fun packageWithAllocation(): NewPlanPackageWithAllocationPrice? = packageWithAllocation - fun tieredWithProration(): NewPlanTierWithProrationPrice? = tieredWithProration + fun unitWithPercent(): NewPlanUnitWithPercentPrice? = unitWithPercent + + fun matrixWithAllocation(): NewPlanMatrixWithAllocationPrice? = matrixWithAllocation + + fun tieredWithProration(): TieredWithProration? = tieredWithProration fun unitWithProration(): NewPlanUnitWithProrationPrice? = unitWithProration fun groupedAllocation(): NewPlanGroupedAllocationPrice? = groupedAllocation + fun bulkWithProration(): NewPlanBulkWithProrationPrice? = bulkWithProration + fun groupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice? = groupedWithProratedMinimum fun groupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice? = groupedWithMeteredMinimum - fun matrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice? = matrixWithDisplayName + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = + groupedWithMinMaxThresholds - fun bulkWithProration(): NewPlanBulkWithProrationPrice? = bulkWithProration + fun matrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice? = matrixWithDisplayName fun groupedTieredPackage(): NewPlanGroupedTieredPackagePrice? = groupedTieredPackage @@ -1595,28 +1648,26 @@ private constructor( fun cumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice? = cumulativeGroupedBulk - fun tieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice? = - tieredPackageWithMinimum - - fun matrixWithAllocation(): NewPlanMatrixWithAllocationPrice? = matrixWithAllocation + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = + cumulativeGroupedAllocation - fun groupedTiered(): NewPlanGroupedTieredPrice? = groupedTiered + fun minimum(): NewPlanMinimumCompositePrice? = minimum - fun isUnit(): Boolean = unit != null + fun percent(): Percent? = percent - fun isPackage(): Boolean = package_ != null + fun eventOutput(): EventOutput? = eventOutput - fun isMatrix(): Boolean = matrix != null + fun isUnit(): Boolean = unit != null fun isTiered(): Boolean = tiered != null - fun isTieredBps(): Boolean = tieredBps != null + fun isBulk(): Boolean = bulk != null - fun isBps(): Boolean = bps != null + fun isBulkWithFilters(): Boolean = bulkWithFilters != null - fun isBulkBps(): Boolean = bulkBps != null + fun isPackage(): Boolean = package_ != null - fun isBulk(): Boolean = bulk != null + fun isMatrix(): Boolean = matrix != null fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null @@ -1624,23 +1675,31 @@ private constructor( fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null - fun isUnitWithPercent(): Boolean = unitWithPercent != null + fun isGroupedTiered(): Boolean = groupedTiered != null + + fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + fun isUnitWithPercent(): Boolean = unitWithPercent != null + + fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isTieredWithProration(): Boolean = tieredWithProration != null fun isUnitWithProration(): Boolean = unitWithProration != null fun isGroupedAllocation(): Boolean = groupedAllocation != null + fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null - fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null @@ -1653,27 +1712,25 @@ private constructor( fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null - fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null - - fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null - fun isGroupedTiered(): Boolean = groupedTiered != null + fun isMinimum(): Boolean = minimum != null - fun asUnit(): NewPlanUnitPrice = unit.getOrThrow("unit") + fun isPercent(): Boolean = percent != null - fun asPackage(): NewPlanPackagePrice = package_.getOrThrow("package_") + fun isEventOutput(): Boolean = eventOutput != null - fun asMatrix(): NewPlanMatrixPrice = matrix.getOrThrow("matrix") + fun asUnit(): NewPlanUnitPrice = unit.getOrThrow("unit") fun asTiered(): NewPlanTieredPrice = tiered.getOrThrow("tiered") - fun asTieredBps(): NewPlanTieredBpsPrice = tieredBps.getOrThrow("tieredBps") + fun asBulk(): NewPlanBulkPrice = bulk.getOrThrow("bulk") - fun asBps(): NewPlanBpsPrice = bps.getOrThrow("bps") + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") - fun asBulkBps(): NewPlanBulkBpsPrice = bulkBps.getOrThrow("bulkBps") + fun asPackage(): NewPlanPackagePrice = package_.getOrThrow("package_") - fun asBulk(): NewPlanBulkPrice = bulk.getOrThrow("bulk") + fun asMatrix(): NewPlanMatrixPrice = matrix.getOrThrow("matrix") fun asThresholdTotalAmount(): NewPlanThresholdTotalAmountPrice = thresholdTotalAmount.getOrThrow("thresholdTotalAmount") @@ -1684,13 +1741,22 @@ private constructor( fun asTieredWithMinimum(): NewPlanTieredWithMinimumPrice = tieredWithMinimum.getOrThrow("tieredWithMinimum") - fun asUnitWithPercent(): NewPlanUnitWithPercentPrice = - unitWithPercent.getOrThrow("unitWithPercent") + fun asGroupedTiered(): NewPlanGroupedTieredPrice = + groupedTiered.getOrThrow("groupedTiered") + + fun asTieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice = + tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") fun asPackageWithAllocation(): NewPlanPackageWithAllocationPrice = packageWithAllocation.getOrThrow("packageWithAllocation") - fun asTieredWithProration(): NewPlanTierWithProrationPrice = + fun asUnitWithPercent(): NewPlanUnitWithPercentPrice = + unitWithPercent.getOrThrow("unitWithPercent") + + fun asMatrixWithAllocation(): NewPlanMatrixWithAllocationPrice = + matrixWithAllocation.getOrThrow("matrixWithAllocation") + + fun asTieredWithProration(): TieredWithProration = tieredWithProration.getOrThrow("tieredWithProration") fun asUnitWithProration(): NewPlanUnitWithProrationPrice = @@ -1699,18 +1765,21 @@ private constructor( fun asGroupedAllocation(): NewPlanGroupedAllocationPrice = groupedAllocation.getOrThrow("groupedAllocation") + fun asBulkWithProration(): NewPlanBulkWithProrationPrice = + bulkWithProration.getOrThrow("bulkWithProration") + fun asGroupedWithProratedMinimum(): NewPlanGroupedWithProratedMinimumPrice = groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") fun asGroupedWithMeteredMinimum(): NewPlanGroupedWithMeteredMinimumPrice = groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") + fun asMatrixWithDisplayName(): NewPlanMatrixWithDisplayNamePrice = matrixWithDisplayName.getOrThrow("matrixWithDisplayName") - fun asBulkWithProration(): NewPlanBulkWithProrationPrice = - bulkWithProration.getOrThrow("bulkWithProration") - fun asGroupedTieredPackage(): NewPlanGroupedTieredPackagePrice = groupedTieredPackage.getOrThrow("groupedTieredPackage") @@ -1726,45 +1795,50 @@ private constructor( fun asCumulativeGroupedBulk(): NewPlanCumulativeGroupedBulkPrice = cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") - fun asTieredPackageWithMinimum(): NewPlanTieredPackageWithMinimumPrice = - tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") - fun asMatrixWithAllocation(): NewPlanMatrixWithAllocationPrice = - matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun asMinimum(): NewPlanMinimumCompositePrice = minimum.getOrThrow("minimum") - fun asGroupedTiered(): NewPlanGroupedTieredPrice = - groupedTiered.getOrThrow("groupedTiered") + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") fun _json(): JsonValue? = _json fun accept(visitor: Visitor): T = when { unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) thresholdTotalAmount != null -> visitor.visitThresholdTotalAmount(thresholdTotalAmount) tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) - unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + tieredPackageWithMinimum != null -> + visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) packageWithAllocation != null -> visitor.visitPackageWithAllocation(packageWithAllocation) + unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + matrixWithAllocation != null -> + visitor.visitMatrixWithAllocation(matrixWithAllocation) tieredWithProration != null -> visitor.visitTieredWithProration(tieredWithProration) unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedWithProratedMinimum != null -> visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) groupedWithMeteredMinimum != null -> visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) matrixWithDisplayName != null -> visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedTieredPackage != null -> visitor.visitGroupedTieredPackage(groupedTieredPackage) maxGroupTieredPackage != null -> @@ -1777,11 +1851,11 @@ private constructor( ) cumulativeGroupedBulk != null -> visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) - tieredPackageWithMinimum != null -> - visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) - matrixWithAllocation != null -> - visitor.visitMatrixWithAllocation(matrixWithAllocation) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) else -> visitor.unknown(_json) } @@ -1798,32 +1872,24 @@ private constructor( unit.validate() } - override fun visitPackage(package_: NewPlanPackagePrice) { - package_.validate() - } - - override fun visitMatrix(matrix: NewPlanMatrixPrice) { - matrix.validate() - } - override fun visitTiered(tiered: NewPlanTieredPrice) { tiered.validate() } - override fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice) { - tieredBps.validate() + override fun visitBulk(bulk: NewPlanBulkPrice) { + bulk.validate() } - override fun visitBps(bps: NewPlanBpsPrice) { - bps.validate() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() } - override fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice) { - bulkBps.validate() + override fun visitPackage(package_: NewPlanPackagePrice) { + package_.validate() } - override fun visitBulk(bulk: NewPlanBulkPrice) { - bulk.validate() + override fun visitMatrix(matrix: NewPlanMatrixPrice) { + matrix.validate() } override fun visitThresholdTotalAmount( @@ -1842,10 +1908,14 @@ private constructor( tieredWithMinimum.validate() } - override fun visitUnitWithPercent( - unitWithPercent: NewPlanUnitWithPercentPrice + override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) { + groupedTiered.validate() + } + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice ) { - unitWithPercent.validate() + tieredPackageWithMinimum.validate() } override fun visitPackageWithAllocation( @@ -1854,8 +1924,20 @@ private constructor( packageWithAllocation.validate() } + override fun visitUnitWithPercent( + unitWithPercent: NewPlanUnitWithPercentPrice + ) { + unitWithPercent.validate() + } + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ) { + matrixWithAllocation.validate() + } + override fun visitTieredWithProration( - tieredWithProration: NewPlanTierWithProrationPrice + tieredWithProration: TieredWithProration ) { tieredWithProration.validate() } @@ -1872,6 +1954,12 @@ private constructor( groupedAllocation.validate() } + override fun visitBulkWithProration( + bulkWithProration: NewPlanBulkWithProrationPrice + ) { + bulkWithProration.validate() + } + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice ) { @@ -1884,16 +1972,16 @@ private constructor( groupedWithMeteredMinimum.validate() } - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds ) { - matrixWithDisplayName.validate() + groupedWithMinMaxThresholds.validate() } - override fun visitBulkWithProration( - bulkWithProration: NewPlanBulkWithProrationPrice + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice ) { - bulkWithProration.validate() + matrixWithDisplayName.validate() } override fun visitGroupedTieredPackage( @@ -1927,20 +2015,22 @@ private constructor( cumulativeGroupedBulk.validate() } - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation ) { - tieredPackageWithMinimum.validate() + cumulativeGroupedAllocation.validate() } - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ) { - matrixWithAllocation.validate() + override fun visitMinimum(minimum: NewPlanMinimumCompositePrice) { + minimum.validate() } - override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) { - groupedTiered.validate() + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() } } ) @@ -1966,21 +2056,17 @@ private constructor( object : Visitor { override fun visitUnit(unit: NewPlanUnitPrice) = unit.validity() - override fun visitPackage(package_: NewPlanPackagePrice) = - package_.validity() - - override fun visitMatrix(matrix: NewPlanMatrixPrice) = matrix.validity() - override fun visitTiered(tiered: NewPlanTieredPrice) = tiered.validity() - override fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice) = - tieredBps.validity() + override fun visitBulk(bulk: NewPlanBulkPrice) = bulk.validity() - override fun visitBps(bps: NewPlanBpsPrice) = bps.validity() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() - override fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice) = bulkBps.validity() + override fun visitPackage(package_: NewPlanPackagePrice) = + package_.validity() - override fun visitBulk(bulk: NewPlanBulkPrice) = bulk.validity() + override fun visitMatrix(matrix: NewPlanMatrixPrice) = matrix.validity() override fun visitThresholdTotalAmount( thresholdTotalAmount: NewPlanThresholdTotalAmountPrice @@ -1993,16 +2079,27 @@ private constructor( tieredWithMinimum: NewPlanTieredWithMinimumPrice ) = tieredWithMinimum.validity() - override fun visitUnitWithPercent( - unitWithPercent: NewPlanUnitWithPercentPrice - ) = unitWithPercent.validity() + override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = + groupedTiered.validity() + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ) = tieredPackageWithMinimum.validity() override fun visitPackageWithAllocation( packageWithAllocation: NewPlanPackageWithAllocationPrice ) = packageWithAllocation.validity() + override fun visitUnitWithPercent( + unitWithPercent: NewPlanUnitWithPercentPrice + ) = unitWithPercent.validity() + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ) = matrixWithAllocation.validity() + override fun visitTieredWithProration( - tieredWithProration: NewPlanTierWithProrationPrice + tieredWithProration: TieredWithProration ) = tieredWithProration.validity() override fun visitUnitWithProration( @@ -2013,6 +2110,10 @@ private constructor( groupedAllocation: NewPlanGroupedAllocationPrice ) = groupedAllocation.validity() + override fun visitBulkWithProration( + bulkWithProration: NewPlanBulkWithProrationPrice + ) = bulkWithProration.validity() + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice ) = groupedWithProratedMinimum.validity() @@ -2021,14 +2122,14 @@ private constructor( groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice ) = groupedWithMeteredMinimum.validity() + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + override fun visitMatrixWithDisplayName( matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice ) = matrixWithDisplayName.validity() - override fun visitBulkWithProration( - bulkWithProration: NewPlanBulkWithProrationPrice - ) = bulkWithProration.validity() - override fun visitGroupedTieredPackage( groupedTieredPackage: NewPlanGroupedTieredPackagePrice ) = groupedTieredPackage.validity() @@ -2050,16 +2151,17 @@ private constructor( cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice ) = cumulativeGroupedBulk.validity() - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ) = tieredPackageWithMinimum.validity() + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ) = matrixWithAllocation.validity() + override fun visitMinimum(minimum: NewPlanMinimumCompositePrice) = + minimum.validity() - override fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = - groupedTiered.validity() + override fun visitPercent(percent: Percent) = percent.validity() + + override fun visitEventOutput(eventOutput: EventOutput) = + eventOutput.validity() override fun unknown(json: JsonValue?) = 0 } @@ -2070,39 +2172,108 @@ private constructor( return true } - return /* spotless:off */ other is InnerPrice && unit == other.unit && package_ == other.package_ && matrix == other.matrix && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && tieredWithMinimum == other.tieredWithMinimum && unitWithPercent == other.unitWithPercent && packageWithAllocation == other.packageWithAllocation && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && bulkWithProration == other.bulkWithProration && groupedTieredPackage == other.groupedTieredPackage && maxGroupTieredPackage == other.maxGroupTieredPackage && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk && tieredPackageWithMinimum == other.tieredPackageWithMinimum && matrixWithAllocation == other.matrixWithAllocation && groupedTiered == other.groupedTiered /* spotless:on */ + return other is InnerPrice && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, tieredWithMinimum, unitWithPercent, packageWithAllocation, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, groupedWithMeteredMinimum, matrixWithDisplayName, bulkWithProration, groupedTieredPackage, maxGroupTieredPackage, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk, tieredPackageWithMinimum, matrixWithAllocation, groupedTiered) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) override fun toString(): String = when { unit != null -> "InnerPrice{unit=$unit}" - package_ != null -> "InnerPrice{package_=$package_}" - matrix != null -> "InnerPrice{matrix=$matrix}" tiered != null -> "InnerPrice{tiered=$tiered}" - tieredBps != null -> "InnerPrice{tieredBps=$tieredBps}" - bps != null -> "InnerPrice{bps=$bps}" - bulkBps != null -> "InnerPrice{bulkBps=$bulkBps}" bulk != null -> "InnerPrice{bulk=$bulk}" + bulkWithFilters != null -> "InnerPrice{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "InnerPrice{package_=$package_}" + matrix != null -> "InnerPrice{matrix=$matrix}" thresholdTotalAmount != null -> "InnerPrice{thresholdTotalAmount=$thresholdTotalAmount}" tieredPackage != null -> "InnerPrice{tieredPackage=$tieredPackage}" tieredWithMinimum != null -> "InnerPrice{tieredWithMinimum=$tieredWithMinimum}" - unitWithPercent != null -> "InnerPrice{unitWithPercent=$unitWithPercent}" + groupedTiered != null -> "InnerPrice{groupedTiered=$groupedTiered}" + tieredPackageWithMinimum != null -> + "InnerPrice{tieredPackageWithMinimum=$tieredPackageWithMinimum}" packageWithAllocation != null -> "InnerPrice{packageWithAllocation=$packageWithAllocation}" + unitWithPercent != null -> "InnerPrice{unitWithPercent=$unitWithPercent}" + matrixWithAllocation != null -> + "InnerPrice{matrixWithAllocation=$matrixWithAllocation}" tieredWithProration != null -> "InnerPrice{tieredWithProration=$tieredWithProration}" unitWithProration != null -> "InnerPrice{unitWithProration=$unitWithProration}" groupedAllocation != null -> "InnerPrice{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "InnerPrice{bulkWithProration=$bulkWithProration}" groupedWithProratedMinimum != null -> "InnerPrice{groupedWithProratedMinimum=$groupedWithProratedMinimum}" groupedWithMeteredMinimum != null -> "InnerPrice{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "InnerPrice{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" matrixWithDisplayName != null -> "InnerPrice{matrixWithDisplayName=$matrixWithDisplayName}" - bulkWithProration != null -> "InnerPrice{bulkWithProration=$bulkWithProration}" groupedTieredPackage != null -> "InnerPrice{groupedTieredPackage=$groupedTieredPackage}" maxGroupTieredPackage != null -> @@ -2113,11 +2284,11 @@ private constructor( "InnerPrice{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" cumulativeGroupedBulk != null -> "InnerPrice{cumulativeGroupedBulk=$cumulativeGroupedBulk}" - tieredPackageWithMinimum != null -> - "InnerPrice{tieredPackageWithMinimum=$tieredPackageWithMinimum}" - matrixWithAllocation != null -> - "InnerPrice{matrixWithAllocation=$matrixWithAllocation}" - groupedTiered != null -> "InnerPrice{groupedTiered=$groupedTiered}" + cumulativeGroupedAllocation != null -> + "InnerPrice{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "InnerPrice{minimum=$minimum}" + percent != null -> "InnerPrice{percent=$percent}" + eventOutput != null -> "InnerPrice{eventOutput=$eventOutput}" _json != null -> "InnerPrice{_unknown=$_json}" else -> throw IllegalStateException("Invalid InnerPrice") } @@ -2126,20 +2297,16 @@ private constructor( fun ofUnit(unit: NewPlanUnitPrice) = InnerPrice(unit = unit) - fun ofPackage(package_: NewPlanPackagePrice) = InnerPrice(package_ = package_) - - fun ofMatrix(matrix: NewPlanMatrixPrice) = InnerPrice(matrix = matrix) - fun ofTiered(tiered: NewPlanTieredPrice) = InnerPrice(tiered = tiered) - fun ofTieredBps(tieredBps: NewPlanTieredBpsPrice) = - InnerPrice(tieredBps = tieredBps) + fun ofBulk(bulk: NewPlanBulkPrice) = InnerPrice(bulk = bulk) - fun ofBps(bps: NewPlanBpsPrice) = InnerPrice(bps = bps) + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + InnerPrice(bulkWithFilters = bulkWithFilters) - fun ofBulkBps(bulkBps: NewPlanBulkBpsPrice) = InnerPrice(bulkBps = bulkBps) + fun ofPackage(package_: NewPlanPackagePrice) = InnerPrice(package_ = package_) - fun ofBulk(bulk: NewPlanBulkPrice) = InnerPrice(bulk = bulk) + fun ofMatrix(matrix: NewPlanMatrixPrice) = InnerPrice(matrix = matrix) fun ofThresholdTotalAmount(thresholdTotalAmount: NewPlanThresholdTotalAmountPrice) = InnerPrice(thresholdTotalAmount = thresholdTotalAmount) @@ -2150,14 +2317,24 @@ private constructor( fun ofTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice) = InnerPrice(tieredWithMinimum = tieredWithMinimum) - fun ofUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice) = - InnerPrice(unitWithPercent = unitWithPercent) + fun ofGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = + InnerPrice(groupedTiered = groupedTiered) + + fun ofTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ) = InnerPrice(tieredPackageWithMinimum = tieredPackageWithMinimum) fun ofPackageWithAllocation( packageWithAllocation: NewPlanPackageWithAllocationPrice ) = InnerPrice(packageWithAllocation = packageWithAllocation) - fun ofTieredWithProration(tieredWithProration: NewPlanTierWithProrationPrice) = + fun ofUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice) = + InnerPrice(unitWithPercent = unitWithPercent) + + fun ofMatrixWithAllocation(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = + InnerPrice(matrixWithAllocation = matrixWithAllocation) + + fun ofTieredWithProration(tieredWithProration: TieredWithProration) = InnerPrice(tieredWithProration = tieredWithProration) fun ofUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice) = @@ -2166,6 +2343,9 @@ private constructor( fun ofGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice) = InnerPrice(groupedAllocation = groupedAllocation) + fun ofBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice) = + InnerPrice(bulkWithProration = bulkWithProration) + fun ofGroupedWithProratedMinimum( groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice ) = InnerPrice(groupedWithProratedMinimum = groupedWithProratedMinimum) @@ -2174,13 +2354,14 @@ private constructor( groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice ) = InnerPrice(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = InnerPrice(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + fun ofMatrixWithDisplayName( matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice ) = InnerPrice(matrixWithDisplayName = matrixWithDisplayName) - fun ofBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice) = - InnerPrice(bulkWithProration = bulkWithProration) - fun ofGroupedTieredPackage(groupedTieredPackage: NewPlanGroupedTieredPackagePrice) = InnerPrice(groupedTieredPackage = groupedTieredPackage) @@ -2200,15 +2381,15 @@ private constructor( cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice ) = InnerPrice(cumulativeGroupedBulk = cumulativeGroupedBulk) - fun ofTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice - ) = InnerPrice(tieredPackageWithMinimum = tieredPackageWithMinimum) + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = InnerPrice(cumulativeGroupedAllocation = cumulativeGroupedAllocation) - fun ofMatrixWithAllocation(matrixWithAllocation: NewPlanMatrixWithAllocationPrice) = - InnerPrice(matrixWithAllocation = matrixWithAllocation) + fun ofMinimum(minimum: NewPlanMinimumCompositePrice) = InnerPrice(minimum = minimum) - fun ofGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice) = - InnerPrice(groupedTiered = groupedTiered) + fun ofPercent(percent: Percent) = InnerPrice(percent = percent) + + fun ofEventOutput(eventOutput: EventOutput) = InnerPrice(eventOutput = eventOutput) } /** @@ -2219,19 +2400,15 @@ private constructor( fun visitUnit(unit: NewPlanUnitPrice): T - fun visitPackage(package_: NewPlanPackagePrice): T - - fun visitMatrix(matrix: NewPlanMatrixPrice): T - fun visitTiered(tiered: NewPlanTieredPrice): T - fun visitTieredBps(tieredBps: NewPlanTieredBpsPrice): T + fun visitBulk(bulk: NewPlanBulkPrice): T - fun visitBps(bps: NewPlanBpsPrice): T + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T - fun visitBulkBps(bulkBps: NewPlanBulkBpsPrice): T + fun visitPackage(package_: NewPlanPackagePrice): T - fun visitBulk(bulk: NewPlanBulkPrice): T + fun visitMatrix(matrix: NewPlanMatrixPrice): T fun visitThresholdTotalAmount( thresholdTotalAmount: NewPlanThresholdTotalAmountPrice @@ -2241,18 +2418,30 @@ private constructor( fun visitTieredWithMinimum(tieredWithMinimum: NewPlanTieredWithMinimumPrice): T - fun visitUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice): T + fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice): T + + fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + ): T fun visitPackageWithAllocation( packageWithAllocation: NewPlanPackageWithAllocationPrice ): T - fun visitTieredWithProration(tieredWithProration: NewPlanTierWithProrationPrice): T + fun visitUnitWithPercent(unitWithPercent: NewPlanUnitWithPercentPrice): T + + fun visitMatrixWithAllocation( + matrixWithAllocation: NewPlanMatrixWithAllocationPrice + ): T + + fun visitTieredWithProration(tieredWithProration: TieredWithProration): T fun visitUnitWithProration(unitWithProration: NewPlanUnitWithProrationPrice): T fun visitGroupedAllocation(groupedAllocation: NewPlanGroupedAllocationPrice): T + fun visitBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice): T + fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewPlanGroupedWithProratedMinimumPrice ): T @@ -2261,12 +2450,14 @@ private constructor( groupedWithMeteredMinimum: NewPlanGroupedWithMeteredMinimumPrice ): T + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ): T + fun visitMatrixWithDisplayName( matrixWithDisplayName: NewPlanMatrixWithDisplayNamePrice ): T - fun visitBulkWithProration(bulkWithProration: NewPlanBulkWithProrationPrice): T - fun visitGroupedTieredPackage( groupedTieredPackage: NewPlanGroupedTieredPackagePrice ): T @@ -2287,15 +2478,15 @@ private constructor( cumulativeGroupedBulk: NewPlanCumulativeGroupedBulkPrice ): T - fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewPlanTieredPackageWithMinimumPrice + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation ): T - fun visitMatrixWithAllocation( - matrixWithAllocation: NewPlanMatrixWithAllocationPrice - ): T + fun visitMinimum(minimum: NewPlanMinimumCompositePrice): T - fun visitGroupedTiered(groupedTiered: NewPlanGroupedTieredPrice): T + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T /** * Maps an unknown variant of [InnerPrice] to a value of type [T]. @@ -2324,39 +2515,29 @@ private constructor( InnerPrice(unit = it, _json = json) } ?: InnerPrice(_json = json) } - "package" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { InnerPrice(package_ = it, _json = json) } - ?: InnerPrice(_json = json) - } - "matrix" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - InnerPrice(matrix = it, _json = json) - } ?: InnerPrice(_json = json) - } "tiered" -> { return tryDeserialize(node, jacksonTypeRef())?.let { InnerPrice(tiered = it, _json = json) } ?: InnerPrice(_json = json) } - "tiered_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { InnerPrice(tieredBps = it, _json = json) } - ?: InnerPrice(_json = json) + "bulk" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + InnerPrice(bulk = it, _json = json) + } ?: InnerPrice(_json = json) } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - InnerPrice(bps = it, _json = json) + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + InnerPrice(bulkWithFilters = it, _json = json) } ?: InnerPrice(_json = json) } - "bulk_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { InnerPrice(bulkBps = it, _json = json) } + "package" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { InnerPrice(package_ = it, _json = json) } ?: InnerPrice(_json = json) } - "bulk" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - InnerPrice(bulk = it, _json = json) + "matrix" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + InnerPrice(matrix = it, _json = json) } ?: InnerPrice(_json = json) } "threshold_total_amount" -> { @@ -2372,213 +2553,10595 @@ private constructor( ?.let { InnerPrice(tieredPackage = it, _json = json) } ?: InnerPrice(_json = json) } - "tiered_with_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(tieredWithMinimum = it, _json = json) } - ?: InnerPrice(_json = json) + "tiered_with_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(tieredWithMinimum = it, _json = json) } + ?: InnerPrice(_json = json) + } + "grouped_tiered" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { InnerPrice(groupedTiered = it, _json = json) } + ?: InnerPrice(_json = json) + } + "tiered_package_with_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(tieredPackageWithMinimum = it, _json = json) } + ?: InnerPrice(_json = json) + } + "package_with_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(packageWithAllocation = it, _json = json) } + ?: InnerPrice(_json = json) + } + "unit_with_percent" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(unitWithPercent = it, _json = json) } + ?: InnerPrice(_json = json) + } + "matrix_with_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(matrixWithAllocation = it, _json = json) } + ?: InnerPrice(_json = json) + } + "tiered_with_proration" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { InnerPrice(tieredWithProration = it, _json = json) } + ?: InnerPrice(_json = json) + } + "unit_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(unitWithProration = it, _json = json) } + ?: InnerPrice(_json = json) + } + "grouped_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(groupedAllocation = it, _json = json) } + ?: InnerPrice(_json = json) + } + "bulk_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(bulkWithProration = it, _json = json) } + ?: InnerPrice(_json = json) + } + "grouped_with_prorated_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(groupedWithProratedMinimum = it, _json = json) } + ?: InnerPrice(_json = json) + } + "grouped_with_metered_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(groupedWithMeteredMinimum = it, _json = json) } + ?: InnerPrice(_json = json) + } + "grouped_with_min_max_thresholds" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(groupedWithMinMaxThresholds = it, _json = json) } + ?: InnerPrice(_json = json) + } + "matrix_with_display_name" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(matrixWithDisplayName = it, _json = json) } + ?: InnerPrice(_json = json) + } + "grouped_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(groupedTieredPackage = it, _json = json) } + ?: InnerPrice(_json = json) + } + "max_group_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(maxGroupTieredPackage = it, _json = json) } + ?: InnerPrice(_json = json) + } + "scalable_matrix_with_unit_pricing" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + InnerPrice(scalableMatrixWithUnitPricing = it, _json = json) + } ?: InnerPrice(_json = json) + } + "scalable_matrix_with_tiered_pricing" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + InnerPrice(scalableMatrixWithTieredPricing = it, _json = json) + } ?: InnerPrice(_json = json) + } + "cumulative_grouped_bulk" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(cumulativeGroupedBulk = it, _json = json) } + ?: InnerPrice(_json = json) + } + "cumulative_grouped_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(cumulativeGroupedAllocation = it, _json = json) } + ?: InnerPrice(_json = json) + } + "minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { InnerPrice(minimum = it, _json = json) } + ?: InnerPrice(_json = json) + } + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + InnerPrice(percent = it, _json = json) + } ?: InnerPrice(_json = json) + } + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + InnerPrice(eventOutput = it, _json = json) + } ?: InnerPrice(_json = json) + } + } + + return InnerPrice(_json = json) + } + } + + internal class Serializer : BaseSerializer(InnerPrice::class) { + + override fun serialize( + value: InnerPrice, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.unit != null -> generator.writeObject(value.unit) + value.tiered != null -> generator.writeObject(value.tiered) + value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> + generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) + value.thresholdTotalAmount != null -> + generator.writeObject(value.thresholdTotalAmount) + value.tieredPackage != null -> generator.writeObject(value.tieredPackage) + value.tieredWithMinimum != null -> + generator.writeObject(value.tieredWithMinimum) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) + value.tieredPackageWithMinimum != null -> + generator.writeObject(value.tieredPackageWithMinimum) + value.packageWithAllocation != null -> + generator.writeObject(value.packageWithAllocation) + value.unitWithPercent != null -> + generator.writeObject(value.unitWithPercent) + value.matrixWithAllocation != null -> + generator.writeObject(value.matrixWithAllocation) + value.tieredWithProration != null -> + generator.writeObject(value.tieredWithProration) + value.unitWithProration != null -> + generator.writeObject(value.unitWithProration) + value.groupedAllocation != null -> + generator.writeObject(value.groupedAllocation) + value.bulkWithProration != null -> + generator.writeObject(value.bulkWithProration) + value.groupedWithProratedMinimum != null -> + generator.writeObject(value.groupedWithProratedMinimum) + value.groupedWithMeteredMinimum != null -> + generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) + value.matrixWithDisplayName != null -> + generator.writeObject(value.matrixWithDisplayName) + value.groupedTieredPackage != null -> + generator.writeObject(value.groupedTieredPackage) + value.maxGroupTieredPackage != null -> + generator.writeObject(value.maxGroupTieredPackage) + value.scalableMatrixWithUnitPricing != null -> + generator.writeObject(value.scalableMatrixWithUnitPricing) + value.scalableMatrixWithTieredPricing != null -> + generator.writeObject(value.scalableMatrixWithTieredPricing) + value.cumulativeGroupedBulk != null -> + generator.writeObject(value.cumulativeGroupedBulk) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid InnerPrice") + } + } + } + + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bulkWithFiltersConfig: JsonField, + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = + bulkWithFiltersConfig + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [BulkWithFilters]. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFilters]. */ + class Builder internal constructor() { + + private var bulkWithFiltersConfig: JsonField? = null + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + itemId = bulkWithFilters.itemId + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + billableMetricId = bulkWithFilters.billableMetricId + billedInAdvance = bulkWithFilters.billedInAdvance + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + currency = bulkWithFilters.currency + dimensionalPriceConfiguration = + bulkWithFilters.dimensionalPriceConfiguration + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoiceGroupingKey = bulkWithFilters.invoiceGroupingKey + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + metadata = bulkWithFilters.metadata + referenceId = bulkWithFilters.referenceId + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() + } + + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig( + bulkWithFiltersConfig: JsonField + ) = apply { this.bulkWithFiltersConfig = bulkWithFiltersConfig } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BulkWithFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFilters = + BulkWithFilters( + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFilters = apply { + if (validated) { + return@apply + } + + bulkWithFiltersConfig().validate() + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("bulk_with_filters")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) + + /** + * Property filters to apply (all must match) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [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 + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { + + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithFiltersConfig.additionalProperties.toMutableMap() + } + + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + + /** Bulk tiers for rating based on total usage volume */ + 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 [BulkWithFiltersConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } + + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = + propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + propertyKey() + propertyValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = + tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filters, tiers, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFilters && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFilters{bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class TieredWithProration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val tieredWithProrationConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + tieredWithProrationConfig: JsonField = + JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for tiered_with_proration pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tieredWithProrationConfig(): TieredWithProrationConfig = + tieredWithProrationConfig.getRequired("tiered_with_proration_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [tieredWithProrationConfig]. + * + * Unlike [tieredWithProrationConfig], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + fun _tieredWithProrationConfig(): JsonField = + tieredWithProrationConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [TieredWithProration]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProration]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("tiered_with_proration") + private var name: JsonField? = null + private var tieredWithProrationConfig: JsonField? = + null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tieredWithProration: TieredWithProration) = apply { + cadence = tieredWithProration.cadence + itemId = tieredWithProration.itemId + modelType = tieredWithProration.modelType + name = tieredWithProration.name + tieredWithProrationConfig = tieredWithProration.tieredWithProrationConfig + billableMetricId = tieredWithProration.billableMetricId + billedInAdvance = tieredWithProration.billedInAdvance + billingCycleConfiguration = tieredWithProration.billingCycleConfiguration + conversionRate = tieredWithProration.conversionRate + conversionRateConfig = tieredWithProration.conversionRateConfig + currency = tieredWithProration.currency + dimensionalPriceConfiguration = + tieredWithProration.dimensionalPriceConfiguration + externalPriceId = tieredWithProration.externalPriceId + fixedPriceQuantity = tieredWithProration.fixedPriceQuantity + invoiceGroupingKey = tieredWithProration.invoiceGroupingKey + invoicingCycleConfiguration = + tieredWithProration.invoicingCycleConfiguration + metadata = tieredWithProration.metadata + referenceId = tieredWithProration.referenceId + additionalProperties = + tieredWithProration.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for tiered_with_proration pricing */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: TieredWithProrationConfig + ) = tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) + + /** + * Sets [Builder.tieredWithProrationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.tieredWithProrationConfig] with a well-typed + * [TieredWithProrationConfig] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: JsonField + ) = apply { this.tieredWithProrationConfig = tieredWithProrationConfig } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TieredWithProration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProration = + TieredWithProration( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("tieredWithProrationConfig", tieredWithProrationConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProration = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("tiered_with_proration")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + tieredWithProrationConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("tiered_with_proration")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (tieredWithProrationConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for tiered_with_proration pricing */ + class TieredWithProrationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Tiers for rating based on total usage quantities into the specified tier with + * proration + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 + * [TieredWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProrationConfig]. */ + class Builder internal constructor() { + + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = + apply { + tiers = tieredWithProrationConfig.tiers.map { it.toMutableList() } + additionalProperties = + tieredWithProrationConfig.additionalProperties.toMutableMap() + } + + /** + * Tiers for rating based on total usage quantities into the specified tier + * with proration + */ + 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 [TieredWithProrationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProrationConfig = + TieredWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProrationConfig = apply { + if (validated) { + return@apply + } + + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tiered with proration tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Inclusive tier starting value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun tierLowerBound(): String = + tierLowerBound.getRequired("tier_lower_bound") + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Inclusive tier starting value */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProration && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredWithProrationConfig == other.tieredWithProrationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProration{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, tieredWithProrationConfig=$tieredWithProrationConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val groupedWithMinMaxThresholdsConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + groupedWithMinMaxThresholdsConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for grouped_with_min_max_thresholds pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired( + "grouped_with_min_max_thresholds_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. + * + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + fun _groupedWithMinMaxThresholdsConfig(): + JsonField = groupedWithMinMaxThresholdsConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [GroupedWithMinMaxThresholds]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholds]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("grouped_with_min_max_thresholds") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = + apply { + cadence = groupedWithMinMaxThresholds.cadence + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + itemId = groupedWithMinMaxThresholds.itemId + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + billableMetricId = groupedWithMinMaxThresholds.billableMetricId + billedInAdvance = groupedWithMinMaxThresholds.billedInAdvance + billingCycleConfiguration = + groupedWithMinMaxThresholds.billingCycleConfiguration + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + currency = groupedWithMinMaxThresholds.currency + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + invoiceGroupingKey = groupedWithMinMaxThresholds.invoiceGroupingKey + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + metadata = groupedWithMinMaxThresholds.metadata + referenceId = groupedWithMinMaxThresholds.referenceId + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = + groupedWithMinMaxThresholdsConfig( + JsonField.of(groupedWithMinMaxThresholdsConfig) + ) + + /** + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a + * well-typed [GroupedWithMinMaxThresholdsConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: + JsonField + ) = apply { + this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( + checkRequired("cadence", cadence), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholds = apply { + if (validated) { + return@apply + } + + cadence().validate() + groupedWithMinMaxThresholdsConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @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 + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate + additionalProperties = + groupedWithMinMaxThresholdsConfig.additionalProperties + .toMutableMap() + } + + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } + + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } + + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = + perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + if (validated) { + return@apply + } + + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholds && + cadence == other.cadence && + groupedWithMinMaxThresholdsConfig == + other.groupedWithMinMaxThresholdsConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholds{cadence=$cadence, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val cumulativeGroupedAllocationConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for cumulative_grouped_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired( + "cumulative_grouped_allocation_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): + JsonField = cumulativeGroupedAllocationConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [CumulativeGroupedAllocation]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocation]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("cumulative_grouped_allocation") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = + apply { + cadence = cumulativeGroupedAllocation.cadence + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + itemId = cumulativeGroupedAllocation.itemId + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + billableMetricId = cumulativeGroupedAllocation.billableMetricId + billedInAdvance = cumulativeGroupedAllocation.billedInAdvance + billingCycleConfiguration = + cumulativeGroupedAllocation.billingCycleConfiguration + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + currency = cumulativeGroupedAllocation.currency + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoiceGroupingKey = cumulativeGroupedAllocation.invoiceGroupingKey + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + metadata = cumulativeGroupedAllocation.metadata + referenceId = cumulativeGroupedAllocation.referenceId + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = + cumulativeGroupedAllocationConfig( + JsonField.of(cumulativeGroupedAllocationConfig) + ) + + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a + * well-typed [CumulativeGroupedAllocationConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: + JsonField + ) = apply { + this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( + checkRequired("cadence", cadence), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocation = apply { + if (validated) { + return@apply + } + + cadence().validate() + cumulativeGroupedAllocationConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("cumulative_grouped_allocation")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + mutableMapOf(), + ) + + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 + * [CumulativeGroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = + cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties + .toMutableMap() + } + + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } + + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation + } + + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply + } + + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocation && + cadence == other.cadence && + cumulativeGroupedAllocationConfig == + other.cumulativeGroupedAllocationConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocation{cadence=$cadence, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val percentConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [Percent]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Percent]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("percent") + private var name: JsonField? = null + private var percentConfig: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percent: Percent) = apply { + cadence = percent.cadence + itemId = percent.itemId + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + billableMetricId = percent.billableMetricId + billedInAdvance = percent.billedInAdvance + billingCycleConfiguration = percent.billingCycleConfiguration + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + currency = percent.currency + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoiceGroupingKey = percent.invoiceGroupingKey + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + metadata = percent.metadata + referenceId = percent.referenceId + additionalProperties = percent.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed + * [PercentConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Percent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Percent = + Percent( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("percentConfig", percentConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Percent = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("percent")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + percentConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent") + @ExcludeMissing + fun _percent(): JsonField = percent + + @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 + * [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PercentConfig]. */ + class Builder internal constructor() { + + private var percent: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() + } + + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PercentConfig = apply { + if (validated) { + return@apply + } + + percent() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(percent, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Percent && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Percent{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, percentConfig=$percentConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val eventOutputConfig: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [EventOutput]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutput]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var eventOutputConfig: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("event_output") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutput: EventOutput) = apply { + cadence = eventOutput.cadence + eventOutputConfig = eventOutput.eventOutputConfig + itemId = eventOutput.itemId + modelType = eventOutput.modelType + name = eventOutput.name + billableMetricId = eventOutput.billableMetricId + billedInAdvance = eventOutput.billedInAdvance + billingCycleConfiguration = eventOutput.billingCycleConfiguration + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + currency = eventOutput.currency + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoiceGroupingKey = eventOutput.invoiceGroupingKey + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + metadata = eventOutput.metadata + referenceId = eventOutput.referenceId + additionalProperties = eventOutput.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutput = + EventOutput( + checkRequired("cadence", cadence), + checkRequired("eventOutputConfig", eventOutputConfig), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutput = apply { + if (validated) { + return@apply + } + + cadence().validate() + eventOutputConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("event_output")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - "unit_with_percent" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(unitWithPercent = it, _json = json) } - ?: InnerPrice(_json = json) + + return other is Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a + * unit rate will be ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = + defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events + * will also be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @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 + * [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutputConfig]. */ + class Builder internal constructor() { + + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = + eventOutputConfig.additionalProperties.toMutableMap() } - "package_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(packageWithAllocation = it, _json = json) } - ?: InnerPrice(_json = json) + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey } - "tiered_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(tieredWithProration = it, _json = json) } - ?: InnerPrice(_json = json) + + /** + * If provided, this amount will be used as the unit rate when an event does + * not have a value for the `unit_rating_key`. If not provided, events + * missing a unit rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate } - "unit_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(unitWithProration = it, _json = json) } - ?: InnerPrice(_json = json) + + /** + * An optional key in the event data to group by (e.g., event ID). All + * events will also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey } - "grouped_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(groupedAllocation = it, _json = json) } - ?: InnerPrice(_json = json) + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - "grouped_with_prorated_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(groupedWithProratedMinimum = it, _json = json) } - ?: InnerPrice(_json = json) + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - "grouped_with_metered_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(groupedWithMeteredMinimum = it, _json = json) } - ?: InnerPrice(_json = json) + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - "matrix_with_display_name" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(matrixWithDisplayName = it, _json = json) } - ?: InnerPrice(_json = json) + + /** + * Returns an immutable instance of [EventOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutputConfig = apply { + if (validated) { + return@apply } - "bulk_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(bulkWithProration = it, _json = json) } - ?: InnerPrice(_json = json) + + unitRatingKey() + defaultUnitRate() + groupingKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "grouped_tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(groupedTieredPackage = it, _json = json) } - ?: InnerPrice(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - "max_group_tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(maxGroupTieredPackage = it, _json = json) } - ?: InnerPrice(_json = json) + + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + unitRatingKey, + defaultUnitRate, + groupingKey, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() } - "scalable_matrix_with_unit_pricing" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - InnerPrice(scalableMatrixWithUnitPricing = it, _json = json) - } ?: InnerPrice(_json = json) + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - "scalable_matrix_with_tiered_pricing" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - InnerPrice(scalableMatrixWithTieredPricing = it, _json = json) - } ?: InnerPrice(_json = json) + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - "cumulative_grouped_bulk" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(cumulativeGroupedBulk = it, _json = json) } - ?: InnerPrice(_json = json) + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - "tiered_package_with_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(tieredPackageWithMinimum = it, _json = json) } - ?: InnerPrice(_json = json) + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply } - "matrix_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { InnerPrice(matrixWithAllocation = it, _json = json) } - ?: InnerPrice(_json = json) + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "grouped_tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { InnerPrice(groupedTiered = it, _json = json) } - ?: InnerPrice(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties } - return InnerPrice(_json = json) - } - } + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - internal class Serializer : BaseSerializer(InnerPrice::class) { + override fun hashCode(): Int = hashCode - override fun serialize( - value: InnerPrice, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) - value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) - value.bulk != null -> generator.writeObject(value.bulk) - value.thresholdTotalAmount != null -> - generator.writeObject(value.thresholdTotalAmount) - value.tieredPackage != null -> generator.writeObject(value.tieredPackage) - value.tieredWithMinimum != null -> - generator.writeObject(value.tieredWithMinimum) - value.unitWithPercent != null -> - generator.writeObject(value.unitWithPercent) - value.packageWithAllocation != null -> - generator.writeObject(value.packageWithAllocation) - value.tieredWithProration != null -> - generator.writeObject(value.tieredWithProration) - value.unitWithProration != null -> - generator.writeObject(value.unitWithProration) - value.groupedAllocation != null -> - generator.writeObject(value.groupedAllocation) - value.groupedWithProratedMinimum != null -> - generator.writeObject(value.groupedWithProratedMinimum) - value.groupedWithMeteredMinimum != null -> - generator.writeObject(value.groupedWithMeteredMinimum) - value.matrixWithDisplayName != null -> - generator.writeObject(value.matrixWithDisplayName) - value.bulkWithProration != null -> - generator.writeObject(value.bulkWithProration) - value.groupedTieredPackage != null -> - generator.writeObject(value.groupedTieredPackage) - value.maxGroupTieredPackage != null -> - generator.writeObject(value.maxGroupTieredPackage) - value.scalableMatrixWithUnitPricing != null -> - generator.writeObject(value.scalableMatrixWithUnitPricing) - value.scalableMatrixWithTieredPricing != null -> - generator.writeObject(value.scalableMatrixWithTieredPricing) - value.cumulativeGroupedBulk != null -> - generator.writeObject(value.cumulativeGroupedBulk) - value.tieredPackageWithMinimum != null -> - generator.writeObject(value.tieredPackageWithMinimum) - value.matrixWithAllocation != null -> - generator.writeObject(value.matrixWithAllocation) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid InnerPrice") + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is EventOutput && + cadence == other.cadence && + eventOutputConfig == other.eventOutputConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutput{cadence=$cadence, eventOutputConfig=$eventOutputConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" } } @@ -2587,12 +13150,16 @@ private constructor( return true } - return /* spotless:off */ other is Price && allocationPrice == other.allocationPrice && planPhaseOrder == other.planPhaseOrder && price == other.price && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Price && + allocationPrice == other.allocationPrice && + planPhaseOrder == other.planPhaseOrder && + price == other.price && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(allocationPrice, planPhaseOrder, price, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(allocationPrice, planPhaseOrder, price, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2601,6 +13168,7 @@ private constructor( } class Adjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val adjustment: JsonField, private val planPhaseOrder: JsonField, @@ -3021,10 +13589,16 @@ private constructor( return true } - return /* spotless:off */ other is InnerAdjustment && percentageDiscount == other.percentageDiscount && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ + return other is InnerAdjustment && + percentageDiscount == other.percentageDiscount && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + minimum == other.minimum && + maximum == other.maximum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) override fun toString(): String = when { @@ -3150,12 +13724,15 @@ private constructor( return true } - return /* spotless:off */ other is Adjustment && adjustment == other.adjustment && planPhaseOrder == other.planPhaseOrder && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Adjustment && + adjustment == other.adjustment && + planPhaseOrder == other.planPhaseOrder && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustment, planPhaseOrder, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(adjustment, planPhaseOrder, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3255,12 +13832,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3268,6 +13843,7 @@ private constructor( } class PlanPhase + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val order: JsonField, private val alignBillingWithPhaseStartDate: JsonField, @@ -3682,7 +14258,7 @@ private constructor( return true } - return /* spotless:off */ other is DurationUnit && value == other.value /* spotless:on */ + return other is DurationUnit && value == other.value } override fun hashCode() = value.hashCode() @@ -3695,12 +14271,23 @@ private constructor( return true } - return /* spotless:off */ other is PlanPhase && order == other.order && alignBillingWithPhaseStartDate == other.alignBillingWithPhaseStartDate && duration == other.duration && durationUnit == other.durationUnit && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PlanPhase && + order == other.order && + alignBillingWithPhaseStartDate == other.alignBillingWithPhaseStartDate && + duration == other.duration && + durationUnit == other.durationUnit && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(order, alignBillingWithPhaseStartDate, duration, durationUnit, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + order, + alignBillingWithPhaseStartDate, + duration, + durationUnit, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -3828,7 +14415,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -3841,10 +14428,13 @@ private constructor( return true } - return /* spotless:off */ other is PlanCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PlanCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "PlanCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanExternalPlanIdFetchParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanExternalPlanIdFetchParams.kt index d42b1ddcb..b2e385a59 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanExternalPlanIdFetchParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanExternalPlanIdFetchParams.kt @@ -17,7 +17,6 @@ import java.util.Objects * plan. * * ## Serialized prices - * * Orb supports a few different pricing models out of the box. Each of these models is serialized * differently in a given [Price](/core-concepts#plan-and-price) object. The `model_type` field * determines the key for the configuration object that is present. A detailed explanation of price @@ -192,10 +191,14 @@ private constructor( return true } - return /* spotless:off */ other is PlanExternalPlanIdFetchParams && externalPlanId == other.externalPlanId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PlanExternalPlanIdFetchParams && + externalPlanId == other.externalPlanId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalPlanId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(externalPlanId, additionalHeaders, additionalQueryParams) override fun toString() = "PlanExternalPlanIdFetchParams{externalPlanId=$externalPlanId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanExternalPlanIdUpdateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanExternalPlanIdUpdateParams.kt index 3f5aea0d2..949b884f1 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanExternalPlanIdUpdateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanExternalPlanIdUpdateParams.kt @@ -294,6 +294,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val externalPlanId: JsonField, private val metadata: JsonField, @@ -474,12 +475,15 @@ private constructor( return true } - return /* spotless:off */ other is Body && externalPlanId == other.externalPlanId && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + externalPlanId == other.externalPlanId && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(externalPlanId, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(externalPlanId, metadata, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -579,12 +583,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -596,10 +598,15 @@ private constructor( return true } - return /* spotless:off */ other is PlanExternalPlanIdUpdateParams && otherExternalPlanId == other.otherExternalPlanId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PlanExternalPlanIdUpdateParams && + otherExternalPlanId == other.otherExternalPlanId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(otherExternalPlanId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(otherExternalPlanId, body, additionalHeaders, additionalQueryParams) override fun toString() = "PlanExternalPlanIdUpdateParams{otherExternalPlanId=$otherExternalPlanId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanFetchParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanFetchParams.kt index 007da8808..cb52dea1c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanFetchParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanFetchParams.kt @@ -13,14 +13,12 @@ import java.util.Objects * as well as the product that the plan is attached to. * * ## Serialized prices - * * Orb supports a few different pricing models out of the box. Each of these models is serialized * differently in a given [Price](/core-concepts#plan-and-price) object. The `model_type` field * determines the key for the configuration object that is present. A detailed explanation of price * types can be found in the [Price schema](/core-concepts#plan-and-price). * * ## Phases - * * Orb supports plan phases, also known as contract ramps. For plans with phases, the serialized * prices refer to all prices across all phases. */ @@ -186,10 +184,13 @@ private constructor( return true } - return /* spotless:off */ other is PlanFetchParams && planId == other.planId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PlanFetchParams && + planId == other.planId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(planId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(planId, additionalHeaders, additionalQueryParams) override fun toString() = "PlanFetchParams{planId=$planId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListPage.kt index 02e4dcd5a..a33ff764e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListPage.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is PlanListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is PlanListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "PlanListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListPageAsync.kt index 523b3130f..100c10444 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListPageAsync.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is PlanListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is PlanListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "PlanListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListPageResponse.kt index 630f21637..d6524a41a 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class PlanListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -213,12 +214,15 @@ private constructor( return true } - return /* spotless:off */ other is PlanListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PlanListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListParams.kt index 62d4b447d..0f6b672b5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanListParams.kt @@ -384,7 +384,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -397,10 +397,30 @@ private constructor( return true } - return /* spotless:off */ other is PlanListParams && createdAtGt == other.createdAtGt && createdAtGte == other.createdAtGte && createdAtLt == other.createdAtLt && createdAtLte == other.createdAtLte && cursor == other.cursor && limit == other.limit && status == other.status && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PlanListParams && + createdAtGt == other.createdAtGt && + createdAtGte == other.createdAtGte && + createdAtLt == other.createdAtLt && + createdAtLte == other.createdAtLte && + cursor == other.cursor && + limit == other.limit && + status == other.status && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(createdAtGt, createdAtGte, createdAtLt, createdAtLte, cursor, limit, status, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + createdAtGt, + createdAtGte, + createdAtLt, + createdAtLte, + cursor, + limit, + status, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "PlanListParams{createdAtGt=$createdAtGt, createdAtGte=$createdAtGte, createdAtLt=$createdAtLt, createdAtLte=$createdAtLte, cursor=$cursor, limit=$limit, status=$status, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseAmountDiscountAdjustment.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseAmountDiscountAdjustment.kt index 4bebe864d..7b168d056 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseAmountDiscountAdjustment.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseAmountDiscountAdjustment.kt @@ -19,12 +19,13 @@ import java.util.Collections import java.util.Objects class PlanPhaseAmountDiscountAdjustment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustmentType: JsonField, private val amountDiscount: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val planPhaseOrder: JsonField, private val reason: JsonField, @@ -46,7 +47,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -106,10 +107,10 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply to + * True for adjustments that apply to an entire invoice, false for adjustments that apply to * only one price. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -183,9 +184,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -263,7 +262,7 @@ private constructor( private var adjustmentType: JsonField? = null private var amountDiscount: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField? = null private var planPhaseOrder: JsonField? = null private var reason: JsonField? = null @@ -358,25 +357,25 @@ private constructor( } /** The filters that determine which prices to apply this adjustment to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -384,8 +383,8 @@ private constructor( } /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply - * to only one price. + * True for adjustments that apply to an entire invoice, false for adjustments that apply to + * only one price. */ fun isInvoiceLevel(isInvoiceLevel: Boolean) = isInvoiceLevel(JsonField.of(isInvoiceLevel)) @@ -662,7 +661,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -670,17 +669,566 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PlanPhaseAmountDiscountAdjustment && id == other.id && adjustmentType == other.adjustmentType && amountDiscount == other.amountDiscount && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && planPhaseOrder == other.planPhaseOrder && reason == other.reason && replacesAdjustmentId == other.replacesAdjustmentId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PlanPhaseAmountDiscountAdjustment && + id == other.id && + adjustmentType == other.adjustmentType && + amountDiscount == other.amountDiscount && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + planPhaseOrder == other.planPhaseOrder && + reason == other.reason && + replacesAdjustmentId == other.replacesAdjustmentId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustmentType, amountDiscount, appliesToPriceIds, filters, isInvoiceLevel, planPhaseOrder, reason, replacesAdjustmentId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustmentType, + amountDiscount, + appliesToPriceIds, + filters, + isInvoiceLevel, + planPhaseOrder, + reason, + replacesAdjustmentId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseMaximumAdjustment.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseMaximumAdjustment.kt index dcbdb5231..634c00386 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseMaximumAdjustment.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseMaximumAdjustment.kt @@ -19,11 +19,12 @@ import java.util.Collections import java.util.Objects class PlanPhaseMaximumAdjustment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustmentType: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val maximumAmount: JsonField, private val planPhaseOrder: JsonField, @@ -43,7 +44,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -97,10 +98,10 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply to + * True for adjustments that apply to an entire invoice, false for adjustments that apply to * only one price. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -174,9 +175,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -261,7 +260,7 @@ private constructor( private var id: JsonField? = null private var adjustmentType: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField? = null private var maximumAmount: JsonField? = null private var planPhaseOrder: JsonField? = null @@ -338,25 +337,25 @@ private constructor( } /** The filters that determine which prices to apply this adjustment to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -364,8 +363,8 @@ private constructor( } /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply - * to only one price. + * True for adjustments that apply to an entire invoice, false for adjustments that apply to + * only one price. */ fun isInvoiceLevel(isInvoiceLevel: Boolean) = isInvoiceLevel(JsonField.of(isInvoiceLevel)) @@ -659,7 +658,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -667,17 +666,566 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PlanPhaseMaximumAdjustment && id == other.id && adjustmentType == other.adjustmentType && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && maximumAmount == other.maximumAmount && planPhaseOrder == other.planPhaseOrder && reason == other.reason && replacesAdjustmentId == other.replacesAdjustmentId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PlanPhaseMaximumAdjustment && + id == other.id && + adjustmentType == other.adjustmentType && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + maximumAmount == other.maximumAmount && + planPhaseOrder == other.planPhaseOrder && + reason == other.reason && + replacesAdjustmentId == other.replacesAdjustmentId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustmentType, appliesToPriceIds, filters, isInvoiceLevel, maximumAmount, planPhaseOrder, reason, replacesAdjustmentId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustmentType, + appliesToPriceIds, + filters, + isInvoiceLevel, + maximumAmount, + planPhaseOrder, + reason, + replacesAdjustmentId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseMinimumAdjustment.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseMinimumAdjustment.kt index 36f5f56a9..b8a20bbe7 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseMinimumAdjustment.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseMinimumAdjustment.kt @@ -19,11 +19,12 @@ import java.util.Collections import java.util.Objects class PlanPhaseMinimumAdjustment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustmentType: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val itemId: JsonField, private val minimumAmount: JsonField, @@ -44,7 +45,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -100,10 +101,10 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply to + * True for adjustments that apply to an entire invoice, false for adjustments that apply to * only one price. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -185,9 +186,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -280,7 +279,7 @@ private constructor( private var id: JsonField? = null private var adjustmentType: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField? = null private var itemId: JsonField? = null private var minimumAmount: JsonField? = null @@ -359,25 +358,25 @@ private constructor( } /** The filters that determine which prices to apply this adjustment to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -385,8 +384,8 @@ private constructor( } /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply - * to only one price. + * True for adjustments that apply to an entire invoice, false for adjustments that apply to + * only one price. */ fun isInvoiceLevel(isInvoiceLevel: Boolean) = isInvoiceLevel(JsonField.of(isInvoiceLevel)) @@ -695,7 +694,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -703,17 +702,568 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PlanPhaseMinimumAdjustment && id == other.id && adjustmentType == other.adjustmentType && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && itemId == other.itemId && minimumAmount == other.minimumAmount && planPhaseOrder == other.planPhaseOrder && reason == other.reason && replacesAdjustmentId == other.replacesAdjustmentId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PlanPhaseMinimumAdjustment && + id == other.id && + adjustmentType == other.adjustmentType && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + itemId == other.itemId && + minimumAmount == other.minimumAmount && + planPhaseOrder == other.planPhaseOrder && + reason == other.reason && + replacesAdjustmentId == other.replacesAdjustmentId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustmentType, appliesToPriceIds, filters, isInvoiceLevel, itemId, minimumAmount, planPhaseOrder, reason, replacesAdjustmentId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustmentType, + appliesToPriceIds, + filters, + isInvoiceLevel, + itemId, + minimumAmount, + planPhaseOrder, + reason, + replacesAdjustmentId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhasePercentageDiscountAdjustment.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhasePercentageDiscountAdjustment.kt index 9b68a4fae..2f36384aa 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhasePercentageDiscountAdjustment.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhasePercentageDiscountAdjustment.kt @@ -19,11 +19,12 @@ import java.util.Collections import java.util.Objects class PlanPhasePercentageDiscountAdjustment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustmentType: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val percentageDiscount: JsonField, private val planPhaseOrder: JsonField, @@ -43,7 +44,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -97,10 +98,10 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply to + * True for adjustments that apply to an entire invoice, false for adjustments that apply to * only one price. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -174,9 +175,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -263,7 +262,7 @@ private constructor( private var id: JsonField? = null private var adjustmentType: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField? = null private var percentageDiscount: JsonField? = null private var planPhaseOrder: JsonField? = null @@ -343,25 +342,25 @@ private constructor( } /** The filters that determine which prices to apply this adjustment to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -369,8 +368,8 @@ private constructor( } /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply - * to only one price. + * True for adjustments that apply to an entire invoice, false for adjustments that apply to + * only one price. */ fun isInvoiceLevel(isInvoiceLevel: Boolean) = isInvoiceLevel(JsonField.of(isInvoiceLevel)) @@ -665,7 +664,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -673,17 +672,566 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PlanPhasePercentageDiscountAdjustment && id == other.id && adjustmentType == other.adjustmentType && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && percentageDiscount == other.percentageDiscount && planPhaseOrder == other.planPhaseOrder && reason == other.reason && replacesAdjustmentId == other.replacesAdjustmentId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PlanPhasePercentageDiscountAdjustment && + id == other.id && + adjustmentType == other.adjustmentType && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + percentageDiscount == other.percentageDiscount && + planPhaseOrder == other.planPhaseOrder && + reason == other.reason && + replacesAdjustmentId == other.replacesAdjustmentId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustmentType, appliesToPriceIds, filters, isInvoiceLevel, percentageDiscount, planPhaseOrder, reason, replacesAdjustmentId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustmentType, + appliesToPriceIds, + filters, + isInvoiceLevel, + percentageDiscount, + planPhaseOrder, + reason, + replacesAdjustmentId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseUsageDiscountAdjustment.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseUsageDiscountAdjustment.kt index 62d4c5876..7c945b7af 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseUsageDiscountAdjustment.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanPhaseUsageDiscountAdjustment.kt @@ -19,11 +19,12 @@ import java.util.Collections import java.util.Objects class PlanPhaseUsageDiscountAdjustment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val adjustmentType: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val isInvoiceLevel: JsonField, private val planPhaseOrder: JsonField, private val reason: JsonField, @@ -43,7 +44,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("is_invoice_level") @ExcludeMissing isInvoiceLevel: JsonField = JsonMissing.of(), @@ -97,10 +98,10 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply to + * True for adjustments that apply to an entire invoice, false for adjustments that apply to * only one price. * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -174,9 +175,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [isInvoiceLevel]. @@ -262,7 +261,7 @@ private constructor( private var id: JsonField? = null private var adjustmentType: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var isInvoiceLevel: JsonField? = null private var planPhaseOrder: JsonField? = null private var reason: JsonField? = null @@ -341,25 +340,25 @@ private constructor( } /** The filters that determine which prices to apply this adjustment to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -367,8 +366,8 @@ private constructor( } /** - * True for adjustments that apply to an entire invocice, false for adjustments that apply - * to only one price. + * True for adjustments that apply to an entire invoice, false for adjustments that apply to + * only one price. */ fun isInvoiceLevel(isInvoiceLevel: Boolean) = isInvoiceLevel(JsonField.of(isInvoiceLevel)) @@ -662,7 +661,7 @@ private constructor( return true } - return /* spotless:off */ other is AdjustmentType && value == other.value /* spotless:on */ + return other is AdjustmentType && value == other.value } override fun hashCode() = value.hashCode() @@ -670,17 +669,566 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PlanPhaseUsageDiscountAdjustment && id == other.id && adjustmentType == other.adjustmentType && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && isInvoiceLevel == other.isInvoiceLevel && planPhaseOrder == other.planPhaseOrder && reason == other.reason && replacesAdjustmentId == other.replacesAdjustmentId && usageDiscount == other.usageDiscount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PlanPhaseUsageDiscountAdjustment && + id == other.id && + adjustmentType == other.adjustmentType && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + isInvoiceLevel == other.isInvoiceLevel && + planPhaseOrder == other.planPhaseOrder && + reason == other.reason && + replacesAdjustmentId == other.replacesAdjustmentId && + usageDiscount == other.usageDiscount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, adjustmentType, appliesToPriceIds, filters, isInvoiceLevel, planPhaseOrder, reason, replacesAdjustmentId, usageDiscount, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + adjustmentType, + appliesToPriceIds, + filters, + isInvoiceLevel, + planPhaseOrder, + reason, + replacesAdjustmentId, + usageDiscount, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanUpdateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanUpdateParams.kt index bdd4fea44..6bf89eb94 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanUpdateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanUpdateParams.kt @@ -289,6 +289,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val externalPlanId: JsonField, private val metadata: JsonField, @@ -469,12 +470,15 @@ private constructor( return true } - return /* spotless:off */ other is Body && externalPlanId == other.externalPlanId && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + externalPlanId == other.externalPlanId && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(externalPlanId, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(externalPlanId, metadata, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -574,12 +578,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -591,10 +593,15 @@ private constructor( return true } - return /* spotless:off */ other is PlanUpdateParams && planId == other.planId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PlanUpdateParams && + planId == other.planId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(planId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(planId, body, additionalHeaders, additionalQueryParams) override fun toString() = "PlanUpdateParams{planId=$planId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanVersion.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanVersion.kt index 2b7770f7e..2e714d649 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanVersion.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanVersion.kt @@ -33,6 +33,7 @@ import java.util.Objects * plan. */ class PlanVersion +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val adjustments: JsonField>, private val createdAt: JsonField, @@ -301,28 +302,23 @@ private constructor( } /** Alias for calling [addPrice] with `Price.ofUnit(unit)`. */ - fun addPrice(unit: Price.Unit) = addPrice(Price.ofUnit(unit)) - - /** Alias for calling [addPrice] with `Price.ofPackage(package_)`. */ - fun addPrice(package_: Price.Package) = addPrice(Price.ofPackage(package_)) - - /** Alias for calling [addPrice] with `Price.ofMatrix(matrix)`. */ - fun addPrice(matrix: Price.Matrix) = addPrice(Price.ofMatrix(matrix)) + fun addPrice(unit: Price.UnitPrice) = addPrice(Price.ofUnit(unit)) /** Alias for calling [addPrice] with `Price.ofTiered(tiered)`. */ fun addPrice(tiered: Price.Tiered) = addPrice(Price.ofTiered(tiered)) - /** Alias for calling [addPrice] with `Price.ofTieredBps(tieredBps)`. */ - fun addPrice(tieredBps: Price.TieredBps) = addPrice(Price.ofTieredBps(tieredBps)) + /** Alias for calling [addPrice] with `Price.ofBulk(bulk)`. */ + fun addPrice(bulk: Price.Bulk) = addPrice(Price.ofBulk(bulk)) - /** Alias for calling [addPrice] with `Price.ofBps(bps)`. */ - fun addPrice(bps: Price.Bps) = addPrice(Price.ofBps(bps)) + /** Alias for calling [addPrice] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun addPrice(bulkWithFilters: Price.BulkWithFilters) = + addPrice(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [addPrice] with `Price.ofBulkBps(bulkBps)`. */ - fun addPrice(bulkBps: Price.BulkBps) = addPrice(Price.ofBulkBps(bulkBps)) + /** Alias for calling [addPrice] with `Price.ofPackage(package_)`. */ + fun addPrice(package_: Price.Package) = addPrice(Price.ofPackage(package_)) - /** Alias for calling [addPrice] with `Price.ofBulk(bulk)`. */ - fun addPrice(bulk: Price.Bulk) = addPrice(Price.ofBulk(bulk)) + /** Alias for calling [addPrice] with `Price.ofMatrix(matrix)`. */ + fun addPrice(matrix: Price.Matrix) = addPrice(Price.ofMatrix(matrix)) /** * Alias for calling [addPrice] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. @@ -334,14 +330,14 @@ private constructor( fun addPrice(tieredPackage: Price.TieredPackage) = addPrice(Price.ofTieredPackage(tieredPackage)) - /** Alias for calling [addPrice] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun addPrice(groupedTiered: Price.GroupedTiered) = - addPrice(Price.ofGroupedTiered(groupedTiered)) - /** Alias for calling [addPrice] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ fun addPrice(tieredWithMinimum: Price.TieredWithMinimum) = addPrice(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** Alias for calling [addPrice] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun addPrice(groupedTiered: Price.GroupedTiered) = + addPrice(Price.ofGroupedTiered(groupedTiered)) + /** * Alias for calling [addPrice] with * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. @@ -377,6 +373,10 @@ private constructor( fun addPrice(groupedAllocation: Price.GroupedAllocation) = addPrice(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [addPrice] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun addPrice(bulkWithProration: Price.BulkWithProration) = + addPrice(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [addPrice] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -391,16 +391,19 @@ private constructor( fun addPrice(groupedWithMeteredMinimum: Price.GroupedWithMeteredMinimum) = addPrice(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [addPrice] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun addPrice(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + addPrice(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** * Alias for calling [addPrice] with `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. */ fun addPrice(matrixWithDisplayName: Price.MatrixWithDisplayName) = addPrice(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [addPrice] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun addPrice(bulkWithProration: Price.BulkWithProration) = - addPrice(Price.ofBulkWithProration(bulkWithProration)) - /** * Alias for calling [addPrice] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. */ @@ -435,10 +438,19 @@ private constructor( /** * Alias for calling [addPrice] with - * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. */ - fun addPrice(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = - addPrice(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + fun addPrice(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + addPrice(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [addPrice] with `Price.ofMinimum(minimum)`. */ + fun addPrice(minimum: Price.Minimum) = addPrice(Price.ofMinimum(minimum)) + + /** Alias for calling [addPrice] with `Price.ofPercent(percent)`. */ + fun addPrice(percent: Price.Percent) = addPrice(Price.ofPercent(percent)) + + /** Alias for calling [addPrice] with `Price.ofEventOutput(eventOutput)`. */ + fun addPrice(eventOutput: Price.EventOutput) = addPrice(Price.ofEventOutput(eventOutput)) fun version(version: Long) = version(JsonField.of(version)) @@ -671,10 +683,16 @@ private constructor( return true } - return /* spotless:off */ other is Adjustment && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && percentageDiscount == other.percentageDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ + return other is Adjustment && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + percentageDiscount == other.percentageDiscount && + minimum == other.minimum && + maximum == other.maximum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(usageDiscount, amountDiscount, percentageDiscount, minimum, maximum) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(usageDiscount, amountDiscount, percentageDiscount, minimum, maximum) override fun toString(): String = when { @@ -808,12 +826,18 @@ private constructor( return true } - return /* spotless:off */ other is PlanVersion && adjustments == other.adjustments && createdAt == other.createdAt && planPhases == other.planPhases && prices == other.prices && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PlanVersion && + adjustments == other.adjustments && + createdAt == other.createdAt && + planPhases == other.planPhases && + prices == other.prices && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustments, createdAt, planPhases, prices, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(adjustments, createdAt, planPhases, prices, version, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanVersionPhase.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanVersionPhase.kt index f89d6bcb5..61eb5e4b1 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanVersionPhase.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PlanVersionPhase.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class PlanVersionPhase +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val description: JsonField, @@ -476,7 +477,7 @@ private constructor( return true } - return /* spotless:off */ other is DurationUnit && value == other.value /* spotless:on */ + return other is DurationUnit && value == other.value } override fun hashCode() = value.hashCode() @@ -489,12 +490,19 @@ private constructor( return true } - return /* spotless:off */ other is PlanVersionPhase && id == other.id && description == other.description && duration == other.duration && durationUnit == other.durationUnit && name == other.name && order == other.order && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PlanVersionPhase && + id == other.id && + description == other.description && + duration == other.duration && + durationUnit == other.durationUnit && + name == other.name && + order == other.order && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, description, duration, durationUnit, name, order, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, description, duration, durationUnit, name, order, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Price.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Price.kt index 52870871c..3ea2981c3 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Price.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Price.kt @@ -20,6 +20,7 @@ import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired import com.withorb.api.core.getOrThrow import com.withorb.api.core.toImmutable @@ -45,18 +46,16 @@ import kotlin.Unit as KUnit @JsonSerialize(using = Price.Serializer::class) class Price private constructor( - private val unit: Unit? = null, - private val package_: Package? = null, - private val matrix: Matrix? = null, + private val unit: UnitPrice? = null, private val tiered: Tiered? = null, - private val tieredBps: TieredBps? = null, - private val bps: Bps? = null, - private val bulkBps: BulkBps? = null, private val bulk: Bulk? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: Package? = null, + private val matrix: Matrix? = null, private val thresholdTotalAmount: ThresholdTotalAmount? = null, private val tieredPackage: TieredPackage? = null, - private val groupedTiered: GroupedTiered? = null, private val tieredWithMinimum: TieredWithMinimum? = null, + private val groupedTiered: GroupedTiered? = null, private val tieredPackageWithMinimum: TieredPackageWithMinimum? = null, private val packageWithAllocation: PackageWithAllocation? = null, private val unitWithPercent: UnitWithPercent? = null, @@ -64,43 +63,43 @@ private constructor( private val tieredWithProration: TieredWithProration? = null, private val unitWithProration: UnitWithProration? = null, private val groupedAllocation: GroupedAllocation? = null, + private val bulkWithProration: BulkWithProration? = null, private val groupedWithProratedMinimum: GroupedWithProratedMinimum? = null, private val groupedWithMeteredMinimum: GroupedWithMeteredMinimum? = null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, private val matrixWithDisplayName: MatrixWithDisplayName? = null, - private val bulkWithProration: BulkWithProration? = null, private val groupedTieredPackage: GroupedTieredPackage? = null, private val maxGroupTieredPackage: MaxGroupTieredPackage? = null, private val scalableMatrixWithUnitPricing: ScalableMatrixWithUnitPricing? = null, private val scalableMatrixWithTieredPricing: ScalableMatrixWithTieredPricing? = null, private val cumulativeGroupedBulk: CumulativeGroupedBulk? = null, - private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: Minimum? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, private val _json: JsonValue? = null, ) { - fun unit(): Unit? = unit - - fun package_(): Package? = package_ - - fun matrix(): Matrix? = matrix + fun unit(): UnitPrice? = unit fun tiered(): Tiered? = tiered - fun tieredBps(): TieredBps? = tieredBps + fun bulk(): Bulk? = bulk - fun bps(): Bps? = bps + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters - fun bulkBps(): BulkBps? = bulkBps + fun package_(): Package? = package_ - fun bulk(): Bulk? = bulk + fun matrix(): Matrix? = matrix fun thresholdTotalAmount(): ThresholdTotalAmount? = thresholdTotalAmount fun tieredPackage(): TieredPackage? = tieredPackage - fun groupedTiered(): GroupedTiered? = groupedTiered - fun tieredWithMinimum(): TieredWithMinimum? = tieredWithMinimum + fun groupedTiered(): GroupedTiered? = groupedTiered + fun tieredPackageWithMinimum(): TieredPackageWithMinimum? = tieredPackageWithMinimum fun packageWithAllocation(): PackageWithAllocation? = packageWithAllocation @@ -115,13 +114,15 @@ private constructor( fun groupedAllocation(): GroupedAllocation? = groupedAllocation + fun bulkWithProration(): BulkWithProration? = bulkWithProration + fun groupedWithProratedMinimum(): GroupedWithProratedMinimum? = groupedWithProratedMinimum fun groupedWithMeteredMinimum(): GroupedWithMeteredMinimum? = groupedWithMeteredMinimum - fun matrixWithDisplayName(): MatrixWithDisplayName? = matrixWithDisplayName + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = groupedWithMinMaxThresholds - fun bulkWithProration(): BulkWithProration? = bulkWithProration + fun matrixWithDisplayName(): MatrixWithDisplayName? = matrixWithDisplayName fun groupedTieredPackage(): GroupedTieredPackage? = groupedTieredPackage @@ -135,32 +136,34 @@ private constructor( fun cumulativeGroupedBulk(): CumulativeGroupedBulk? = cumulativeGroupedBulk - fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = groupedWithMinMaxThresholds + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = cumulativeGroupedAllocation - fun isUnit(): Boolean = unit != null + fun minimum(): Minimum? = minimum - fun isPackage(): Boolean = package_ != null + fun percent(): Percent? = percent - fun isMatrix(): Boolean = matrix != null + fun eventOutput(): EventOutput? = eventOutput + + fun isUnit(): Boolean = unit != null fun isTiered(): Boolean = tiered != null - fun isTieredBps(): Boolean = tieredBps != null + fun isBulk(): Boolean = bulk != null - fun isBps(): Boolean = bps != null + fun isBulkWithFilters(): Boolean = bulkWithFilters != null - fun isBulkBps(): Boolean = bulkBps != null + fun isPackage(): Boolean = package_ != null - fun isBulk(): Boolean = bulk != null + fun isMatrix(): Boolean = matrix != null fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null fun isTieredPackage(): Boolean = tieredPackage != null - fun isGroupedTiered(): Boolean = groupedTiered != null - fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null + fun isGroupedTiered(): Boolean = groupedTiered != null + fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null fun isPackageWithAllocation(): Boolean = packageWithAllocation != null @@ -175,13 +178,15 @@ private constructor( fun isGroupedAllocation(): Boolean = groupedAllocation != null + fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null - fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null @@ -193,33 +198,35 @@ private constructor( fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null - fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null - fun asUnit(): Unit = unit.getOrThrow("unit") + fun isMinimum(): Boolean = minimum != null - fun asPackage(): Package = package_.getOrThrow("package_") + fun isPercent(): Boolean = percent != null - fun asMatrix(): Matrix = matrix.getOrThrow("matrix") + fun isEventOutput(): Boolean = eventOutput != null + + fun asUnit(): UnitPrice = unit.getOrThrow("unit") fun asTiered(): Tiered = tiered.getOrThrow("tiered") - fun asTieredBps(): TieredBps = tieredBps.getOrThrow("tieredBps") + fun asBulk(): Bulk = bulk.getOrThrow("bulk") - fun asBps(): Bps = bps.getOrThrow("bps") + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") - fun asBulkBps(): BulkBps = bulkBps.getOrThrow("bulkBps") + fun asPackage(): Package = package_.getOrThrow("package_") - fun asBulk(): Bulk = bulk.getOrThrow("bulk") + fun asMatrix(): Matrix = matrix.getOrThrow("matrix") fun asThresholdTotalAmount(): ThresholdTotalAmount = thresholdTotalAmount.getOrThrow("thresholdTotalAmount") fun asTieredPackage(): TieredPackage = tieredPackage.getOrThrow("tieredPackage") - fun asGroupedTiered(): GroupedTiered = groupedTiered.getOrThrow("groupedTiered") - fun asTieredWithMinimum(): TieredWithMinimum = tieredWithMinimum.getOrThrow("tieredWithMinimum") + fun asGroupedTiered(): GroupedTiered = groupedTiered.getOrThrow("groupedTiered") + fun asTieredPackageWithMinimum(): TieredPackageWithMinimum = tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") @@ -238,17 +245,20 @@ private constructor( fun asGroupedAllocation(): GroupedAllocation = groupedAllocation.getOrThrow("groupedAllocation") + fun asBulkWithProration(): BulkWithProration = bulkWithProration.getOrThrow("bulkWithProration") + fun asGroupedWithProratedMinimum(): GroupedWithProratedMinimum = groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") fun asGroupedWithMeteredMinimum(): GroupedWithMeteredMinimum = groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") + fun asMatrixWithDisplayName(): MatrixWithDisplayName = matrixWithDisplayName.getOrThrow("matrixWithDisplayName") - fun asBulkWithProration(): BulkWithProration = bulkWithProration.getOrThrow("bulkWithProration") - fun asGroupedTieredPackage(): GroupedTieredPackage = groupedTieredPackage.getOrThrow("groupedTieredPackage") @@ -264,25 +274,29 @@ private constructor( fun asCumulativeGroupedBulk(): CumulativeGroupedBulk = cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") - fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = - groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") + + fun asMinimum(): Minimum = minimum.getOrThrow("minimum") + + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") fun _json(): JsonValue? = _json fun accept(visitor: Visitor): T = when { unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) thresholdTotalAmount != null -> visitor.visitThresholdTotalAmount(thresholdTotalAmount) tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) tieredPackageWithMinimum != null -> visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) packageWithAllocation != null -> @@ -292,13 +306,15 @@ private constructor( tieredWithProration != null -> visitor.visitTieredWithProration(tieredWithProration) unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedWithProratedMinimum != null -> visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) groupedWithMeteredMinimum != null -> visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) matrixWithDisplayName != null -> visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedTieredPackage != null -> visitor.visitGroupedTieredPackage(groupedTieredPackage) maxGroupTieredPackage != null -> visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) @@ -308,8 +324,11 @@ private constructor( visitor.visitScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing) cumulativeGroupedBulk != null -> visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) - groupedWithMinMaxThresholds != null -> - visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) else -> visitor.unknown(_json) } @@ -321,37 +340,29 @@ private constructor( } accept( - object : Visitor { - override fun visitUnit(unit: Unit) { + object : Visitor { + override fun visitUnit(unit: UnitPrice) { unit.validate() } - override fun visitPackage(package_: Package) { - package_.validate() - } - - override fun visitMatrix(matrix: Matrix) { - matrix.validate() - } - override fun visitTiered(tiered: Tiered) { tiered.validate() } - override fun visitTieredBps(tieredBps: TieredBps) { - tieredBps.validate() + override fun visitBulk(bulk: Bulk) { + bulk.validate() } - override fun visitBps(bps: Bps) { - bps.validate() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() } - override fun visitBulkBps(bulkBps: BulkBps) { - bulkBps.validate() + override fun visitPackage(package_: Package) { + package_.validate() } - override fun visitBulk(bulk: Bulk) { - bulk.validate() + override fun visitMatrix(matrix: Matrix) { + matrix.validate() } override fun visitThresholdTotalAmount(thresholdTotalAmount: ThresholdTotalAmount) { @@ -362,14 +373,14 @@ private constructor( tieredPackage.validate() } - override fun visitGroupedTiered(groupedTiered: GroupedTiered) { - groupedTiered.validate() - } - override fun visitTieredWithMinimum(tieredWithMinimum: TieredWithMinimum) { tieredWithMinimum.validate() } + override fun visitGroupedTiered(groupedTiered: GroupedTiered) { + groupedTiered.validate() + } + override fun visitTieredPackageWithMinimum( tieredPackageWithMinimum: TieredPackageWithMinimum ) { @@ -402,6 +413,10 @@ private constructor( groupedAllocation.validate() } + override fun visitBulkWithProration(bulkWithProration: BulkWithProration) { + bulkWithProration.validate() + } + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: GroupedWithProratedMinimum ) { @@ -414,16 +429,18 @@ private constructor( groupedWithMeteredMinimum.validate() } + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) { + groupedWithMinMaxThresholds.validate() + } + override fun visitMatrixWithDisplayName( matrixWithDisplayName: MatrixWithDisplayName ) { matrixWithDisplayName.validate() } - override fun visitBulkWithProration(bulkWithProration: BulkWithProration) { - bulkWithProration.validate() - } - override fun visitGroupedTieredPackage(groupedTieredPackage: GroupedTieredPackage) { groupedTieredPackage.validate() } @@ -452,10 +469,22 @@ private constructor( cumulativeGroupedBulk.validate() } - override fun visitGroupedWithMinMaxThresholds( - groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation ) { - groupedWithMinMaxThresholds.validate() + cumulativeGroupedAllocation.validate() + } + + override fun visitMinimum(minimum: Minimum) { + minimum.validate() + } + + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() } } ) @@ -478,21 +507,18 @@ private constructor( internal fun validity(): Int = accept( object : Visitor { - override fun visitUnit(unit: Unit) = unit.validity() - - override fun visitPackage(package_: Package) = package_.validity() - - override fun visitMatrix(matrix: Matrix) = matrix.validity() + override fun visitUnit(unit: UnitPrice) = unit.validity() override fun visitTiered(tiered: Tiered) = tiered.validity() - override fun visitTieredBps(tieredBps: TieredBps) = tieredBps.validity() + override fun visitBulk(bulk: Bulk) = bulk.validity() - override fun visitBps(bps: Bps) = bps.validity() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() - override fun visitBulkBps(bulkBps: BulkBps) = bulkBps.validity() + override fun visitPackage(package_: Package) = package_.validity() - override fun visitBulk(bulk: Bulk) = bulk.validity() + override fun visitMatrix(matrix: Matrix) = matrix.validity() override fun visitThresholdTotalAmount(thresholdTotalAmount: ThresholdTotalAmount) = thresholdTotalAmount.validity() @@ -500,12 +526,12 @@ private constructor( override fun visitTieredPackage(tieredPackage: TieredPackage) = tieredPackage.validity() - override fun visitGroupedTiered(groupedTiered: GroupedTiered) = - groupedTiered.validity() - override fun visitTieredWithMinimum(tieredWithMinimum: TieredWithMinimum) = tieredWithMinimum.validity() + override fun visitGroupedTiered(groupedTiered: GroupedTiered) = + groupedTiered.validity() + override fun visitTieredPackageWithMinimum( tieredPackageWithMinimum: TieredPackageWithMinimum ) = tieredPackageWithMinimum.validity() @@ -529,6 +555,9 @@ private constructor( override fun visitGroupedAllocation(groupedAllocation: GroupedAllocation) = groupedAllocation.validity() + override fun visitBulkWithProration(bulkWithProration: BulkWithProration) = + bulkWithProration.validity() + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: GroupedWithProratedMinimum ) = groupedWithProratedMinimum.validity() @@ -537,13 +566,14 @@ private constructor( groupedWithMeteredMinimum: GroupedWithMeteredMinimum ) = groupedWithMeteredMinimum.validity() + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + override fun visitMatrixWithDisplayName( matrixWithDisplayName: MatrixWithDisplayName ) = matrixWithDisplayName.validity() - override fun visitBulkWithProration(bulkWithProration: BulkWithProration) = - bulkWithProration.validity() - override fun visitGroupedTieredPackage(groupedTieredPackage: GroupedTieredPackage) = groupedTieredPackage.validity() @@ -563,9 +593,15 @@ private constructor( cumulativeGroupedBulk: CumulativeGroupedBulk ) = cumulativeGroupedBulk.validity() - override fun visitGroupedWithMinMaxThresholds( - groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds - ) = groupedWithMinMaxThresholds.validity() + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() + + override fun visitMinimum(minimum: Minimum) = minimum.validity() + + override fun visitPercent(percent: Percent) = percent.validity() + + override fun visitEventOutput(eventOutput: EventOutput) = eventOutput.validity() override fun unknown(json: JsonValue?) = 0 } @@ -576,25 +612,87 @@ private constructor( return true } - return /* spotless:off */ other is Price && unit == other.unit && package_ == other.package_ && matrix == other.matrix && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && groupedTiered == other.groupedTiered && tieredWithMinimum == other.tieredWithMinimum && tieredPackageWithMinimum == other.tieredPackageWithMinimum && packageWithAllocation == other.packageWithAllocation && unitWithPercent == other.unitWithPercent && matrixWithAllocation == other.matrixWithAllocation && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && bulkWithProration == other.bulkWithProration && groupedTieredPackage == other.groupedTieredPackage && maxGroupTieredPackage == other.maxGroupTieredPackage && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk && groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds /* spotless:on */ + return other is Price && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, groupedTiered, tieredWithMinimum, tieredPackageWithMinimum, packageWithAllocation, unitWithPercent, matrixWithAllocation, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, groupedWithMeteredMinimum, matrixWithDisplayName, bulkWithProration, groupedTieredPackage, maxGroupTieredPackage, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk, groupedWithMinMaxThresholds) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) override fun toString(): String = when { unit != null -> "Price{unit=$unit}" - package_ != null -> "Price{package_=$package_}" - matrix != null -> "Price{matrix=$matrix}" tiered != null -> "Price{tiered=$tiered}" - tieredBps != null -> "Price{tieredBps=$tieredBps}" - bps != null -> "Price{bps=$bps}" - bulkBps != null -> "Price{bulkBps=$bulkBps}" bulk != null -> "Price{bulk=$bulk}" + bulkWithFilters != null -> "Price{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "Price{package_=$package_}" + matrix != null -> "Price{matrix=$matrix}" thresholdTotalAmount != null -> "Price{thresholdTotalAmount=$thresholdTotalAmount}" tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" - groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" + groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" tieredPackageWithMinimum != null -> "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" packageWithAllocation != null -> "Price{packageWithAllocation=$packageWithAllocation}" @@ -603,12 +701,14 @@ private constructor( tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedWithProratedMinimum != null -> "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" groupedWithMeteredMinimum != null -> "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "Price{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" matrixWithDisplayName != null -> "Price{matrixWithDisplayName=$matrixWithDisplayName}" - bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedTieredPackage != null -> "Price{groupedTieredPackage=$groupedTieredPackage}" maxGroupTieredPackage != null -> "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" scalableMatrixWithUnitPricing != null -> @@ -616,40 +716,40 @@ private constructor( scalableMatrixWithTieredPricing != null -> "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" cumulativeGroupedBulk != null -> "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" - groupedWithMinMaxThresholds != null -> - "Price{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" + cumulativeGroupedAllocation != null -> + "Price{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "Price{minimum=$minimum}" + percent != null -> "Price{percent=$percent}" + eventOutput != null -> "Price{eventOutput=$eventOutput}" _json != null -> "Price{_unknown=$_json}" else -> throw IllegalStateException("Invalid Price") } companion object { - fun ofUnit(unit: Unit) = Price(unit = unit) - - fun ofPackage(package_: Package) = Price(package_ = package_) - - fun ofMatrix(matrix: Matrix) = Price(matrix = matrix) + fun ofUnit(unit: UnitPrice) = Price(unit = unit) fun ofTiered(tiered: Tiered) = Price(tiered = tiered) - fun ofTieredBps(tieredBps: TieredBps) = Price(tieredBps = tieredBps) + fun ofBulk(bulk: Bulk) = Price(bulk = bulk) - fun ofBps(bps: Bps) = Price(bps = bps) + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + Price(bulkWithFilters = bulkWithFilters) - fun ofBulkBps(bulkBps: BulkBps) = Price(bulkBps = bulkBps) + fun ofPackage(package_: Package) = Price(package_ = package_) - fun ofBulk(bulk: Bulk) = Price(bulk = bulk) + fun ofMatrix(matrix: Matrix) = Price(matrix = matrix) fun ofThresholdTotalAmount(thresholdTotalAmount: ThresholdTotalAmount) = Price(thresholdTotalAmount = thresholdTotalAmount) fun ofTieredPackage(tieredPackage: TieredPackage) = Price(tieredPackage = tieredPackage) - fun ofGroupedTiered(groupedTiered: GroupedTiered) = Price(groupedTiered = groupedTiered) - fun ofTieredWithMinimum(tieredWithMinimum: TieredWithMinimum) = Price(tieredWithMinimum = tieredWithMinimum) + fun ofGroupedTiered(groupedTiered: GroupedTiered) = Price(groupedTiered = groupedTiered) + fun ofTieredPackageWithMinimum(tieredPackageWithMinimum: TieredPackageWithMinimum) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) @@ -671,18 +771,22 @@ private constructor( fun ofGroupedAllocation(groupedAllocation: GroupedAllocation) = Price(groupedAllocation = groupedAllocation) + fun ofBulkWithProration(bulkWithProration: BulkWithProration) = + Price(bulkWithProration = bulkWithProration) + fun ofGroupedWithProratedMinimum(groupedWithProratedMinimum: GroupedWithProratedMinimum) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) fun ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum: GroupedWithMeteredMinimum) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = Price(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + fun ofMatrixWithDisplayName(matrixWithDisplayName: MatrixWithDisplayName) = Price(matrixWithDisplayName = matrixWithDisplayName) - fun ofBulkWithProration(bulkWithProration: BulkWithProration) = - Price(bulkWithProration = bulkWithProration) - fun ofGroupedTieredPackage(groupedTieredPackage: GroupedTieredPackage) = Price(groupedTieredPackage = groupedTieredPackage) @@ -700,38 +804,40 @@ private constructor( fun ofCumulativeGroupedBulk(cumulativeGroupedBulk: CumulativeGroupedBulk) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) - fun ofGroupedWithMinMaxThresholds( - groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds - ) = Price(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = Price(cumulativeGroupedAllocation = cumulativeGroupedAllocation) + + fun ofMinimum(minimum: Minimum) = Price(minimum = minimum) + + fun ofPercent(percent: Percent) = Price(percent = percent) + + fun ofEventOutput(eventOutput: EventOutput) = Price(eventOutput = eventOutput) } /** An interface that defines how to map each variant of [Price] to a value of type [T]. */ interface Visitor { - fun visitUnit(unit: Unit): T - - fun visitPackage(package_: Package): T - - fun visitMatrix(matrix: Matrix): T + fun visitUnit(unit: UnitPrice): T fun visitTiered(tiered: Tiered): T - fun visitTieredBps(tieredBps: TieredBps): T + fun visitBulk(bulk: Bulk): T - fun visitBps(bps: Bps): T + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T - fun visitBulkBps(bulkBps: BulkBps): T + fun visitPackage(package_: Package): T - fun visitBulk(bulk: Bulk): T + fun visitMatrix(matrix: Matrix): T fun visitThresholdTotalAmount(thresholdTotalAmount: ThresholdTotalAmount): T fun visitTieredPackage(tieredPackage: TieredPackage): T - fun visitGroupedTiered(groupedTiered: GroupedTiered): T - fun visitTieredWithMinimum(tieredWithMinimum: TieredWithMinimum): T + fun visitGroupedTiered(groupedTiered: GroupedTiered): T + fun visitTieredPackageWithMinimum(tieredPackageWithMinimum: TieredPackageWithMinimum): T fun visitPackageWithAllocation(packageWithAllocation: PackageWithAllocation): T @@ -746,15 +852,19 @@ private constructor( fun visitGroupedAllocation(groupedAllocation: GroupedAllocation): T + fun visitBulkWithProration(bulkWithProration: BulkWithProration): T + fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: GroupedWithProratedMinimum ): T fun visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum: GroupedWithMeteredMinimum): T - fun visitMatrixWithDisplayName(matrixWithDisplayName: MatrixWithDisplayName): T + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ): T - fun visitBulkWithProration(bulkWithProration: BulkWithProration): T + fun visitMatrixWithDisplayName(matrixWithDisplayName: MatrixWithDisplayName): T fun visitGroupedTieredPackage(groupedTieredPackage: GroupedTieredPackage): T @@ -770,10 +880,16 @@ private constructor( fun visitCumulativeGroupedBulk(cumulativeGroupedBulk: CumulativeGroupedBulk): T - fun visitGroupedWithMinMaxThresholds( - groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation ): T + fun visitMinimum(minimum: Minimum): T + + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T + /** * Maps an unknown variant of [Price] to a value of type [T]. * @@ -796,43 +912,33 @@ private constructor( when (modelType) { "unit" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { + return tryDeserialize(node, jacksonTypeRef())?.let { Price(unit = it, _json = json) } ?: Price(_json = json) } - "package" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(package_ = it, _json = json) - } ?: Price(_json = json) - } - "matrix" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(matrix = it, _json = json) - } ?: Price(_json = json) - } "tiered" -> { return tryDeserialize(node, jacksonTypeRef())?.let { Price(tiered = it, _json = json) } ?: Price(_json = json) } - "tiered_bps" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(tieredBps = it, _json = json) + "bulk" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulk = it, _json = json) } ?: Price(_json = json) } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(bps = it, _json = json) + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulkWithFilters = it, _json = json) } ?: Price(_json = json) } - "bulk_bps" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(bulkBps = it, _json = json) + "package" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(package_ = it, _json = json) } ?: Price(_json = json) } - "bulk" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(bulk = it, _json = json) + "matrix" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(matrix = it, _json = json) } ?: Price(_json = json) } "threshold_total_amount" -> { @@ -845,16 +951,16 @@ private constructor( Price(tieredPackage = it, _json = json) } ?: Price(_json = json) } - "grouped_tiered" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(groupedTiered = it, _json = json) - } ?: Price(_json = json) - } "tiered_with_minimum" -> { return tryDeserialize(node, jacksonTypeRef())?.let { Price(tieredWithMinimum = it, _json = json) } ?: Price(_json = json) } + "grouped_tiered" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(groupedTiered = it, _json = json) + } ?: Price(_json = json) + } "tiered_package_with_minimum" -> { return tryDeserialize(node, jacksonTypeRef())?.let { Price(tieredPackageWithMinimum = it, _json = json) @@ -890,6 +996,11 @@ private constructor( Price(groupedAllocation = it, _json = json) } ?: Price(_json = json) } + "bulk_with_proration" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulkWithProration = it, _json = json) + } ?: Price(_json = json) + } "grouped_with_prorated_minimum" -> { return tryDeserialize(node, jacksonTypeRef())?.let { Price(groupedWithProratedMinimum = it, _json = json) @@ -900,16 +1011,16 @@ private constructor( Price(groupedWithMeteredMinimum = it, _json = json) } ?: Price(_json = json) } + "grouped_with_min_max_thresholds" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(groupedWithMinMaxThresholds = it, _json = json) } + ?: Price(_json = json) + } "matrix_with_display_name" -> { return tryDeserialize(node, jacksonTypeRef())?.let { Price(matrixWithDisplayName = it, _json = json) } ?: Price(_json = json) } - "bulk_with_proration" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Price(bulkWithProration = it, _json = json) - } ?: Price(_json = json) - } "grouped_tiered_package" -> { return tryDeserialize(node, jacksonTypeRef())?.let { Price(groupedTieredPackage = it, _json = json) @@ -935,11 +1046,26 @@ private constructor( Price(cumulativeGroupedBulk = it, _json = json) } ?: Price(_json = json) } - "grouped_with_min_max_thresholds" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(groupedWithMinMaxThresholds = it, _json = json) } + "cumulative_grouped_allocation" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(cumulativeGroupedAllocation = it, _json = json) } ?: Price(_json = json) } + "minimum" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(minimum = it, _json = json) + } ?: Price(_json = json) + } + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(percent = it, _json = json) + } ?: Price(_json = json) + } + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(eventOutput = it, _json = json) + } ?: Price(_json = json) + } } return Price(_json = json) @@ -955,18 +1081,16 @@ private constructor( ) { when { value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) value.thresholdTotalAmount != null -> generator.writeObject(value.thresholdTotalAmount) value.tieredPackage != null -> generator.writeObject(value.tieredPackage) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) value.tieredWithMinimum != null -> generator.writeObject(value.tieredWithMinimum) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) value.tieredPackageWithMinimum != null -> generator.writeObject(value.tieredPackageWithMinimum) value.packageWithAllocation != null -> @@ -978,13 +1102,15 @@ private constructor( generator.writeObject(value.tieredWithProration) value.unitWithProration != null -> generator.writeObject(value.unitWithProration) value.groupedAllocation != null -> generator.writeObject(value.groupedAllocation) + value.bulkWithProration != null -> generator.writeObject(value.bulkWithProration) value.groupedWithProratedMinimum != null -> generator.writeObject(value.groupedWithProratedMinimum) value.groupedWithMeteredMinimum != null -> generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) value.matrixWithDisplayName != null -> generator.writeObject(value.matrixWithDisplayName) - value.bulkWithProration != null -> generator.writeObject(value.bulkWithProration) value.groupedTieredPackage != null -> generator.writeObject(value.groupedTieredPackage) value.maxGroupTieredPackage != null -> @@ -995,20 +1121,26 @@ private constructor( generator.writeObject(value.scalableMatrixWithTieredPricing) value.cumulativeGroupedBulk != null -> generator.writeObject(value.cumulativeGroupedBulk) - value.groupedWithMinMaxThresholds != null -> - generator.writeObject(value.groupedWithMinMaxThresholds) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Price") } } } - class Unit + class UnitPrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -1043,7 +1175,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -1105,7 +1243,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -1150,12 +1290,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1213,6 +1366,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -1255,6 +1411,8 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin * JsonValue.from("unit") @@ -1293,6 +1451,8 @@ private constructor( fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") /** + * Configuration for unit pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -1333,6 +1493,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -1340,6 +1509,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -1554,14 +1733,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [Unit]. + * Returns a mutable builder for constructing an instance of [UnitPrice]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -1587,13 +1768,15 @@ private constructor( fun builder() = Builder() } - /** A builder for [Unit]. */ + /** A builder for [UnitPrice]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -1619,34 +1802,36 @@ private constructor( JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(unit: Unit) = apply { - id = unit.id - billableMetric = unit.billableMetric - billingCycleConfiguration = unit.billingCycleConfiguration - cadence = unit.cadence - conversionRate = unit.conversionRate - conversionRateConfig = unit.conversionRateConfig - createdAt = unit.createdAt - creditAllocation = unit.creditAllocation - currency = unit.currency - discount = unit.discount - externalPriceId = unit.externalPriceId - fixedPriceQuantity = unit.fixedPriceQuantity - invoicingCycleConfiguration = unit.invoicingCycleConfiguration - item = unit.item - maximum = unit.maximum - maximumAmount = unit.maximumAmount - metadata = unit.metadata - minimum = unit.minimum - minimumAmount = unit.minimumAmount - modelType = unit.modelType - name = unit.name - planPhaseOrder = unit.planPhaseOrder - priceType = unit.priceType - replacesPriceId = unit.replacesPriceId - unitConfig = unit.unitConfig - dimensionalPriceConfiguration = unit.dimensionalPriceConfiguration - additionalProperties = unit.additionalProperties.toMutableMap() + internal fun from(unitPrice: UnitPrice) = apply { + id = unitPrice.id + billableMetric = unitPrice.billableMetric + billingCycleConfiguration = unitPrice.billingCycleConfiguration + billingMode = unitPrice.billingMode + cadence = unitPrice.cadence + compositePriceFilters = unitPrice.compositePriceFilters.map { it.toMutableList() } + conversionRate = unitPrice.conversionRate + conversionRateConfig = unitPrice.conversionRateConfig + createdAt = unitPrice.createdAt + creditAllocation = unitPrice.creditAllocation + currency = unitPrice.currency + discount = unitPrice.discount + externalPriceId = unitPrice.externalPriceId + fixedPriceQuantity = unitPrice.fixedPriceQuantity + invoicingCycleConfiguration = unitPrice.invoicingCycleConfiguration + item = unitPrice.item + maximum = unitPrice.maximum + maximumAmount = unitPrice.maximumAmount + metadata = unitPrice.metadata + minimum = unitPrice.minimum + minimumAmount = unitPrice.minimumAmount + modelType = unitPrice.modelType + name = unitPrice.name + planPhaseOrder = unitPrice.planPhaseOrder + priceType = unitPrice.priceType + replacesPriceId = unitPrice.replacesPriceId + unitConfig = unitPrice.unitConfig + dimensionalPriceConfiguration = unitPrice.dimensionalPriceConfiguration + additionalProperties = unitPrice.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -1688,6 +1873,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -1699,6 +1897,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -1955,6 +2181,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -2115,6 +2345,7 @@ private constructor( this.replacesPriceId = replacesPriceId } + /** Configuration for unit pricing */ fun unitConfig(unitConfig: UnitConfig) = unitConfig(JsonField.of(unitConfig)) /** @@ -2163,7 +2394,7 @@ private constructor( } /** - * Returns an immutable instance of [Unit]. + * Returns an immutable instance of [UnitPrice]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -2172,7 +2403,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -2197,12 +2430,16 @@ private constructor( * * @throws IllegalStateException if any required field is unset. */ - fun build(): Unit = - Unit( + fun build(): UnitPrice = + UnitPrice( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -2231,7 +2468,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Unit = apply { + fun validate(): UnitPrice = apply { if (validated) { return@apply } @@ -2239,7 +2476,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -2287,7 +2526,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -2311,6 +2552,135 @@ private constructor( (unitConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2455,7 +2825,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -2463,211 +2833,577 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") /** - * Returns a score indicating how many valid values are contained in this object - * recursively. + * The IDs or values that match this filter. * - * Used for best match union deserialization. + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + fun values(): List = values.getRequired("values") - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + fun toBuilder() = Builder().from(this) companion object { - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } + fun builder() = Builder() } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - return ConversionRateConfig(_json = json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { - - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - /** - * User specified key-value pairs for the resource. If not present, this defaults to an - * empty dictionary. Individual keys can be removed by setting the value to `null`, and the - * entire metadata mapping can be cleared by setting `metadata` to `null`. - */ - class Metadata - @JsonCreator - private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map - ) { - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun toBuilder() = Builder().from(this) + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } - companion object { + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) - /** Returns a mutable builder for constructing an instance of [Metadata]. */ - fun builder() = Builder() - } + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } - /** A builder for [Metadata]. */ - class Builder internal constructor() { + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.additionalProperties.toMutableMap() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and the + * entire metadata mapping can be cleared by setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() } fun additionalProperties(additionalProperties: Map) = apply { @@ -2732,12 +3468,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2763,6 +3497,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -2770,6 +3506,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -2784,6 +3521,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -2802,6 +3540,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -2818,6 +3557,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -2865,7 +3605,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -2878,25 +3618,87 @@ private constructor( return true } - return /* spotless:off */ other is Unit && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && unitConfig == other.unitConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UnitPrice && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + unitConfig == other.unitConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, unitConfig, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + unitConfig, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Unit{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, unitConfig=$unitConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "UnitPrice{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, unitConfig=$unitConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class Package + class Tiered + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -2914,10 +3716,10 @@ private constructor( private val minimumAmount: JsonField, private val modelType: JsonValue, private val name: JsonField, - private val packageConfig: JsonField, private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, + private val tieredConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -2931,7 +3733,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -2973,9 +3781,6 @@ private constructor( minimumAmount: JsonField = JsonMissing.of(), @JsonProperty("model_type") @ExcludeMissing modelType: JsonValue = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("package_config") - @ExcludeMissing - packageConfig: JsonField = JsonMissing.of(), @JsonProperty("plan_phase_order") @ExcludeMissing planPhaseOrder: JsonField = JsonMissing.of(), @@ -2985,6 +3790,9 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), + @JsonProperty("tiered_config") + @ExcludeMissing + tieredConfig: JsonField = JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -2993,7 +3801,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -3011,10 +3821,10 @@ private constructor( minimumAmount, modelType, name, - packageConfig, planPhaseOrder, priceType, replacesPriceId, + tieredConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -3038,12 +3848,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -3101,6 +3924,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -3143,9 +3969,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("package") + * JsonValue.from("tiered") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -3159,12 +3987,6 @@ private constructor( */ fun name(): String = name.getRequired("name") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun packageConfig(): PackageConfig = packageConfig.getRequired("package_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -3186,6 +4008,14 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") + /** + * Configuration for tiered pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tieredConfig(): TieredConfig = tieredConfig.getRequired("tiered_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -3221,6 +4051,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -3228,6 +4067,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -3378,16 +4227,6 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - /** - * Returns the raw JSON value of [packageConfig]. - * - * Unlike [packageConfig], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("package_config") - @ExcludeMissing - fun _packageConfig(): JsonField = packageConfig - /** * Returns the raw JSON value of [planPhaseOrder]. * @@ -3417,6 +4256,16 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId + /** + * Returns the raw JSON value of [tieredConfig]. + * + * Unlike [tieredConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tiered_config") + @ExcludeMissing + fun _tieredConfig(): JsonField = tieredConfig + /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -3443,14 +4292,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [Package]. + * Returns a mutable builder for constructing an instance of [Tiered]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -3467,22 +4318,24 @@ private constructor( * .minimum() * .minimumAmount() * .name() - * .packageConfig() * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .tieredConfig() * ``` */ fun builder() = Builder() } - /** A builder for [Package]. */ + /** A builder for [Tiered]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -3498,44 +4351,46 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("package") + private var modelType: JsonValue = JsonValue.from("tiered") private var name: JsonField? = null - private var packageConfig: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null + private var tieredConfig: JsonField? = null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(package_: Package) = apply { - id = package_.id - billableMetric = package_.billableMetric - billingCycleConfiguration = package_.billingCycleConfiguration - cadence = package_.cadence - conversionRate = package_.conversionRate - conversionRateConfig = package_.conversionRateConfig - createdAt = package_.createdAt - creditAllocation = package_.creditAllocation - currency = package_.currency - discount = package_.discount - externalPriceId = package_.externalPriceId - fixedPriceQuantity = package_.fixedPriceQuantity - invoicingCycleConfiguration = package_.invoicingCycleConfiguration - item = package_.item - maximum = package_.maximum - maximumAmount = package_.maximumAmount - metadata = package_.metadata - minimum = package_.minimum - minimumAmount = package_.minimumAmount - modelType = package_.modelType - name = package_.name - packageConfig = package_.packageConfig - planPhaseOrder = package_.planPhaseOrder - priceType = package_.priceType - replacesPriceId = package_.replacesPriceId - dimensionalPriceConfiguration = package_.dimensionalPriceConfiguration - additionalProperties = package_.additionalProperties.toMutableMap() + internal fun from(tiered: Tiered) = apply { + id = tiered.id + billableMetric = tiered.billableMetric + billingCycleConfiguration = tiered.billingCycleConfiguration + billingMode = tiered.billingMode + cadence = tiered.cadence + compositePriceFilters = tiered.compositePriceFilters.map { it.toMutableList() } + conversionRate = tiered.conversionRate + conversionRateConfig = tiered.conversionRateConfig + createdAt = tiered.createdAt + creditAllocation = tiered.creditAllocation + currency = tiered.currency + discount = tiered.discount + externalPriceId = tiered.externalPriceId + fixedPriceQuantity = tiered.fixedPriceQuantity + invoicingCycleConfiguration = tiered.invoicingCycleConfiguration + item = tiered.item + maximum = tiered.maximum + maximumAmount = tiered.maximumAmount + metadata = tiered.metadata + minimum = tiered.minimum + minimumAmount = tiered.minimumAmount + modelType = tiered.modelType + name = tiered.name + planPhaseOrder = tiered.planPhaseOrder + priceType = tiered.priceType + replacesPriceId = tiered.replacesPriceId + tieredConfig = tiered.tieredConfig + dimensionalPriceConfiguration = tiered.dimensionalPriceConfiguration + additionalProperties = tiered.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -3577,6 +4432,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -3588,6 +4456,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -3844,6 +4740,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -3935,7 +4835,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("package") + * JsonValue.from("tiered") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -3954,20 +4854,6 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } - fun packageConfig(packageConfig: PackageConfig) = - packageConfig(JsonField.of(packageConfig)) - - /** - * Sets [Builder.packageConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.packageConfig] with a well-typed [PackageConfig] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun packageConfig(packageConfig: JsonField) = apply { - this.packageConfig = packageConfig - } - fun planPhaseOrder(planPhaseOrder: Long?) = planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) @@ -4018,6 +4904,20 @@ private constructor( this.replacesPriceId = replacesPriceId } + /** Configuration for tiered pricing */ + fun tieredConfig(tieredConfig: TieredConfig) = tieredConfig(JsonField.of(tieredConfig)) + + /** + * Sets [Builder.tieredConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.tieredConfig] with a well-typed [TieredConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tieredConfig(tieredConfig: JsonField) = apply { + this.tieredConfig = tieredConfig + } + fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -4053,7 +4953,7 @@ private constructor( } /** - * Returns an immutable instance of [Package]. + * Returns an immutable instance of [Tiered]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -4062,7 +4962,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -4079,20 +4981,24 @@ private constructor( * .minimum() * .minimumAmount() * .name() - * .packageConfig() * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .tieredConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): Package = - Package( + fun build(): Tiered = + Tiered( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -4110,10 +5016,10 @@ private constructor( checkRequired("minimumAmount", minimumAmount), modelType, checkRequired("name", name), - checkRequired("packageConfig", packageConfig), checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), + checkRequired("tieredConfig", tieredConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -4121,7 +5027,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Package = apply { + fun validate(): Tiered = apply { if (validated) { return@apply } @@ -4129,7 +5035,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -4146,15 +5054,15 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("package")) { + if (it != JsonValue.from("tiered")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } name() - packageConfig().validate() planPhaseOrder() priceType().validate() replacesPriceId() + tieredConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -4177,7 +5085,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -4193,14 +5103,143 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("package")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("tiered")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + - (packageConfig.asKnown()?.validity() ?: 0) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (tieredConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -4345,7 +5384,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -4353,54 +5392,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun tiered(): TieredConversionRateConfig? = tiered + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") - fun isUnit(): Boolean = unit != null + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") - fun isTiered(): Boolean = tiered != null + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @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 [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -4419,112 +5628,308 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + private var validated: Boolean = false - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() - fun visitUnit(unit: UnitConversionRateConfig): T + override fun toString() = value.toString() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + private var validated: Boolean = false - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } /** @@ -4622,12 +6027,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -4653,6 +6056,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -4660,6 +6065,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -4674,6 +6080,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -4692,6 +6099,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -4708,6 +6116,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -4755,7 +6164,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -4768,25 +6177,88 @@ private constructor( return true } - return /* spotless:off */ other is Package && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && packageConfig == other.packageConfig && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Tiered && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + tieredConfig == other.tieredConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, packageConfig, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + tieredConfig, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Package{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, packageConfig=$packageConfig, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "Tiered{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, tieredConfig=$tieredConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class Matrix + class Bulk + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, + private val bulkConfig: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -4797,7 +6269,6 @@ private constructor( private val fixedPriceQuantity: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, - private val matrixConfig: JsonField, private val maximum: JsonField, private val maximumAmount: JsonField, private val metadata: JsonField, @@ -4821,7 +6292,16 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), + @JsonProperty("bulk_config") + @ExcludeMissing + bulkConfig: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -4850,9 +6330,6 @@ private constructor( @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @JsonProperty("item") @ExcludeMissing item: JsonField = JsonMissing.of(), - @JsonProperty("matrix_config") - @ExcludeMissing - matrixConfig: JsonField = JsonMissing.of(), @JsonProperty("maximum") @ExcludeMissing maximum: JsonField = JsonMissing.of(), @JsonProperty("maximum_amount") @ExcludeMissing @@ -4883,7 +6360,10 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, + bulkConfig, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -4894,7 +6374,6 @@ private constructor( fixedPriceQuantity, invoicingCycleConfiguration, item, - matrixConfig, maximum, maximumAmount, metadata, @@ -4928,12 +6407,33 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + + /** + * Configuration for bulk pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun bulkConfig(): BulkConfig = bulkConfig.getRequired("bulk_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -4991,17 +6491,14 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun item(): ItemSlim = item.getRequired("item") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun matrixConfig(): MatrixConfig = matrixConfig.getRequired("matrix_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -5039,9 +6536,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("matrix") + * JsonValue.from("bulk") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -5111,6 +6610,24 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + + /** + * Returns the raw JSON value of [bulkConfig]. + * + * Unlike [bulkConfig], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("bulk_config") + @ExcludeMissing + fun _bulkConfig(): JsonField = bulkConfig + /** * Returns the raw JSON value of [cadence]. * @@ -5118,6 +6635,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -5212,16 +6739,6 @@ private constructor( */ @JsonProperty("item") @ExcludeMissing fun _item(): JsonField = item - /** - * Returns the raw JSON value of [matrixConfig]. - * - * Unlike [matrixConfig], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("matrix_config") - @ExcludeMissing - fun _matrixConfig(): JsonField = matrixConfig - /** * Returns the raw JSON value of [maximum]. * @@ -5333,14 +6850,17 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [Matrix]. + * Returns a mutable builder for constructing an instance of [Bulk]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() + * .bulkConfig() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -5351,7 +6871,6 @@ private constructor( * .fixedPriceQuantity() * .invoicingCycleConfiguration() * .item() - * .matrixConfig() * .maximum() * .maximumAmount() * .metadata() @@ -5366,13 +6885,16 @@ private constructor( fun builder() = Builder() } - /** A builder for [Matrix]. */ + /** A builder for [Bulk]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null + private var bulkConfig: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -5383,13 +6905,12 @@ private constructor( private var fixedPriceQuantity: JsonField? = null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null - private var matrixConfig: JsonField? = null private var maximum: JsonField? = null private var maximumAmount: JsonField? = null private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("matrix") + private var modelType: JsonValue = JsonValue.from("bulk") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null @@ -5398,34 +6919,36 @@ private constructor( JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(matrix: Matrix) = apply { - id = matrix.id - billableMetric = matrix.billableMetric - billingCycleConfiguration = matrix.billingCycleConfiguration - cadence = matrix.cadence - conversionRate = matrix.conversionRate - conversionRateConfig = matrix.conversionRateConfig - createdAt = matrix.createdAt - creditAllocation = matrix.creditAllocation - currency = matrix.currency - discount = matrix.discount - externalPriceId = matrix.externalPriceId - fixedPriceQuantity = matrix.fixedPriceQuantity - invoicingCycleConfiguration = matrix.invoicingCycleConfiguration - item = matrix.item - matrixConfig = matrix.matrixConfig - maximum = matrix.maximum - maximumAmount = matrix.maximumAmount - metadata = matrix.metadata - minimum = matrix.minimum - minimumAmount = matrix.minimumAmount - modelType = matrix.modelType - name = matrix.name - planPhaseOrder = matrix.planPhaseOrder - priceType = matrix.priceType - replacesPriceId = matrix.replacesPriceId - dimensionalPriceConfiguration = matrix.dimensionalPriceConfiguration - additionalProperties = matrix.additionalProperties.toMutableMap() + internal fun from(bulk: Bulk) = apply { + id = bulk.id + billableMetric = bulk.billableMetric + billingCycleConfiguration = bulk.billingCycleConfiguration + billingMode = bulk.billingMode + bulkConfig = bulk.bulkConfig + cadence = bulk.cadence + compositePriceFilters = bulk.compositePriceFilters.map { it.toMutableList() } + conversionRate = bulk.conversionRate + conversionRateConfig = bulk.conversionRateConfig + createdAt = bulk.createdAt + creditAllocation = bulk.creditAllocation + currency = bulk.currency + discount = bulk.discount + externalPriceId = bulk.externalPriceId + fixedPriceQuantity = bulk.fixedPriceQuantity + invoicingCycleConfiguration = bulk.invoicingCycleConfiguration + item = bulk.item + maximum = bulk.maximum + maximumAmount = bulk.maximumAmount + metadata = bulk.metadata + minimum = bulk.minimum + minimumAmount = bulk.minimumAmount + modelType = bulk.modelType + name = bulk.name + planPhaseOrder = bulk.planPhaseOrder + priceType = bulk.priceType + replacesPriceId = bulk.replacesPriceId + dimensionalPriceConfiguration = bulk.dimensionalPriceConfiguration + additionalProperties = bulk.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -5467,6 +6990,33 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + + /** Configuration for bulk pricing */ + fun bulkConfig(bulkConfig: BulkConfig) = bulkConfig(JsonField.of(bulkConfig)) + + /** + * Sets [Builder.bulkConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkConfig] with a well-typed [BulkConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun bulkConfig(bulkConfig: JsonField) = apply { + this.bulkConfig = bulkConfig + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -5478,6 +7028,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -5734,6 +7312,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -5745,19 +7327,6 @@ private constructor( */ fun item(item: JsonField) = apply { this.item = item } - fun matrixConfig(matrixConfig: MatrixConfig) = matrixConfig(JsonField.of(matrixConfig)) - - /** - * Sets [Builder.matrixConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.matrixConfig] with a well-typed [MatrixConfig] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun matrixConfig(matrixConfig: JsonField) = apply { - this.matrixConfig = matrixConfig - } - @Deprecated("deprecated") fun maximum(maximum: Maximum?) = maximum(JsonField.ofNullable(maximum)) @@ -5838,7 +7407,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("matrix") + * JsonValue.from("bulk") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -5942,7 +7511,7 @@ private constructor( } /** - * Returns an immutable instance of [Matrix]. + * Returns an immutable instance of [Bulk]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -5951,7 +7520,10 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() + * .bulkConfig() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -5962,7 +7534,6 @@ private constructor( * .fixedPriceQuantity() * .invoicingCycleConfiguration() * .item() - * .matrixConfig() * .maximum() * .maximumAmount() * .metadata() @@ -5976,12 +7547,17 @@ private constructor( * * @throws IllegalStateException if any required field is unset. */ - fun build(): Matrix = - Matrix( + fun build(): Bulk = + Bulk( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), + checkRequired("bulkConfig", bulkConfig), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -5992,7 +7568,6 @@ private constructor( checkRequired("fixedPriceQuantity", fixedPriceQuantity), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), - checkRequired("matrixConfig", matrixConfig), checkRequired("maximum", maximum), checkRequired("maximumAmount", maximumAmount), checkRequired("metadata", metadata), @@ -6010,7 +7585,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Matrix = apply { + fun validate(): Bulk = apply { if (validated) { return@apply } @@ -6018,7 +7593,10 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() + bulkConfig().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -6029,14 +7607,13 @@ private constructor( fixedPriceQuantity() invoicingCycleConfiguration()?.validate() item().validate() - matrixConfig().validate() maximum()?.validate() maximumAmount() metadata().validate() minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("matrix")) { + if (it != JsonValue.from("bulk")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -6066,7 +7643,10 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + + (bulkConfig.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -6077,19 +7657,147 @@ private constructor( (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + - (matrixConfig.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + (if (maximumAmount.asKnown() == null) 0 else 1) + (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("matrix")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("bulk")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -6234,7 +7942,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -6242,54 +7950,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun tiered(): TieredConversionRateConfig? = tiered + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") - fun isUnit(): Boolean = unit != null + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") - fun isTiered(): Boolean = tiered != null + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @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 [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -6308,112 +8186,308 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + private var validated: Boolean = false - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() - fun visitUnit(unit: UnitConversionRateConfig): T + override fun toString() = value.toString() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + private var validated: Boolean = false - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } /** @@ -6511,12 +8585,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -6542,6 +8614,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -6549,6 +8623,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -6563,6 +8638,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -6581,6 +8657,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -6597,6 +8674,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -6644,7 +8722,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -6657,25 +8735,88 @@ private constructor( return true } - return /* spotless:off */ other is Matrix && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && matrixConfig == other.matrixConfig && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Bulk && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + bulkConfig == other.bulkConfig && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, matrixConfig, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + bulkConfig, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Matrix{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, matrixConfig=$matrixConfig, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "Bulk{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, bulkConfig=$bulkConfig, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class Tiered + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, + private val bulkWithFiltersConfig: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -6696,7 +8837,6 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, - private val tieredConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -6710,7 +8850,16 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -6761,9 +8910,6 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("tiered_config") - @ExcludeMissing - tieredConfig: JsonField = JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -6772,7 +8918,10 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, + bulkWithFiltersConfig, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -6793,7 +8942,6 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, - tieredConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -6817,12 +8965,34 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -6880,6 +9050,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -6922,9 +9095,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("tiered") + * JsonValue.from("bulk_with_filters") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -6959,12 +9134,6 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun tieredConfig(): TieredConfig = tieredConfig.getRequired("tiered_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -7000,6 +9169,25 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = bulkWithFiltersConfig + /** * Returns the raw JSON value of [cadence]. * @@ -7007,6 +9195,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -7186,16 +9384,6 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId - /** - * Returns the raw JSON value of [tieredConfig]. - * - * Unlike [tieredConfig], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("tiered_config") - @ExcludeMissing - fun _tieredConfig(): JsonField = tieredConfig - /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -7222,14 +9410,17 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [Tiered]. + * Returns a mutable builder for constructing an instance of [BulkWithFilters]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() + * .bulkWithFiltersConfig() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -7249,19 +9440,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .tieredConfig() * ``` */ fun builder() = Builder() } - /** A builder for [Tiered]. */ + /** A builder for [BulkWithFilters]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null + private var bulkWithFiltersConfig: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -7277,44 +9470,46 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("tiered") + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null - private var tieredConfig: JsonField? = null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(tiered: Tiered) = apply { - id = tiered.id - billableMetric = tiered.billableMetric - billingCycleConfiguration = tiered.billingCycleConfiguration - cadence = tiered.cadence - conversionRate = tiered.conversionRate - conversionRateConfig = tiered.conversionRateConfig - createdAt = tiered.createdAt - creditAllocation = tiered.creditAllocation - currency = tiered.currency - discount = tiered.discount - externalPriceId = tiered.externalPriceId - fixedPriceQuantity = tiered.fixedPriceQuantity - invoicingCycleConfiguration = tiered.invoicingCycleConfiguration - item = tiered.item - maximum = tiered.maximum - maximumAmount = tiered.maximumAmount - metadata = tiered.metadata - minimum = tiered.minimum - minimumAmount = tiered.minimumAmount - modelType = tiered.modelType - name = tiered.name - planPhaseOrder = tiered.planPhaseOrder - priceType = tiered.priceType - replacesPriceId = tiered.replacesPriceId - tieredConfig = tiered.tieredConfig - dimensionalPriceConfiguration = tiered.dimensionalPriceConfiguration - additionalProperties = tiered.additionalProperties.toMutableMap() + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + id = bulkWithFilters.id + billableMetric = bulkWithFilters.billableMetric + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + billingMode = bulkWithFilters.billingMode + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + compositePriceFilters = + bulkWithFilters.compositePriceFilters.map { it.toMutableList() } + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + createdAt = bulkWithFilters.createdAt + creditAllocation = bulkWithFilters.creditAllocation + currency = bulkWithFilters.currency + discount = bulkWithFilters.discount + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + item = bulkWithFilters.item + maximum = bulkWithFilters.maximum + maximumAmount = bulkWithFilters.maximumAmount + metadata = bulkWithFilters.metadata + minimum = bulkWithFilters.minimum + minimumAmount = bulkWithFilters.minimumAmount + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + planPhaseOrder = bulkWithFilters.planPhaseOrder + priceType = bulkWithFilters.priceType + replacesPriceId = bulkWithFilters.replacesPriceId + dimensionalPriceConfiguration = bulkWithFilters.dimensionalPriceConfiguration + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -7356,6 +9551,35 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: JsonField) = + apply { + this.bulkWithFiltersConfig = bulkWithFiltersConfig + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -7367,6 +9591,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -7623,6 +9875,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -7714,7 +9970,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("tiered") + * JsonValue.from("bulk_with_filters") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -7783,19 +10039,6 @@ private constructor( this.replacesPriceId = replacesPriceId } - fun tieredConfig(tieredConfig: TieredConfig) = tieredConfig(JsonField.of(tieredConfig)) - - /** - * Sets [Builder.tieredConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.tieredConfig] with a well-typed [TieredConfig] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun tieredConfig(tieredConfig: JsonField) = apply { - this.tieredConfig = tieredConfig - } - fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -7831,7 +10074,7 @@ private constructor( } /** - * Returns an immutable instance of [Tiered]. + * Returns an immutable instance of [BulkWithFilters]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -7840,7 +10083,10 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() + * .bulkWithFiltersConfig() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -7860,17 +10106,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .tieredConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): Tiered = - Tiered( + fun build(): BulkWithFilters = + BulkWithFilters( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -7891,7 +10141,6 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), - checkRequired("tieredConfig", tieredConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -7899,7 +10148,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Tiered = apply { + fun validate(): BulkWithFilters = apply { if (validated) { return@apply } @@ -7907,7 +10156,10 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() + bulkWithFiltersConfig().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -7924,7 +10176,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("tiered")) { + if (it != JsonValue.from("bulk_with_filters")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -7932,7 +10184,6 @@ private constructor( planPhaseOrder() priceType().validate() replacesPriceId() - tieredConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -7955,7 +10206,10 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -7971,15 +10225,14 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("tiered")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + - (tieredConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) - class Cadence @JsonCreator private constructor(private val value: JsonField) : + class BillingMode @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -7994,49 +10247,34 @@ private constructor( companion object { - val ONE_TIME = of("one_time") - - val MONTHLY = of("monthly") - - val QUARTERLY = of("quarterly") - - val SEMI_ANNUAL = of("semi_annual") - - val ANNUAL = of("annual") + val IN_ADVANCE = of("in_advance") - val CUSTOM = of("custom") + val IN_ARREAR = of("in_arrear") - fun of(value: String) = Cadence(JsonField.of(value)) + fun of(value: String) = BillingMode(JsonField.of(value)) } - /** An enum containing [Cadence]'s known values. */ + /** An enum containing [BillingMode]'s known values. */ enum class Known { - ONE_TIME, - MONTHLY, - QUARTERLY, - SEMI_ANNUAL, - ANNUAL, - CUSTOM, + IN_ADVANCE, + IN_ARREAR, } /** - * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [Cadence] can contain an unknown value in a couple of cases: + * An instance of [BillingMode] 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 { - ONE_TIME, - MONTHLY, - QUARTERLY, - SEMI_ANNUAL, - ANNUAL, - CUSTOM, + IN_ADVANCE, + IN_ARREAR, /** - * An enum member indicating that [Cadence] was instantiated with an unknown value. + * An enum member indicating that [BillingMode] was instantiated with an unknown + * value. */ _UNKNOWN, } @@ -8050,12 +10288,8 @@ private constructor( */ fun value(): Value = when (this) { - ONE_TIME -> Value.ONE_TIME - MONTHLY -> Value.MONTHLY - QUARTERLY -> Value.QUARTERLY - SEMI_ANNUAL -> Value.SEMI_ANNUAL - ANNUAL -> Value.ANNUAL - CUSTOM -> Value.CUSTOM + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR else -> Value._UNKNOWN } @@ -8070,13 +10304,9 @@ private constructor( */ fun known(): Known = when (this) { - ONE_TIME -> Known.ONE_TIME - MONTHLY -> Known.MONTHLY - QUARTERLY -> Known.QUARTERLY - SEMI_ANNUAL -> Known.SEMI_ANNUAL - ANNUAL -> Known.ANNUAL - CUSTOM -> Known.CUSTOM - else -> throw OrbInvalidDataException("Unknown Cadence: $value") + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $value") } /** @@ -8093,7 +10323,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Cadence = apply { + fun validate(): BillingMode = apply { if (validated) { return@apply } @@ -8123,7 +10353,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is BillingMode && value == other.value } override fun hashCode() = value.hashCode() @@ -8131,211 +10361,149 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null - - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) /** - * Returns a score indicating how many valid values are contained in this object - * recursively. + * Property filters to apply (all must match) * - * Used for best match union deserialization. + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + fun filters(): List = filters.getRequired("filters") - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tiers(): List = tiers.getRequired("tiers") - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * 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 - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + fun toBuilder() = Builder().from(this) companion object { - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) + /** + * Returns a mutable builder for constructing an instance of + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { + + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun visitUnit(unit: UnitConversionRateConfig): T + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = bulkWithFiltersConfig.additionalProperties.toMutableMap() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Sets [Builder.filters] to an arbitrary JSON value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. + * You should usually call [Builder.filters] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() - - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) } - } - - return ConversionRateConfig(_json = json) } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + /** Bulk tiers for rating based on total usage volume */ + fun tiers(tiers: List) = tiers(JsonField.of(tiers)) - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + /** + * 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() } } - } - } - - /** - * User specified key-value pairs for the resource. If not present, this defaults to an - * empty dictionary. Individual keys can be removed by setting the value to `null`, and the - * entire metadata mapping can be cleared by setting `metadata` to `null`. - */ - class Metadata - @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 [Metadata]. */ - fun builder() = Builder() - } - /** A builder for [Metadata]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.additionalProperties.toMutableMap() + /** + * 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 { @@ -8361,16 +10529,6387 @@ private constructor( } /** - * Returns an immutable instance of [Metadata]. + * Returns an immutable instance of [BulkWithFiltersConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): Metadata = apply { + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } + + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + propertyKey() + propertyValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(filters, tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } + + class Cadence @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 { + + val ONE_TIME = of("one_time") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val SEMI_ANNUAL = of("semi_annual") + + val ANNUAL = of("annual") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ONE_TIME, + MONTHLY, + QUARTERLY, + SEMI_ANNUAL, + ANNUAL, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ONE_TIME, + MONTHLY, + QUARTERLY, + SEMI_ANNUAL, + ANNUAL, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ONE_TIME -> Value.ONE_TIME + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + SEMI_ANNUAL -> Value.SEMI_ANNUAL + ANNUAL -> Value.ANNUAL + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ONE_TIME -> Known.ONE_TIME + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + SEMI_ANNUAL -> Known.SEMI_ANNUAL + ANNUAL -> Known.ANNUAL + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @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 [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and the + * entire metadata mapping can be cleared by setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + class PriceType @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 { + + val USAGE_PRICE = of("usage_price") + + val FIXED_PRICE = of("fixed_price") + + val COMPOSITE_PRICE = of("composite_price") + + fun of(value: String) = PriceType(JsonField.of(value)) + } + + /** An enum containing [PriceType]'s known values. */ + enum class Known { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + } + + /** + * An enum containing [PriceType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [PriceType] 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 { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + /** + * An enum member indicating that [PriceType] 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) { + USAGE_PRICE -> Value.USAGE_PRICE + FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USAGE_PRICE -> Known.USAGE_PRICE + FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE + else -> throw OrbInvalidDataException("Unknown PriceType: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): PriceType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 PriceType && 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 BulkWithFilters && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + bulkWithFiltersConfig, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFilters{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + } + + class Package + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val billableMetric: JsonField, + private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, + private val cadence: JsonField, + private val compositePriceFilters: JsonField>, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val createdAt: JsonField, + private val creditAllocation: JsonField, + private val currency: JsonField, + private val discount: JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val item: JsonField, + private val maximum: JsonField, + private val maximumAmount: JsonField, + private val metadata: JsonField, + private val minimum: JsonField, + private val minimumAmount: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val packageConfig: JsonField, + private val planPhaseOrder: JsonField, + private val priceType: JsonField, + private val replacesPriceId: JsonField, + private val dimensionalPriceConfiguration: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric") + @ExcludeMissing + billableMetric: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), + @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("credit_allocation") + @ExcludeMissing + creditAllocation: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("discount") + @ExcludeMissing + discount: JsonField = JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("item") @ExcludeMissing item: JsonField = JsonMissing.of(), + @JsonProperty("maximum") @ExcludeMissing maximum: JsonField = JsonMissing.of(), + @JsonProperty("maximum_amount") + @ExcludeMissing + maximumAmount: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("minimum") @ExcludeMissing minimum: JsonField = JsonMissing.of(), + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("model_type") @ExcludeMissing modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("package_config") + @ExcludeMissing + packageConfig: JsonField = JsonMissing.of(), + @JsonProperty("plan_phase_order") + @ExcludeMissing + planPhaseOrder: JsonField = JsonMissing.of(), + @JsonProperty("price_type") + @ExcludeMissing + priceType: JsonField = JsonMissing.of(), + @JsonProperty("replaces_price_id") + @ExcludeMissing + replacesPriceId: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + ) : this( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + packageConfig, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + mutableMapOf(), + ) + + /** + * @throws OrbInvalidDataException if 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 OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billableMetric(): BillableMetricTiny? = billableMetric.getNullable("billable_metric") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): BillingCycleConfiguration = + billingCycleConfiguration.getRequired("billing_cycle_configuration") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * @throws OrbInvalidDataException if 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 OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun creditAllocation(): Allocation? = creditAllocation.getNullable("credit_allocation") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") fun discount(): Discount? = discount.getNullable("discount") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): BillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * A minimal representation of an Item containing only the essential identifying + * information. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun item(): ItemSlim = item.getRequired("item") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") fun maximum(): Maximum? = maximum.getNullable("maximum") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") + fun maximumAmount(): String? = maximumAmount.getNullable("maximum_amount") + + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and the + * entire metadata mapping can be cleared by setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun metadata(): Metadata = metadata.getRequired("metadata") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") fun minimum(): Minimum? = minimum.getNullable("minimum") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") + fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("package") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for package pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageConfig(): PackageConfig = packageConfig.getRequired("package_config") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun priceType(): PriceType = priceType.getRequired("price_type") + + /** + * The price id this price replaces. This price will take the place of the replaced price in + * plan version migrations. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): DimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * 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 [billableMetric]. + * + * Unlike [billableMetric], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("billable_metric") + @ExcludeMissing + fun _billableMetric(): JsonField = billableMetric + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * 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 [creditAllocation]. + * + * Unlike [creditAllocation], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("credit_allocation") + @ExcludeMissing + fun _creditAllocation(): JsonField = creditAllocation + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [discount]. + * + * Unlike [discount], this method doesn't throw if the JSON field has an unexpected type. + */ + @Deprecated("deprecated") + @JsonProperty("discount") + @ExcludeMissing + fun _discount(): JsonField = discount + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [item]. + * + * Unlike [item], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("item") @ExcludeMissing fun _item(): JsonField = item + + /** + * Returns the raw JSON value of [maximum]. + * + * Unlike [maximum], this method doesn't throw if the JSON field has an unexpected type. + */ + @Deprecated("deprecated") + @JsonProperty("maximum") + @ExcludeMissing + fun _maximum(): JsonField = maximum + + /** + * Returns the raw JSON value of [maximumAmount]. + * + * Unlike [maximumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @Deprecated("deprecated") + @JsonProperty("maximum_amount") + @ExcludeMissing + fun _maximumAmount(): JsonField = maximumAmount + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [minimum]. + * + * Unlike [minimum], this method doesn't throw if the JSON field has an unexpected type. + */ + @Deprecated("deprecated") + @JsonProperty("minimum") + @ExcludeMissing + fun _minimum(): JsonField = minimum + + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @Deprecated("deprecated") + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount + + /** + * 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 [packageConfig]. + * + * Unlike [packageConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("package_config") + @ExcludeMissing + fun _packageConfig(): JsonField = packageConfig + + /** + * Returns the raw JSON value of [planPhaseOrder]. + * + * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("plan_phase_order") + @ExcludeMissing + fun _planPhaseOrder(): JsonField = planPhaseOrder + + /** + * Returns the raw JSON value of [priceType]. + * + * Unlike [priceType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("price_type") + @ExcludeMissing + fun _priceType(): JsonField = priceType + + /** + * Returns the raw JSON value of [replacesPriceId]. + * + * Unlike [replacesPriceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("replaces_price_id") + @ExcludeMissing + fun _replacesPriceId(): JsonField = replacesPriceId + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + @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 [Package]. + * + * The following fields are required: + * ```kotlin + * .id() + * .billableMetric() + * .billingCycleConfiguration() + * .billingMode() + * .cadence() + * .compositePriceFilters() + * .conversionRate() + * .conversionRateConfig() + * .createdAt() + * .creditAllocation() + * .currency() + * .discount() + * .externalPriceId() + * .fixedPriceQuantity() + * .invoicingCycleConfiguration() + * .item() + * .maximum() + * .maximumAmount() + * .metadata() + * .minimum() + * .minimumAmount() + * .name() + * .packageConfig() + * .planPhaseOrder() + * .priceType() + * .replacesPriceId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Package]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var billableMetric: JsonField? = null + private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null + private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null + private var conversionRate: JsonField? = null + private var conversionRateConfig: JsonField? = null + private var createdAt: JsonField? = null + private var creditAllocation: JsonField? = null + private var currency: JsonField? = null + private var discount: JsonField? = null + private var externalPriceId: JsonField? = null + private var fixedPriceQuantity: JsonField? = null + private var invoicingCycleConfiguration: JsonField? = null + private var item: JsonField? = null + private var maximum: JsonField? = null + private var maximumAmount: JsonField? = null + private var metadata: JsonField? = null + private var minimum: JsonField? = null + private var minimumAmount: JsonField? = null + private var modelType: JsonValue = JsonValue.from("package") + private var name: JsonField? = null + private var packageConfig: JsonField? = null + private var planPhaseOrder: JsonField? = null + private var priceType: JsonField? = null + private var replacesPriceId: JsonField? = null + private var dimensionalPriceConfiguration: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(package_: Package) = apply { + id = package_.id + billableMetric = package_.billableMetric + billingCycleConfiguration = package_.billingCycleConfiguration + billingMode = package_.billingMode + cadence = package_.cadence + compositePriceFilters = package_.compositePriceFilters.map { it.toMutableList() } + conversionRate = package_.conversionRate + conversionRateConfig = package_.conversionRateConfig + createdAt = package_.createdAt + creditAllocation = package_.creditAllocation + currency = package_.currency + discount = package_.discount + externalPriceId = package_.externalPriceId + fixedPriceQuantity = package_.fixedPriceQuantity + invoicingCycleConfiguration = package_.invoicingCycleConfiguration + item = package_.item + maximum = package_.maximum + maximumAmount = package_.maximumAmount + metadata = package_.metadata + minimum = package_.minimum + minimumAmount = package_.minimumAmount + modelType = package_.modelType + name = package_.name + packageConfig = package_.packageConfig + planPhaseOrder = package_.planPhaseOrder + priceType = package_.priceType + replacesPriceId = package_.replacesPriceId + dimensionalPriceConfiguration = package_.dimensionalPriceConfiguration + additionalProperties = package_.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 billableMetric(billableMetric: BillableMetricTiny?) = + billableMetric(JsonField.ofNullable(billableMetric)) + + /** + * Sets [Builder.billableMetric] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetric] with a well-typed + * [BillableMetricTiny] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun billableMetric(billableMetric: JsonField) = apply { + this.billableMetric = billableMetric + } + + fun billingCycleConfiguration(billingCycleConfiguration: BillingCycleConfiguration) = + billingCycleConfiguration(JsonField.of(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [BillingCycleConfiguration] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun conversionRateConfig(conversionRateConfig: JsonField) = + apply { + this.conversionRateConfig = conversionRateConfig + } + + /** + * Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + .tieredConfig(tieredConfig) + .build() + ) + + 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 creditAllocation(creditAllocation: Allocation?) = + creditAllocation(JsonField.ofNullable(creditAllocation)) + + /** + * Sets [Builder.creditAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.creditAllocation] with a well-typed [Allocation] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun creditAllocation(creditAllocation: JsonField) = apply { + this.creditAllocation = creditAllocation + } + + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + @Deprecated("deprecated") + fun discount(discount: Discount?) = discount(JsonField.ofNullable(discount)) + + /** + * Sets [Builder.discount] to an arbitrary JSON value. + * + * You should usually call [Builder.discount] with a well-typed [Discount] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun discount(discount: JsonField) = apply { this.discount = discount } + + /** Alias for calling [discount] with `Discount.ofPercentage(percentage)`. */ + @Deprecated("deprecated") + fun discount(percentage: PercentageDiscount) = + discount(Discount.ofPercentage(percentage)) + + /** + * Alias for calling [discount] with the following: + * ```kotlin + * PercentageDiscount.builder() + * .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + * .percentageDiscount(percentageDiscount) + * .build() + * ``` + */ + @Deprecated("deprecated") + fun percentageDiscount(percentageDiscount: Double) = + discount( + PercentageDiscount.builder() + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(percentageDiscount) + .build() + ) + + /** Alias for calling [discount] with `Discount.ofTrial(trial)`. */ + @Deprecated("deprecated") + fun discount(trial: TrialDiscount) = discount(Discount.ofTrial(trial)) + + /** Alias for calling [discount] with `Discount.ofUsage(usage)`. */ + @Deprecated("deprecated") + fun discount(usage: UsageDiscount) = discount(Discount.ofUsage(usage)) + + /** + * Alias for calling [discount] with the following: + * ```kotlin + * UsageDiscount.builder() + * .discountType(UsageDiscount.DiscountType.USAGE) + * .usageDiscount(usageDiscount) + * .build() + * ``` + */ + @Deprecated("deprecated") + fun usageDiscount(usageDiscount: Double) = + discount( + UsageDiscount.builder() + .discountType(UsageDiscount.DiscountType.USAGE) + .usageDiscount(usageDiscount) + .build() + ) + + /** Alias for calling [discount] with `Discount.ofAmount(amount)`. */ + @Deprecated("deprecated") + fun discount(amount: AmountDiscount) = discount(Discount.ofAmount(amount)) + + /** + * Alias for calling [discount] with the following: + * ```kotlin + * AmountDiscount.builder() + * .discountType(AmountDiscount.DiscountType.AMOUNT) + * .amountDiscount(amountDiscount) + * .build() + * ``` + */ + @Deprecated("deprecated") + fun amountDiscount(amountDiscount: String) = + discount( + AmountDiscount.builder() + .discountType(AmountDiscount.DiscountType.AMOUNT) + .amountDiscount(amountDiscount) + .build() + ) + + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: BillingCycleConfiguration? + ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed + * [BillingCycleConfiguration] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ + fun item(item: ItemSlim) = item(JsonField.of(item)) + + /** + * Sets [Builder.item] to an arbitrary JSON value. + * + * You should usually call [Builder.item] with a well-typed [ItemSlim] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun item(item: JsonField) = apply { this.item = item } + + @Deprecated("deprecated") + fun maximum(maximum: Maximum?) = maximum(JsonField.ofNullable(maximum)) + + /** + * Sets [Builder.maximum] to an arbitrary JSON value. + * + * You should usually call [Builder.maximum] with a well-typed [Maximum] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun maximum(maximum: JsonField) = apply { this.maximum = maximum } + + @Deprecated("deprecated") + fun maximumAmount(maximumAmount: String?) = + maximumAmount(JsonField.ofNullable(maximumAmount)) + + /** + * Sets [Builder.maximumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun maximumAmount(maximumAmount: JsonField) = apply { + this.maximumAmount = maximumAmount + } + + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and + * the entire metadata mapping can be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + @Deprecated("deprecated") + fun minimum(minimum: Minimum?) = minimum(JsonField.ofNullable(minimum)) + + /** + * Sets [Builder.minimum] to an arbitrary JSON value. + * + * You should usually call [Builder.minimum] with a well-typed [Minimum] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun minimum(minimum: JsonField) = apply { this.minimum = minimum } + + @Deprecated("deprecated") + fun minimumAmount(minimumAmount: String?) = + minimumAmount(JsonField.ofNullable(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("package") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + 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 } + + /** Configuration for package pricing */ + fun packageConfig(packageConfig: PackageConfig) = + packageConfig(JsonField.of(packageConfig)) + + /** + * Sets [Builder.packageConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.packageConfig] with a well-typed [PackageConfig] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun packageConfig(packageConfig: JsonField) = apply { + this.packageConfig = packageConfig + } + + fun planPhaseOrder(planPhaseOrder: Long?) = + planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + + /** + * Alias for [Builder.planPhaseOrder]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + + /** + * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. + * + * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun planPhaseOrder(planPhaseOrder: JsonField) = apply { + this.planPhaseOrder = planPhaseOrder + } + + fun priceType(priceType: PriceType) = priceType(JsonField.of(priceType)) + + /** + * Sets [Builder.priceType] to an arbitrary JSON value. + * + * You should usually call [Builder.priceType] with a well-typed [PriceType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun priceType(priceType: JsonField) = apply { this.priceType = priceType } + + /** + * The price id this price replaces. This price will take the place of the replaced + * price in plan version migrations. + */ + fun replacesPriceId(replacesPriceId: String?) = + replacesPriceId(JsonField.ofNullable(replacesPriceId)) + + /** + * Sets [Builder.replacesPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.replacesPriceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun replacesPriceId(replacesPriceId: JsonField) = apply { + this.replacesPriceId = replacesPriceId + } + + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: DimensionalPriceConfiguration? + ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed + * [DimensionalPriceConfiguration] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Package]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .id() + * .billableMetric() + * .billingCycleConfiguration() + * .billingMode() + * .cadence() + * .compositePriceFilters() + * .conversionRate() + * .conversionRateConfig() + * .createdAt() + * .creditAllocation() + * .currency() + * .discount() + * .externalPriceId() + * .fixedPriceQuantity() + * .invoicingCycleConfiguration() + * .item() + * .maximum() + * .maximumAmount() + * .metadata() + * .minimum() + * .minimumAmount() + * .name() + * .packageConfig() + * .planPhaseOrder() + * .priceType() + * .replacesPriceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Package = + Package( + checkRequired("id", id), + checkRequired("billableMetric", billableMetric), + checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), + checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, + checkRequired("conversionRate", conversionRate), + checkRequired("conversionRateConfig", conversionRateConfig), + checkRequired("createdAt", createdAt), + checkRequired("creditAllocation", creditAllocation), + checkRequired("currency", currency), + checkRequired("discount", discount), + checkRequired("externalPriceId", externalPriceId), + checkRequired("fixedPriceQuantity", fixedPriceQuantity), + checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), + checkRequired("item", item), + checkRequired("maximum", maximum), + checkRequired("maximumAmount", maximumAmount), + checkRequired("metadata", metadata), + checkRequired("minimum", minimum), + checkRequired("minimumAmount", minimumAmount), + modelType, + checkRequired("name", name), + checkRequired("packageConfig", packageConfig), + checkRequired("planPhaseOrder", planPhaseOrder), + checkRequired("priceType", priceType), + checkRequired("replacesPriceId", replacesPriceId), + dimensionalPriceConfiguration, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Package = apply { + if (validated) { + return@apply + } + + id() + billableMetric()?.validate() + billingCycleConfiguration().validate() + billingMode().validate() + cadence().validate() + compositePriceFilters()?.forEach { it.validate() } + conversionRate() + conversionRateConfig()?.validate() + createdAt() + creditAllocation()?.validate() + currency() + discount()?.validate() + externalPriceId() + fixedPriceQuantity() + invoicingCycleConfiguration()?.validate() + item().validate() + maximum()?.validate() + maximumAmount() + metadata().validate() + minimum()?.validate() + minimumAmount() + _modelType().let { + if (it != JsonValue.from("package")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + packageConfig().validate() + planPhaseOrder() + priceType().validate() + replacesPriceId() + dimensionalPriceConfiguration()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (id.asKnown() == null) 0 else 1) + + (billableMetric.asKnown()?.validity() ?: 0) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (createdAt.asKnown() == null) 0 else 1) + + (creditAllocation.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (discount.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (item.asKnown()?.validity() ?: 0) + + (maximum.asKnown()?.validity() ?: 0) + + (if (maximumAmount.asKnown() == null) 0 else 1) + + (metadata.asKnown()?.validity() ?: 0) + + (minimum.asKnown()?.validity() ?: 0) + + (if (minimumAmount.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("package")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (packageConfig.asKnown()?.validity() ?: 0) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + (priceType.asKnown()?.validity() ?: 0) + + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Cadence @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 { + + val ONE_TIME = of("one_time") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val SEMI_ANNUAL = of("semi_annual") + + val ANNUAL = of("annual") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ONE_TIME, + MONTHLY, + QUARTERLY, + SEMI_ANNUAL, + ANNUAL, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ONE_TIME, + MONTHLY, + QUARTERLY, + SEMI_ANNUAL, + ANNUAL, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ONE_TIME -> Value.ONE_TIME + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + SEMI_ANNUAL -> Value.SEMI_ANNUAL + ANNUAL -> Value.ANNUAL + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ONE_TIME -> Known.ONE_TIME + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + SEMI_ANNUAL -> Known.SEMI_ANNUAL + ANNUAL -> Known.ANNUAL + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @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 [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and the + * entire metadata mapping can be cleared by setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + class PriceType @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 { + + val USAGE_PRICE = of("usage_price") + + val FIXED_PRICE = of("fixed_price") + + val COMPOSITE_PRICE = of("composite_price") + + fun of(value: String) = PriceType(JsonField.of(value)) + } + + /** An enum containing [PriceType]'s known values. */ + enum class Known { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + } + + /** + * An enum containing [PriceType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [PriceType] 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 { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + /** + * An enum member indicating that [PriceType] 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) { + USAGE_PRICE -> Value.USAGE_PRICE + FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USAGE_PRICE -> Known.USAGE_PRICE + FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE + else -> throw OrbInvalidDataException("Unknown PriceType: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): PriceType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 PriceType && 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 Package && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + packageConfig == other.packageConfig && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + packageConfig, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Package{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, packageConfig=$packageConfig, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + } + + class Matrix + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val billableMetric: JsonField, + private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, + private val cadence: JsonField, + private val compositePriceFilters: JsonField>, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val createdAt: JsonField, + private val creditAllocation: JsonField, + private val currency: JsonField, + private val discount: JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val item: JsonField, + private val matrixConfig: JsonField, + private val maximum: JsonField, + private val maximumAmount: JsonField, + private val metadata: JsonField, + private val minimum: JsonField, + private val minimumAmount: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val planPhaseOrder: JsonField, + private val priceType: JsonField, + private val replacesPriceId: JsonField, + private val dimensionalPriceConfiguration: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric") + @ExcludeMissing + billableMetric: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), + @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("credit_allocation") + @ExcludeMissing + creditAllocation: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("discount") + @ExcludeMissing + discount: JsonField = JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("item") @ExcludeMissing item: JsonField = JsonMissing.of(), + @JsonProperty("matrix_config") + @ExcludeMissing + matrixConfig: JsonField = JsonMissing.of(), + @JsonProperty("maximum") @ExcludeMissing maximum: JsonField = JsonMissing.of(), + @JsonProperty("maximum_amount") + @ExcludeMissing + maximumAmount: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("minimum") @ExcludeMissing minimum: JsonField = JsonMissing.of(), + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("model_type") @ExcludeMissing modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("plan_phase_order") + @ExcludeMissing + planPhaseOrder: JsonField = JsonMissing.of(), + @JsonProperty("price_type") + @ExcludeMissing + priceType: JsonField = JsonMissing.of(), + @JsonProperty("replaces_price_id") + @ExcludeMissing + replacesPriceId: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + ) : this( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + matrixConfig, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + mutableMapOf(), + ) + + /** + * @throws OrbInvalidDataException if 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 OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billableMetric(): BillableMetricTiny? = billableMetric.getNullable("billable_metric") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): BillingCycleConfiguration = + billingCycleConfiguration.getRequired("billing_cycle_configuration") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * @throws OrbInvalidDataException if 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 OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun creditAllocation(): Allocation? = creditAllocation.getNullable("credit_allocation") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") fun discount(): Discount? = discount.getNullable("discount") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): BillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * A minimal representation of an Item containing only the essential identifying + * information. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun item(): ItemSlim = item.getRequired("item") + + /** + * Configuration for matrix pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun matrixConfig(): MatrixConfig = matrixConfig.getRequired("matrix_config") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") fun maximum(): Maximum? = maximum.getNullable("maximum") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") + fun maximumAmount(): String? = maximumAmount.getNullable("maximum_amount") + + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and the + * entire metadata mapping can be cleared by setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun metadata(): Metadata = metadata.getRequired("metadata") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") fun minimum(): Minimum? = minimum.getNullable("minimum") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") + fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("matrix") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun priceType(): PriceType = priceType.getRequired("price_type") + + /** + * The price id this price replaces. This price will take the place of the replaced price in + * plan version migrations. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): DimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * 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 [billableMetric]. + * + * Unlike [billableMetric], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("billable_metric") + @ExcludeMissing + fun _billableMetric(): JsonField = billableMetric + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * 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 [creditAllocation]. + * + * Unlike [creditAllocation], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("credit_allocation") + @ExcludeMissing + fun _creditAllocation(): JsonField = creditAllocation + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [discount]. + * + * Unlike [discount], this method doesn't throw if the JSON field has an unexpected type. + */ + @Deprecated("deprecated") + @JsonProperty("discount") + @ExcludeMissing + fun _discount(): JsonField = discount + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [item]. + * + * Unlike [item], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("item") @ExcludeMissing fun _item(): JsonField = item + + /** + * Returns the raw JSON value of [matrixConfig]. + * + * Unlike [matrixConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("matrix_config") + @ExcludeMissing + fun _matrixConfig(): JsonField = matrixConfig + + /** + * Returns the raw JSON value of [maximum]. + * + * Unlike [maximum], this method doesn't throw if the JSON field has an unexpected type. + */ + @Deprecated("deprecated") + @JsonProperty("maximum") + @ExcludeMissing + fun _maximum(): JsonField = maximum + + /** + * Returns the raw JSON value of [maximumAmount]. + * + * Unlike [maximumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @Deprecated("deprecated") + @JsonProperty("maximum_amount") + @ExcludeMissing + fun _maximumAmount(): JsonField = maximumAmount + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [minimum]. + * + * Unlike [minimum], this method doesn't throw if the JSON field has an unexpected type. + */ + @Deprecated("deprecated") + @JsonProperty("minimum") + @ExcludeMissing + fun _minimum(): JsonField = minimum + + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @Deprecated("deprecated") + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount + + /** + * 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 [planPhaseOrder]. + * + * Unlike [planPhaseOrder], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("plan_phase_order") + @ExcludeMissing + fun _planPhaseOrder(): JsonField = planPhaseOrder + + /** + * Returns the raw JSON value of [priceType]. + * + * Unlike [priceType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("price_type") + @ExcludeMissing + fun _priceType(): JsonField = priceType + + /** + * Returns the raw JSON value of [replacesPriceId]. + * + * Unlike [replacesPriceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("replaces_price_id") + @ExcludeMissing + fun _replacesPriceId(): JsonField = replacesPriceId + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + @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 [Matrix]. + * + * The following fields are required: + * ```kotlin + * .id() + * .billableMetric() + * .billingCycleConfiguration() + * .billingMode() + * .cadence() + * .compositePriceFilters() + * .conversionRate() + * .conversionRateConfig() + * .createdAt() + * .creditAllocation() + * .currency() + * .discount() + * .externalPriceId() + * .fixedPriceQuantity() + * .invoicingCycleConfiguration() + * .item() + * .matrixConfig() + * .maximum() + * .maximumAmount() + * .metadata() + * .minimum() + * .minimumAmount() + * .name() + * .planPhaseOrder() + * .priceType() + * .replacesPriceId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Matrix]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var billableMetric: JsonField? = null + private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null + private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null + private var conversionRate: JsonField? = null + private var conversionRateConfig: JsonField? = null + private var createdAt: JsonField? = null + private var creditAllocation: JsonField? = null + private var currency: JsonField? = null + private var discount: JsonField? = null + private var externalPriceId: JsonField? = null + private var fixedPriceQuantity: JsonField? = null + private var invoicingCycleConfiguration: JsonField? = null + private var item: JsonField? = null + private var matrixConfig: JsonField? = null + private var maximum: JsonField? = null + private var maximumAmount: JsonField? = null + private var metadata: JsonField? = null + private var minimum: JsonField? = null + private var minimumAmount: JsonField? = null + private var modelType: JsonValue = JsonValue.from("matrix") + private var name: JsonField? = null + private var planPhaseOrder: JsonField? = null + private var priceType: JsonField? = null + private var replacesPriceId: JsonField? = null + private var dimensionalPriceConfiguration: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(matrix: Matrix) = apply { + id = matrix.id + billableMetric = matrix.billableMetric + billingCycleConfiguration = matrix.billingCycleConfiguration + billingMode = matrix.billingMode + cadence = matrix.cadence + compositePriceFilters = matrix.compositePriceFilters.map { it.toMutableList() } + conversionRate = matrix.conversionRate + conversionRateConfig = matrix.conversionRateConfig + createdAt = matrix.createdAt + creditAllocation = matrix.creditAllocation + currency = matrix.currency + discount = matrix.discount + externalPriceId = matrix.externalPriceId + fixedPriceQuantity = matrix.fixedPriceQuantity + invoicingCycleConfiguration = matrix.invoicingCycleConfiguration + item = matrix.item + matrixConfig = matrix.matrixConfig + maximum = matrix.maximum + maximumAmount = matrix.maximumAmount + metadata = matrix.metadata + minimum = matrix.minimum + minimumAmount = matrix.minimumAmount + modelType = matrix.modelType + name = matrix.name + planPhaseOrder = matrix.planPhaseOrder + priceType = matrix.priceType + replacesPriceId = matrix.replacesPriceId + dimensionalPriceConfiguration = matrix.dimensionalPriceConfiguration + additionalProperties = matrix.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 billableMetric(billableMetric: BillableMetricTiny?) = + billableMetric(JsonField.ofNullable(billableMetric)) + + /** + * Sets [Builder.billableMetric] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetric] with a well-typed + * [BillableMetricTiny] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun billableMetric(billableMetric: JsonField) = apply { + this.billableMetric = billableMetric + } + + fun billingCycleConfiguration(billingCycleConfiguration: BillingCycleConfiguration) = + billingCycleConfiguration(JsonField.of(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [BillingCycleConfiguration] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun conversionRateConfig(conversionRateConfig: JsonField) = + apply { + this.conversionRateConfig = conversionRateConfig + } + + /** + * Alias for calling [conversionRateConfig] with `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + .tieredConfig(tieredConfig) + .build() + ) + + 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 creditAllocation(creditAllocation: Allocation?) = + creditAllocation(JsonField.ofNullable(creditAllocation)) + + /** + * Sets [Builder.creditAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.creditAllocation] with a well-typed [Allocation] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun creditAllocation(creditAllocation: JsonField) = apply { + this.creditAllocation = creditAllocation + } + + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + @Deprecated("deprecated") + fun discount(discount: Discount?) = discount(JsonField.ofNullable(discount)) + + /** + * Sets [Builder.discount] to an arbitrary JSON value. + * + * You should usually call [Builder.discount] with a well-typed [Discount] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun discount(discount: JsonField) = apply { this.discount = discount } + + /** Alias for calling [discount] with `Discount.ofPercentage(percentage)`. */ + @Deprecated("deprecated") + fun discount(percentage: PercentageDiscount) = + discount(Discount.ofPercentage(percentage)) + + /** + * Alias for calling [discount] with the following: + * ```kotlin + * PercentageDiscount.builder() + * .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + * .percentageDiscount(percentageDiscount) + * .build() + * ``` + */ + @Deprecated("deprecated") + fun percentageDiscount(percentageDiscount: Double) = + discount( + PercentageDiscount.builder() + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(percentageDiscount) + .build() + ) + + /** Alias for calling [discount] with `Discount.ofTrial(trial)`. */ + @Deprecated("deprecated") + fun discount(trial: TrialDiscount) = discount(Discount.ofTrial(trial)) + + /** Alias for calling [discount] with `Discount.ofUsage(usage)`. */ + @Deprecated("deprecated") + fun discount(usage: UsageDiscount) = discount(Discount.ofUsage(usage)) + + /** + * Alias for calling [discount] with the following: + * ```kotlin + * UsageDiscount.builder() + * .discountType(UsageDiscount.DiscountType.USAGE) + * .usageDiscount(usageDiscount) + * .build() + * ``` + */ + @Deprecated("deprecated") + fun usageDiscount(usageDiscount: Double) = + discount( + UsageDiscount.builder() + .discountType(UsageDiscount.DiscountType.USAGE) + .usageDiscount(usageDiscount) + .build() + ) + + /** Alias for calling [discount] with `Discount.ofAmount(amount)`. */ + @Deprecated("deprecated") + fun discount(amount: AmountDiscount) = discount(Discount.ofAmount(amount)) + + /** + * Alias for calling [discount] with the following: + * ```kotlin + * AmountDiscount.builder() + * .discountType(AmountDiscount.DiscountType.AMOUNT) + * .amountDiscount(amountDiscount) + * .build() + * ``` + */ + @Deprecated("deprecated") + fun amountDiscount(amountDiscount: String) = + discount( + AmountDiscount.builder() + .discountType(AmountDiscount.DiscountType.AMOUNT) + .amountDiscount(amountDiscount) + .build() + ) + + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: BillingCycleConfiguration? + ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed + * [BillingCycleConfiguration] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ + fun item(item: ItemSlim) = item(JsonField.of(item)) + + /** + * Sets [Builder.item] to an arbitrary JSON value. + * + * You should usually call [Builder.item] with a well-typed [ItemSlim] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun item(item: JsonField) = apply { this.item = item } + + /** Configuration for matrix pricing */ + fun matrixConfig(matrixConfig: MatrixConfig) = matrixConfig(JsonField.of(matrixConfig)) + + /** + * Sets [Builder.matrixConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.matrixConfig] with a well-typed [MatrixConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun matrixConfig(matrixConfig: JsonField) = apply { + this.matrixConfig = matrixConfig + } + + @Deprecated("deprecated") + fun maximum(maximum: Maximum?) = maximum(JsonField.ofNullable(maximum)) + + /** + * Sets [Builder.maximum] to an arbitrary JSON value. + * + * You should usually call [Builder.maximum] with a well-typed [Maximum] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun maximum(maximum: JsonField) = apply { this.maximum = maximum } + + @Deprecated("deprecated") + fun maximumAmount(maximumAmount: String?) = + maximumAmount(JsonField.ofNullable(maximumAmount)) + + /** + * Sets [Builder.maximumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun maximumAmount(maximumAmount: JsonField) = apply { + this.maximumAmount = maximumAmount + } + + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and + * the entire metadata mapping can be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + @Deprecated("deprecated") + fun minimum(minimum: Minimum?) = minimum(JsonField.ofNullable(minimum)) + + /** + * Sets [Builder.minimum] to an arbitrary JSON value. + * + * You should usually call [Builder.minimum] with a well-typed [Minimum] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun minimum(minimum: JsonField) = apply { this.minimum = minimum } + + @Deprecated("deprecated") + fun minimumAmount(minimumAmount: String?) = + minimumAmount(JsonField.ofNullable(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("matrix") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + 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 planPhaseOrder(planPhaseOrder: Long?) = + planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) + + /** + * Alias for [Builder.planPhaseOrder]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun planPhaseOrder(planPhaseOrder: Long) = planPhaseOrder(planPhaseOrder as Long?) + + /** + * Sets [Builder.planPhaseOrder] to an arbitrary JSON value. + * + * You should usually call [Builder.planPhaseOrder] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun planPhaseOrder(planPhaseOrder: JsonField) = apply { + this.planPhaseOrder = planPhaseOrder + } + + fun priceType(priceType: PriceType) = priceType(JsonField.of(priceType)) + + /** + * Sets [Builder.priceType] to an arbitrary JSON value. + * + * You should usually call [Builder.priceType] with a well-typed [PriceType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun priceType(priceType: JsonField) = apply { this.priceType = priceType } + + /** + * The price id this price replaces. This price will take the place of the replaced + * price in plan version migrations. + */ + fun replacesPriceId(replacesPriceId: String?) = + replacesPriceId(JsonField.ofNullable(replacesPriceId)) + + /** + * Sets [Builder.replacesPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.replacesPriceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun replacesPriceId(replacesPriceId: JsonField) = apply { + this.replacesPriceId = replacesPriceId + } + + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: DimensionalPriceConfiguration? + ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed + * [DimensionalPriceConfiguration] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Matrix]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .id() + * .billableMetric() + * .billingCycleConfiguration() + * .billingMode() + * .cadence() + * .compositePriceFilters() + * .conversionRate() + * .conversionRateConfig() + * .createdAt() + * .creditAllocation() + * .currency() + * .discount() + * .externalPriceId() + * .fixedPriceQuantity() + * .invoicingCycleConfiguration() + * .item() + * .matrixConfig() + * .maximum() + * .maximumAmount() + * .metadata() + * .minimum() + * .minimumAmount() + * .name() + * .planPhaseOrder() + * .priceType() + * .replacesPriceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Matrix = + Matrix( + checkRequired("id", id), + checkRequired("billableMetric", billableMetric), + checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), + checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, + checkRequired("conversionRate", conversionRate), + checkRequired("conversionRateConfig", conversionRateConfig), + checkRequired("createdAt", createdAt), + checkRequired("creditAllocation", creditAllocation), + checkRequired("currency", currency), + checkRequired("discount", discount), + checkRequired("externalPriceId", externalPriceId), + checkRequired("fixedPriceQuantity", fixedPriceQuantity), + checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), + checkRequired("item", item), + checkRequired("matrixConfig", matrixConfig), + checkRequired("maximum", maximum), + checkRequired("maximumAmount", maximumAmount), + checkRequired("metadata", metadata), + checkRequired("minimum", minimum), + checkRequired("minimumAmount", minimumAmount), + modelType, + checkRequired("name", name), + checkRequired("planPhaseOrder", planPhaseOrder), + checkRequired("priceType", priceType), + checkRequired("replacesPriceId", replacesPriceId), + dimensionalPriceConfiguration, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Matrix = apply { + if (validated) { + return@apply + } + + id() + billableMetric()?.validate() + billingCycleConfiguration().validate() + billingMode().validate() + cadence().validate() + compositePriceFilters()?.forEach { it.validate() } + conversionRate() + conversionRateConfig()?.validate() + createdAt() + creditAllocation()?.validate() + currency() + discount()?.validate() + externalPriceId() + fixedPriceQuantity() + invoicingCycleConfiguration()?.validate() + item().validate() + matrixConfig().validate() + maximum()?.validate() + maximumAmount() + metadata().validate() + minimum()?.validate() + minimumAmount() + _modelType().let { + if (it != JsonValue.from("matrix")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + planPhaseOrder() + priceType().validate() + replacesPriceId() + dimensionalPriceConfiguration()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (id.asKnown() == null) 0 else 1) + + (billableMetric.asKnown()?.validity() ?: 0) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (createdAt.asKnown() == null) 0 else 1) + + (creditAllocation.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (discount.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (item.asKnown()?.validity() ?: 0) + + (matrixConfig.asKnown()?.validity() ?: 0) + + (maximum.asKnown()?.validity() ?: 0) + + (if (maximumAmount.asKnown() == null) 0 else 1) + + (metadata.asKnown()?.validity() ?: 0) + + (minimum.asKnown()?.validity() ?: 0) + + (if (minimumAmount.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("matrix")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + (priceType.asKnown()?.validity() ?: 0) + + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Cadence @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 { + + val ONE_TIME = of("one_time") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val SEMI_ANNUAL = of("semi_annual") + + val ANNUAL = of("annual") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ONE_TIME, + MONTHLY, + QUARTERLY, + SEMI_ANNUAL, + ANNUAL, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ONE_TIME, + MONTHLY, + QUARTERLY, + SEMI_ANNUAL, + ANNUAL, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ONE_TIME -> Value.ONE_TIME + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + SEMI_ANNUAL -> Value.SEMI_ANNUAL + ANNUAL -> Value.ANNUAL + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ONE_TIME -> Known.ONE_TIME + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + SEMI_ANNUAL -> Known.SEMI_ANNUAL + ANNUAL -> Known.ANNUAL + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @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 [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and the + * entire metadata mapping can be cleared by setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { if (validated) { return@apply } @@ -8400,12 +16939,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -8431,6 +16968,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -8438,6 +16977,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -8452,6 +16992,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -8470,6 +17011,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -8486,6 +17028,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -8533,7 +17076,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -8546,25 +17089,87 @@ private constructor( return true } - return /* spotless:off */ other is Tiered && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && tieredConfig == other.tieredConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Matrix && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + matrixConfig == other.matrixConfig && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, tieredConfig, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + matrixConfig, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Tiered{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, tieredConfig=$tieredConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "Matrix{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, matrixConfig=$matrixConfig, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class TieredBps + class ThresholdTotalAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -8585,7 +17190,7 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, - private val tieredBpsConfig: JsonField, + private val thresholdTotalAmountConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -8599,7 +17204,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -8650,9 +17261,9 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("tiered_bps_config") + @JsonProperty("threshold_total_amount_config") @ExcludeMissing - tieredBpsConfig: JsonField = JsonMissing.of(), + thresholdTotalAmountConfig: JsonField = JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -8661,7 +17272,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -8682,7 +17295,7 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, - tieredBpsConfig, + thresholdTotalAmountConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -8706,12 +17319,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -8769,6 +17395,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -8811,9 +17440,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("tiered_bps") + * JsonValue.from("threshold_total_amount") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -8849,10 +17480,13 @@ private constructor( fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") /** + * Configuration for threshold_total_amount pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun tieredBpsConfig(): TieredBpsConfig = tieredBpsConfig.getRequired("tiered_bps_config") + fun thresholdTotalAmountConfig(): ThresholdTotalAmountConfig = + thresholdTotalAmountConfig.getRequired("threshold_total_amount_config") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -8889,6 +17523,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -8896,6 +17539,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -9076,14 +17729,15 @@ private constructor( fun _replacesPriceId(): JsonField = replacesPriceId /** - * Returns the raw JSON value of [tieredBpsConfig]. + * Returns the raw JSON value of [thresholdTotalAmountConfig]. * - * Unlike [tieredBpsConfig], this method doesn't throw if the JSON field has an unexpected - * type. + * Unlike [thresholdTotalAmountConfig], this method doesn't throw if the JSON field has an + * unexpected type. */ - @JsonProperty("tiered_bps_config") + @JsonProperty("threshold_total_amount_config") @ExcludeMissing - fun _tieredBpsConfig(): JsonField = tieredBpsConfig + fun _thresholdTotalAmountConfig(): JsonField = + thresholdTotalAmountConfig /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. @@ -9111,14 +17765,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [TieredBps]. + * Returns a mutable builder for constructing an instance of [ThresholdTotalAmount]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -9138,19 +17794,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .tieredBpsConfig() + * .thresholdTotalAmountConfig() * ``` */ fun builder() = Builder() } - /** A builder for [TieredBps]. */ + /** A builder for [ThresholdTotalAmount]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -9166,44 +17824,47 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("tiered_bps") + private var modelType: JsonValue = JsonValue.from("threshold_total_amount") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null - private var tieredBpsConfig: JsonField? = null + private var thresholdTotalAmountConfig: JsonField? = null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(tieredBps: TieredBps) = apply { - id = tieredBps.id - billableMetric = tieredBps.billableMetric - billingCycleConfiguration = tieredBps.billingCycleConfiguration - cadence = tieredBps.cadence - conversionRate = tieredBps.conversionRate - conversionRateConfig = tieredBps.conversionRateConfig - createdAt = tieredBps.createdAt - creditAllocation = tieredBps.creditAllocation - currency = tieredBps.currency - discount = tieredBps.discount - externalPriceId = tieredBps.externalPriceId - fixedPriceQuantity = tieredBps.fixedPriceQuantity - invoicingCycleConfiguration = tieredBps.invoicingCycleConfiguration - item = tieredBps.item - maximum = tieredBps.maximum - maximumAmount = tieredBps.maximumAmount - metadata = tieredBps.metadata - minimum = tieredBps.minimum - minimumAmount = tieredBps.minimumAmount - modelType = tieredBps.modelType - name = tieredBps.name - planPhaseOrder = tieredBps.planPhaseOrder - priceType = tieredBps.priceType - replacesPriceId = tieredBps.replacesPriceId - tieredBpsConfig = tieredBps.tieredBpsConfig - dimensionalPriceConfiguration = tieredBps.dimensionalPriceConfiguration - additionalProperties = tieredBps.additionalProperties.toMutableMap() + internal fun from(thresholdTotalAmount: ThresholdTotalAmount) = apply { + id = thresholdTotalAmount.id + billableMetric = thresholdTotalAmount.billableMetric + billingCycleConfiguration = thresholdTotalAmount.billingCycleConfiguration + billingMode = thresholdTotalAmount.billingMode + cadence = thresholdTotalAmount.cadence + compositePriceFilters = + thresholdTotalAmount.compositePriceFilters.map { it.toMutableList() } + conversionRate = thresholdTotalAmount.conversionRate + conversionRateConfig = thresholdTotalAmount.conversionRateConfig + createdAt = thresholdTotalAmount.createdAt + creditAllocation = thresholdTotalAmount.creditAllocation + currency = thresholdTotalAmount.currency + discount = thresholdTotalAmount.discount + externalPriceId = thresholdTotalAmount.externalPriceId + fixedPriceQuantity = thresholdTotalAmount.fixedPriceQuantity + invoicingCycleConfiguration = thresholdTotalAmount.invoicingCycleConfiguration + item = thresholdTotalAmount.item + maximum = thresholdTotalAmount.maximum + maximumAmount = thresholdTotalAmount.maximumAmount + metadata = thresholdTotalAmount.metadata + minimum = thresholdTotalAmount.minimum + minimumAmount = thresholdTotalAmount.minimumAmount + modelType = thresholdTotalAmount.modelType + name = thresholdTotalAmount.name + planPhaseOrder = thresholdTotalAmount.planPhaseOrder + priceType = thresholdTotalAmount.priceType + replacesPriceId = thresholdTotalAmount.replacesPriceId + thresholdTotalAmountConfig = thresholdTotalAmount.thresholdTotalAmountConfig + dimensionalPriceConfiguration = thresholdTotalAmount.dimensionalPriceConfiguration + additionalProperties = thresholdTotalAmount.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -9245,6 +17906,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -9256,6 +17930,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -9512,6 +18214,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -9603,7 +18309,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("tiered_bps") + * JsonValue.from("threshold_total_amount") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -9672,19 +18378,20 @@ private constructor( this.replacesPriceId = replacesPriceId } - fun tieredBpsConfig(tieredBpsConfig: TieredBpsConfig) = - tieredBpsConfig(JsonField.of(tieredBpsConfig)) + /** Configuration for threshold_total_amount pricing */ + fun thresholdTotalAmountConfig(thresholdTotalAmountConfig: ThresholdTotalAmountConfig) = + thresholdTotalAmountConfig(JsonField.of(thresholdTotalAmountConfig)) /** - * Sets [Builder.tieredBpsConfig] to an arbitrary JSON value. + * Sets [Builder.thresholdTotalAmountConfig] to an arbitrary JSON value. * - * You should usually call [Builder.tieredBpsConfig] with a well-typed [TieredBpsConfig] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. + * You should usually call [Builder.thresholdTotalAmountConfig] with a well-typed + * [ThresholdTotalAmountConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. */ - fun tieredBpsConfig(tieredBpsConfig: JsonField) = apply { - this.tieredBpsConfig = tieredBpsConfig - } + fun thresholdTotalAmountConfig( + thresholdTotalAmountConfig: JsonField + ) = apply { this.thresholdTotalAmountConfig = thresholdTotalAmountConfig } fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? @@ -9721,7 +18428,7 @@ private constructor( } /** - * Returns an immutable instance of [TieredBps]. + * Returns an immutable instance of [ThresholdTotalAmount]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -9730,7 +18437,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -9750,17 +18459,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .tieredBpsConfig() + * .thresholdTotalAmountConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): TieredBps = - TieredBps( + fun build(): ThresholdTotalAmount = + ThresholdTotalAmount( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -9781,7 +18494,7 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), - checkRequired("tieredBpsConfig", tieredBpsConfig), + checkRequired("thresholdTotalAmountConfig", thresholdTotalAmountConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -9789,7 +18502,7 @@ private constructor( private var validated: Boolean = false - fun validate(): TieredBps = apply { + fun validate(): ThresholdTotalAmount = apply { if (validated) { return@apply } @@ -9797,7 +18510,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -9814,7 +18529,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("tiered_bps")) { + if (it != JsonValue.from("threshold_total_amount")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -9822,7 +18537,7 @@ private constructor( planPhaseOrder() priceType().validate() replacesPriceId() - tieredBpsConfig().validate() + thresholdTotalAmountConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -9835,39 +18550,170 @@ private constructor( false } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (id.asKnown() == null) 0 else 1) + - (billableMetric.asKnown()?.validity() ?: 0) + - (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (cadence.asKnown()?.validity() ?: 0) + - (if (conversionRate.asKnown() == null) 0 else 1) + - (conversionRateConfig.asKnown()?.validity() ?: 0) + - (if (createdAt.asKnown() == null) 0 else 1) + - (creditAllocation.asKnown()?.validity() ?: 0) + - (if (currency.asKnown() == null) 0 else 1) + - (discount.asKnown()?.validity() ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + - (item.asKnown()?.validity() ?: 0) + - (maximum.asKnown()?.validity() ?: 0) + - (if (maximumAmount.asKnown() == null) 0 else 1) + - (metadata.asKnown()?.validity() ?: 0) + - (minimum.asKnown()?.validity() ?: 0) + - (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("tiered_bps")) 1 else 0 } + - (if (name.asKnown() == null) 0 else 1) + - (if (planPhaseOrder.asKnown() == null) 0 else 1) + - (priceType.asKnown()?.validity() ?: 0) + - (if (replacesPriceId.asKnown() == null) 0 else 1) + - (tieredBpsConfig.asKnown()?.validity() ?: 0) + - (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (id.asKnown() == null) 0 else 1) + + (billableMetric.asKnown()?.validity() ?: 0) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (createdAt.asKnown() == null) 0 else 1) + + (creditAllocation.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (discount.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (item.asKnown()?.validity() ?: 0) + + (maximum.asKnown()?.validity() ?: 0) + + (if (maximumAmount.asKnown() == null) 0 else 1) + + (metadata.asKnown()?.validity() ?: 0) + + (minimum.asKnown()?.validity() ?: 0) + + (if (minimumAmount.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("threshold_total_amount")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + (priceType.asKnown()?.validity() ?: 0) + + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (thresholdTotalAmountConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -10013,7 +18859,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -10021,54 +18867,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun isUnit(): Boolean = unit != null + fun toBuilder() = Builder().from(this) - fun isTiered(): Boolean = tiered != null + companion object { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -10087,112 +19103,308 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + private var validated: Boolean = false - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } - fun visitUnit(unit: UnitConversionRateConfig): T + override fun hashCode() = value.hashCode() - fun visitTiered(tiered: TieredConversionRateConfig): T + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + else -> Value._UNKNOWN + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } /** @@ -10283,152 +19495,614 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + class PriceType @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 { + + val USAGE_PRICE = of("usage_price") + + val FIXED_PRICE = of("fixed_price") + + val COMPOSITE_PRICE = of("composite_price") + + fun of(value: String) = PriceType(JsonField.of(value)) + } + + /** An enum containing [PriceType]'s known values. */ + enum class Known { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + } + + /** + * An enum containing [PriceType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [PriceType] 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 { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + /** + * An enum member indicating that [PriceType] 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) { + USAGE_PRICE -> Value.USAGE_PRICE + FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USAGE_PRICE -> Known.USAGE_PRICE + FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE + else -> throw OrbInvalidDataException("Unknown PriceType: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): PriceType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 PriceType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for threshold_total_amount pricing */ + class ThresholdTotalAmountConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val consumptionTable: JsonField>, + private val prorate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("consumption_table") + @ExcludeMissing + consumptionTable: JsonField> = JsonMissing.of(), + @JsonProperty("prorate") + @ExcludeMissing + prorate: JsonField = JsonMissing.of(), + ) : this(consumptionTable, prorate, mutableMapOf()) + + /** + * When the quantity consumed passes a provided threshold, the configured total will be + * charged + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun consumptionTable(): List = + consumptionTable.getRequired("consumption_table") + + /** + * If true, the unit price will be prorated to the billing period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorate(): Boolean? = prorate.getNullable("prorate") + + /** + * Returns the raw JSON value of [consumptionTable]. + * + * Unlike [consumptionTable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("consumption_table") + @ExcludeMissing + fun _consumptionTable(): JsonField> = consumptionTable + + /** + * Returns the raw JSON value of [prorate]. + * + * Unlike [prorate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorate") @ExcludeMissing fun _prorate(): JsonField = prorate + + @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 + * [ThresholdTotalAmountConfig]. + * + * The following fields are required: + * ```kotlin + * .consumptionTable() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ThresholdTotalAmountConfig]. */ + class Builder internal constructor() { + + private var consumptionTable: JsonField>? = null + private var prorate: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(thresholdTotalAmountConfig: ThresholdTotalAmountConfig) = apply { + consumptionTable = + thresholdTotalAmountConfig.consumptionTable.map { it.toMutableList() } + prorate = thresholdTotalAmountConfig.prorate + additionalProperties = + thresholdTotalAmountConfig.additionalProperties.toMutableMap() + } + + /** + * When the quantity consumed passes a provided threshold, the configured total will + * be charged + */ + fun consumptionTable(consumptionTable: List) = + consumptionTable(JsonField.of(consumptionTable)) + + /** + * Sets [Builder.consumptionTable] to an arbitrary JSON value. + * + * You should usually call [Builder.consumptionTable] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun consumptionTable(consumptionTable: JsonField>) = apply { + this.consumptionTable = consumptionTable.map { it.toMutableList() } + } + + /** + * Adds a single [ConsumptionTable] to [Builder.consumptionTable]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addConsumptionTable(consumptionTable: ConsumptionTable) = apply { + this.consumptionTable = + (this.consumptionTable ?: JsonField.of(mutableListOf())).also { + checkKnown("consumptionTable", it).add(consumptionTable) + } + } + + /** If true, the unit price will be prorated to the billing period */ + fun prorate(prorate: Boolean?) = prorate(JsonField.ofNullable(prorate)) + + /** + * Alias for [Builder.prorate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun prorate(prorate: Boolean) = prorate(prorate as Boolean?) + + /** + * Sets [Builder.prorate] to an arbitrary JSON value. + * + * You should usually call [Builder.prorate] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun prorate(prorate: JsonField) = apply { this.prorate = prorate } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ThresholdTotalAmountConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .consumptionTable() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ThresholdTotalAmountConfig = + ThresholdTotalAmountConfig( + checkRequired("consumptionTable", consumptionTable).map { + it.toImmutable() + }, + prorate, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ThresholdTotalAmountConfig = apply { + if (validated) { + return@apply + } + + consumptionTable().forEach { it.validate() } + prorate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (consumptionTable.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (prorate.asKnown() == null) 0 else 1) + + /** Configuration for a single threshold */ + class ConsumptionTable + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val threshold: JsonField, + private val totalAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("threshold") + @ExcludeMissing + threshold: JsonField = JsonMissing.of(), + @JsonProperty("total_amount") + @ExcludeMissing + totalAmount: JsonField = JsonMissing.of(), + ) : this(threshold, totalAmount, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** + * Quantity threshold + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun threshold(): String = threshold.getRequired("threshold") + + /** + * Total amount for this threshold + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun totalAmount(): String = totalAmount.getRequired("total_amount") + + /** + * Returns the raw JSON value of [threshold]. + * + * Unlike [threshold], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("threshold") + @ExcludeMissing + fun _threshold(): JsonField = threshold + + /** + * Returns the raw JSON value of [totalAmount]. + * + * Unlike [totalAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("total_amount") + @ExcludeMissing + fun _totalAmount(): JsonField = totalAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + fun toBuilder() = Builder().from(this) - override fun hashCode(): Int = hashCode + companion object { - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } + /** + * Returns a mutable builder for constructing an instance of [ConsumptionTable]. + * + * The following fields are required: + * ```kotlin + * .threshold() + * .totalAmount() + * ``` + */ + fun builder() = Builder() + } - class PriceType @JsonCreator private constructor(private val value: JsonField) : - Enum { + /** A builder for [ConsumptionTable]. */ + class Builder internal constructor() { - /** - * 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 var threshold: JsonField? = null + private var totalAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - companion object { + internal fun from(consumptionTable: ConsumptionTable) = apply { + threshold = consumptionTable.threshold + totalAmount = consumptionTable.totalAmount + additionalProperties = consumptionTable.additionalProperties.toMutableMap() + } - val USAGE_PRICE = of("usage_price") + /** Quantity threshold */ + fun threshold(threshold: String) = threshold(JsonField.of(threshold)) + + /** + * Sets [Builder.threshold] to an arbitrary JSON value. + * + * You should usually call [Builder.threshold] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun threshold(threshold: JsonField) = apply { + this.threshold = threshold + } - val FIXED_PRICE = of("fixed_price") + /** Total amount for this threshold */ + fun totalAmount(totalAmount: String) = totalAmount(JsonField.of(totalAmount)) + + /** + * Sets [Builder.totalAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.totalAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun totalAmount(totalAmount: JsonField) = apply { + this.totalAmount = totalAmount + } - fun of(value: String) = PriceType(JsonField.of(value)) - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** An enum containing [PriceType]'s known values. */ - enum class Known { - USAGE_PRICE, - FIXED_PRICE, - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** - * An enum containing [PriceType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [PriceType] 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 { - USAGE_PRICE, - FIXED_PRICE, - /** - * An enum member indicating that [PriceType] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** - * 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) { - USAGE_PRICE -> Value.USAGE_PRICE - FIXED_PRICE -> Value.FIXED_PRICE - else -> Value._UNKNOWN - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - /** - * 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 OrbInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - USAGE_PRICE -> Known.USAGE_PRICE - FIXED_PRICE -> Known.FIXED_PRICE - else -> throw OrbInvalidDataException("Unknown PriceType: $value") + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ConsumptionTable]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .threshold() + * .totalAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ConsumptionTable = + ConsumptionTable( + checkRequired("threshold", threshold), + checkRequired("totalAmount", totalAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ConsumptionTable = apply { + if (validated) { + return@apply + } + + threshold() + totalAmount() + validated = true } - /** - * 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 OrbInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - private var validated: Boolean = false + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (threshold.asKnown() == null) 0 else 1) + + (if (totalAmount.asKnown() == null) 0 else 1) - fun validate(): PriceType = apply { - if (validated) { - return@apply - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - known() - validated = true - } + return other is ConsumptionTable && + threshold == other.threshold && + totalAmount == other.totalAmount && + additionalProperties == other.additionalProperties + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + private val hashCode: Int by lazy { + Objects.hash(threshold, totalAmount, additionalProperties) } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun hashCode(): Int = hashCode + + override fun toString() = + "ConsumptionTable{threshold=$threshold, totalAmount=$totalAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is ThresholdTotalAmountConfig && + consumptionTable == other.consumptionTable && + prorate == other.prorate && + additionalProperties == other.additionalProperties } - override fun hashCode() = value.hashCode() + private val hashCode: Int by lazy { + Objects.hash(consumptionTable, prorate, additionalProperties) + } - override fun toString() = value.toString() + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThresholdTotalAmountConfig{consumptionTable=$consumptionTable, prorate=$prorate, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -10436,26 +20110,87 @@ private constructor( return true } - return /* spotless:off */ other is TieredBps && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && tieredBpsConfig == other.tieredBpsConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ThresholdTotalAmount && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + thresholdTotalAmountConfig == other.thresholdTotalAmountConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, tieredBpsConfig, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + thresholdTotalAmountConfig, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "TieredBps{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, tieredBpsConfig=$tieredBpsConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "ThresholdTotalAmount{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, thresholdTotalAmountConfig=$thresholdTotalAmountConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class Bps + class TieredPackage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, - private val bpsConfig: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -10476,6 +20211,7 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, + private val tieredPackageConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -10489,10 +20225,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("bps_config") + @JsonProperty("billing_mode") @ExcludeMissing - bpsConfig: JsonField = JsonMissing.of(), + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -10543,6 +20282,9 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), + @JsonProperty("tiered_package_config") + @ExcludeMissing + tieredPackageConfig: JsonField = JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -10551,8 +20293,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, - bpsConfig, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -10573,6 +20316,7 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, + tieredPackageConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -10600,7 +20344,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun bpsConfig(): BpsConfig = bpsConfig.getRequired("bps_config") + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is @@ -10608,6 +20352,13 @@ private constructor( */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -10665,6 +20416,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -10707,9 +20461,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("bps") + * JsonValue.from("tiered_package") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -10744,6 +20500,15 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") + /** + * Configuration for tiered_package pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tieredPackageConfig(): TieredPackageConfig = + tieredPackageConfig.getRequired("tiered_package_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -10780,13 +20545,13 @@ private constructor( billingCycleConfiguration /** - * Returns the raw JSON value of [bpsConfig]. + * Returns the raw JSON value of [billingMode]. * - * Unlike [bpsConfig], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("bps_config") + @JsonProperty("billing_mode") @ExcludeMissing - fun _bpsConfig(): JsonField = bpsConfig + fun _billingMode(): JsonField = billingMode /** * Returns the raw JSON value of [cadence]. @@ -10795,6 +20560,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -10974,6 +20749,16 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId + /** + * Returns the raw JSON value of [tieredPackageConfig]. + * + * Unlike [tieredPackageConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tiered_package_config") + @ExcludeMissing + fun _tieredPackageConfig(): JsonField = tieredPackageConfig + /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -11000,15 +20785,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [Bps]. + * Returns a mutable builder for constructing an instance of [TieredPackage]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() - * .bpsConfig() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -11028,19 +20814,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .tieredPackageConfig() * ``` */ fun builder() = Builder() } - /** A builder for [Bps]. */ + /** A builder for [TieredPackage]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null - private var bpsConfig: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -11056,43 +20844,47 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("bps") + private var modelType: JsonValue = JsonValue.from("tiered_package") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null + private var tieredPackageConfig: JsonField? = null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(bps: Bps) = apply { - id = bps.id - billableMetric = bps.billableMetric - billingCycleConfiguration = bps.billingCycleConfiguration - bpsConfig = bps.bpsConfig - cadence = bps.cadence - conversionRate = bps.conversionRate - conversionRateConfig = bps.conversionRateConfig - createdAt = bps.createdAt - creditAllocation = bps.creditAllocation - currency = bps.currency - discount = bps.discount - externalPriceId = bps.externalPriceId - fixedPriceQuantity = bps.fixedPriceQuantity - invoicingCycleConfiguration = bps.invoicingCycleConfiguration - item = bps.item - maximum = bps.maximum - maximumAmount = bps.maximumAmount - metadata = bps.metadata - minimum = bps.minimum - minimumAmount = bps.minimumAmount - modelType = bps.modelType - name = bps.name - planPhaseOrder = bps.planPhaseOrder - priceType = bps.priceType - replacesPriceId = bps.replacesPriceId - dimensionalPriceConfiguration = bps.dimensionalPriceConfiguration - additionalProperties = bps.additionalProperties.toMutableMap() + internal fun from(tieredPackage: TieredPackage) = apply { + id = tieredPackage.id + billableMetric = tieredPackage.billableMetric + billingCycleConfiguration = tieredPackage.billingCycleConfiguration + billingMode = tieredPackage.billingMode + cadence = tieredPackage.cadence + compositePriceFilters = + tieredPackage.compositePriceFilters.map { it.toMutableList() } + conversionRate = tieredPackage.conversionRate + conversionRateConfig = tieredPackage.conversionRateConfig + createdAt = tieredPackage.createdAt + creditAllocation = tieredPackage.creditAllocation + currency = tieredPackage.currency + discount = tieredPackage.discount + externalPriceId = tieredPackage.externalPriceId + fixedPriceQuantity = tieredPackage.fixedPriceQuantity + invoicingCycleConfiguration = tieredPackage.invoicingCycleConfiguration + item = tieredPackage.item + maximum = tieredPackage.maximum + maximumAmount = tieredPackage.maximumAmount + metadata = tieredPackage.metadata + minimum = tieredPackage.minimum + minimumAmount = tieredPackage.minimumAmount + modelType = tieredPackage.modelType + name = tieredPackage.name + planPhaseOrder = tieredPackage.planPhaseOrder + priceType = tieredPackage.priceType + replacesPriceId = tieredPackage.replacesPriceId + tieredPackageConfig = tieredPackage.tieredPackageConfig + dimensionalPriceConfiguration = tieredPackage.dimensionalPriceConfiguration + additionalProperties = tieredPackage.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -11134,16 +20926,18 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } - fun bpsConfig(bpsConfig: BpsConfig) = bpsConfig(JsonField.of(bpsConfig)) + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) /** - * Sets [Builder.bpsConfig] to an arbitrary JSON value. + * Sets [Builder.billingMode] to an arbitrary JSON value. * - * You should usually call [Builder.bpsConfig] with a well-typed [BpsConfig] value + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value * instead. This method is primarily for setting the field to an undocumented or not yet * supported value. */ - fun bpsConfig(bpsConfig: JsonField) = apply { this.bpsConfig = bpsConfig } + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) @@ -11156,6 +20950,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -11412,6 +21234,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -11503,7 +21329,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("bps") + * JsonValue.from("tiered_package") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -11572,6 +21398,21 @@ private constructor( this.replacesPriceId = replacesPriceId } + /** Configuration for tiered_package pricing */ + fun tieredPackageConfig(tieredPackageConfig: TieredPackageConfig) = + tieredPackageConfig(JsonField.of(tieredPackageConfig)) + + /** + * Sets [Builder.tieredPackageConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.tieredPackageConfig] with a well-typed + * [TieredPackageConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun tieredPackageConfig(tieredPackageConfig: JsonField) = apply { + this.tieredPackageConfig = tieredPackageConfig + } + fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -11607,7 +21448,7 @@ private constructor( } /** - * Returns an immutable instance of [Bps]. + * Returns an immutable instance of [TieredPackage]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -11616,8 +21457,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() - * .bpsConfig() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -11637,17 +21479,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .tieredPackageConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): Bps = - Bps( + fun build(): TieredPackage = + TieredPackage( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), - checkRequired("bpsConfig", bpsConfig), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -11668,6 +21514,7 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), + checkRequired("tieredPackageConfig", tieredPackageConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -11675,7 +21522,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Bps = apply { + fun validate(): TieredPackage = apply { if (validated) { return@apply } @@ -11683,8 +21530,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() - bpsConfig().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -11701,7 +21549,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("bps")) { + if (it != JsonValue.from("tiered_package")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -11709,51 +21557,183 @@ private constructor( planPhaseOrder() priceType().validate() replacesPriceId() + tieredPackageConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (id.asKnown() == null) 0 else 1) + + (billableMetric.asKnown()?.validity() ?: 0) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (createdAt.asKnown() == null) 0 else 1) + + (creditAllocation.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (discount.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (item.asKnown()?.validity() ?: 0) + + (maximum.asKnown()?.validity() ?: 0) + + (if (maximumAmount.asKnown() == null) 0 else 1) + + (metadata.asKnown()?.validity() ?: 0) + + (minimum.asKnown()?.validity() ?: 0) + + (if (minimumAmount.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("tiered_package")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + (priceType.asKnown()?.validity() ?: 0) + + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (tieredPackageConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (id.asKnown() == null) 0 else 1) + - (billableMetric.asKnown()?.validity() ?: 0) + - (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (bpsConfig.asKnown()?.validity() ?: 0) + - (cadence.asKnown()?.validity() ?: 0) + - (if (conversionRate.asKnown() == null) 0 else 1) + - (conversionRateConfig.asKnown()?.validity() ?: 0) + - (if (createdAt.asKnown() == null) 0 else 1) + - (creditAllocation.asKnown()?.validity() ?: 0) + - (if (currency.asKnown() == null) 0 else 1) + - (discount.asKnown()?.validity() ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + - (item.asKnown()?.validity() ?: 0) + - (maximum.asKnown()?.validity() ?: 0) + - (if (maximumAmount.asKnown() == null) 0 else 1) + - (metadata.asKnown()?.validity() ?: 0) + - (minimum.asKnown()?.validity() ?: 0) + - (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("bps")) 1 else 0 } + - (if (name.asKnown() == null) 0 else 1) + - (if (planPhaseOrder.asKnown() == null) 0 else 1) + - (priceType.asKnown()?.validity() ?: 0) + - (if (replacesPriceId.asKnown() == null) 0 else 1) + - (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -11899,7 +21879,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -11907,54 +21887,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun isUnit(): Boolean = unit != null + fun toBuilder() = Builder().from(this) - fun isTiered(): Boolean = tiered != null + companion object { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -11973,112 +22123,308 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun validate(): Field = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + return other is Field && value == other.value + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + override fun hashCode() = value.hashCode() - fun visitUnit(unit: UnitConversionRateConfig): T + override fun toString() = value.toString() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + private var validated: Boolean = false - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } /** @@ -12169,152 +22515,608 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + class PriceType @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 { + + val USAGE_PRICE = of("usage_price") + + val FIXED_PRICE = of("fixed_price") + + val COMPOSITE_PRICE = of("composite_price") + + fun of(value: String) = PriceType(JsonField.of(value)) + } + + /** An enum containing [PriceType]'s known values. */ + enum class Known { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + } + + /** + * An enum containing [PriceType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [PriceType] 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 { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + /** + * An enum member indicating that [PriceType] 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) { + USAGE_PRICE -> Value.USAGE_PRICE + FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USAGE_PRICE -> Known.USAGE_PRICE + FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE + else -> throw OrbInvalidDataException("Unknown PriceType: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): PriceType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 PriceType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for tiered_package pricing */ + class TieredPackageConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(packageSize, tiers, mutableMapOf()) + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. The tier bounds are defined based on the total + * quantity rather than the number of packages, so they must be multiples of the package + * size. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 [TieredPackageConfig]. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredPackageConfig]. */ + class Builder internal constructor() { + + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tieredPackageConfig: TieredPackageConfig) = apply { + packageSize = tieredPackageConfig.packageSize + tiers = tieredPackageConfig.tiers.map { it.toMutableList() } + additionalProperties = tieredPackageConfig.additionalProperties.toMutableMap() + } + + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers + * are defined using exclusive lower bounds. The tier bounds are defined based on + * the total quantity rather than the number of packages, so they must be multiples + * of the package size. + */ + 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 [TieredPackageConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredPackageConfig = + TieredPackageConfig( + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredPackageConfig = apply { + if (validated) { + return@apply + } + + packageSize() + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier with business logic */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val perUnit: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("per_unit") + @ExcludeMissing + perUnit: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(perUnit, tierLowerBound, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnit(): String = perUnit.getRequired("per_unit") + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Returns the raw JSON value of [perUnit]. + * + * Unlike [perUnit], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("per_unit") + @ExcludeMissing + fun _perUnit(): JsonField = perUnit + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + fun toBuilder() = Builder().from(this) - override fun hashCode(): Int = hashCode + companion object { - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } + /** + * Returns a mutable builder for constructing an instance of [Tier]. + * + * The following fields are required: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + */ + fun builder() = Builder() + } - class PriceType @JsonCreator private constructor(private val value: JsonField) : - Enum { + /** A builder for [Tier]. */ + class Builder internal constructor() { - /** - * 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 var perUnit: JsonField? = null + private var tierLowerBound: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - companion object { + internal fun from(tier: Tier) = apply { + perUnit = tier.perUnit + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } - val USAGE_PRICE = of("usage_price") + /** Price per package */ + fun perUnit(perUnit: String) = perUnit(JsonField.of(perUnit)) + + /** + * Sets [Builder.perUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnit] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun perUnit(perUnit: JsonField) = apply { this.perUnit = perUnit } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } - val FIXED_PRICE = of("fixed_price") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun of(value: String) = PriceType(JsonField.of(value)) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** An enum containing [PriceType]'s known values. */ - enum class Known { - USAGE_PRICE, - FIXED_PRICE, - } + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** - * An enum containing [PriceType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [PriceType] 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 { - USAGE_PRICE, - FIXED_PRICE, - /** - * An enum member indicating that [PriceType] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - /** - * 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) { - USAGE_PRICE -> Value.USAGE_PRICE - FIXED_PRICE -> Value.FIXED_PRICE - else -> Value._UNKNOWN - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** - * 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 OrbInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - USAGE_PRICE -> Known.USAGE_PRICE - FIXED_PRICE -> Known.FIXED_PRICE - else -> throw OrbInvalidDataException("Unknown PriceType: $value") + /** + * Returns an immutable instance of [Tier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("perUnit", perUnit), + checkRequired("tierLowerBound", tierLowerBound), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + perUnit() + tierLowerBound() + validated = true } - /** - * 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 OrbInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - private var validated: Boolean = false + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (perUnit.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) - fun validate(): PriceType = apply { - if (validated) { - return@apply - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - known() - validated = true - } + return other is Tier && + perUnit == other.perUnit && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + private val hashCode: Int by lazy { + Objects.hash(perUnit, tierLowerBound, additionalProperties) } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{perUnit=$perUnit, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is TieredPackageConfig && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - override fun hashCode() = value.hashCode() + private val hashCode: Int by lazy { + Objects.hash(packageSize, tiers, additionalProperties) + } - override fun toString() = value.toString() + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredPackageConfig{packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -12322,26 +23124,87 @@ private constructor( return true } - return /* spotless:off */ other is Bps && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && bpsConfig == other.bpsConfig && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TieredPackage && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + tieredPackageConfig == other.tieredPackageConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, bpsConfig, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + tieredPackageConfig, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Bps{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, bpsConfig=$bpsConfig, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "TieredPackage{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, tieredPackageConfig=$tieredPackageConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class BulkBps + class TieredWithMinimum + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, - private val bulkBpsConfig: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -12362,6 +23225,7 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, + private val tieredWithMinimumConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -12375,10 +23239,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("bulk_bps_config") + @JsonProperty("billing_mode") @ExcludeMissing - bulkBpsConfig: JsonField = JsonMissing.of(), + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -12429,6 +23296,9 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), + @JsonProperty("tiered_with_minimum_config") + @ExcludeMissing + tieredWithMinimumConfig: JsonField = JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -12437,8 +23307,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, - bulkBpsConfig, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -12459,6 +23330,7 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, + tieredWithMinimumConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -12486,7 +23358,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun bulkBpsConfig(): BulkBpsConfig = bulkBpsConfig.getRequired("bulk_bps_config") + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is @@ -12494,6 +23366,13 @@ private constructor( */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -12551,6 +23430,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -12593,9 +23475,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("bulk_bps") + * JsonValue.from("tiered_with_minimum") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -12630,6 +23514,15 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") + /** + * Configuration for tiered_with_minimum pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tieredWithMinimumConfig(): TieredWithMinimumConfig = + tieredWithMinimumConfig.getRequired("tiered_with_minimum_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -12666,14 +23559,13 @@ private constructor( billingCycleConfiguration /** - * Returns the raw JSON value of [bulkBpsConfig]. + * Returns the raw JSON value of [billingMode]. * - * Unlike [bulkBpsConfig], this method doesn't throw if the JSON field has an unexpected - * type. + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("bulk_bps_config") + @JsonProperty("billing_mode") @ExcludeMissing - fun _bulkBpsConfig(): JsonField = bulkBpsConfig + fun _billingMode(): JsonField = billingMode /** * Returns the raw JSON value of [cadence]. @@ -12682,6 +23574,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -12861,6 +23763,16 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId + /** + * Returns the raw JSON value of [tieredWithMinimumConfig]. + * + * Unlike [tieredWithMinimumConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tiered_with_minimum_config") + @ExcludeMissing + fun _tieredWithMinimumConfig(): JsonField = tieredWithMinimumConfig + /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -12887,15 +23799,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [BulkBps]. + * Returns a mutable builder for constructing an instance of [TieredWithMinimum]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() - * .bulkBpsConfig() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -12915,19 +23828,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .tieredWithMinimumConfig() * ``` */ fun builder() = Builder() } - /** A builder for [BulkBps]. */ + /** A builder for [TieredWithMinimum]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null - private var bulkBpsConfig: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -12943,43 +23858,47 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("bulk_bps") + private var modelType: JsonValue = JsonValue.from("tiered_with_minimum") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null + private var tieredWithMinimumConfig: JsonField? = null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(bulkBps: BulkBps) = apply { - id = bulkBps.id - billableMetric = bulkBps.billableMetric - billingCycleConfiguration = bulkBps.billingCycleConfiguration - bulkBpsConfig = bulkBps.bulkBpsConfig - cadence = bulkBps.cadence - conversionRate = bulkBps.conversionRate - conversionRateConfig = bulkBps.conversionRateConfig - createdAt = bulkBps.createdAt - creditAllocation = bulkBps.creditAllocation - currency = bulkBps.currency - discount = bulkBps.discount - externalPriceId = bulkBps.externalPriceId - fixedPriceQuantity = bulkBps.fixedPriceQuantity - invoicingCycleConfiguration = bulkBps.invoicingCycleConfiguration - item = bulkBps.item - maximum = bulkBps.maximum - maximumAmount = bulkBps.maximumAmount - metadata = bulkBps.metadata - minimum = bulkBps.minimum - minimumAmount = bulkBps.minimumAmount - modelType = bulkBps.modelType - name = bulkBps.name - planPhaseOrder = bulkBps.planPhaseOrder - priceType = bulkBps.priceType - replacesPriceId = bulkBps.replacesPriceId - dimensionalPriceConfiguration = bulkBps.dimensionalPriceConfiguration - additionalProperties = bulkBps.additionalProperties.toMutableMap() + internal fun from(tieredWithMinimum: TieredWithMinimum) = apply { + id = tieredWithMinimum.id + billableMetric = tieredWithMinimum.billableMetric + billingCycleConfiguration = tieredWithMinimum.billingCycleConfiguration + billingMode = tieredWithMinimum.billingMode + cadence = tieredWithMinimum.cadence + compositePriceFilters = + tieredWithMinimum.compositePriceFilters.map { it.toMutableList() } + conversionRate = tieredWithMinimum.conversionRate + conversionRateConfig = tieredWithMinimum.conversionRateConfig + createdAt = tieredWithMinimum.createdAt + creditAllocation = tieredWithMinimum.creditAllocation + currency = tieredWithMinimum.currency + discount = tieredWithMinimum.discount + externalPriceId = tieredWithMinimum.externalPriceId + fixedPriceQuantity = tieredWithMinimum.fixedPriceQuantity + invoicingCycleConfiguration = tieredWithMinimum.invoicingCycleConfiguration + item = tieredWithMinimum.item + maximum = tieredWithMinimum.maximum + maximumAmount = tieredWithMinimum.maximumAmount + metadata = tieredWithMinimum.metadata + minimum = tieredWithMinimum.minimum + minimumAmount = tieredWithMinimum.minimumAmount + modelType = tieredWithMinimum.modelType + name = tieredWithMinimum.name + planPhaseOrder = tieredWithMinimum.planPhaseOrder + priceType = tieredWithMinimum.priceType + replacesPriceId = tieredWithMinimum.replacesPriceId + tieredWithMinimumConfig = tieredWithMinimum.tieredWithMinimumConfig + dimensionalPriceConfiguration = tieredWithMinimum.dimensionalPriceConfiguration + additionalProperties = tieredWithMinimum.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -13021,18 +23940,17 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } - fun bulkBpsConfig(bulkBpsConfig: BulkBpsConfig) = - bulkBpsConfig(JsonField.of(bulkBpsConfig)) + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) /** - * Sets [Builder.bulkBpsConfig] to an arbitrary JSON value. + * Sets [Builder.billingMode] to an arbitrary JSON value. * - * You should usually call [Builder.bulkBpsConfig] with a well-typed [BulkBpsConfig] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun bulkBpsConfig(bulkBpsConfig: JsonField) = apply { - this.bulkBpsConfig = bulkBpsConfig + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode } fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) @@ -13046,6 +23964,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -13302,6 +24248,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -13393,7 +24343,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("bulk_bps") + * JsonValue.from("tiered_with_minimum") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -13462,6 +24412,21 @@ private constructor( this.replacesPriceId = replacesPriceId } + /** Configuration for tiered_with_minimum pricing */ + fun tieredWithMinimumConfig(tieredWithMinimumConfig: TieredWithMinimumConfig) = + tieredWithMinimumConfig(JsonField.of(tieredWithMinimumConfig)) + + /** + * Sets [Builder.tieredWithMinimumConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.tieredWithMinimumConfig] with a well-typed + * [TieredWithMinimumConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tieredWithMinimumConfig( + tieredWithMinimumConfig: JsonField + ) = apply { this.tieredWithMinimumConfig = tieredWithMinimumConfig } + fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -13497,7 +24462,7 @@ private constructor( } /** - * Returns an immutable instance of [BulkBps]. + * Returns an immutable instance of [TieredWithMinimum]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -13506,8 +24471,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() - * .bulkBpsConfig() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -13527,17 +24493,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .tieredWithMinimumConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): BulkBps = - BulkBps( + fun build(): TieredWithMinimum = + TieredWithMinimum( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), - checkRequired("bulkBpsConfig", bulkBpsConfig), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -13558,6 +24528,7 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), + checkRequired("tieredWithMinimumConfig", tieredWithMinimumConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -13565,7 +24536,7 @@ private constructor( private var validated: Boolean = false - fun validate(): BulkBps = apply { + fun validate(): TieredWithMinimum = apply { if (validated) { return@apply } @@ -13573,8 +24544,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() - bulkBpsConfig().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -13591,7 +24563,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("bulk_bps")) { + if (it != JsonValue.from("tiered_with_minimum")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -13599,6 +24571,7 @@ private constructor( planPhaseOrder() priceType().validate() replacesPriceId() + tieredWithMinimumConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -13621,8 +24594,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (bulkBpsConfig.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -13638,13 +24612,143 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("bulk_bps")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("tiered_with_minimum")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (tieredWithMinimumConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -13789,7 +24893,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -13797,54 +24901,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @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 [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) - fun tiered(): TieredConversionRateConfig? = tiered + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } - fun isUnit(): Boolean = unit != null + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) + } + } - fun isTiered(): Boolean = tiered != null + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun _json(): JsonValue? = _json + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + private var validated: Boolean = false - fun validate(): ConversionRateConfig = apply { + fun validate(): CompositePriceFilter = apply { if (validated) { return@apply } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) + field().validate() + operator().validate() + values() validated = true } @@ -13863,112 +25137,308 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + private var validated: Boolean = false - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } - fun visitUnit(unit: UnitConversionRateConfig): T + override fun hashCode() = value.hashCode() - fun visitTiered(tiered: TieredConversionRateConfig): T + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + private var validated: Boolean = false - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } /** @@ -14059,152 +25529,692 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + class PriceType @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 { + + val USAGE_PRICE = of("usage_price") + + val FIXED_PRICE = of("fixed_price") + + val COMPOSITE_PRICE = of("composite_price") + + fun of(value: String) = PriceType(JsonField.of(value)) + } + + /** An enum containing [PriceType]'s known values. */ + enum class Known { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + } + + /** + * An enum containing [PriceType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [PriceType] 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 { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + /** + * An enum member indicating that [PriceType] 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) { + USAGE_PRICE -> Value.USAGE_PRICE + FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USAGE_PRICE -> Known.USAGE_PRICE + FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE + else -> throw OrbInvalidDataException("Unknown PriceType: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): PriceType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 PriceType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for tiered_with_minimum pricing */ + class TieredWithMinimumConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tiers: JsonField>, + private val hideZeroAmountTiers: JsonField, + private val prorate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + @JsonProperty("hide_zero_amount_tiers") + @ExcludeMissing + hideZeroAmountTiers: JsonField = JsonMissing.of(), + @JsonProperty("prorate") + @ExcludeMissing + prorate: JsonField = JsonMissing.of(), + ) : this(tiers, hideZeroAmountTiers, prorate, mutableMapOf()) + + /** + * Tiered pricing with a minimum amount dependent on the volume tier. Tiers are defined + * using exclusive lower bounds. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * If true, tiers with an accrued amount of 0 will not be included in the rating. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun hideZeroAmountTiers(): Boolean? = + hideZeroAmountTiers.getNullable("hide_zero_amount_tiers") + + /** + * If true, the unit price will be prorated to the billing period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorate(): Boolean? = prorate.getNullable("prorate") + + /** + * 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 + + /** + * Returns the raw JSON value of [hideZeroAmountTiers]. + * + * Unlike [hideZeroAmountTiers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("hide_zero_amount_tiers") + @ExcludeMissing + fun _hideZeroAmountTiers(): JsonField = hideZeroAmountTiers + + /** + * Returns the raw JSON value of [prorate]. + * + * Unlike [prorate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorate") @ExcludeMissing fun _prorate(): JsonField = prorate + + @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 + * [TieredWithMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithMinimumConfig]. */ + class Builder internal constructor() { + + private var tiers: JsonField>? = null + private var hideZeroAmountTiers: JsonField = JsonMissing.of() + private var prorate: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tieredWithMinimumConfig: TieredWithMinimumConfig) = apply { + tiers = tieredWithMinimumConfig.tiers.map { it.toMutableList() } + hideZeroAmountTiers = tieredWithMinimumConfig.hideZeroAmountTiers + prorate = tieredWithMinimumConfig.prorate + additionalProperties = + tieredWithMinimumConfig.additionalProperties.toMutableMap() + } + + /** + * Tiered pricing with a minimum amount dependent on the volume tier. Tiers are + * defined using exclusive lower bounds. + */ + 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) + } + } + + /** + * If true, tiers with an accrued amount of 0 will not be included in the rating. + */ + fun hideZeroAmountTiers(hideZeroAmountTiers: Boolean) = + hideZeroAmountTiers(JsonField.of(hideZeroAmountTiers)) + + /** + * Sets [Builder.hideZeroAmountTiers] to an arbitrary JSON value. + * + * You should usually call [Builder.hideZeroAmountTiers] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun hideZeroAmountTiers(hideZeroAmountTiers: JsonField) = apply { + this.hideZeroAmountTiers = hideZeroAmountTiers + } + + /** If true, the unit price will be prorated to the billing period */ + fun prorate(prorate: Boolean) = prorate(JsonField.of(prorate)) + + /** + * Sets [Builder.prorate] to an arbitrary JSON value. + * + * You should usually call [Builder.prorate] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun prorate(prorate: JsonField) = apply { this.prorate = prorate } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TieredWithMinimumConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithMinimumConfig = + TieredWithMinimumConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + hideZeroAmountTiers, + prorate, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithMinimumConfig = apply { + if (validated) { + return@apply + } + + tiers().forEach { it.validate() } + hideZeroAmountTiers() + prorate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (hideZeroAmountTiers.asKnown() == null) 0 else 1) + + (if (prorate.asKnown() == null) 0 else 1) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val minimumAmount: JsonField, + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(minimumAmount, tierLowerBound, unitAmount, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** + * Minimum amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun minimumAmount(): String = minimumAmount.getRequired("minimum_amount") + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + fun toBuilder() = Builder().from(this) - override fun hashCode(): Int = hashCode + companion object { - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } + /** + * Returns a mutable builder for constructing an instance of [Tier]. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - class PriceType @JsonCreator private constructor(private val value: JsonField) : - Enum { + /** A builder for [Tier]. */ + class Builder internal constructor() { - /** - * 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 var minimumAmount: JsonField? = null + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - companion object { + internal fun from(tier: Tier) = apply { + minimumAmount = tier.minimumAmount + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } - val USAGE_PRICE = of("usage_price") + /** Minimum amount */ + fun minimumAmount(minimumAmount: String) = + minimumAmount(JsonField.of(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } - val FIXED_PRICE = of("fixed_price") + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } - fun of(value: String) = PriceType(JsonField.of(value)) - } + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } - /** An enum containing [PriceType]'s known values. */ - enum class Known { - USAGE_PRICE, - FIXED_PRICE, - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** - * An enum containing [PriceType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [PriceType] 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 { - USAGE_PRICE, - FIXED_PRICE, - /** - * An enum member indicating that [PriceType] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + 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) { - USAGE_PRICE -> Value.USAGE_PRICE - FIXED_PRICE -> Value.FIXED_PRICE - else -> Value._UNKNOWN - } + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(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 OrbInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - USAGE_PRICE -> Known.USAGE_PRICE - FIXED_PRICE -> Known.FIXED_PRICE - else -> throw OrbInvalidDataException("Unknown PriceType: $value") - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - /** - * 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 OrbInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - private var validated: Boolean = false + /** + * Returns an immutable instance of [Tier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("minimumAmount", minimumAmount), + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } - fun validate(): PriceType = apply { - if (validated) { - return@apply + minimumAmount() + tierLowerBound() + unitAmount() + validated = true } - known() - validated = true - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (minimumAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + minimumAmount == other.minimumAmount && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + private val hashCode: Int by lazy { + Objects.hash(minimumAmount, tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{minimumAmount=$minimumAmount, tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is TieredWithMinimumConfig && + tiers == other.tiers && + hideZeroAmountTiers == other.hideZeroAmountTiers && + prorate == other.prorate && + additionalProperties == other.additionalProperties } - override fun hashCode() = value.hashCode() + private val hashCode: Int by lazy { + Objects.hash(tiers, hideZeroAmountTiers, prorate, additionalProperties) + } - override fun toString() = value.toString() + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithMinimumConfig{tiers=$tiers, hideZeroAmountTiers=$hideZeroAmountTiers, prorate=$prorate, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -14212,26 +26222,87 @@ private constructor( return true } - return /* spotless:off */ other is BulkBps && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && bulkBpsConfig == other.bulkBpsConfig && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TieredWithMinimum && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + tieredWithMinimumConfig == other.tieredWithMinimumConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, bulkBpsConfig, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + tieredWithMinimumConfig, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "BulkBps{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, bulkBpsConfig=$bulkBpsConfig, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "TieredWithMinimum{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, tieredWithMinimumConfig=$tieredWithMinimumConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class Bulk + class GroupedTiered + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, - private val bulkConfig: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -14240,6 +26311,7 @@ private constructor( private val discount: JsonField, private val externalPriceId: JsonField, private val fixedPriceQuantity: JsonField, + private val groupedTieredConfig: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, private val maximum: JsonField, @@ -14265,10 +26337,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("bulk_config") + @JsonProperty("billing_mode") @ExcludeMissing - bulkConfig: JsonField = JsonMissing.of(), + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -14293,6 +26368,9 @@ private constructor( @JsonProperty("fixed_price_quantity") @ExcludeMissing fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("grouped_tiered_config") + @ExcludeMissing + groupedTieredConfig: JsonField = JsonMissing.of(), @JsonProperty("invoicing_cycle_configuration") @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @@ -14327,8 +26405,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, - bulkConfig, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -14337,6 +26416,7 @@ private constructor( discount, externalPriceId, fixedPriceQuantity, + groupedTieredConfig, invoicingCycleConfiguration, item, maximum, @@ -14376,7 +26456,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun bulkConfig(): BulkConfig = bulkConfig.getRequired("bulk_config") + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is @@ -14384,6 +26464,13 @@ private constructor( */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -14433,6 +26520,15 @@ private constructor( */ fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") + /** + * Configuration for grouped_tiered pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupedTieredConfig(): GroupedTieredConfig = + groupedTieredConfig.getRequired("grouped_tiered_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -14441,6 +26537,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -14483,9 +26582,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("bulk") + * JsonValue.from("grouped_tiered") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -14556,13 +26657,13 @@ private constructor( billingCycleConfiguration /** - * Returns the raw JSON value of [bulkConfig]. + * Returns the raw JSON value of [billingMode]. * - * Unlike [bulkConfig], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("bulk_config") + @JsonProperty("billing_mode") @ExcludeMissing - fun _bulkConfig(): JsonField = bulkConfig + fun _billingMode(): JsonField = billingMode /** * Returns the raw JSON value of [cadence]. @@ -14571,6 +26672,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -14647,6 +26758,16 @@ private constructor( @ExcludeMissing fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + /** + * Returns the raw JSON value of [groupedTieredConfig]. + * + * Unlike [groupedTieredConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouped_tiered_config") + @ExcludeMissing + fun _groupedTieredConfig(): JsonField = groupedTieredConfig + /** * Returns the raw JSON value of [invoicingCycleConfiguration]. * @@ -14776,15 +26897,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [Bulk]. + * Returns a mutable builder for constructing an instance of [GroupedTiered]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() - * .bulkConfig() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -14793,6 +26915,7 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() + * .groupedTieredConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -14809,14 +26932,15 @@ private constructor( fun builder() = Builder() } - /** A builder for [Bulk]. */ + /** A builder for [GroupedTiered]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null - private var bulkConfig: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -14825,6 +26949,7 @@ private constructor( private var discount: JsonField? = null private var externalPriceId: JsonField? = null private var fixedPriceQuantity: JsonField? = null + private var groupedTieredConfig: JsonField? = null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null private var maximum: JsonField? = null @@ -14832,7 +26957,7 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("bulk") + private var modelType: JsonValue = JsonValue.from("grouped_tiered") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null @@ -14841,34 +26966,37 @@ private constructor( JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(bulk: Bulk) = apply { - id = bulk.id - billableMetric = bulk.billableMetric - billingCycleConfiguration = bulk.billingCycleConfiguration - bulkConfig = bulk.bulkConfig - cadence = bulk.cadence - conversionRate = bulk.conversionRate - conversionRateConfig = bulk.conversionRateConfig - createdAt = bulk.createdAt - creditAllocation = bulk.creditAllocation - currency = bulk.currency - discount = bulk.discount - externalPriceId = bulk.externalPriceId - fixedPriceQuantity = bulk.fixedPriceQuantity - invoicingCycleConfiguration = bulk.invoicingCycleConfiguration - item = bulk.item - maximum = bulk.maximum - maximumAmount = bulk.maximumAmount - metadata = bulk.metadata - minimum = bulk.minimum - minimumAmount = bulk.minimumAmount - modelType = bulk.modelType - name = bulk.name - planPhaseOrder = bulk.planPhaseOrder - priceType = bulk.priceType - replacesPriceId = bulk.replacesPriceId - dimensionalPriceConfiguration = bulk.dimensionalPriceConfiguration - additionalProperties = bulk.additionalProperties.toMutableMap() + internal fun from(groupedTiered: GroupedTiered) = apply { + id = groupedTiered.id + billableMetric = groupedTiered.billableMetric + billingCycleConfiguration = groupedTiered.billingCycleConfiguration + billingMode = groupedTiered.billingMode + cadence = groupedTiered.cadence + compositePriceFilters = + groupedTiered.compositePriceFilters.map { it.toMutableList() } + conversionRate = groupedTiered.conversionRate + conversionRateConfig = groupedTiered.conversionRateConfig + createdAt = groupedTiered.createdAt + creditAllocation = groupedTiered.creditAllocation + currency = groupedTiered.currency + discount = groupedTiered.discount + externalPriceId = groupedTiered.externalPriceId + fixedPriceQuantity = groupedTiered.fixedPriceQuantity + groupedTieredConfig = groupedTiered.groupedTieredConfig + invoicingCycleConfiguration = groupedTiered.invoicingCycleConfiguration + item = groupedTiered.item + maximum = groupedTiered.maximum + maximumAmount = groupedTiered.maximumAmount + metadata = groupedTiered.metadata + minimum = groupedTiered.minimum + minimumAmount = groupedTiered.minimumAmount + modelType = groupedTiered.modelType + name = groupedTiered.name + planPhaseOrder = groupedTiered.planPhaseOrder + priceType = groupedTiered.priceType + replacesPriceId = groupedTiered.replacesPriceId + dimensionalPriceConfiguration = groupedTiered.dimensionalPriceConfiguration + additionalProperties = groupedTiered.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -14910,17 +27038,17 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } - fun bulkConfig(bulkConfig: BulkConfig) = bulkConfig(JsonField.of(bulkConfig)) + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) /** - * Sets [Builder.bulkConfig] to an arbitrary JSON value. + * Sets [Builder.billingMode] to an arbitrary JSON value. * - * You should usually call [Builder.bulkConfig] with a well-typed [BulkConfig] value + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value * instead. This method is primarily for setting the field to an undocumented or not yet * supported value. */ - fun bulkConfig(bulkConfig: JsonField) = apply { - this.bulkConfig = bulkConfig + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode } fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) @@ -14934,6 +27062,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -15175,6 +27331,21 @@ private constructor( this.fixedPriceQuantity = fixedPriceQuantity } + /** Configuration for grouped_tiered pricing */ + fun groupedTieredConfig(groupedTieredConfig: GroupedTieredConfig) = + groupedTieredConfig(JsonField.of(groupedTieredConfig)) + + /** + * Sets [Builder.groupedTieredConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedTieredConfig] with a well-typed + * [GroupedTieredConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun groupedTieredConfig(groupedTieredConfig: JsonField) = apply { + this.groupedTieredConfig = groupedTieredConfig + } + fun invoicingCycleConfiguration( invoicingCycleConfiguration: BillingCycleConfiguration? ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) @@ -15190,6 +27361,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -15281,7 +27456,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("bulk") + * JsonValue.from("grouped_tiered") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -15385,7 +27560,7 @@ private constructor( } /** - * Returns an immutable instance of [Bulk]. + * Returns an immutable instance of [GroupedTiered]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -15394,8 +27569,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() - * .bulkConfig() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -15404,6 +27580,7 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() + * .groupedTieredConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -15419,13 +27596,16 @@ private constructor( * * @throws IllegalStateException if any required field is unset. */ - fun build(): Bulk = - Bulk( + fun build(): GroupedTiered = + GroupedTiered( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), - checkRequired("bulkConfig", bulkConfig), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -15434,6 +27614,7 @@ private constructor( checkRequired("discount", discount), checkRequired("externalPriceId", externalPriceId), checkRequired("fixedPriceQuantity", fixedPriceQuantity), + checkRequired("groupedTieredConfig", groupedTieredConfig), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), checkRequired("maximum", maximum), @@ -15453,7 +27634,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Bulk = apply { + fun validate(): GroupedTiered = apply { if (validated) { return@apply } @@ -15461,8 +27642,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() - bulkConfig().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -15471,6 +27653,7 @@ private constructor( discount()?.validate() externalPriceId() fixedPriceQuantity() + groupedTieredConfig().validate() invoicingCycleConfiguration()?.validate() item().validate() maximum()?.validate() @@ -15479,7 +27662,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("bulk")) { + if (it != JsonValue.from("grouped_tiered")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -15509,8 +27692,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (bulkConfig.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -15519,6 +27703,7 @@ private constructor( (discount.asKnown()?.validity() ?: 0) + (if (externalPriceId.asKnown() == null) 0 else 1) + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (groupedTieredConfig.asKnown()?.validity() ?: 0) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + @@ -15526,13 +27711,142 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("bulk")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("grouped_tiered")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -15590,69 +27904,319 @@ private constructor( ANNUAL, CUSTOM, /** - * An enum member indicating that [Cadence] was instantiated with an unknown value. + * An enum member indicating that [Cadence] 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) { + ONE_TIME -> Value.ONE_TIME + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + SEMI_ANNUAL -> Value.SEMI_ANNUAL + ANNUAL -> Value.ANNUAL + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ONE_TIME -> Known.ONE_TIME + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + SEMI_ANNUAL -> Known.SEMI_ANNUAL + ANNUAL -> Known.ANNUAL + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @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 [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - _UNKNOWN, - } + fun operator(operator: JsonField) = apply { this.operator = operator } - /** - * 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) { - ONE_TIME -> Value.ONE_TIME - MONTHLY -> Value.MONTHLY - QUARTERLY -> Value.QUARTERLY - SEMI_ANNUAL -> Value.SEMI_ANNUAL - ANNUAL -> Value.ANNUAL - CUSTOM -> Value.CUSTOM - else -> Value._UNKNOWN + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - /** - * 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 OrbInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - ONE_TIME -> Known.ONE_TIME - MONTHLY -> Known.MONTHLY - QUARTERLY -> Known.QUARTERLY - SEMI_ANNUAL -> Known.SEMI_ANNUAL - ANNUAL -> Known.ANNUAL - CUSTOM -> Known.CUSTOM - else -> throw OrbInvalidDataException("Unknown Cadence: $value") + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 OrbInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } private var validated: Boolean = false - fun validate(): Cadence = apply { + fun validate(): CompositePriceFilter = apply { if (validated) { return@apply } - known() + field().validate() + operator().validate() + values() validated = true } @@ -15670,69 +28234,499 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties } - override fun hashCode() = value.hashCode() + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } - override fun toString() = value.toString() + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + /** Configuration for grouped_tiered pricing */ + class GroupedTieredConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val groupingKey: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(groupingKey, tiers, mutableMapOf()) + + /** + * The billable metric property used to group before tiering + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Apply tiered pricing to each segment generated after grouping with the provided key + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * 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) - fun tiered(): TieredConversionRateConfig? = tiered + companion object { - fun isUnit(): Boolean = unit != null + /** + * Returns a mutable builder for constructing an instance of [GroupedTieredConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tiers() + * ``` + */ + fun builder() = Builder() + } - fun isTiered(): Boolean = tiered != null + /** A builder for [GroupedTieredConfig]. */ + class Builder internal constructor() { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + private var groupingKey: JsonField? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + internal fun from(groupedTieredConfig: GroupedTieredConfig) = apply { + groupingKey = groupedTieredConfig.groupingKey + tiers = groupedTieredConfig.tiers.map { it.toMutableList() } + additionalProperties = groupedTieredConfig.additionalProperties.toMutableMap() + } - fun _json(): JsonValue? = _json + /** The billable metric property used to group before tiering */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey } - private var validated: Boolean = false + /** + * Apply tiered pricing to each segment generated after grouping with the provided + * key + */ + fun tiers(tiers: List) = tiers(JsonField.of(tiers)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * 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() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * 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) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedTieredConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedTieredConfig = + GroupedTieredConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedTieredConfig = apply { + if (validated) { + return@apply + } + + groupingKey() + tiers().forEach { it.validate() } validated = true } @@ -15751,112 +28745,247 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (if (groupingKey.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun toBuilder() = Builder().from(this) - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Tier]. + * + * The following fields are required: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() } - companion object { + /** A builder for [Tier]. */ + class Builder internal constructor() { - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } - fun visitUnit(unit: UnitConversionRateConfig): T + tierLowerBound() + unitAmount() + validated = true + } - fun visitTiered(tiered: TieredConversionRateConfig): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. - * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + override fun hashCode(): Int = hashCode - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } - return ConversionRateConfig(_json = json) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + return other is GroupedTieredConfig && + groupingKey == other.groupingKey && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } + private val hashCode: Int by lazy { + Objects.hash(groupingKey, tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedTieredConfig{groupingKey=$groupingKey, tiers=$tiers, additionalProperties=$additionalProperties}" } /** @@ -15954,12 +29083,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -15985,6 +29112,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -15992,6 +29121,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -16006,6 +29136,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -16024,6 +29155,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -16040,6 +29172,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -16087,7 +29220,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -16100,25 +29233,87 @@ private constructor( return true } - return /* spotless:off */ other is Bulk && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && bulkConfig == other.bulkConfig && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedTiered && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + groupedTieredConfig == other.groupedTieredConfig && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, bulkConfig, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + groupedTieredConfig, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Bulk{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, bulkConfig=$bulkConfig, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "GroupedTiered{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, groupedTieredConfig=$groupedTieredConfig, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class ThresholdTotalAmount + class TieredPackageWithMinimum + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -16139,7 +29334,7 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, - private val thresholdTotalAmountConfig: JsonField, + private val tieredPackageWithMinimumConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -16153,7 +29348,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -16204,9 +29405,10 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("threshold_total_amount_config") + @JsonProperty("tiered_package_with_minimum_config") @ExcludeMissing - thresholdTotalAmountConfig: JsonField = JsonMissing.of(), + tieredPackageWithMinimumConfig: JsonField = + JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -16215,7 +29417,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -16236,7 +29440,7 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, - thresholdTotalAmountConfig, + tieredPackageWithMinimumConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -16260,12 +29464,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -16323,6 +29540,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -16365,9 +29585,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("threshold_total_amount") + * JsonValue.from("tiered_package_with_minimum") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -16403,11 +29625,13 @@ private constructor( fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") /** + * Configuration for tiered_package_with_minimum pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun thresholdTotalAmountConfig(): ThresholdTotalAmountConfig = - thresholdTotalAmountConfig.getRequired("threshold_total_amount_config") + fun tieredPackageWithMinimumConfig(): TieredPackageWithMinimumConfig = + tieredPackageWithMinimumConfig.getRequired("tiered_package_with_minimum_config") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -16444,6 +29668,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -16451,6 +29684,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -16631,15 +29874,15 @@ private constructor( fun _replacesPriceId(): JsonField = replacesPriceId /** - * Returns the raw JSON value of [thresholdTotalAmountConfig]. + * Returns the raw JSON value of [tieredPackageWithMinimumConfig]. * - * Unlike [thresholdTotalAmountConfig], this method doesn't throw if the JSON field has an - * unexpected type. + * Unlike [tieredPackageWithMinimumConfig], this method doesn't throw if the JSON field has + * an unexpected type. */ - @JsonProperty("threshold_total_amount_config") + @JsonProperty("tiered_package_with_minimum_config") @ExcludeMissing - fun _thresholdTotalAmountConfig(): JsonField = - thresholdTotalAmountConfig + fun _tieredPackageWithMinimumConfig(): JsonField = + tieredPackageWithMinimumConfig /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. @@ -16667,14 +29910,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [ThresholdTotalAmount]. + * Returns a mutable builder for constructing an instance of [TieredPackageWithMinimum]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -16694,19 +29939,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .thresholdTotalAmountConfig() + * .tieredPackageWithMinimumConfig() * ``` */ fun builder() = Builder() } - /** A builder for [ThresholdTotalAmount]. */ + /** A builder for [TieredPackageWithMinimum]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -16722,44 +29969,50 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("threshold_total_amount") + private var modelType: JsonValue = JsonValue.from("tiered_package_with_minimum") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null - private var thresholdTotalAmountConfig: JsonField? = null + private var tieredPackageWithMinimumConfig: JsonField? = + null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(thresholdTotalAmount: ThresholdTotalAmount) = apply { - id = thresholdTotalAmount.id - billableMetric = thresholdTotalAmount.billableMetric - billingCycleConfiguration = thresholdTotalAmount.billingCycleConfiguration - cadence = thresholdTotalAmount.cadence - conversionRate = thresholdTotalAmount.conversionRate - conversionRateConfig = thresholdTotalAmount.conversionRateConfig - createdAt = thresholdTotalAmount.createdAt - creditAllocation = thresholdTotalAmount.creditAllocation - currency = thresholdTotalAmount.currency - discount = thresholdTotalAmount.discount - externalPriceId = thresholdTotalAmount.externalPriceId - fixedPriceQuantity = thresholdTotalAmount.fixedPriceQuantity - invoicingCycleConfiguration = thresholdTotalAmount.invoicingCycleConfiguration - item = thresholdTotalAmount.item - maximum = thresholdTotalAmount.maximum - maximumAmount = thresholdTotalAmount.maximumAmount - metadata = thresholdTotalAmount.metadata - minimum = thresholdTotalAmount.minimum - minimumAmount = thresholdTotalAmount.minimumAmount - modelType = thresholdTotalAmount.modelType - name = thresholdTotalAmount.name - planPhaseOrder = thresholdTotalAmount.planPhaseOrder - priceType = thresholdTotalAmount.priceType - replacesPriceId = thresholdTotalAmount.replacesPriceId - thresholdTotalAmountConfig = thresholdTotalAmount.thresholdTotalAmountConfig - dimensionalPriceConfiguration = thresholdTotalAmount.dimensionalPriceConfiguration - additionalProperties = thresholdTotalAmount.additionalProperties.toMutableMap() + internal fun from(tieredPackageWithMinimum: TieredPackageWithMinimum) = apply { + id = tieredPackageWithMinimum.id + billableMetric = tieredPackageWithMinimum.billableMetric + billingCycleConfiguration = tieredPackageWithMinimum.billingCycleConfiguration + billingMode = tieredPackageWithMinimum.billingMode + cadence = tieredPackageWithMinimum.cadence + compositePriceFilters = + tieredPackageWithMinimum.compositePriceFilters.map { it.toMutableList() } + conversionRate = tieredPackageWithMinimum.conversionRate + conversionRateConfig = tieredPackageWithMinimum.conversionRateConfig + createdAt = tieredPackageWithMinimum.createdAt + creditAllocation = tieredPackageWithMinimum.creditAllocation + currency = tieredPackageWithMinimum.currency + discount = tieredPackageWithMinimum.discount + externalPriceId = tieredPackageWithMinimum.externalPriceId + fixedPriceQuantity = tieredPackageWithMinimum.fixedPriceQuantity + invoicingCycleConfiguration = tieredPackageWithMinimum.invoicingCycleConfiguration + item = tieredPackageWithMinimum.item + maximum = tieredPackageWithMinimum.maximum + maximumAmount = tieredPackageWithMinimum.maximumAmount + metadata = tieredPackageWithMinimum.metadata + minimum = tieredPackageWithMinimum.minimum + minimumAmount = tieredPackageWithMinimum.minimumAmount + modelType = tieredPackageWithMinimum.modelType + name = tieredPackageWithMinimum.name + planPhaseOrder = tieredPackageWithMinimum.planPhaseOrder + priceType = tieredPackageWithMinimum.priceType + replacesPriceId = tieredPackageWithMinimum.replacesPriceId + tieredPackageWithMinimumConfig = + tieredPackageWithMinimum.tieredPackageWithMinimumConfig + dimensionalPriceConfiguration = + tieredPackageWithMinimum.dimensionalPriceConfiguration + additionalProperties = tieredPackageWithMinimum.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -16801,6 +30054,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -16812,6 +30078,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -17068,6 +30362,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -17159,7 +30457,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("threshold_total_amount") + * JsonValue.from("tiered_package_with_minimum") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -17228,19 +30526,21 @@ private constructor( this.replacesPriceId = replacesPriceId } - fun thresholdTotalAmountConfig(thresholdTotalAmountConfig: ThresholdTotalAmountConfig) = - thresholdTotalAmountConfig(JsonField.of(thresholdTotalAmountConfig)) + /** Configuration for tiered_package_with_minimum pricing */ + fun tieredPackageWithMinimumConfig( + tieredPackageWithMinimumConfig: TieredPackageWithMinimumConfig + ) = tieredPackageWithMinimumConfig(JsonField.of(tieredPackageWithMinimumConfig)) /** - * Sets [Builder.thresholdTotalAmountConfig] to an arbitrary JSON value. + * Sets [Builder.tieredPackageWithMinimumConfig] to an arbitrary JSON value. * - * You should usually call [Builder.thresholdTotalAmountConfig] with a well-typed - * [ThresholdTotalAmountConfig] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. + * You should usually call [Builder.tieredPackageWithMinimumConfig] with a well-typed + * [TieredPackageWithMinimumConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. */ - fun thresholdTotalAmountConfig( - thresholdTotalAmountConfig: JsonField - ) = apply { this.thresholdTotalAmountConfig = thresholdTotalAmountConfig } + fun tieredPackageWithMinimumConfig( + tieredPackageWithMinimumConfig: JsonField + ) = apply { this.tieredPackageWithMinimumConfig = tieredPackageWithMinimumConfig } fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? @@ -17277,7 +30577,7 @@ private constructor( } /** - * Returns an immutable instance of [ThresholdTotalAmount]. + * Returns an immutable instance of [TieredPackageWithMinimum]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -17286,7 +30586,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -17306,17 +30608,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .thresholdTotalAmountConfig() + * .tieredPackageWithMinimumConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): ThresholdTotalAmount = - ThresholdTotalAmount( + fun build(): TieredPackageWithMinimum = + TieredPackageWithMinimum( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -17337,7 +30643,7 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), - checkRequired("thresholdTotalAmountConfig", thresholdTotalAmountConfig), + checkRequired("tieredPackageWithMinimumConfig", tieredPackageWithMinimumConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -17345,7 +30651,7 @@ private constructor( private var validated: Boolean = false - fun validate(): ThresholdTotalAmount = apply { + fun validate(): TieredPackageWithMinimum = apply { if (validated) { return@apply } @@ -17353,7 +30659,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -17370,7 +30678,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("threshold_total_amount")) { + if (it != JsonValue.from("tiered_package_with_minimum")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -17378,7 +30686,7 @@ private constructor( planPhaseOrder() priceType().validate() replacesPriceId() - thresholdTotalAmountConfig().validate() + tieredPackageWithMinimumConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -17401,7 +30709,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -17417,14 +30727,145 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("threshold_total_amount")) 1 else 0 } + + modelType.let { + if (it == JsonValue.from("tiered_package_with_minimum")) 1 else 0 + } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + - (thresholdTotalAmountConfig.asKnown()?.validity() ?: 0) + + (tieredPackageWithMinimumConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -17569,7 +31010,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -17577,54 +31018,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun isUnit(): Boolean = unit != null + fun toBuilder() = Builder().from(this) - fun isTiered(): Boolean = tiered != null + companion object { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -17643,112 +31254,308 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + private var validated: Boolean = false - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() - fun visitUnit(unit: UnitConversionRateConfig): T + override fun toString() = value.toString() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + private var validated: Boolean = false - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } /** @@ -17846,12 +31653,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -17877,6 +31682,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -17884,6 +31691,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -17898,6 +31706,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -17916,6 +31725,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -17932,6 +31742,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -17979,7 +31790,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -17987,16 +31798,70 @@ private constructor( override fun toString() = value.toString() } - class ThresholdTotalAmountConfig - @JsonCreator + /** Configuration for tiered_package_with_minimum pricing */ + class TieredPackageWithMinimumConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(packageSize, tiers, mutableMapOf()) + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun packageSize(): Double = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -18004,19 +31869,73 @@ private constructor( /** * Returns a mutable builder for constructing an instance of - * [ThresholdTotalAmountConfig]. + * [TieredPackageWithMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` */ fun builder() = Builder() } - /** A builder for [ThresholdTotalAmountConfig]. */ + /** A builder for [TieredPackageWithMinimumConfig]. */ class Builder internal constructor() { + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(thresholdTotalAmountConfig: ThresholdTotalAmountConfig) = apply { - additionalProperties = - thresholdTotalAmountConfig.additionalProperties.toMutableMap() + internal fun from(tieredPackageWithMinimumConfig: TieredPackageWithMinimumConfig) = + apply { + packageSize = tieredPackageWithMinimumConfig.packageSize + tiers = tieredPackageWithMinimumConfig.tiers.map { it.toMutableList() } + additionalProperties = + tieredPackageWithMinimumConfig.additionalProperties.toMutableMap() + } + + /** Package size */ + fun packageSize(packageSize: Double) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers + * are defined using exclusive lower bounds. + */ + 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 { @@ -18042,21 +31961,35 @@ private constructor( } /** - * Returns an immutable instance of [ThresholdTotalAmountConfig]. + * Returns an immutable instance of [TieredPackageWithMinimumConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): ThresholdTotalAmountConfig = - ThresholdTotalAmountConfig(additionalProperties.toImmutable()) + fun build(): TieredPackageWithMinimumConfig = + TieredPackageWithMinimumConfig( + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): ThresholdTotalAmountConfig = apply { + fun validate(): TieredPackageWithMinimumConfig = apply { if (validated) { return@apply } + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -18075,24 +32008,291 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val minimumAmount: JsonField, + private val perUnit: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("per_unit") + @ExcludeMissing + perUnit: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(minimumAmount, perUnit, tierLowerBound, mutableMapOf()) + + /** + * Minimum amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun minimumAmount(): String = minimumAmount.getRequired("minimum_amount") + + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnit(): String = perUnit.getRequired("per_unit") + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount + + /** + * Returns the raw JSON value of [perUnit]. + * + * Unlike [perUnit], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("per_unit") + @ExcludeMissing + fun _perUnit(): JsonField = perUnit + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .minimumAmount() + * .perUnit() + * .tierLowerBound() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var minimumAmount: JsonField? = null + private var perUnit: JsonField? = null + private var tierLowerBound: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + minimumAmount = tier.minimumAmount + perUnit = tier.perUnit + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Minimum amount */ + fun minimumAmount(minimumAmount: String) = + minimumAmount(JsonField.of(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } + + /** Price per package */ + fun perUnit(perUnit: String) = perUnit(JsonField.of(perUnit)) + + /** + * Sets [Builder.perUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnit] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun perUnit(perUnit: JsonField) = apply { this.perUnit = perUnit } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .minimumAmount() + * .perUnit() + * .tierLowerBound() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("minimumAmount", minimumAmount), + checkRequired("perUnit", perUnit), + checkRequired("tierLowerBound", tierLowerBound), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + minimumAmount() + perUnit() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (minimumAmount.asKnown() == null) 0 else 1) + + (if (perUnit.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + minimumAmount == other.minimumAmount && + perUnit == other.perUnit && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(minimumAmount, perUnit, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{minimumAmount=$minimumAmount, perUnit=$perUnit, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ThresholdTotalAmountConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TieredPackageWithMinimumConfig && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(packageSize, tiers, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "ThresholdTotalAmountConfig{additionalProperties=$additionalProperties}" + "TieredPackageWithMinimumConfig{packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -18100,25 +32300,87 @@ private constructor( return true } - return /* spotless:off */ other is ThresholdTotalAmount && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && thresholdTotalAmountConfig == other.thresholdTotalAmountConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TieredPackageWithMinimum && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + tieredPackageWithMinimumConfig == other.tieredPackageWithMinimumConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, thresholdTotalAmountConfig, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + tieredPackageWithMinimumConfig, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "ThresholdTotalAmount{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, thresholdTotalAmountConfig=$thresholdTotalAmountConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "TieredPackageWithMinimum{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, tieredPackageWithMinimumConfig=$tieredPackageWithMinimumConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class TieredPackage + class PackageWithAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -18136,10 +32398,10 @@ private constructor( private val minimumAmount: JsonField, private val modelType: JsonValue, private val name: JsonField, + private val packageWithAllocationConfig: JsonField, private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, - private val tieredPackageConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -18153,7 +32415,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -18195,6 +32463,9 @@ private constructor( minimumAmount: JsonField = JsonMissing.of(), @JsonProperty("model_type") @ExcludeMissing modelType: JsonValue = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("package_with_allocation_config") + @ExcludeMissing + packageWithAllocationConfig: JsonField = JsonMissing.of(), @JsonProperty("plan_phase_order") @ExcludeMissing planPhaseOrder: JsonField = JsonMissing.of(), @@ -18204,9 +32475,6 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("tiered_package_config") - @ExcludeMissing - tieredPackageConfig: JsonField = JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -18215,7 +32483,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -18233,10 +32503,10 @@ private constructor( minimumAmount, modelType, name, + packageWithAllocationConfig, planPhaseOrder, priceType, replacesPriceId, - tieredPackageConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -18260,12 +32530,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -18323,6 +32606,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -18365,9 +32651,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("tiered_package") + * JsonValue.from("package_with_allocation") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -18381,6 +32669,15 @@ private constructor( */ fun name(): String = name.getRequired("name") + /** + * Configuration for package_with_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun packageWithAllocationConfig(): PackageWithAllocationConfig = + packageWithAllocationConfig.getRequired("package_with_allocation_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -18402,13 +32699,6 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun tieredPackageConfig(): TieredPackageConfig = - tieredPackageConfig.getRequired("tiered_package_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -18444,6 +32734,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -18451,6 +32750,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -18601,6 +32910,17 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + /** + * Returns the raw JSON value of [packageWithAllocationConfig]. + * + * Unlike [packageWithAllocationConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("package_with_allocation_config") + @ExcludeMissing + fun _packageWithAllocationConfig(): JsonField = + packageWithAllocationConfig + /** * Returns the raw JSON value of [planPhaseOrder]. * @@ -18630,16 +32950,6 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId - /** - * Returns the raw JSON value of [tieredPackageConfig]. - * - * Unlike [tieredPackageConfig], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("tiered_package_config") - @ExcludeMissing - fun _tieredPackageConfig(): JsonField = tieredPackageConfig - /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -18666,14 +32976,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [TieredPackage]. + * Returns a mutable builder for constructing an instance of [PackageWithAllocation]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -18690,22 +33002,24 @@ private constructor( * .minimum() * .minimumAmount() * .name() + * .packageWithAllocationConfig() * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .tieredPackageConfig() * ``` */ fun builder() = Builder() } - /** A builder for [TieredPackage]. */ + /** A builder for [PackageWithAllocation]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -18721,44 +33035,47 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("tiered_package") + private var modelType: JsonValue = JsonValue.from("package_with_allocation") private var name: JsonField? = null + private var packageWithAllocationConfig: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null - private var tieredPackageConfig: JsonField? = null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(tieredPackage: TieredPackage) = apply { - id = tieredPackage.id - billableMetric = tieredPackage.billableMetric - billingCycleConfiguration = tieredPackage.billingCycleConfiguration - cadence = tieredPackage.cadence - conversionRate = tieredPackage.conversionRate - conversionRateConfig = tieredPackage.conversionRateConfig - createdAt = tieredPackage.createdAt - creditAllocation = tieredPackage.creditAllocation - currency = tieredPackage.currency - discount = tieredPackage.discount - externalPriceId = tieredPackage.externalPriceId - fixedPriceQuantity = tieredPackage.fixedPriceQuantity - invoicingCycleConfiguration = tieredPackage.invoicingCycleConfiguration - item = tieredPackage.item - maximum = tieredPackage.maximum - maximumAmount = tieredPackage.maximumAmount - metadata = tieredPackage.metadata - minimum = tieredPackage.minimum - minimumAmount = tieredPackage.minimumAmount - modelType = tieredPackage.modelType - name = tieredPackage.name - planPhaseOrder = tieredPackage.planPhaseOrder - priceType = tieredPackage.priceType - replacesPriceId = tieredPackage.replacesPriceId - tieredPackageConfig = tieredPackage.tieredPackageConfig - dimensionalPriceConfiguration = tieredPackage.dimensionalPriceConfiguration - additionalProperties = tieredPackage.additionalProperties.toMutableMap() + internal fun from(packageWithAllocation: PackageWithAllocation) = apply { + id = packageWithAllocation.id + billableMetric = packageWithAllocation.billableMetric + billingCycleConfiguration = packageWithAllocation.billingCycleConfiguration + billingMode = packageWithAllocation.billingMode + cadence = packageWithAllocation.cadence + compositePriceFilters = + packageWithAllocation.compositePriceFilters.map { it.toMutableList() } + conversionRate = packageWithAllocation.conversionRate + conversionRateConfig = packageWithAllocation.conversionRateConfig + createdAt = packageWithAllocation.createdAt + creditAllocation = packageWithAllocation.creditAllocation + currency = packageWithAllocation.currency + discount = packageWithAllocation.discount + externalPriceId = packageWithAllocation.externalPriceId + fixedPriceQuantity = packageWithAllocation.fixedPriceQuantity + invoicingCycleConfiguration = packageWithAllocation.invoicingCycleConfiguration + item = packageWithAllocation.item + maximum = packageWithAllocation.maximum + maximumAmount = packageWithAllocation.maximumAmount + metadata = packageWithAllocation.metadata + minimum = packageWithAllocation.minimum + minimumAmount = packageWithAllocation.minimumAmount + modelType = packageWithAllocation.modelType + name = packageWithAllocation.name + packageWithAllocationConfig = packageWithAllocation.packageWithAllocationConfig + planPhaseOrder = packageWithAllocation.planPhaseOrder + priceType = packageWithAllocation.priceType + replacesPriceId = packageWithAllocation.replacesPriceId + dimensionalPriceConfiguration = packageWithAllocation.dimensionalPriceConfiguration + additionalProperties = packageWithAllocation.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -18800,6 +33117,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -18811,6 +33141,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -19067,6 +33425,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -19158,7 +33520,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("tiered_package") + * JsonValue.from("package_with_allocation") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -19177,6 +33539,22 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for package_with_allocation pricing */ + fun packageWithAllocationConfig( + packageWithAllocationConfig: PackageWithAllocationConfig + ) = packageWithAllocationConfig(JsonField.of(packageWithAllocationConfig)) + + /** + * Sets [Builder.packageWithAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.packageWithAllocationConfig] with a well-typed + * [PackageWithAllocationConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun packageWithAllocationConfig( + packageWithAllocationConfig: JsonField + ) = apply { this.packageWithAllocationConfig = packageWithAllocationConfig } + fun planPhaseOrder(planPhaseOrder: Long?) = planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) @@ -19227,20 +33605,6 @@ private constructor( this.replacesPriceId = replacesPriceId } - fun tieredPackageConfig(tieredPackageConfig: TieredPackageConfig) = - tieredPackageConfig(JsonField.of(tieredPackageConfig)) - - /** - * Sets [Builder.tieredPackageConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.tieredPackageConfig] with a well-typed - * [TieredPackageConfig] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. - */ - fun tieredPackageConfig(tieredPackageConfig: JsonField) = apply { - this.tieredPackageConfig = tieredPackageConfig - } - fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -19276,7 +33640,7 @@ private constructor( } /** - * Returns an immutable instance of [TieredPackage]. + * Returns an immutable instance of [PackageWithAllocation]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -19285,7 +33649,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -19302,20 +33668,24 @@ private constructor( * .minimum() * .minimumAmount() * .name() + * .packageWithAllocationConfig() * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .tieredPackageConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): TieredPackage = - TieredPackage( + fun build(): PackageWithAllocation = + PackageWithAllocation( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -19333,10 +33703,10 @@ private constructor( checkRequired("minimumAmount", minimumAmount), modelType, checkRequired("name", name), + checkRequired("packageWithAllocationConfig", packageWithAllocationConfig), checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), - checkRequired("tieredPackageConfig", tieredPackageConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -19344,7 +33714,7 @@ private constructor( private var validated: Boolean = false - fun validate(): TieredPackage = apply { + fun validate(): PackageWithAllocation = apply { if (validated) { return@apply } @@ -19352,7 +33722,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -19369,15 +33741,15 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("tiered_package")) { + if (it != JsonValue.from("package_with_allocation")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } name() + packageWithAllocationConfig().validate() planPhaseOrder() priceType().validate() replacesPriceId() - tieredPackageConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -19400,7 +33772,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -19416,14 +33790,143 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("tiered_package")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("package_with_allocation")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + + (packageWithAllocationConfig.asKnown()?.validity() ?: 0) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + - (tieredPackageConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -19568,7 +34071,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -19576,54 +34079,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun isUnit(): Boolean = unit != null + fun toBuilder() = Builder().from(this) - fun isTiered(): Boolean = tiered != null + companion object { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -19642,112 +34315,308 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun validate(): Field = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() - fun visitUnit(unit: UnitConversionRateConfig): T + override fun toString() = value.toString() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } /** @@ -19845,18 +34714,283 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } + /** Configuration for package_with_allocation pricing */ + class PackageWithAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val allocation: JsonField, + private val packageAmount: JsonField, + private val packageSize: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("allocation") + @ExcludeMissing + allocation: JsonField = JsonMissing.of(), + @JsonProperty("package_amount") + @ExcludeMissing + packageAmount: JsonField = JsonMissing.of(), + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + ) : this(allocation, packageAmount, packageSize, mutableMapOf()) + + /** + * Usage allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun allocation(): String = allocation.getRequired("allocation") + + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun packageAmount(): String = packageAmount.getRequired("package_amount") + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Returns the raw JSON value of [allocation]. + * + * Unlike [allocation], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("allocation") + @ExcludeMissing + fun _allocation(): JsonField = allocation + + /** + * Returns the raw JSON value of [packageAmount]. + * + * Unlike [packageAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("package_amount") + @ExcludeMissing + fun _packageAmount(): JsonField = packageAmount + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + @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 + * [PackageWithAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .packageAmount() + * .packageSize() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PackageWithAllocationConfig]. */ + class Builder internal constructor() { + + private var allocation: JsonField? = null + private var packageAmount: JsonField? = null + private var packageSize: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(packageWithAllocationConfig: PackageWithAllocationConfig) = + apply { + allocation = packageWithAllocationConfig.allocation + packageAmount = packageWithAllocationConfig.packageAmount + packageSize = packageWithAllocationConfig.packageSize + additionalProperties = + packageWithAllocationConfig.additionalProperties.toMutableMap() + } + + /** Usage allocation */ + fun allocation(allocation: String) = allocation(JsonField.of(allocation)) + + /** + * Sets [Builder.allocation] to an arbitrary JSON value. + * + * You should usually call [Builder.allocation] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allocation(allocation: JsonField) = apply { + this.allocation = allocation + } + + /** Price per package */ + fun packageAmount(packageAmount: String) = + packageAmount(JsonField.of(packageAmount)) + + /** + * Sets [Builder.packageAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.packageAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun packageAmount(packageAmount: JsonField) = apply { + this.packageAmount = packageAmount + } + + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PackageWithAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .packageAmount() + * .packageSize() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PackageWithAllocationConfig = + PackageWithAllocationConfig( + checkRequired("allocation", allocation), + checkRequired("packageAmount", packageAmount), + checkRequired("packageSize", packageSize), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PackageWithAllocationConfig = apply { + if (validated) { + return@apply + } + + allocation() + packageAmount() + packageSize() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (allocation.asKnown() == null) 0 else 1) + + (if (packageAmount.asKnown() == null) 0 else 1) + + (if (packageSize.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PackageWithAllocationConfig && + allocation == other.allocation && + packageAmount == other.packageAmount && + packageSize == other.packageSize && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(allocation, packageAmount, packageSize, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PackageWithAllocationConfig{allocation=$allocation, packageAmount=$packageAmount, packageSize=$packageSize, additionalProperties=$additionalProperties}" + } + class PriceType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -19876,6 +35010,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -19883,6 +35019,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -19897,6 +35034,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -19915,6 +35053,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -19931,6 +35070,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -19978,7 +35118,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -19986,136 +35126,92 @@ private constructor( override fun toString() = value.toString() } - class TieredPackageConfig - @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 [TieredPackageConfig]. - */ - fun builder() = Builder() - } - - /** A builder for [TieredPackageConfig]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(tieredPackageConfig: TieredPackageConfig) = apply { - additionalProperties = tieredPackageConfig.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 [TieredPackageConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): TieredPackageConfig = - TieredPackageConfig(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): TieredPackageConfig = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TieredPackageConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "TieredPackageConfig{additionalProperties=$additionalProperties}" - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is TieredPackage && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && tieredPackageConfig == other.tieredPackageConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PackageWithAllocation && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + packageWithAllocationConfig == other.packageWithAllocationConfig && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, tieredPackageConfig, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + packageWithAllocationConfig, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "TieredPackage{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, tieredPackageConfig=$tieredPackageConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "PackageWithAllocation{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, packageWithAllocationConfig=$packageWithAllocationConfig, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class GroupedTiered + class UnitWithPercent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -20124,7 +35220,6 @@ private constructor( private val discount: JsonField, private val externalPriceId: JsonField, private val fixedPriceQuantity: JsonField, - private val groupedTieredConfig: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, private val maximum: JsonField, @@ -20137,6 +35232,7 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, + private val unitWithPercentConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -20150,7 +35246,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -20175,9 +35277,6 @@ private constructor( @JsonProperty("fixed_price_quantity") @ExcludeMissing fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("grouped_tiered_config") - @ExcludeMissing - groupedTieredConfig: JsonField = JsonMissing.of(), @JsonProperty("invoicing_cycle_configuration") @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @@ -20204,6 +35303,9 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), + @JsonProperty("unit_with_percent_config") + @ExcludeMissing + unitWithPercentConfig: JsonField = JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -20212,7 +35314,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -20221,7 +35325,6 @@ private constructor( discount, externalPriceId, fixedPriceQuantity, - groupedTieredConfig, invoicingCycleConfiguration, item, maximum, @@ -20234,6 +35337,7 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, + unitWithPercentConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -20257,12 +35361,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -20312,13 +35429,6 @@ private constructor( */ fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun groupedTieredConfig(): GroupedTieredConfig = - groupedTieredConfig.getRequired("grouped_tiered_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -20327,6 +35437,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -20369,9 +35482,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("grouped_tiered") + * JsonValue.from("unit_with_percent") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -20406,6 +35521,15 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") + /** + * Configuration for unit_with_percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitWithPercentConfig(): UnitWithPercentConfig = + unitWithPercentConfig.getRequired("unit_with_percent_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -20441,6 +35565,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -20448,6 +35581,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -20524,16 +35667,6 @@ private constructor( @ExcludeMissing fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - /** - * Returns the raw JSON value of [groupedTieredConfig]. - * - * Unlike [groupedTieredConfig], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("grouped_tiered_config") - @ExcludeMissing - fun _groupedTieredConfig(): JsonField = groupedTieredConfig - /** * Returns the raw JSON value of [invoicingCycleConfiguration]. * @@ -20637,6 +35770,16 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId + /** + * Returns the raw JSON value of [unitWithPercentConfig]. + * + * Unlike [unitWithPercentConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_with_percent_config") + @ExcludeMissing + fun _unitWithPercentConfig(): JsonField = unitWithPercentConfig + /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -20663,14 +35806,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [GroupedTiered]. + * Returns a mutable builder for constructing an instance of [UnitWithPercent]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -20679,7 +35824,6 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() - * .groupedTieredConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -20691,18 +35835,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .unitWithPercentConfig() * ``` */ fun builder() = Builder() } - /** A builder for [GroupedTiered]. */ + /** A builder for [UnitWithPercent]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -20711,7 +35858,6 @@ private constructor( private var discount: JsonField? = null private var externalPriceId: JsonField? = null private var fixedPriceQuantity: JsonField? = null - private var groupedTieredConfig: JsonField? = null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null private var maximum: JsonField? = null @@ -20719,43 +35865,47 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("grouped_tiered") + private var modelType: JsonValue = JsonValue.from("unit_with_percent") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null + private var unitWithPercentConfig: JsonField? = null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(groupedTiered: GroupedTiered) = apply { - id = groupedTiered.id - billableMetric = groupedTiered.billableMetric - billingCycleConfiguration = groupedTiered.billingCycleConfiguration - cadence = groupedTiered.cadence - conversionRate = groupedTiered.conversionRate - conversionRateConfig = groupedTiered.conversionRateConfig - createdAt = groupedTiered.createdAt - creditAllocation = groupedTiered.creditAllocation - currency = groupedTiered.currency - discount = groupedTiered.discount - externalPriceId = groupedTiered.externalPriceId - fixedPriceQuantity = groupedTiered.fixedPriceQuantity - groupedTieredConfig = groupedTiered.groupedTieredConfig - invoicingCycleConfiguration = groupedTiered.invoicingCycleConfiguration - item = groupedTiered.item - maximum = groupedTiered.maximum - maximumAmount = groupedTiered.maximumAmount - metadata = groupedTiered.metadata - minimum = groupedTiered.minimum - minimumAmount = groupedTiered.minimumAmount - modelType = groupedTiered.modelType - name = groupedTiered.name - planPhaseOrder = groupedTiered.planPhaseOrder - priceType = groupedTiered.priceType - replacesPriceId = groupedTiered.replacesPriceId - dimensionalPriceConfiguration = groupedTiered.dimensionalPriceConfiguration - additionalProperties = groupedTiered.additionalProperties.toMutableMap() + internal fun from(unitWithPercent: UnitWithPercent) = apply { + id = unitWithPercent.id + billableMetric = unitWithPercent.billableMetric + billingCycleConfiguration = unitWithPercent.billingCycleConfiguration + billingMode = unitWithPercent.billingMode + cadence = unitWithPercent.cadence + compositePriceFilters = + unitWithPercent.compositePriceFilters.map { it.toMutableList() } + conversionRate = unitWithPercent.conversionRate + conversionRateConfig = unitWithPercent.conversionRateConfig + createdAt = unitWithPercent.createdAt + creditAllocation = unitWithPercent.creditAllocation + currency = unitWithPercent.currency + discount = unitWithPercent.discount + externalPriceId = unitWithPercent.externalPriceId + fixedPriceQuantity = unitWithPercent.fixedPriceQuantity + invoicingCycleConfiguration = unitWithPercent.invoicingCycleConfiguration + item = unitWithPercent.item + maximum = unitWithPercent.maximum + maximumAmount = unitWithPercent.maximumAmount + metadata = unitWithPercent.metadata + minimum = unitWithPercent.minimum + minimumAmount = unitWithPercent.minimumAmount + modelType = unitWithPercent.modelType + name = unitWithPercent.name + planPhaseOrder = unitWithPercent.planPhaseOrder + priceType = unitWithPercent.priceType + replacesPriceId = unitWithPercent.replacesPriceId + unitWithPercentConfig = unitWithPercent.unitWithPercentConfig + dimensionalPriceConfiguration = unitWithPercent.dimensionalPriceConfiguration + additionalProperties = unitWithPercent.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -20797,6 +35947,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -20808,6 +35971,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -21049,20 +36240,6 @@ private constructor( this.fixedPriceQuantity = fixedPriceQuantity } - fun groupedTieredConfig(groupedTieredConfig: GroupedTieredConfig) = - groupedTieredConfig(JsonField.of(groupedTieredConfig)) - - /** - * Sets [Builder.groupedTieredConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.groupedTieredConfig] with a well-typed - * [GroupedTieredConfig] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. - */ - fun groupedTieredConfig(groupedTieredConfig: JsonField) = apply { - this.groupedTieredConfig = groupedTieredConfig - } - fun invoicingCycleConfiguration( invoicingCycleConfiguration: BillingCycleConfiguration? ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) @@ -21078,6 +36255,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -21169,7 +36350,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("grouped_tiered") + * JsonValue.from("unit_with_percent") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -21238,6 +36419,22 @@ private constructor( this.replacesPriceId = replacesPriceId } + /** Configuration for unit_with_percent pricing */ + fun unitWithPercentConfig(unitWithPercentConfig: UnitWithPercentConfig) = + unitWithPercentConfig(JsonField.of(unitWithPercentConfig)) + + /** + * Sets [Builder.unitWithPercentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.unitWithPercentConfig] with a well-typed + * [UnitWithPercentConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun unitWithPercentConfig(unitWithPercentConfig: JsonField) = + apply { + this.unitWithPercentConfig = unitWithPercentConfig + } + fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -21273,7 +36470,7 @@ private constructor( } /** - * Returns an immutable instance of [GroupedTiered]. + * Returns an immutable instance of [UnitWithPercent]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -21282,7 +36479,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -21291,7 +36490,6 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() - * .groupedTieredConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -21303,16 +36501,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .unitWithPercentConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): GroupedTiered = - GroupedTiered( + fun build(): UnitWithPercent = + UnitWithPercent( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -21321,7 +36524,6 @@ private constructor( checkRequired("discount", discount), checkRequired("externalPriceId", externalPriceId), checkRequired("fixedPriceQuantity", fixedPriceQuantity), - checkRequired("groupedTieredConfig", groupedTieredConfig), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), checkRequired("maximum", maximum), @@ -21334,6 +36536,7 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), + checkRequired("unitWithPercentConfig", unitWithPercentConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -21341,7 +36544,7 @@ private constructor( private var validated: Boolean = false - fun validate(): GroupedTiered = apply { + fun validate(): UnitWithPercent = apply { if (validated) { return@apply } @@ -21349,7 +36552,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -21358,7 +36563,6 @@ private constructor( discount()?.validate() externalPriceId() fixedPriceQuantity() - groupedTieredConfig().validate() invoicingCycleConfiguration()?.validate() item().validate() maximum()?.validate() @@ -21367,7 +36571,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("grouped_tiered")) { + if (it != JsonValue.from("unit_with_percent")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -21375,6 +36579,7 @@ private constructor( planPhaseOrder() priceType().validate() replacesPriceId() + unitWithPercentConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -21397,7 +36602,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -21406,7 +36613,6 @@ private constructor( (discount.asKnown()?.validity() ?: 0) + (if (externalPriceId.asKnown() == null) 0 else 1) + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (groupedTieredConfig.asKnown()?.validity() ?: 0) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + @@ -21414,13 +36620,143 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("grouped_tiered")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("unit_with_percent")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (unitWithPercentConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -21565,7 +36901,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -21573,54 +36909,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun tiered(): TieredConversionRateConfig? = tiered + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") - fun isUnit(): Boolean = unit != null + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") - fun isTiered(): Boolean = tiered != null + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator - fun _json(): JsonValue? = _json + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @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) - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + companion object { + + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -21639,218 +37145,308 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + companion object { - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + val PRICE_ID = of("price_id") - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + val ITEM_ID = of("item_id") - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + val PRICE_TYPE = of("price_type") - companion object { + val CURRENCY = of("currency") - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + val PRICING_UNIT_ID = of("pricing_unit_id") - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + fun of(value: String) = Field(JsonField.of(value)) + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } - fun visitUnit(unit: UnitConversionRateConfig): T + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** + * 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns an enum member corresponding to this class instance's value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 OrbInvalidDataException in the default implementation. + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $value") + } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + private var validated: Boolean = false - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun validate(): Field = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - } - } - } - class GroupedTieredConfig - @JsonCreator - private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map - ) { + return other is Field && value == other.value + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + override fun hashCode() = value.hashCode() - fun toBuilder() = Builder().from(this) + override fun toString() = value.toString() + } - companion object { + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Returns a mutable builder for constructing an instance of [GroupedTieredConfig]. + * 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. */ - fun builder() = Builder() - } + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - /** A builder for [GroupedTieredConfig]. */ - class Builder internal constructor() { + companion object { - private var additionalProperties: MutableMap = mutableMapOf() + val INCLUDES = of("includes") - internal fun from(groupedTieredConfig: GroupedTieredConfig) = apply { - additionalProperties = groupedTieredConfig.additionalProperties.toMutableMap() + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + else -> Value._UNKNOWN } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } /** - * Returns an immutable instance of [GroupedTieredConfig]. + * Returns this class instance's primitive wire representation. * - * Further updates to this [Builder] will not mutate the returned instance. + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. */ - fun build(): GroupedTieredConfig = - GroupedTieredConfig(additionalProperties.toImmutable()) - } + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - private var validated: Boolean = false + private var validated: Boolean = false - fun validate(): GroupedTieredConfig = apply { - if (validated) { - return@apply + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true } - validated = true - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedTieredConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedTieredConfig{additionalProperties=$additionalProperties}" + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } /** @@ -21948,12 +37544,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -21979,6 +37573,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -21986,6 +37582,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -22000,6 +37597,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -22018,6 +37616,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -22034,6 +37633,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -22081,7 +37681,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -22089,30 +37689,306 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for unit_with_percent pricing */ + class UnitWithPercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(percent, unitAmount, mutableMapOf()) + + /** + * What percent, out of 100, of the calculated total to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percent(): String = percent.getRequired("percent") + + /** + * Rate per unit of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("percent") @ExcludeMissing fun _percent(): JsonField = percent + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 + * [UnitWithPercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [UnitWithPercentConfig]. */ + class Builder internal constructor() { + + private var percent: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(unitWithPercentConfig: UnitWithPercentConfig) = apply { + percent = unitWithPercentConfig.percent + unitAmount = unitWithPercentConfig.unitAmount + additionalProperties = unitWithPercentConfig.additionalProperties.toMutableMap() + } + + /** What percent, out of 100, of the calculated total to charge */ + fun percent(percent: String) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + /** Rate per unit of usage */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UnitWithPercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnitWithPercentConfig = + UnitWithPercentConfig( + checkRequired("percent", percent), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): UnitWithPercentConfig = apply { + if (validated) { + return@apply + } + + percent() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (percent.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnitWithPercentConfig && + percent == other.percent && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(percent, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UnitWithPercentConfig{percent=$percent, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedTiered && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && groupedTieredConfig == other.groupedTieredConfig && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UnitWithPercent && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + unitWithPercentConfig == other.unitWithPercentConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, groupedTieredConfig, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + unitWithPercentConfig, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedTiered{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, groupedTieredConfig=$groupedTieredConfig, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "UnitWithPercent{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, unitWithPercentConfig=$unitWithPercentConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class TieredWithMinimum + class MatrixWithAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -22123,6 +37999,7 @@ private constructor( private val fixedPriceQuantity: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, + private val matrixWithAllocationConfig: JsonField, private val maximum: JsonField, private val maximumAmount: JsonField, private val metadata: JsonField, @@ -22133,7 +38010,6 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, - private val tieredWithMinimumConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -22147,7 +38023,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -22176,6 +38058,9 @@ private constructor( @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @JsonProperty("item") @ExcludeMissing item: JsonField = JsonMissing.of(), + @JsonProperty("matrix_with_allocation_config") + @ExcludeMissing + matrixWithAllocationConfig: JsonField = JsonMissing.of(), @JsonProperty("maximum") @ExcludeMissing maximum: JsonField = JsonMissing.of(), @JsonProperty("maximum_amount") @ExcludeMissing @@ -22198,9 +38083,6 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("tiered_with_minimum_config") - @ExcludeMissing - tieredWithMinimumConfig: JsonField = JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -22209,7 +38091,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -22220,6 +38104,7 @@ private constructor( fixedPriceQuantity, invoicingCycleConfiguration, item, + matrixWithAllocationConfig, maximum, maximumAmount, metadata, @@ -22230,7 +38115,6 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, - tieredWithMinimumConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -22254,12 +38138,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -22317,11 +38214,23 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun item(): ItemSlim = item.getRequired("item") + /** + * Configuration for matrix_with_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun matrixWithAllocationConfig(): MatrixWithAllocationConfig = + matrixWithAllocationConfig.getRequired("matrix_with_allocation_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -22359,9 +38268,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("tiered_with_minimum") + * JsonValue.from("matrix_with_allocation") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -22396,13 +38307,6 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun tieredWithMinimumConfig(): TieredWithMinimumConfig = - tieredWithMinimumConfig.getRequired("tiered_with_minimum_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -22438,6 +38342,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -22445,6 +38358,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -22539,6 +38462,17 @@ private constructor( */ @JsonProperty("item") @ExcludeMissing fun _item(): JsonField = item + /** + * Returns the raw JSON value of [matrixWithAllocationConfig]. + * + * Unlike [matrixWithAllocationConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("matrix_with_allocation_config") + @ExcludeMissing + fun _matrixWithAllocationConfig(): JsonField = + matrixWithAllocationConfig + /** * Returns the raw JSON value of [maximum]. * @@ -22624,16 +38558,6 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId - /** - * Returns the raw JSON value of [tieredWithMinimumConfig]. - * - * Unlike [tieredWithMinimumConfig], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("tiered_with_minimum_config") - @ExcludeMissing - fun _tieredWithMinimumConfig(): JsonField = tieredWithMinimumConfig - /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -22660,14 +38584,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [TieredWithMinimum]. + * Returns a mutable builder for constructing an instance of [MatrixWithAllocation]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -22678,6 +38604,7 @@ private constructor( * .fixedPriceQuantity() * .invoicingCycleConfiguration() * .item() + * .matrixWithAllocationConfig() * .maximum() * .maximumAmount() * .metadata() @@ -22687,19 +38614,20 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .tieredWithMinimumConfig() * ``` */ fun builder() = Builder() } - /** A builder for [TieredWithMinimum]. */ + /** A builder for [MatrixWithAllocation]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -22710,49 +38638,52 @@ private constructor( private var fixedPriceQuantity: JsonField? = null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null + private var matrixWithAllocationConfig: JsonField? = null private var maximum: JsonField? = null private var maximumAmount: JsonField? = null private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("tiered_with_minimum") + private var modelType: JsonValue = JsonValue.from("matrix_with_allocation") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null - private var tieredWithMinimumConfig: JsonField? = null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(tieredWithMinimum: TieredWithMinimum) = apply { - id = tieredWithMinimum.id - billableMetric = tieredWithMinimum.billableMetric - billingCycleConfiguration = tieredWithMinimum.billingCycleConfiguration - cadence = tieredWithMinimum.cadence - conversionRate = tieredWithMinimum.conversionRate - conversionRateConfig = tieredWithMinimum.conversionRateConfig - createdAt = tieredWithMinimum.createdAt - creditAllocation = tieredWithMinimum.creditAllocation - currency = tieredWithMinimum.currency - discount = tieredWithMinimum.discount - externalPriceId = tieredWithMinimum.externalPriceId - fixedPriceQuantity = tieredWithMinimum.fixedPriceQuantity - invoicingCycleConfiguration = tieredWithMinimum.invoicingCycleConfiguration - item = tieredWithMinimum.item - maximum = tieredWithMinimum.maximum - maximumAmount = tieredWithMinimum.maximumAmount - metadata = tieredWithMinimum.metadata - minimum = tieredWithMinimum.minimum - minimumAmount = tieredWithMinimum.minimumAmount - modelType = tieredWithMinimum.modelType - name = tieredWithMinimum.name - planPhaseOrder = tieredWithMinimum.planPhaseOrder - priceType = tieredWithMinimum.priceType - replacesPriceId = tieredWithMinimum.replacesPriceId - tieredWithMinimumConfig = tieredWithMinimum.tieredWithMinimumConfig - dimensionalPriceConfiguration = tieredWithMinimum.dimensionalPriceConfiguration - additionalProperties = tieredWithMinimum.additionalProperties.toMutableMap() + internal fun from(matrixWithAllocation: MatrixWithAllocation) = apply { + id = matrixWithAllocation.id + billableMetric = matrixWithAllocation.billableMetric + billingCycleConfiguration = matrixWithAllocation.billingCycleConfiguration + billingMode = matrixWithAllocation.billingMode + cadence = matrixWithAllocation.cadence + compositePriceFilters = + matrixWithAllocation.compositePriceFilters.map { it.toMutableList() } + conversionRate = matrixWithAllocation.conversionRate + conversionRateConfig = matrixWithAllocation.conversionRateConfig + createdAt = matrixWithAllocation.createdAt + creditAllocation = matrixWithAllocation.creditAllocation + currency = matrixWithAllocation.currency + discount = matrixWithAllocation.discount + externalPriceId = matrixWithAllocation.externalPriceId + fixedPriceQuantity = matrixWithAllocation.fixedPriceQuantity + invoicingCycleConfiguration = matrixWithAllocation.invoicingCycleConfiguration + item = matrixWithAllocation.item + matrixWithAllocationConfig = matrixWithAllocation.matrixWithAllocationConfig + maximum = matrixWithAllocation.maximum + maximumAmount = matrixWithAllocation.maximumAmount + metadata = matrixWithAllocation.metadata + minimum = matrixWithAllocation.minimum + minimumAmount = matrixWithAllocation.minimumAmount + modelType = matrixWithAllocation.modelType + name = matrixWithAllocation.name + planPhaseOrder = matrixWithAllocation.planPhaseOrder + priceType = matrixWithAllocation.priceType + replacesPriceId = matrixWithAllocation.replacesPriceId + dimensionalPriceConfiguration = matrixWithAllocation.dimensionalPriceConfiguration + additionalProperties = matrixWithAllocation.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -22794,6 +38725,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -22805,6 +38749,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -23061,6 +39033,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -23072,6 +39048,21 @@ private constructor( */ fun item(item: JsonField) = apply { this.item = item } + /** Configuration for matrix_with_allocation pricing */ + fun matrixWithAllocationConfig(matrixWithAllocationConfig: MatrixWithAllocationConfig) = + matrixWithAllocationConfig(JsonField.of(matrixWithAllocationConfig)) + + /** + * Sets [Builder.matrixWithAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.matrixWithAllocationConfig] with a well-typed + * [MatrixWithAllocationConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun matrixWithAllocationConfig( + matrixWithAllocationConfig: JsonField + ) = apply { this.matrixWithAllocationConfig = matrixWithAllocationConfig } + @Deprecated("deprecated") fun maximum(maximum: Maximum?) = maximum(JsonField.ofNullable(maximum)) @@ -23152,7 +39143,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("tiered_with_minimum") + * JsonValue.from("matrix_with_allocation") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -23221,20 +39212,6 @@ private constructor( this.replacesPriceId = replacesPriceId } - fun tieredWithMinimumConfig(tieredWithMinimumConfig: TieredWithMinimumConfig) = - tieredWithMinimumConfig(JsonField.of(tieredWithMinimumConfig)) - - /** - * Sets [Builder.tieredWithMinimumConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.tieredWithMinimumConfig] with a well-typed - * [TieredWithMinimumConfig] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun tieredWithMinimumConfig( - tieredWithMinimumConfig: JsonField - ) = apply { this.tieredWithMinimumConfig = tieredWithMinimumConfig } - fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -23270,7 +39247,7 @@ private constructor( } /** - * Returns an immutable instance of [TieredWithMinimum]. + * Returns an immutable instance of [MatrixWithAllocation]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -23279,7 +39256,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -23290,6 +39269,7 @@ private constructor( * .fixedPriceQuantity() * .invoicingCycleConfiguration() * .item() + * .matrixWithAllocationConfig() * .maximum() * .maximumAmount() * .metadata() @@ -23299,17 +39279,20 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .tieredWithMinimumConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): TieredWithMinimum = - TieredWithMinimum( + fun build(): MatrixWithAllocation = + MatrixWithAllocation( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -23320,6 +39303,7 @@ private constructor( checkRequired("fixedPriceQuantity", fixedPriceQuantity), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), + checkRequired("matrixWithAllocationConfig", matrixWithAllocationConfig), checkRequired("maximum", maximum), checkRequired("maximumAmount", maximumAmount), checkRequired("metadata", metadata), @@ -23330,7 +39314,6 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), - checkRequired("tieredWithMinimumConfig", tieredWithMinimumConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -23338,7 +39321,7 @@ private constructor( private var validated: Boolean = false - fun validate(): TieredWithMinimum = apply { + fun validate(): MatrixWithAllocation = apply { if (validated) { return@apply } @@ -23346,7 +39329,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -23357,13 +39342,14 @@ private constructor( fixedPriceQuantity() invoicingCycleConfiguration()?.validate() item().validate() + matrixWithAllocationConfig().validate() maximum()?.validate() maximumAmount() metadata().validate() minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("tiered_with_minimum")) { + if (it != JsonValue.from("matrix_with_allocation")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -23371,7 +39357,6 @@ private constructor( planPhaseOrder() priceType().validate() replacesPriceId() - tieredWithMinimumConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -23394,7 +39379,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -23405,19 +39392,148 @@ private constructor( (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + + (matrixWithAllocationConfig.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + (if (maximumAmount.asKnown() == null) 0 else 1) + (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("tiered_with_minimum")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("matrix_with_allocation")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + - (tieredWithMinimumConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -23562,7 +39678,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -23570,211 +39686,167 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit - - fun tiered(): TieredConversionRateConfig? = tiered - - fun isUnit(): Boolean = unit != null - - fun isTiered(): Boolean = tiered != null + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") - - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } - - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } - } - ) - validated = true - } + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") /** - * Returns a score indicating how many valid values are contained in this object - * recursively. + * The IDs or values that match this filter. * - * Used for best match union deserialization. + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + fun values(): List = values.getRequired("values") - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + fun toBuilder() = Builder().from(this) companion object { - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) - - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } - - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { - - fun visitUnit(unit: UnitConversionRateConfig): T - - fun visitTiered(tiered: TieredConversionRateConfig): T - /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } + fun builder() = Builder() } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - } + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - return ConversionRateConfig(_json = json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } - } - } - } - - /** - * User specified key-value pairs for the resource. If not present, this defaults to an - * empty dictionary. Individual keys can be removed by setting the value to `null`, and the - * entire metadata mapping can be cleared by setting `metadata` to `null`. - */ - class Metadata - @JsonCreator - private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map - ) { - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun toBuilder() = Builder().from(this) + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } - companion object { + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) - /** Returns a mutable builder for constructing an instance of [Metadata]. */ - fun builder() = Builder() - } + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } - /** A builder for [Metadata]. */ - class Builder internal constructor() { + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.additionalProperties.toMutableMap() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) + } } fun additionalProperties(additionalProperties: Map) = apply { @@ -23800,20 +39872,38 @@ private constructor( } /** - * Returns an immutable instance of [Metadata]. + * Returns an immutable instance of [CompositePriceFilter]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): Metadata = apply { + fun validate(): CompositePriceFilter = apply { if (validated) { return@apply } + field().validate() + operator().validate() + values() validated = true } @@ -23832,155 +39922,316 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - override fun hashCode(): Int = hashCode + /** + * 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } - override fun toString() = "Metadata{additionalProperties=$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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $value") + } - class PriceType @JsonCreator private constructor(private val value: JsonField) : - Enum { + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - /** - * 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 var validated: Boolean = false - companion object { + fun validate(): Field = apply { + if (validated) { + return@apply + } - val USAGE_PRICE = of("usage_price") + known() + validated = true + } - val FIXED_PRICE = of("fixed_price") + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun of(value: String) = PriceType(JsonField.of(value)) - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - /** An enum containing [PriceType]'s known values. */ - enum class Known { - USAGE_PRICE, - FIXED_PRICE, + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() } - /** - * An enum containing [PriceType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [PriceType] 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 { - USAGE_PRICE, - FIXED_PRICE, + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + /** - * An enum member indicating that [PriceType] was instantiated with an unknown - * value. + * 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. */ - _UNKNOWN, - } + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = 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) { - USAGE_PRICE -> Value.USAGE_PRICE - FIXED_PRICE -> Value.FIXED_PRICE - else -> Value._UNKNOWN + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) } - /** - * 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 OrbInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - USAGE_PRICE -> Known.USAGE_PRICE - FIXED_PRICE -> Known.FIXED_PRICE - else -> throw OrbInvalidDataException("Unknown PriceType: $value") + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, } - /** - * 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 OrbInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - private var validated: Boolean = false + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + else -> Value._UNKNOWN + } - fun validate(): PriceType = apply { - if (validated) { - return@apply + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true } - known() - validated = true - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties } - override fun hashCode() = value.hashCode() + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } - override fun toString() = value.toString() + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } - class TieredWithMinimumConfig + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and the + * entire metadata mapping can be cleared by setting `metadata` to `null`. + */ + class Metadata @JsonCreator private constructor( @com.fasterxml.jackson.annotation.JsonValue @@ -23995,21 +40246,17 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of - * [TieredWithMinimumConfig]. - */ + /** Returns a mutable builder for constructing an instance of [Metadata]. */ fun builder() = Builder() } - /** A builder for [TieredWithMinimumConfig]. */ + /** A builder for [Metadata]. */ class Builder internal constructor() { private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(tieredWithMinimumConfig: TieredWithMinimumConfig) = apply { - additionalProperties = - tieredWithMinimumConfig.additionalProperties.toMutableMap() + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() } fun additionalProperties(additionalProperties: Map) = apply { @@ -24035,17 +40282,16 @@ private constructor( } /** - * Returns an immutable instance of [TieredWithMinimumConfig]. + * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): TieredWithMinimumConfig = - TieredWithMinimumConfig(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false - fun validate(): TieredWithMinimumConfig = apply { + fun validate(): Metadata = apply { if (validated) { return@apply } @@ -24075,17 +40321,149 @@ private constructor( return true } - return /* spotless:off */ other is TieredWithMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode - override fun toString() = - "TieredWithMinimumConfig{additionalProperties=$additionalProperties}" + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + class PriceType @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 { + + val USAGE_PRICE = of("usage_price") + + val FIXED_PRICE = of("fixed_price") + + val COMPOSITE_PRICE = of("composite_price") + + fun of(value: String) = PriceType(JsonField.of(value)) + } + + /** An enum containing [PriceType]'s known values. */ + enum class Known { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + } + + /** + * An enum containing [PriceType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [PriceType] 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 { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + /** + * An enum member indicating that [PriceType] 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) { + USAGE_PRICE -> Value.USAGE_PRICE + FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USAGE_PRICE -> Known.USAGE_PRICE + FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE + else -> throw OrbInvalidDataException("Unknown PriceType: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): PriceType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 PriceType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() } override fun equals(other: Any?): Boolean { @@ -24093,25 +40471,87 @@ private constructor( return true } - return /* spotless:off */ other is TieredWithMinimum && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && tieredWithMinimumConfig == other.tieredWithMinimumConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MatrixWithAllocation && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + matrixWithAllocationConfig == other.matrixWithAllocationConfig && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, tieredWithMinimumConfig, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + matrixWithAllocationConfig, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "TieredWithMinimum{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, tieredWithMinimumConfig=$tieredWithMinimumConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "MatrixWithAllocation{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, matrixWithAllocationConfig=$matrixWithAllocationConfig, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class TieredPackageWithMinimum + class TieredWithProration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -24132,7 +40572,7 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, - private val tieredPackageWithMinimumConfig: JsonField, + private val tieredWithProrationConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -24146,7 +40586,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -24197,10 +40643,9 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("tiered_package_with_minimum_config") + @JsonProperty("tiered_with_proration_config") @ExcludeMissing - tieredPackageWithMinimumConfig: JsonField = - JsonMissing.of(), + tieredWithProrationConfig: JsonField = JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -24209,7 +40654,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -24230,7 +40677,7 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, - tieredPackageWithMinimumConfig, + tieredWithProrationConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -24254,12 +40701,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -24317,6 +40777,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -24359,9 +40822,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("tiered_package_with_minimum") + * JsonValue.from("tiered_with_proration") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -24397,11 +40862,13 @@ private constructor( fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") /** + * Configuration for tiered_with_proration pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun tieredPackageWithMinimumConfig(): TieredPackageWithMinimumConfig = - tieredPackageWithMinimumConfig.getRequired("tiered_package_with_minimum_config") + fun tieredWithProrationConfig(): TieredWithProrationConfig = + tieredWithProrationConfig.getRequired("tiered_with_proration_config") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -24438,6 +40905,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -24445,6 +40921,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -24625,15 +41111,15 @@ private constructor( fun _replacesPriceId(): JsonField = replacesPriceId /** - * Returns the raw JSON value of [tieredPackageWithMinimumConfig]. + * Returns the raw JSON value of [tieredWithProrationConfig]. * - * Unlike [tieredPackageWithMinimumConfig], this method doesn't throw if the JSON field has - * an unexpected type. + * Unlike [tieredWithProrationConfig], this method doesn't throw if the JSON field has an + * unexpected type. */ - @JsonProperty("tiered_package_with_minimum_config") + @JsonProperty("tiered_with_proration_config") @ExcludeMissing - fun _tieredPackageWithMinimumConfig(): JsonField = - tieredPackageWithMinimumConfig + fun _tieredWithProrationConfig(): JsonField = + tieredWithProrationConfig /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. @@ -24661,14 +41147,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [TieredPackageWithMinimum]. + * Returns a mutable builder for constructing an instance of [TieredWithProration]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -24688,19 +41176,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .tieredPackageWithMinimumConfig() + * .tieredWithProrationConfig() * ``` */ fun builder() = Builder() } - /** A builder for [TieredPackageWithMinimum]. */ + /** A builder for [TieredWithProration]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -24716,47 +41206,47 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("tiered_package_with_minimum") + private var modelType: JsonValue = JsonValue.from("tiered_with_proration") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null - private var tieredPackageWithMinimumConfig: JsonField? = - null + private var tieredWithProrationConfig: JsonField? = null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(tieredPackageWithMinimum: TieredPackageWithMinimum) = apply { - id = tieredPackageWithMinimum.id - billableMetric = tieredPackageWithMinimum.billableMetric - billingCycleConfiguration = tieredPackageWithMinimum.billingCycleConfiguration - cadence = tieredPackageWithMinimum.cadence - conversionRate = tieredPackageWithMinimum.conversionRate - conversionRateConfig = tieredPackageWithMinimum.conversionRateConfig - createdAt = tieredPackageWithMinimum.createdAt - creditAllocation = tieredPackageWithMinimum.creditAllocation - currency = tieredPackageWithMinimum.currency - discount = tieredPackageWithMinimum.discount - externalPriceId = tieredPackageWithMinimum.externalPriceId - fixedPriceQuantity = tieredPackageWithMinimum.fixedPriceQuantity - invoicingCycleConfiguration = tieredPackageWithMinimum.invoicingCycleConfiguration - item = tieredPackageWithMinimum.item - maximum = tieredPackageWithMinimum.maximum - maximumAmount = tieredPackageWithMinimum.maximumAmount - metadata = tieredPackageWithMinimum.metadata - minimum = tieredPackageWithMinimum.minimum - minimumAmount = tieredPackageWithMinimum.minimumAmount - modelType = tieredPackageWithMinimum.modelType - name = tieredPackageWithMinimum.name - planPhaseOrder = tieredPackageWithMinimum.planPhaseOrder - priceType = tieredPackageWithMinimum.priceType - replacesPriceId = tieredPackageWithMinimum.replacesPriceId - tieredPackageWithMinimumConfig = - tieredPackageWithMinimum.tieredPackageWithMinimumConfig - dimensionalPriceConfiguration = - tieredPackageWithMinimum.dimensionalPriceConfiguration - additionalProperties = tieredPackageWithMinimum.additionalProperties.toMutableMap() + internal fun from(tieredWithProration: TieredWithProration) = apply { + id = tieredWithProration.id + billableMetric = tieredWithProration.billableMetric + billingCycleConfiguration = tieredWithProration.billingCycleConfiguration + billingMode = tieredWithProration.billingMode + cadence = tieredWithProration.cadence + compositePriceFilters = + tieredWithProration.compositePriceFilters.map { it.toMutableList() } + conversionRate = tieredWithProration.conversionRate + conversionRateConfig = tieredWithProration.conversionRateConfig + createdAt = tieredWithProration.createdAt + creditAllocation = tieredWithProration.creditAllocation + currency = tieredWithProration.currency + discount = tieredWithProration.discount + externalPriceId = tieredWithProration.externalPriceId + fixedPriceQuantity = tieredWithProration.fixedPriceQuantity + invoicingCycleConfiguration = tieredWithProration.invoicingCycleConfiguration + item = tieredWithProration.item + maximum = tieredWithProration.maximum + maximumAmount = tieredWithProration.maximumAmount + metadata = tieredWithProration.metadata + minimum = tieredWithProration.minimum + minimumAmount = tieredWithProration.minimumAmount + modelType = tieredWithProration.modelType + name = tieredWithProration.name + planPhaseOrder = tieredWithProration.planPhaseOrder + priceType = tieredWithProration.priceType + replacesPriceId = tieredWithProration.replacesPriceId + tieredWithProrationConfig = tieredWithProration.tieredWithProrationConfig + dimensionalPriceConfiguration = tieredWithProration.dimensionalPriceConfiguration + additionalProperties = tieredWithProration.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -24798,6 +41288,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -24809,6 +41312,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -25065,6 +41596,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -25156,7 +41691,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("tiered_package_with_minimum") + * JsonValue.from("tiered_with_proration") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -25225,20 +41760,20 @@ private constructor( this.replacesPriceId = replacesPriceId } - fun tieredPackageWithMinimumConfig( - tieredPackageWithMinimumConfig: TieredPackageWithMinimumConfig - ) = tieredPackageWithMinimumConfig(JsonField.of(tieredPackageWithMinimumConfig)) + /** Configuration for tiered_with_proration pricing */ + fun tieredWithProrationConfig(tieredWithProrationConfig: TieredWithProrationConfig) = + tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) /** - * Sets [Builder.tieredPackageWithMinimumConfig] to an arbitrary JSON value. + * Sets [Builder.tieredWithProrationConfig] to an arbitrary JSON value. * - * You should usually call [Builder.tieredPackageWithMinimumConfig] with a well-typed - * [TieredPackageWithMinimumConfig] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. + * You should usually call [Builder.tieredWithProrationConfig] with a well-typed + * [TieredWithProrationConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. */ - fun tieredPackageWithMinimumConfig( - tieredPackageWithMinimumConfig: JsonField - ) = apply { this.tieredPackageWithMinimumConfig = tieredPackageWithMinimumConfig } + fun tieredWithProrationConfig( + tieredWithProrationConfig: JsonField + ) = apply { this.tieredWithProrationConfig = tieredWithProrationConfig } fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? @@ -25275,7 +41810,7 @@ private constructor( } /** - * Returns an immutable instance of [TieredPackageWithMinimum]. + * Returns an immutable instance of [TieredWithProration]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -25284,7 +41819,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -25304,17 +41841,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .tieredPackageWithMinimumConfig() + * .tieredWithProrationConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): TieredPackageWithMinimum = - TieredPackageWithMinimum( + fun build(): TieredWithProration = + TieredWithProration( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -25335,7 +41876,7 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), - checkRequired("tieredPackageWithMinimumConfig", tieredPackageWithMinimumConfig), + checkRequired("tieredWithProrationConfig", tieredWithProrationConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -25343,7 +41884,7 @@ private constructor( private var validated: Boolean = false - fun validate(): TieredPackageWithMinimum = apply { + fun validate(): TieredWithProration = apply { if (validated) { return@apply } @@ -25351,7 +41892,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -25368,7 +41911,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("tiered_package_with_minimum")) { + if (it != JsonValue.from("tiered_with_proration")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -25376,7 +41919,7 @@ private constructor( planPhaseOrder() priceType().validate() replacesPriceId() - tieredPackageWithMinimumConfig().validate() + tieredWithProrationConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -25399,7 +41942,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -25415,16 +41960,143 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { - if (it == JsonValue.from("tiered_package_with_minimum")) 1 else 0 - } + + modelType.let { if (it == JsonValue.from("tiered_with_proration")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + - (tieredPackageWithMinimumConfig.asKnown()?.validity() ?: 0) + + (tieredWithProrationConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -25569,7 +42241,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -25577,54 +42249,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun isUnit(): Boolean = unit != null + fun toBuilder() = Builder().from(this) - fun isTiered(): Boolean = tiered != null + companion object { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -25643,112 +42485,308 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + private var validated: Boolean = false - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() - fun visitUnit(unit: UnitConversionRateConfig): T + override fun toString() = value.toString() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + private var validated: Boolean = false - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } /** @@ -25846,12 +42884,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -25877,6 +42913,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -25884,6 +42922,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -25898,6 +42937,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -25916,6 +42956,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -25932,6 +42973,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -25979,7 +43021,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -25987,16 +43029,47 @@ private constructor( override fun toString() = value.toString() } - class TieredPackageWithMinimumConfig - @JsonCreator + /** Configuration for tiered_with_proration pricing */ + class TieredWithProrationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Tiers for rating based on total usage quantities into the specified tier with + * proration + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -26004,21 +43077,56 @@ private constructor( /** * Returns a mutable builder for constructing an instance of - * [TieredPackageWithMinimumConfig]. + * [TieredWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` */ fun builder() = Builder() } - /** A builder for [TieredPackageWithMinimumConfig]. */ + /** A builder for [TieredWithProrationConfig]. */ class Builder internal constructor() { + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(tieredPackageWithMinimumConfig: TieredPackageWithMinimumConfig) = - apply { - additionalProperties = - tieredPackageWithMinimumConfig.additionalProperties.toMutableMap() - } + internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = apply { + tiers = tieredWithProrationConfig.tiers.map { it.toMutableList() } + additionalProperties = + tieredWithProrationConfig.additionalProperties.toMutableMap() + } + + /** + * Tiers for rating based on total usage quantities into the specified tier with + * proration + */ + 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() @@ -26043,21 +43151,32 @@ private constructor( } /** - * Returns an immutable instance of [TieredPackageWithMinimumConfig]. + * Returns an immutable instance of [TieredWithProrationConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): TieredPackageWithMinimumConfig = - TieredPackageWithMinimumConfig(additionalProperties.toImmutable()) + fun build(): TieredWithProrationConfig = + TieredWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): TieredPackageWithMinimumConfig = apply { + fun validate(): TieredWithProrationConfig = apply { if (validated) { return@apply } + tiers().forEach { it.validate() } validated = true } @@ -26075,25 +43194,243 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + internal fun validity(): Int = (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tiered with proration tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Inclusive tier starting value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Inclusive tier starting value */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is TieredPackageWithMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TieredWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "TieredPackageWithMinimumConfig{additionalProperties=$additionalProperties}" + "TieredWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -26101,25 +43438,87 @@ private constructor( return true } - return /* spotless:off */ other is TieredPackageWithMinimum && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && tieredPackageWithMinimumConfig == other.tieredPackageWithMinimumConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TieredWithProration && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + tieredWithProrationConfig == other.tieredWithProrationConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, tieredPackageWithMinimumConfig, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + tieredWithProrationConfig, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "TieredPackageWithMinimum{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, tieredPackageWithMinimumConfig=$tieredPackageWithMinimumConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "TieredWithProration{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, tieredWithProrationConfig=$tieredWithProrationConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class PackageWithAllocation + class UnitWithProration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -26137,10 +43536,10 @@ private constructor( private val minimumAmount: JsonField, private val modelType: JsonValue, private val name: JsonField, - private val packageWithAllocationConfig: JsonField, private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, + private val unitWithProrationConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -26154,7 +43553,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -26196,9 +43601,6 @@ private constructor( minimumAmount: JsonField = JsonMissing.of(), @JsonProperty("model_type") @ExcludeMissing modelType: JsonValue = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("package_with_allocation_config") - @ExcludeMissing - packageWithAllocationConfig: JsonField = JsonMissing.of(), @JsonProperty("plan_phase_order") @ExcludeMissing planPhaseOrder: JsonField = JsonMissing.of(), @@ -26208,6 +43610,9 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), + @JsonProperty("unit_with_proration_config") + @ExcludeMissing + unitWithProrationConfig: JsonField = JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -26216,7 +43621,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -26234,10 +43641,10 @@ private constructor( minimumAmount, modelType, name, - packageWithAllocationConfig, planPhaseOrder, priceType, replacesPriceId, + unitWithProrationConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -26261,12 +43668,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -26324,6 +43744,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -26366,9 +43789,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("package_with_allocation") + * JsonValue.from("unit_with_proration") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -26382,13 +43807,6 @@ private constructor( */ fun name(): String = name.getRequired("name") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun packageWithAllocationConfig(): PackageWithAllocationConfig = - packageWithAllocationConfig.getRequired("package_with_allocation_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -26410,6 +43828,15 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") + /** + * Configuration for unit_with_proration pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitWithProrationConfig(): UnitWithProrationConfig = + unitWithProrationConfig.getRequired("unit_with_proration_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -26445,6 +43872,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -26452,6 +43888,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -26602,17 +44048,6 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - /** - * Returns the raw JSON value of [packageWithAllocationConfig]. - * - * Unlike [packageWithAllocationConfig], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("package_with_allocation_config") - @ExcludeMissing - fun _packageWithAllocationConfig(): JsonField = - packageWithAllocationConfig - /** * Returns the raw JSON value of [planPhaseOrder]. * @@ -26642,6 +44077,16 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId + /** + * Returns the raw JSON value of [unitWithProrationConfig]. + * + * Unlike [unitWithProrationConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_with_proration_config") + @ExcludeMissing + fun _unitWithProrationConfig(): JsonField = unitWithProrationConfig + /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -26668,14 +44113,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [PackageWithAllocation]. + * Returns a mutable builder for constructing an instance of [UnitWithProration]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -26692,22 +44139,24 @@ private constructor( * .minimum() * .minimumAmount() * .name() - * .packageWithAllocationConfig() * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .unitWithProrationConfig() * ``` */ fun builder() = Builder() } - /** A builder for [PackageWithAllocation]. */ + /** A builder for [UnitWithProration]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -26723,44 +44172,47 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("package_with_allocation") + private var modelType: JsonValue = JsonValue.from("unit_with_proration") private var name: JsonField? = null - private var packageWithAllocationConfig: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null + private var unitWithProrationConfig: JsonField? = null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(packageWithAllocation: PackageWithAllocation) = apply { - id = packageWithAllocation.id - billableMetric = packageWithAllocation.billableMetric - billingCycleConfiguration = packageWithAllocation.billingCycleConfiguration - cadence = packageWithAllocation.cadence - conversionRate = packageWithAllocation.conversionRate - conversionRateConfig = packageWithAllocation.conversionRateConfig - createdAt = packageWithAllocation.createdAt - creditAllocation = packageWithAllocation.creditAllocation - currency = packageWithAllocation.currency - discount = packageWithAllocation.discount - externalPriceId = packageWithAllocation.externalPriceId - fixedPriceQuantity = packageWithAllocation.fixedPriceQuantity - invoicingCycleConfiguration = packageWithAllocation.invoicingCycleConfiguration - item = packageWithAllocation.item - maximum = packageWithAllocation.maximum - maximumAmount = packageWithAllocation.maximumAmount - metadata = packageWithAllocation.metadata - minimum = packageWithAllocation.minimum - minimumAmount = packageWithAllocation.minimumAmount - modelType = packageWithAllocation.modelType - name = packageWithAllocation.name - packageWithAllocationConfig = packageWithAllocation.packageWithAllocationConfig - planPhaseOrder = packageWithAllocation.planPhaseOrder - priceType = packageWithAllocation.priceType - replacesPriceId = packageWithAllocation.replacesPriceId - dimensionalPriceConfiguration = packageWithAllocation.dimensionalPriceConfiguration - additionalProperties = packageWithAllocation.additionalProperties.toMutableMap() + internal fun from(unitWithProration: UnitWithProration) = apply { + id = unitWithProration.id + billableMetric = unitWithProration.billableMetric + billingCycleConfiguration = unitWithProration.billingCycleConfiguration + billingMode = unitWithProration.billingMode + cadence = unitWithProration.cadence + compositePriceFilters = + unitWithProration.compositePriceFilters.map { it.toMutableList() } + conversionRate = unitWithProration.conversionRate + conversionRateConfig = unitWithProration.conversionRateConfig + createdAt = unitWithProration.createdAt + creditAllocation = unitWithProration.creditAllocation + currency = unitWithProration.currency + discount = unitWithProration.discount + externalPriceId = unitWithProration.externalPriceId + fixedPriceQuantity = unitWithProration.fixedPriceQuantity + invoicingCycleConfiguration = unitWithProration.invoicingCycleConfiguration + item = unitWithProration.item + maximum = unitWithProration.maximum + maximumAmount = unitWithProration.maximumAmount + metadata = unitWithProration.metadata + minimum = unitWithProration.minimum + minimumAmount = unitWithProration.minimumAmount + modelType = unitWithProration.modelType + name = unitWithProration.name + planPhaseOrder = unitWithProration.planPhaseOrder + priceType = unitWithProration.priceType + replacesPriceId = unitWithProration.replacesPriceId + unitWithProrationConfig = unitWithProration.unitWithProrationConfig + dimensionalPriceConfiguration = unitWithProration.dimensionalPriceConfiguration + additionalProperties = unitWithProration.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -26802,6 +44254,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -26813,6 +44278,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -27069,6 +44562,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -27160,7 +44657,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("package_with_allocation") + * JsonValue.from("unit_with_proration") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -27179,21 +44676,6 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } - fun packageWithAllocationConfig( - packageWithAllocationConfig: PackageWithAllocationConfig - ) = packageWithAllocationConfig(JsonField.of(packageWithAllocationConfig)) - - /** - * Sets [Builder.packageWithAllocationConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.packageWithAllocationConfig] with a well-typed - * [PackageWithAllocationConfig] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun packageWithAllocationConfig( - packageWithAllocationConfig: JsonField - ) = apply { this.packageWithAllocationConfig = packageWithAllocationConfig } - fun planPhaseOrder(planPhaseOrder: Long?) = planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) @@ -27244,6 +44726,21 @@ private constructor( this.replacesPriceId = replacesPriceId } + /** Configuration for unit_with_proration pricing */ + fun unitWithProrationConfig(unitWithProrationConfig: UnitWithProrationConfig) = + unitWithProrationConfig(JsonField.of(unitWithProrationConfig)) + + /** + * Sets [Builder.unitWithProrationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.unitWithProrationConfig] with a well-typed + * [UnitWithProrationConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitWithProrationConfig( + unitWithProrationConfig: JsonField + ) = apply { this.unitWithProrationConfig = unitWithProrationConfig } + fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -27279,7 +44776,7 @@ private constructor( } /** - * Returns an immutable instance of [PackageWithAllocation]. + * Returns an immutable instance of [UnitWithProration]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -27288,7 +44785,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -27305,20 +44804,24 @@ private constructor( * .minimum() * .minimumAmount() * .name() - * .packageWithAllocationConfig() * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .unitWithProrationConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): PackageWithAllocation = - PackageWithAllocation( + fun build(): UnitWithProration = + UnitWithProration( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -27336,10 +44839,10 @@ private constructor( checkRequired("minimumAmount", minimumAmount), modelType, checkRequired("name", name), - checkRequired("packageWithAllocationConfig", packageWithAllocationConfig), checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), + checkRequired("unitWithProrationConfig", unitWithProrationConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -27347,7 +44850,7 @@ private constructor( private var validated: Boolean = false - fun validate(): PackageWithAllocation = apply { + fun validate(): UnitWithProration = apply { if (validated) { return@apply } @@ -27355,7 +44858,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -27372,15 +44877,15 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("package_with_allocation")) { + if (it != JsonValue.from("unit_with_proration")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } name() - packageWithAllocationConfig().validate() planPhaseOrder() priceType().validate() replacesPriceId() + unitWithProrationConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -27403,7 +44908,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -27419,14 +44926,143 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("package_with_allocation")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("unit_with_proration")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + - (packageWithAllocationConfig.asKnown()?.validity() ?: 0) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (unitWithProrationConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -27571,7 +45207,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -27579,54 +45215,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun tiered(): TieredConversionRateConfig? = tiered + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") - fun isUnit(): Boolean = unit != null + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") - fun isTiered(): Boolean = tiered != null + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator - fun _json(): JsonValue? = _json + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -27645,222 +45451,316 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + companion object { - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + val PRICE_ID = of("price_id") - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + val ITEM_ID = of("item_id") - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + val PRICE_TYPE = of("price_type") - companion object { + val CURRENCY = of("currency") - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + val PRICING_UNIT_ID = of("pricing_unit_id") - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + fun of(value: String) = Field(JsonField.of(value)) + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } - fun visitUnit(unit: UnitConversionRateConfig): T + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** + * 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns an enum member corresponding to this class instance's value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 OrbInvalidDataException in the default implementation. + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") - } - } + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $value") + } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + private var validated: Boolean = false - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun validate(): Field = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value } - } - } - /** - * User specified key-value pairs for the resource. If not present, this defaults to an - * empty dictionary. Individual keys can be removed by setting the value to `null`, and the - * entire metadata mapping can be cleared by setting `metadata` to `null`. - */ - class Metadata - @JsonCreator - private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map - ) { + override fun hashCode() = value.hashCode() - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + override fun toString() = value.toString() + } - fun toBuilder() = Builder().from(this) + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { - companion object { + /** + * 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 - /** Returns a mutable builder for constructing an instance of [Metadata]. */ - fun builder() = Builder() - } + companion object { - /** A builder for [Metadata]. */ - class Builder internal constructor() { + val INCLUDES = of("includes") - private var additionalProperties: MutableMap = mutableMapOf() + val EXCLUDES = of("excludes") - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.additionalProperties.toMutableMap() + fun of(value: String) = Operator(JsonField.of(value)) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + else -> Value._UNKNOWN } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } /** - * Returns an immutable instance of [Metadata]. + * Returns this class instance's primitive wire representation. * - * Further updates to this [Builder] will not mutate the returned instance. + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) - } + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - private var validated: Boolean = false + private var validated: Boolean = false - fun validate(): Metadata = apply { - if (validated) { - return@apply + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true } - validated = true - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } override fun hashCode(): Int = hashCode - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } - class PackageWithAllocationConfig + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and the + * entire metadata mapping can be cleared by setting `metadata` to `null`. + */ + class Metadata @JsonCreator private constructor( @com.fasterxml.jackson.annotation.JsonValue @@ -27875,23 +45775,18 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of - * [PackageWithAllocationConfig]. - */ + /** Returns a mutable builder for constructing an instance of [Metadata]. */ fun builder() = Builder() } - /** A builder for [PackageWithAllocationConfig]. */ + /** A builder for [Metadata]. */ class Builder internal constructor() { private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(packageWithAllocationConfig: PackageWithAllocationConfig) = - apply { - additionalProperties = - packageWithAllocationConfig.additionalProperties.toMutableMap() - } + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -27916,17 +45811,16 @@ private constructor( } /** - * Returns an immutable instance of [PackageWithAllocationConfig]. + * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): PackageWithAllocationConfig = - PackageWithAllocationConfig(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false - fun validate(): PackageWithAllocationConfig = apply { + fun validate(): Metadata = apply { if (validated) { return@apply } @@ -27956,17 +45850,14 @@ private constructor( return true } - return /* spotless:off */ other is PackageWithAllocationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode - override fun toString() = - "PackageWithAllocationConfig{additionalProperties=$additionalProperties}" + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } class PriceType @JsonCreator private constructor(private val value: JsonField) : @@ -27988,6 +45879,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -27995,6 +45888,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -28009,6 +45903,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -28027,6 +45922,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -28043,6 +45939,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -28090,7 +45987,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -28098,30 +45995,264 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for unit_with_proration pricing */ + class UnitWithProrationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of() + ) : this(unitAmount, mutableMapOf()) + + /** + * Rate per unit of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 + * [UnitWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [UnitWithProrationConfig]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(unitWithProrationConfig: UnitWithProrationConfig) = apply { + unitAmount = unitWithProrationConfig.unitAmount + additionalProperties = + unitWithProrationConfig.additionalProperties.toMutableMap() + } + + /** Rate per unit of usage */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UnitWithProrationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnitWithProrationConfig = + UnitWithProrationConfig( + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): UnitWithProrationConfig = apply { + if (validated) { + return@apply + } + + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnitWithProrationConfig && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(unitAmount, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UnitWithProrationConfig{unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PackageWithAllocation && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && packageWithAllocationConfig == other.packageWithAllocationConfig && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UnitWithProration && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + unitWithProrationConfig == other.unitWithProrationConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, packageWithAllocationConfig, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + unitWithProrationConfig, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "PackageWithAllocation{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, packageWithAllocationConfig=$packageWithAllocationConfig, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "UnitWithProration{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, unitWithProrationConfig=$unitWithProrationConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class UnitWithPercent + class GroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -28130,6 +46261,7 @@ private constructor( private val discount: JsonField, private val externalPriceId: JsonField, private val fixedPriceQuantity: JsonField, + private val groupedAllocationConfig: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, private val maximum: JsonField, @@ -28142,7 +46274,6 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, - private val unitWithPercentConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -28156,7 +46287,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -28181,6 +46318,9 @@ private constructor( @JsonProperty("fixed_price_quantity") @ExcludeMissing fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("grouped_allocation_config") + @ExcludeMissing + groupedAllocationConfig: JsonField = JsonMissing.of(), @JsonProperty("invoicing_cycle_configuration") @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @@ -28207,9 +46347,6 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("unit_with_percent_config") - @ExcludeMissing - unitWithPercentConfig: JsonField = JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -28218,7 +46355,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -28227,6 +46366,7 @@ private constructor( discount, externalPriceId, fixedPriceQuantity, + groupedAllocationConfig, invoicingCycleConfiguration, item, maximum, @@ -28239,7 +46379,6 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, - unitWithPercentConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -28263,12 +46402,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -28318,6 +46470,15 @@ private constructor( */ fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") + /** + * Configuration for grouped_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupedAllocationConfig(): GroupedAllocationConfig = + groupedAllocationConfig.getRequired("grouped_allocation_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -28326,6 +46487,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -28368,9 +46532,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("unit_with_percent") + * JsonValue.from("grouped_allocation") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -28405,13 +46571,6 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun unitWithPercentConfig(): UnitWithPercentConfig = - unitWithPercentConfig.getRequired("unit_with_percent_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -28447,6 +46606,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -28454,6 +46622,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -28530,6 +46708,16 @@ private constructor( @ExcludeMissing fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + /** + * Returns the raw JSON value of [groupedAllocationConfig]. + * + * Unlike [groupedAllocationConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouped_allocation_config") + @ExcludeMissing + fun _groupedAllocationConfig(): JsonField = groupedAllocationConfig + /** * Returns the raw JSON value of [invoicingCycleConfiguration]. * @@ -28633,16 +46821,6 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId - /** - * Returns the raw JSON value of [unitWithPercentConfig]. - * - * Unlike [unitWithPercentConfig], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("unit_with_percent_config") - @ExcludeMissing - fun _unitWithPercentConfig(): JsonField = unitWithPercentConfig - /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -28669,14 +46847,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [UnitWithPercent]. + * Returns a mutable builder for constructing an instance of [GroupedAllocation]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -28685,6 +46865,7 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() + * .groupedAllocationConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -28696,19 +46877,20 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .unitWithPercentConfig() * ``` */ fun builder() = Builder() } - /** A builder for [UnitWithPercent]. */ + /** A builder for [GroupedAllocation]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -28717,6 +46899,7 @@ private constructor( private var discount: JsonField? = null private var externalPriceId: JsonField? = null private var fixedPriceQuantity: JsonField? = null + private var groupedAllocationConfig: JsonField? = null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null private var maximum: JsonField? = null @@ -28724,44 +46907,46 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("unit_with_percent") + private var modelType: JsonValue = JsonValue.from("grouped_allocation") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null - private var unitWithPercentConfig: JsonField? = null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(unitWithPercent: UnitWithPercent) = apply { - id = unitWithPercent.id - billableMetric = unitWithPercent.billableMetric - billingCycleConfiguration = unitWithPercent.billingCycleConfiguration - cadence = unitWithPercent.cadence - conversionRate = unitWithPercent.conversionRate - conversionRateConfig = unitWithPercent.conversionRateConfig - createdAt = unitWithPercent.createdAt - creditAllocation = unitWithPercent.creditAllocation - currency = unitWithPercent.currency - discount = unitWithPercent.discount - externalPriceId = unitWithPercent.externalPriceId - fixedPriceQuantity = unitWithPercent.fixedPriceQuantity - invoicingCycleConfiguration = unitWithPercent.invoicingCycleConfiguration - item = unitWithPercent.item - maximum = unitWithPercent.maximum - maximumAmount = unitWithPercent.maximumAmount - metadata = unitWithPercent.metadata - minimum = unitWithPercent.minimum - minimumAmount = unitWithPercent.minimumAmount - modelType = unitWithPercent.modelType - name = unitWithPercent.name - planPhaseOrder = unitWithPercent.planPhaseOrder - priceType = unitWithPercent.priceType - replacesPriceId = unitWithPercent.replacesPriceId - unitWithPercentConfig = unitWithPercent.unitWithPercentConfig - dimensionalPriceConfiguration = unitWithPercent.dimensionalPriceConfiguration - additionalProperties = unitWithPercent.additionalProperties.toMutableMap() + internal fun from(groupedAllocation: GroupedAllocation) = apply { + id = groupedAllocation.id + billableMetric = groupedAllocation.billableMetric + billingCycleConfiguration = groupedAllocation.billingCycleConfiguration + billingMode = groupedAllocation.billingMode + cadence = groupedAllocation.cadence + compositePriceFilters = + groupedAllocation.compositePriceFilters.map { it.toMutableList() } + conversionRate = groupedAllocation.conversionRate + conversionRateConfig = groupedAllocation.conversionRateConfig + createdAt = groupedAllocation.createdAt + creditAllocation = groupedAllocation.creditAllocation + currency = groupedAllocation.currency + discount = groupedAllocation.discount + externalPriceId = groupedAllocation.externalPriceId + fixedPriceQuantity = groupedAllocation.fixedPriceQuantity + groupedAllocationConfig = groupedAllocation.groupedAllocationConfig + invoicingCycleConfiguration = groupedAllocation.invoicingCycleConfiguration + item = groupedAllocation.item + maximum = groupedAllocation.maximum + maximumAmount = groupedAllocation.maximumAmount + metadata = groupedAllocation.metadata + minimum = groupedAllocation.minimum + minimumAmount = groupedAllocation.minimumAmount + modelType = groupedAllocation.modelType + name = groupedAllocation.name + planPhaseOrder = groupedAllocation.planPhaseOrder + priceType = groupedAllocation.priceType + replacesPriceId = groupedAllocation.replacesPriceId + dimensionalPriceConfiguration = groupedAllocation.dimensionalPriceConfiguration + additionalProperties = groupedAllocation.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -28803,6 +46988,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -28814,6 +47012,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -29055,6 +47281,21 @@ private constructor( this.fixedPriceQuantity = fixedPriceQuantity } + /** Configuration for grouped_allocation pricing */ + fun groupedAllocationConfig(groupedAllocationConfig: GroupedAllocationConfig) = + groupedAllocationConfig(JsonField.of(groupedAllocationConfig)) + + /** + * Sets [Builder.groupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedAllocationConfig] with a well-typed + * [GroupedAllocationConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun groupedAllocationConfig( + groupedAllocationConfig: JsonField + ) = apply { this.groupedAllocationConfig = groupedAllocationConfig } + fun invoicingCycleConfiguration( invoicingCycleConfiguration: BillingCycleConfiguration? ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) @@ -29070,6 +47311,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -29161,7 +47406,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("unit_with_percent") + * JsonValue.from("grouped_allocation") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -29230,21 +47475,6 @@ private constructor( this.replacesPriceId = replacesPriceId } - fun unitWithPercentConfig(unitWithPercentConfig: UnitWithPercentConfig) = - unitWithPercentConfig(JsonField.of(unitWithPercentConfig)) - - /** - * Sets [Builder.unitWithPercentConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.unitWithPercentConfig] with a well-typed - * [UnitWithPercentConfig] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. - */ - fun unitWithPercentConfig(unitWithPercentConfig: JsonField) = - apply { - this.unitWithPercentConfig = unitWithPercentConfig - } - fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -29280,7 +47510,7 @@ private constructor( } /** - * Returns an immutable instance of [UnitWithPercent]. + * Returns an immutable instance of [GroupedAllocation]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -29289,7 +47519,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -29298,6 +47530,7 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() + * .groupedAllocationConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -29309,17 +47542,20 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .unitWithPercentConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): UnitWithPercent = - UnitWithPercent( + fun build(): GroupedAllocation = + GroupedAllocation( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -29328,6 +47564,7 @@ private constructor( checkRequired("discount", discount), checkRequired("externalPriceId", externalPriceId), checkRequired("fixedPriceQuantity", fixedPriceQuantity), + checkRequired("groupedAllocationConfig", groupedAllocationConfig), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), checkRequired("maximum", maximum), @@ -29340,7 +47577,6 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), - checkRequired("unitWithPercentConfig", unitWithPercentConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -29348,7 +47584,7 @@ private constructor( private var validated: Boolean = false - fun validate(): UnitWithPercent = apply { + fun validate(): GroupedAllocation = apply { if (validated) { return@apply } @@ -29356,7 +47592,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -29365,6 +47603,7 @@ private constructor( discount()?.validate() externalPriceId() fixedPriceQuantity() + groupedAllocationConfig().validate() invoicingCycleConfiguration()?.validate() item().validate() maximum()?.validate() @@ -29373,7 +47612,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("unit_with_percent")) { + if (it != JsonValue.from("grouped_allocation")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -29381,7 +47620,6 @@ private constructor( planPhaseOrder() priceType().validate() replacesPriceId() - unitWithPercentConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -29404,7 +47642,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -29413,6 +47653,7 @@ private constructor( (discount.asKnown()?.validity() ?: 0) + (if (externalPriceId.asKnown() == null) 0 else 1) + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (groupedAllocationConfig.asKnown()?.validity() ?: 0) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + @@ -29420,14 +47661,142 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("unit_with_percent")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("grouped_allocation")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + - (unitWithPercentConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -29485,69 +47854,319 @@ private constructor( ANNUAL, CUSTOM, /** - * An enum member indicating that [Cadence] was instantiated with an unknown value. + * An enum member indicating that [Cadence] 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) { + ONE_TIME -> Value.ONE_TIME + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + SEMI_ANNUAL -> Value.SEMI_ANNUAL + ANNUAL -> Value.ANNUAL + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ONE_TIME -> Known.ONE_TIME + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + SEMI_ANNUAL -> Known.SEMI_ANNUAL + ANNUAL -> Known.ANNUAL + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @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 [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - _UNKNOWN, - } + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } - /** - * 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) { - ONE_TIME -> Value.ONE_TIME - MONTHLY -> Value.MONTHLY - QUARTERLY -> Value.QUARTERLY - SEMI_ANNUAL -> Value.SEMI_ANNUAL - ANNUAL -> Value.ANNUAL - CUSTOM -> Value.CUSTOM - else -> Value._UNKNOWN + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) + } } - /** - * 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 OrbInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - ONE_TIME -> Known.ONE_TIME - MONTHLY -> Known.MONTHLY - QUARTERLY -> Known.QUARTERLY - SEMI_ANNUAL -> Known.SEMI_ANNUAL - ANNUAL -> Known.ANNUAL - CUSTOM -> Known.CUSTOM - else -> throw OrbInvalidDataException("Unknown Cadence: $value") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - /** - * 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 OrbInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } private var validated: Boolean = false - fun validate(): Cadence = apply { + fun validate(): CompositePriceFilter = apply { if (validated) { return@apply } - known() + field().validate() + operator().validate() + values() validated = true } @@ -29565,193 +48184,575 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } - override fun hashCode() = value.hashCode() + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - override fun toString() = value.toString() - } + /** + * 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } - fun unit(): UnitConversionRateConfig? = unit + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() - fun tiered(): TieredConversionRateConfig? = tiered + override fun toString() = value.toString() + } - fun isUnit(): Boolean = unit != null + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { - fun isTiered(): Boolean = tiered != null + /** + * 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 - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + companion object { - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + val INCLUDES = of("includes") - fun _json(): JsonValue? = _json + val EXCLUDES = of("excludes") - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + fun of(value: String) = Operator(JsonField.of(value)) } - private var validated: Boolean = false + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() - } + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + else -> Value._UNKNOWN + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - override fun unknown(json: JsonValue?) = 0 + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - ) + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + override fun hashCode(): Int = hashCode - companion object { + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + + /** Configuration for grouped_allocation pricing */ + class GroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val allocation: JsonField, + private val groupingKey: JsonField, + private val overageUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + @JsonCreator + private constructor( + @JsonProperty("allocation") + @ExcludeMissing + allocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("overage_unit_rate") + @ExcludeMissing + overageUnitRate: JsonField = JsonMissing.of(), + ) : this(allocation, groupingKey, overageUnitRate, mutableMapOf()) - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + /** + * Usage allocation per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun allocation(): String = allocation.getRequired("allocation") + + /** + * How to determine the groups that should each be allocated some quantity + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Unit rate for post-allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun overageUnitRate(): String = overageUnitRate.getRequired("overage_unit_rate") + + /** + * Returns the raw JSON value of [allocation]. + * + * Unlike [allocation], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("allocation") + @ExcludeMissing + fun _allocation(): JsonField = allocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. + * Returns the raw JSON value of [overageUnitRate]. + * + * Unlike [overageUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. */ - interface Visitor { + @JsonProperty("overage_unit_rate") + @ExcludeMissing + fun _overageUnitRate(): JsonField = overageUnitRate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun visitUnit(unit: UnitConversionRateConfig): T + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) - fun visitTiered(tiered: TieredConversionRateConfig): T + companion object { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a mutable builder for constructing an instance of + * [GroupedAllocationConfig]. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * The following fields are required: + * ```kotlin + * .allocation() + * .groupingKey() + * .overageUnitRate() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var allocation: JsonField? = null + private var groupingKey: JsonField? = null + private var overageUnitRate: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedAllocationConfig: GroupedAllocationConfig) = apply { + allocation = groupedAllocationConfig.allocation + groupingKey = groupedAllocationConfig.groupingKey + overageUnitRate = groupedAllocationConfig.overageUnitRate + additionalProperties = + groupedAllocationConfig.additionalProperties.toMutableMap() + } + + /** Usage allocation per group */ + fun allocation(allocation: String) = allocation(JsonField.of(allocation)) + + /** + * Sets [Builder.allocation] to an arbitrary JSON value. * - * @throws OrbInvalidDataException in the default implementation. + * You should usually call [Builder.allocation] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + fun allocation(allocation: JsonField) = apply { + this.allocation = allocation } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** How to determine the groups that should each be allocated some quantity */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + /** Unit rate for post-allocation */ + fun overageUnitRate(overageUnitRate: String) = + overageUnitRate(JsonField.of(overageUnitRate)) + + /** + * Sets [Builder.overageUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.overageUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun overageUnitRate(overageUnitRate: JsonField) = apply { + this.overageUnitRate = overageUnitRate + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - return ConversionRateConfig(_json = json) + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .allocation() + * .groupingKey() + * .overageUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedAllocationConfig = + GroupedAllocationConfig( + checkRequired("allocation", allocation), + checkRequired("groupingKey", groupingKey), + checkRequired("overageUnitRate", overageUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedAllocationConfig = apply { + if (validated) { + return@apply } + + allocation() + groupingKey() + overageUnitRate() + validated = true } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (allocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (overageUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is GroupedAllocationConfig && + allocation == other.allocation && + groupingKey == other.groupingKey && + overageUnitRate == other.overageUnitRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(allocation, groupingKey, overageUnitRate, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedAllocationConfig{allocation=$allocation, groupingKey=$groupingKey, overageUnitRate=$overageUnitRate, additionalProperties=$additionalProperties}" } /** @@ -29849,12 +48850,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -29880,6 +48879,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -29887,6 +48888,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -29901,6 +48903,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -29919,6 +48922,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -29935,6 +48939,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -29982,7 +48987,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -29990,137 +48995,93 @@ private constructor( override fun toString() = value.toString() } - class UnitWithPercentConfig - @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 - * [UnitWithPercentConfig]. - */ - fun builder() = Builder() - } - - /** A builder for [UnitWithPercentConfig]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(unitWithPercentConfig: UnitWithPercentConfig) = apply { - additionalProperties = unitWithPercentConfig.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 [UnitWithPercentConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): UnitWithPercentConfig = - UnitWithPercentConfig(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): UnitWithPercentConfig = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is UnitWithPercentConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "UnitWithPercentConfig{additionalProperties=$additionalProperties}" - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is UnitWithPercent && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && unitWithPercentConfig == other.unitWithPercentConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedAllocation && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + groupedAllocationConfig == other.groupedAllocationConfig && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, unitWithPercentConfig, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + groupedAllocationConfig, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "UnitWithPercent{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, unitWithPercentConfig=$unitWithPercentConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "GroupedAllocation{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, groupedAllocationConfig=$groupedAllocationConfig, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class MatrixWithAllocation + class BulkWithProration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, + private val bulkWithProrationConfig: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -30131,7 +49092,6 @@ private constructor( private val fixedPriceQuantity: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, - private val matrixWithAllocationConfig: JsonField, private val maximum: JsonField, private val maximumAmount: JsonField, private val metadata: JsonField, @@ -30155,7 +49115,16 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), + @JsonProperty("bulk_with_proration_config") + @ExcludeMissing + bulkWithProrationConfig: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -30184,9 +49153,6 @@ private constructor( @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @JsonProperty("item") @ExcludeMissing item: JsonField = JsonMissing.of(), - @JsonProperty("matrix_with_allocation_config") - @ExcludeMissing - matrixWithAllocationConfig: JsonField = JsonMissing.of(), @JsonProperty("maximum") @ExcludeMissing maximum: JsonField = JsonMissing.of(), @JsonProperty("maximum_amount") @ExcludeMissing @@ -30217,7 +49183,10 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, + bulkWithProrationConfig, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -30228,7 +49197,6 @@ private constructor( fixedPriceQuantity, invoicingCycleConfiguration, item, - matrixWithAllocationConfig, maximum, maximumAmount, metadata, @@ -30262,12 +49230,34 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + + /** + * Configuration for bulk_with_proration pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun bulkWithProrationConfig(): BulkWithProrationConfig = + bulkWithProrationConfig.getRequired("bulk_with_proration_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -30325,18 +49315,14 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun item(): ItemSlim = item.getRequired("item") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun matrixWithAllocationConfig(): MatrixWithAllocationConfig = - matrixWithAllocationConfig.getRequired("matrix_with_allocation_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -30374,9 +49360,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("matrix_with_allocation") + * JsonValue.from("bulk_with_proration") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -30446,6 +49434,25 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + + /** + * Returns the raw JSON value of [bulkWithProrationConfig]. + * + * Unlike [bulkWithProrationConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("bulk_with_proration_config") + @ExcludeMissing + fun _bulkWithProrationConfig(): JsonField = bulkWithProrationConfig + /** * Returns the raw JSON value of [cadence]. * @@ -30453,6 +49460,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -30547,17 +49564,6 @@ private constructor( */ @JsonProperty("item") @ExcludeMissing fun _item(): JsonField = item - /** - * Returns the raw JSON value of [matrixWithAllocationConfig]. - * - * Unlike [matrixWithAllocationConfig], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("matrix_with_allocation_config") - @ExcludeMissing - fun _matrixWithAllocationConfig(): JsonField = - matrixWithAllocationConfig - /** * Returns the raw JSON value of [maximum]. * @@ -30669,14 +49675,17 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [MatrixWithAllocation]. + * Returns a mutable builder for constructing an instance of [BulkWithProration]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() + * .bulkWithProrationConfig() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -30687,7 +49696,6 @@ private constructor( * .fixedPriceQuantity() * .invoicingCycleConfiguration() * .item() - * .matrixWithAllocationConfig() * .maximum() * .maximumAmount() * .metadata() @@ -30702,13 +49710,16 @@ private constructor( fun builder() = Builder() } - /** A builder for [MatrixWithAllocation]. */ + /** A builder for [BulkWithProration]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null + private var bulkWithProrationConfig: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -30719,13 +49730,12 @@ private constructor( private var fixedPriceQuantity: JsonField? = null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null - private var matrixWithAllocationConfig: JsonField? = null private var maximum: JsonField? = null private var maximumAmount: JsonField? = null private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("matrix_with_allocation") + private var modelType: JsonValue = JsonValue.from("bulk_with_proration") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null @@ -30734,34 +49744,37 @@ private constructor( JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(matrixWithAllocation: MatrixWithAllocation) = apply { - id = matrixWithAllocation.id - billableMetric = matrixWithAllocation.billableMetric - billingCycleConfiguration = matrixWithAllocation.billingCycleConfiguration - cadence = matrixWithAllocation.cadence - conversionRate = matrixWithAllocation.conversionRate - conversionRateConfig = matrixWithAllocation.conversionRateConfig - createdAt = matrixWithAllocation.createdAt - creditAllocation = matrixWithAllocation.creditAllocation - currency = matrixWithAllocation.currency - discount = matrixWithAllocation.discount - externalPriceId = matrixWithAllocation.externalPriceId - fixedPriceQuantity = matrixWithAllocation.fixedPriceQuantity - invoicingCycleConfiguration = matrixWithAllocation.invoicingCycleConfiguration - item = matrixWithAllocation.item - matrixWithAllocationConfig = matrixWithAllocation.matrixWithAllocationConfig - maximum = matrixWithAllocation.maximum - maximumAmount = matrixWithAllocation.maximumAmount - metadata = matrixWithAllocation.metadata - minimum = matrixWithAllocation.minimum - minimumAmount = matrixWithAllocation.minimumAmount - modelType = matrixWithAllocation.modelType - name = matrixWithAllocation.name - planPhaseOrder = matrixWithAllocation.planPhaseOrder - priceType = matrixWithAllocation.priceType - replacesPriceId = matrixWithAllocation.replacesPriceId - dimensionalPriceConfiguration = matrixWithAllocation.dimensionalPriceConfiguration - additionalProperties = matrixWithAllocation.additionalProperties.toMutableMap() + internal fun from(bulkWithProration: BulkWithProration) = apply { + id = bulkWithProration.id + billableMetric = bulkWithProration.billableMetric + billingCycleConfiguration = bulkWithProration.billingCycleConfiguration + billingMode = bulkWithProration.billingMode + bulkWithProrationConfig = bulkWithProration.bulkWithProrationConfig + cadence = bulkWithProration.cadence + compositePriceFilters = + bulkWithProration.compositePriceFilters.map { it.toMutableList() } + conversionRate = bulkWithProration.conversionRate + conversionRateConfig = bulkWithProration.conversionRateConfig + createdAt = bulkWithProration.createdAt + creditAllocation = bulkWithProration.creditAllocation + currency = bulkWithProration.currency + discount = bulkWithProration.discount + externalPriceId = bulkWithProration.externalPriceId + fixedPriceQuantity = bulkWithProration.fixedPriceQuantity + invoicingCycleConfiguration = bulkWithProration.invoicingCycleConfiguration + item = bulkWithProration.item + maximum = bulkWithProration.maximum + maximumAmount = bulkWithProration.maximumAmount + metadata = bulkWithProration.metadata + minimum = bulkWithProration.minimum + minimumAmount = bulkWithProration.minimumAmount + modelType = bulkWithProration.modelType + name = bulkWithProration.name + planPhaseOrder = bulkWithProration.planPhaseOrder + priceType = bulkWithProration.priceType + replacesPriceId = bulkWithProration.replacesPriceId + dimensionalPriceConfiguration = bulkWithProration.dimensionalPriceConfiguration + additionalProperties = bulkWithProration.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -30803,6 +49816,34 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + + /** Configuration for bulk_with_proration pricing */ + fun bulkWithProrationConfig(bulkWithProrationConfig: BulkWithProrationConfig) = + bulkWithProrationConfig(JsonField.of(bulkWithProrationConfig)) + + /** + * Sets [Builder.bulkWithProrationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithProrationConfig] with a well-typed + * [BulkWithProrationConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun bulkWithProrationConfig( + bulkWithProrationConfig: JsonField + ) = apply { this.bulkWithProrationConfig = bulkWithProrationConfig } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -30814,6 +49855,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -31070,6 +50139,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -31081,20 +50154,6 @@ private constructor( */ fun item(item: JsonField) = apply { this.item = item } - fun matrixWithAllocationConfig(matrixWithAllocationConfig: MatrixWithAllocationConfig) = - matrixWithAllocationConfig(JsonField.of(matrixWithAllocationConfig)) - - /** - * Sets [Builder.matrixWithAllocationConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.matrixWithAllocationConfig] with a well-typed - * [MatrixWithAllocationConfig] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun matrixWithAllocationConfig( - matrixWithAllocationConfig: JsonField - ) = apply { this.matrixWithAllocationConfig = matrixWithAllocationConfig } - @Deprecated("deprecated") fun maximum(maximum: Maximum?) = maximum(JsonField.ofNullable(maximum)) @@ -31175,7 +50234,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("matrix_with_allocation") + * JsonValue.from("bulk_with_proration") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -31279,7 +50338,7 @@ private constructor( } /** - * Returns an immutable instance of [MatrixWithAllocation]. + * Returns an immutable instance of [BulkWithProration]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -31288,7 +50347,10 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() + * .bulkWithProrationConfig() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -31299,7 +50361,6 @@ private constructor( * .fixedPriceQuantity() * .invoicingCycleConfiguration() * .item() - * .matrixWithAllocationConfig() * .maximum() * .maximumAmount() * .metadata() @@ -31313,12 +50374,17 @@ private constructor( * * @throws IllegalStateException if any required field is unset. */ - fun build(): MatrixWithAllocation = - MatrixWithAllocation( + fun build(): BulkWithProration = + BulkWithProration( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), + checkRequired("bulkWithProrationConfig", bulkWithProrationConfig), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -31329,7 +50395,6 @@ private constructor( checkRequired("fixedPriceQuantity", fixedPriceQuantity), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), - checkRequired("matrixWithAllocationConfig", matrixWithAllocationConfig), checkRequired("maximum", maximum), checkRequired("maximumAmount", maximumAmount), checkRequired("metadata", metadata), @@ -31347,7 +50412,7 @@ private constructor( private var validated: Boolean = false - fun validate(): MatrixWithAllocation = apply { + fun validate(): BulkWithProration = apply { if (validated) { return@apply } @@ -31355,7 +50420,10 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() + bulkWithProrationConfig().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -31366,14 +50434,13 @@ private constructor( fixedPriceQuantity() invoicingCycleConfiguration()?.validate() item().validate() - matrixWithAllocationConfig().validate() maximum()?.validate() maximumAmount() metadata().validate() minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("matrix_with_allocation")) { + if (it != JsonValue.from("bulk_with_proration")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -31403,7 +50470,10 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + + (bulkWithProrationConfig.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -31414,19 +50484,544 @@ private constructor( (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + - (matrixWithAllocationConfig.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + (if (maximumAmount.asKnown() == null) 0 else 1) + (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("matrix_with_allocation")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("bulk_with_proration")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for bulk_with_proration pricing */ + class BulkWithProrationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 + * [BulkWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithProrationConfig]. */ + class Builder internal constructor() { + + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithProrationConfig: BulkWithProrationConfig) = apply { + tiers = bulkWithProrationConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithProrationConfig.additionalProperties.toMutableMap() + } + + /** Bulk tiers for rating based on total usage volume */ + 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 [BulkWithProrationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithProrationConfig = + BulkWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithProrationConfig = apply { + if (validated) { + return@apply + } + + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single bulk pricing tier with proration */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Cost per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Cost per unit */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -31571,7 +51166,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -31579,54 +51174,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun tiered(): TieredConversionRateConfig? = tiered + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") - fun isUnit(): Boolean = unit != null + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") - fun isTiered(): Boolean = tiered != null + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values - fun _json(): JsonValue? = _json + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -31645,112 +51410,308 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() - fun visitUnit(unit: UnitConversionRateConfig): T + override fun toString() = value.toString() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + private var validated: Boolean = false - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } /** @@ -31848,12 +51809,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -31879,6 +51838,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -31886,6 +51847,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -31900,6 +51862,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -31918,6 +51881,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -31934,6 +51898,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -31981,7 +51946,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -31994,25 +51959,87 @@ private constructor( return true } - return /* spotless:off */ other is MatrixWithAllocation && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && matrixWithAllocationConfig == other.matrixWithAllocationConfig && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BulkWithProration && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + bulkWithProrationConfig == other.bulkWithProrationConfig && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, matrixWithAllocationConfig, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + bulkWithProrationConfig, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "MatrixWithAllocation{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, matrixWithAllocationConfig=$matrixWithAllocationConfig, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "BulkWithProration{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, bulkWithProrationConfig=$bulkWithProrationConfig, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class TieredWithProration + class GroupedWithProratedMinimum + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -32021,6 +52048,7 @@ private constructor( private val discount: JsonField, private val externalPriceId: JsonField, private val fixedPriceQuantity: JsonField, + private val groupedWithProratedMinimumConfig: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, private val maximum: JsonField, @@ -32033,7 +52061,6 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, - private val tieredWithProrationConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -32047,7 +52074,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -32072,6 +52105,10 @@ private constructor( @JsonProperty("fixed_price_quantity") @ExcludeMissing fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_prorated_minimum_config") + @ExcludeMissing + groupedWithProratedMinimumConfig: JsonField = + JsonMissing.of(), @JsonProperty("invoicing_cycle_configuration") @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @@ -32098,9 +52135,6 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("tiered_with_proration_config") - @ExcludeMissing - tieredWithProrationConfig: JsonField = JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -32109,7 +52143,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -32118,6 +52154,7 @@ private constructor( discount, externalPriceId, fixedPriceQuantity, + groupedWithProratedMinimumConfig, invoicingCycleConfiguration, item, maximum, @@ -32130,7 +52167,6 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, - tieredWithProrationConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -32154,12 +52190,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -32209,6 +52258,15 @@ private constructor( */ fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") + /** + * Configuration for grouped_with_prorated_minimum pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupedWithProratedMinimumConfig(): GroupedWithProratedMinimumConfig = + groupedWithProratedMinimumConfig.getRequired("grouped_with_prorated_minimum_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -32217,6 +52275,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -32259,9 +52320,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("tiered_with_proration") + * JsonValue.from("grouped_with_prorated_minimum") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -32296,13 +52359,6 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun tieredWithProrationConfig(): TieredWithProrationConfig = - tieredWithProrationConfig.getRequired("tiered_with_proration_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -32338,6 +52394,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -32345,6 +52410,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -32421,6 +52496,17 @@ private constructor( @ExcludeMissing fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + /** + * Returns the raw JSON value of [groupedWithProratedMinimumConfig]. + * + * Unlike [groupedWithProratedMinimumConfig], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("grouped_with_prorated_minimum_config") + @ExcludeMissing + fun _groupedWithProratedMinimumConfig(): JsonField = + groupedWithProratedMinimumConfig + /** * Returns the raw JSON value of [invoicingCycleConfiguration]. * @@ -32524,17 +52610,6 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId - /** - * Returns the raw JSON value of [tieredWithProrationConfig]. - * - * Unlike [tieredWithProrationConfig], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("tiered_with_proration_config") - @ExcludeMissing - fun _tieredWithProrationConfig(): JsonField = - tieredWithProrationConfig - /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -32561,14 +52636,17 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [TieredWithProration]. + * Returns a mutable builder for constructing an instance of + * [GroupedWithProratedMinimum]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -32577,6 +52655,7 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() + * .groupedWithProratedMinimumConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -32588,19 +52667,20 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .tieredWithProrationConfig() * ``` */ fun builder() = Builder() } - /** A builder for [TieredWithProration]. */ + /** A builder for [GroupedWithProratedMinimum]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -32609,6 +52689,9 @@ private constructor( private var discount: JsonField? = null private var externalPriceId: JsonField? = null private var fixedPriceQuantity: JsonField? = null + private var groupedWithProratedMinimumConfig: + JsonField? = + null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null private var maximum: JsonField? = null @@ -32616,44 +52699,49 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("tiered_with_proration") + private var modelType: JsonValue = JsonValue.from("grouped_with_prorated_minimum") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null - private var tieredWithProrationConfig: JsonField? = null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(tieredWithProration: TieredWithProration) = apply { - id = tieredWithProration.id - billableMetric = tieredWithProration.billableMetric - billingCycleConfiguration = tieredWithProration.billingCycleConfiguration - cadence = tieredWithProration.cadence - conversionRate = tieredWithProration.conversionRate - conversionRateConfig = tieredWithProration.conversionRateConfig - createdAt = tieredWithProration.createdAt - creditAllocation = tieredWithProration.creditAllocation - currency = tieredWithProration.currency - discount = tieredWithProration.discount - externalPriceId = tieredWithProration.externalPriceId - fixedPriceQuantity = tieredWithProration.fixedPriceQuantity - invoicingCycleConfiguration = tieredWithProration.invoicingCycleConfiguration - item = tieredWithProration.item - maximum = tieredWithProration.maximum - maximumAmount = tieredWithProration.maximumAmount - metadata = tieredWithProration.metadata - minimum = tieredWithProration.minimum - minimumAmount = tieredWithProration.minimumAmount - modelType = tieredWithProration.modelType - name = tieredWithProration.name - planPhaseOrder = tieredWithProration.planPhaseOrder - priceType = tieredWithProration.priceType - replacesPriceId = tieredWithProration.replacesPriceId - tieredWithProrationConfig = tieredWithProration.tieredWithProrationConfig - dimensionalPriceConfiguration = tieredWithProration.dimensionalPriceConfiguration - additionalProperties = tieredWithProration.additionalProperties.toMutableMap() + internal fun from(groupedWithProratedMinimum: GroupedWithProratedMinimum) = apply { + id = groupedWithProratedMinimum.id + billableMetric = groupedWithProratedMinimum.billableMetric + billingCycleConfiguration = groupedWithProratedMinimum.billingCycleConfiguration + billingMode = groupedWithProratedMinimum.billingMode + cadence = groupedWithProratedMinimum.cadence + compositePriceFilters = + groupedWithProratedMinimum.compositePriceFilters.map { it.toMutableList() } + conversionRate = groupedWithProratedMinimum.conversionRate + conversionRateConfig = groupedWithProratedMinimum.conversionRateConfig + createdAt = groupedWithProratedMinimum.createdAt + creditAllocation = groupedWithProratedMinimum.creditAllocation + currency = groupedWithProratedMinimum.currency + discount = groupedWithProratedMinimum.discount + externalPriceId = groupedWithProratedMinimum.externalPriceId + fixedPriceQuantity = groupedWithProratedMinimum.fixedPriceQuantity + groupedWithProratedMinimumConfig = + groupedWithProratedMinimum.groupedWithProratedMinimumConfig + invoicingCycleConfiguration = groupedWithProratedMinimum.invoicingCycleConfiguration + item = groupedWithProratedMinimum.item + maximum = groupedWithProratedMinimum.maximum + maximumAmount = groupedWithProratedMinimum.maximumAmount + metadata = groupedWithProratedMinimum.metadata + minimum = groupedWithProratedMinimum.minimum + minimumAmount = groupedWithProratedMinimum.minimumAmount + modelType = groupedWithProratedMinimum.modelType + name = groupedWithProratedMinimum.name + planPhaseOrder = groupedWithProratedMinimum.planPhaseOrder + priceType = groupedWithProratedMinimum.priceType + replacesPriceId = groupedWithProratedMinimum.replacesPriceId + dimensionalPriceConfiguration = + groupedWithProratedMinimum.dimensionalPriceConfiguration + additionalProperties = + groupedWithProratedMinimum.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -32695,16 +52783,57 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** - * Sets [Builder.cadence] to an arbitrary JSON value. + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. * - * You should usually call [Builder.cadence] with a well-typed [Cadence] 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 cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -32947,6 +53076,22 @@ private constructor( this.fixedPriceQuantity = fixedPriceQuantity } + /** Configuration for grouped_with_prorated_minimum pricing */ + fun groupedWithProratedMinimumConfig( + groupedWithProratedMinimumConfig: GroupedWithProratedMinimumConfig + ) = groupedWithProratedMinimumConfig(JsonField.of(groupedWithProratedMinimumConfig)) + + /** + * Sets [Builder.groupedWithProratedMinimumConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithProratedMinimumConfig] with a well-typed + * [GroupedWithProratedMinimumConfig] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun groupedWithProratedMinimumConfig( + groupedWithProratedMinimumConfig: JsonField + ) = apply { this.groupedWithProratedMinimumConfig = groupedWithProratedMinimumConfig } + fun invoicingCycleConfiguration( invoicingCycleConfiguration: BillingCycleConfiguration? ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) @@ -32962,6 +53107,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -33053,7 +53202,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("tiered_with_proration") + * JsonValue.from("grouped_with_prorated_minimum") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -33122,20 +53271,6 @@ private constructor( this.replacesPriceId = replacesPriceId } - fun tieredWithProrationConfig(tieredWithProrationConfig: TieredWithProrationConfig) = - tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) - - /** - * Sets [Builder.tieredWithProrationConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.tieredWithProrationConfig] with a well-typed - * [TieredWithProrationConfig] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun tieredWithProrationConfig( - tieredWithProrationConfig: JsonField - ) = apply { this.tieredWithProrationConfig = tieredWithProrationConfig } - fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -33171,7 +53306,7 @@ private constructor( } /** - * Returns an immutable instance of [TieredWithProration]. + * Returns an immutable instance of [GroupedWithProratedMinimum]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -33180,7 +53315,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -33189,6 +53326,7 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() + * .groupedWithProratedMinimumConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -33200,17 +53338,20 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .tieredWithProrationConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): TieredWithProration = - TieredWithProration( + fun build(): GroupedWithProratedMinimum = + GroupedWithProratedMinimum( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -33219,6 +53360,10 @@ private constructor( checkRequired("discount", discount), checkRequired("externalPriceId", externalPriceId), checkRequired("fixedPriceQuantity", fixedPriceQuantity), + checkRequired( + "groupedWithProratedMinimumConfig", + groupedWithProratedMinimumConfig, + ), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), checkRequired("maximum", maximum), @@ -33231,7 +53376,6 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), - checkRequired("tieredWithProrationConfig", tieredWithProrationConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -33239,7 +53383,7 @@ private constructor( private var validated: Boolean = false - fun validate(): TieredWithProration = apply { + fun validate(): GroupedWithProratedMinimum = apply { if (validated) { return@apply } @@ -33247,7 +53391,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -33256,6 +53402,7 @@ private constructor( discount()?.validate() externalPriceId() fixedPriceQuantity() + groupedWithProratedMinimumConfig().validate() invoicingCycleConfiguration()?.validate() item().validate() maximum()?.validate() @@ -33264,7 +53411,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("tiered_with_proration")) { + if (it != JsonValue.from("grouped_with_prorated_minimum")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -33272,7 +53419,6 @@ private constructor( planPhaseOrder() priceType().validate() replacesPriceId() - tieredWithProrationConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -33295,7 +53441,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -33304,6 +53452,7 @@ private constructor( (discount.asKnown()?.validity() ?: 0) + (if (externalPriceId.asKnown() == null) 0 else 1) + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (groupedWithProratedMinimumConfig.asKnown()?.validity() ?: 0) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + @@ -33311,14 +53460,144 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("tiered_with_proration")) 1 else 0 } + + modelType.let { + if (it == JsonValue.from("grouped_with_prorated_minimum")) 1 else 0 + } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + - (tieredWithProrationConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -33463,7 +53742,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -33471,54 +53750,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun isUnit(): Boolean = unit != null + fun toBuilder() = Builder().from(this) - fun isTiered(): Boolean = tiered != null + companion object { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -33537,112 +53986,566 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - override fun unknown(json: JsonValue?) = 0 + /** + * 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + override fun hashCode(): Int = hashCode - companion object { + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + + /** Configuration for grouped_with_prorated_minimum pricing */ + class GroupedWithProratedMinimumConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val minimum: JsonField, + private val unitRate: JsonField, + private val additionalProperties: MutableMap, + ) { - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("minimum") + @ExcludeMissing + minimum: JsonField = JsonMissing.of(), + @JsonProperty("unit_rate") + @ExcludeMissing + unitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, minimum, unitRate, mutableMapOf()) - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + /** + * How to determine the groups that should each have a minimum + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The minimum amount to charge per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun minimum(): String = minimum.getRequired("minimum") + + /** + * The amount to charge per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitRate(): String = unitRate.getRequired("unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [minimum]. + * + * Unlike [minimum], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("minimum") @ExcludeMissing fun _minimum(): JsonField = minimum /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. + * Returns the raw JSON value of [unitRate]. + * + * Unlike [unitRate], this method doesn't throw if the JSON field has an unexpected + * type. */ - interface Visitor { + @JsonProperty("unit_rate") @ExcludeMissing fun _unitRate(): JsonField = unitRate - fun visitUnit(unit: UnitConversionRateConfig): T + @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) - fun visitTiered(tiered: TieredConversionRateConfig): T + companion object { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a mutable builder for constructing an instance of + * [GroupedWithProratedMinimumConfig]. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimum() + * .unitRate() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithProratedMinimumConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var minimum: JsonField? = null + private var unitRate: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from( + groupedWithProratedMinimumConfig: GroupedWithProratedMinimumConfig + ) = apply { + groupingKey = groupedWithProratedMinimumConfig.groupingKey + minimum = groupedWithProratedMinimumConfig.minimum + unitRate = groupedWithProratedMinimumConfig.unitRate + additionalProperties = + groupedWithProratedMinimumConfig.additionalProperties.toMutableMap() + } + + /** How to determine the groups that should each have a minimum */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. * - * @throws OrbInvalidDataException in the default implementation. + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** The minimum amount to charge per group */ + fun minimum(minimum: String) = minimum(JsonField.of(minimum)) + + /** + * Sets [Builder.minimum] to an arbitrary JSON value. + * + * You should usually call [Builder.minimum] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun minimum(minimum: JsonField) = apply { this.minimum = minimum } + + /** The amount to charge per unit */ + fun unitRate(unitRate: String) = unitRate(JsonField.of(unitRate)) - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + /** + * Sets [Builder.unitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRate] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitRate(unitRate: JsonField) = apply { this.unitRate = unitRate } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - return ConversionRateConfig(_json = json) + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } + + /** + * Returns an immutable instance of [GroupedWithProratedMinimumConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimum() + * .unitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithProratedMinimumConfig = + GroupedWithProratedMinimumConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("minimum", minimum), + checkRequired("unitRate", unitRate), + additionalProperties.toMutableMap(), + ) } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + private var validated: Boolean = false - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + fun validate(): GroupedWithProratedMinimumConfig = apply { + if (validated) { + return@apply } + + groupingKey() + minimum() + unitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (minimum.asKnown() == null) 0 else 1) + + (if (unitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithProratedMinimumConfig && + groupingKey == other.groupingKey && + minimum == other.minimum && + unitRate == other.unitRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(groupingKey, minimum, unitRate, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithProratedMinimumConfig{groupingKey=$groupingKey, minimum=$minimum, unitRate=$unitRate, additionalProperties=$additionalProperties}" } /** @@ -33740,12 +54643,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -33771,6 +54672,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -33778,6 +54681,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -33792,6 +54696,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -33810,6 +54715,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -33826,6 +54732,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -33873,7 +54780,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -33881,138 +54788,92 @@ private constructor( override fun toString() = value.toString() } - class TieredWithProrationConfig - @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 - * [TieredWithProrationConfig]. - */ - fun builder() = Builder() - } - - /** A builder for [TieredWithProrationConfig]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = apply { - additionalProperties = - tieredWithProrationConfig.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 [TieredWithProrationConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): TieredWithProrationConfig = - TieredWithProrationConfig(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): TieredWithProrationConfig = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TieredWithProrationConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "TieredWithProrationConfig{additionalProperties=$additionalProperties}" - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is TieredWithProration && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && tieredWithProrationConfig == other.tieredWithProrationConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedWithProratedMinimum && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + groupedWithProratedMinimumConfig == other.groupedWithProratedMinimumConfig && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, tieredWithProrationConfig, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + groupedWithProratedMinimumConfig, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "TieredWithProration{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, tieredWithProrationConfig=$tieredWithProrationConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "GroupedWithProratedMinimum{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, groupedWithProratedMinimumConfig=$groupedWithProratedMinimumConfig, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class UnitWithProration + class GroupedWithMeteredMinimum + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -34021,6 +54882,7 @@ private constructor( private val discount: JsonField, private val externalPriceId: JsonField, private val fixedPriceQuantity: JsonField, + private val groupedWithMeteredMinimumConfig: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, private val maximum: JsonField, @@ -34033,7 +54895,6 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, - private val unitWithProrationConfig: JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -34047,7 +54908,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -34072,6 +54939,10 @@ private constructor( @JsonProperty("fixed_price_quantity") @ExcludeMissing fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_metered_minimum_config") + @ExcludeMissing + groupedWithMeteredMinimumConfig: JsonField = + JsonMissing.of(), @JsonProperty("invoicing_cycle_configuration") @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @@ -34098,9 +54969,6 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("unit_with_proration_config") - @ExcludeMissing - unitWithProrationConfig: JsonField = JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -34109,7 +54977,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -34118,6 +54988,7 @@ private constructor( discount, externalPriceId, fixedPriceQuantity, + groupedWithMeteredMinimumConfig, invoicingCycleConfiguration, item, maximum, @@ -34130,7 +55001,6 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, - unitWithProrationConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -34154,12 +55024,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -34209,6 +55092,15 @@ private constructor( */ fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") + /** + * Configuration for grouped_with_metered_minimum pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupedWithMeteredMinimumConfig(): GroupedWithMeteredMinimumConfig = + groupedWithMeteredMinimumConfig.getRequired("grouped_with_metered_minimum_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -34217,6 +55109,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -34259,9 +55154,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("unit_with_proration") + * JsonValue.from("grouped_with_metered_minimum") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -34296,13 +55193,6 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun unitWithProrationConfig(): UnitWithProrationConfig = - unitWithProrationConfig.getRequired("unit_with_proration_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -34338,6 +55228,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -34345,6 +55244,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -34421,6 +55330,17 @@ private constructor( @ExcludeMissing fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + /** + * Returns the raw JSON value of [groupedWithMeteredMinimumConfig]. + * + * Unlike [groupedWithMeteredMinimumConfig], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("grouped_with_metered_minimum_config") + @ExcludeMissing + fun _groupedWithMeteredMinimumConfig(): JsonField = + groupedWithMeteredMinimumConfig + /** * Returns the raw JSON value of [invoicingCycleConfiguration]. * @@ -34524,16 +55444,6 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId - /** - * Returns the raw JSON value of [unitWithProrationConfig]. - * - * Unlike [unitWithProrationConfig], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("unit_with_proration_config") - @ExcludeMissing - fun _unitWithProrationConfig(): JsonField = unitWithProrationConfig - /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -34560,14 +55470,17 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [UnitWithProration]. + * Returns a mutable builder for constructing an instance of + * [GroupedWithMeteredMinimum]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -34576,6 +55489,7 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() + * .groupedWithMeteredMinimumConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -34587,19 +55501,20 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .unitWithProrationConfig() * ``` */ fun builder() = Builder() } - /** A builder for [UnitWithProration]. */ + /** A builder for [GroupedWithMeteredMinimum]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -34608,6 +55523,9 @@ private constructor( private var discount: JsonField? = null private var externalPriceId: JsonField? = null private var fixedPriceQuantity: JsonField? = null + private var groupedWithMeteredMinimumConfig: + JsonField? = + null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null private var maximum: JsonField? = null @@ -34615,44 +55533,48 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("unit_with_proration") + private var modelType: JsonValue = JsonValue.from("grouped_with_metered_minimum") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null - private var unitWithProrationConfig: JsonField? = null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(unitWithProration: UnitWithProration) = apply { - id = unitWithProration.id - billableMetric = unitWithProration.billableMetric - billingCycleConfiguration = unitWithProration.billingCycleConfiguration - cadence = unitWithProration.cadence - conversionRate = unitWithProration.conversionRate - conversionRateConfig = unitWithProration.conversionRateConfig - createdAt = unitWithProration.createdAt - creditAllocation = unitWithProration.creditAllocation - currency = unitWithProration.currency - discount = unitWithProration.discount - externalPriceId = unitWithProration.externalPriceId - fixedPriceQuantity = unitWithProration.fixedPriceQuantity - invoicingCycleConfiguration = unitWithProration.invoicingCycleConfiguration - item = unitWithProration.item - maximum = unitWithProration.maximum - maximumAmount = unitWithProration.maximumAmount - metadata = unitWithProration.metadata - minimum = unitWithProration.minimum - minimumAmount = unitWithProration.minimumAmount - modelType = unitWithProration.modelType - name = unitWithProration.name - planPhaseOrder = unitWithProration.planPhaseOrder - priceType = unitWithProration.priceType - replacesPriceId = unitWithProration.replacesPriceId - unitWithProrationConfig = unitWithProration.unitWithProrationConfig - dimensionalPriceConfiguration = unitWithProration.dimensionalPriceConfiguration - additionalProperties = unitWithProration.additionalProperties.toMutableMap() + internal fun from(groupedWithMeteredMinimum: GroupedWithMeteredMinimum) = apply { + id = groupedWithMeteredMinimum.id + billableMetric = groupedWithMeteredMinimum.billableMetric + billingCycleConfiguration = groupedWithMeteredMinimum.billingCycleConfiguration + billingMode = groupedWithMeteredMinimum.billingMode + cadence = groupedWithMeteredMinimum.cadence + compositePriceFilters = + groupedWithMeteredMinimum.compositePriceFilters.map { it.toMutableList() } + conversionRate = groupedWithMeteredMinimum.conversionRate + conversionRateConfig = groupedWithMeteredMinimum.conversionRateConfig + createdAt = groupedWithMeteredMinimum.createdAt + creditAllocation = groupedWithMeteredMinimum.creditAllocation + currency = groupedWithMeteredMinimum.currency + discount = groupedWithMeteredMinimum.discount + externalPriceId = groupedWithMeteredMinimum.externalPriceId + fixedPriceQuantity = groupedWithMeteredMinimum.fixedPriceQuantity + groupedWithMeteredMinimumConfig = + groupedWithMeteredMinimum.groupedWithMeteredMinimumConfig + invoicingCycleConfiguration = groupedWithMeteredMinimum.invoicingCycleConfiguration + item = groupedWithMeteredMinimum.item + maximum = groupedWithMeteredMinimum.maximum + maximumAmount = groupedWithMeteredMinimum.maximumAmount + metadata = groupedWithMeteredMinimum.metadata + minimum = groupedWithMeteredMinimum.minimum + minimumAmount = groupedWithMeteredMinimum.minimumAmount + modelType = groupedWithMeteredMinimum.modelType + name = groupedWithMeteredMinimum.name + planPhaseOrder = groupedWithMeteredMinimum.planPhaseOrder + priceType = groupedWithMeteredMinimum.priceType + replacesPriceId = groupedWithMeteredMinimum.replacesPriceId + dimensionalPriceConfiguration = + groupedWithMeteredMinimum.dimensionalPriceConfiguration + additionalProperties = groupedWithMeteredMinimum.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -34694,6 +55616,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -34705,6 +55640,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -34946,6 +55909,22 @@ private constructor( this.fixedPriceQuantity = fixedPriceQuantity } + /** Configuration for grouped_with_metered_minimum pricing */ + fun groupedWithMeteredMinimumConfig( + groupedWithMeteredMinimumConfig: GroupedWithMeteredMinimumConfig + ) = groupedWithMeteredMinimumConfig(JsonField.of(groupedWithMeteredMinimumConfig)) + + /** + * Sets [Builder.groupedWithMeteredMinimumConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMeteredMinimumConfig] with a well-typed + * [GroupedWithMeteredMinimumConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun groupedWithMeteredMinimumConfig( + groupedWithMeteredMinimumConfig: JsonField + ) = apply { this.groupedWithMeteredMinimumConfig = groupedWithMeteredMinimumConfig } + fun invoicingCycleConfiguration( invoicingCycleConfiguration: BillingCycleConfiguration? ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) @@ -34961,6 +55940,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -35052,7 +56035,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("unit_with_proration") + * JsonValue.from("grouped_with_metered_minimum") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -35121,20 +56104,6 @@ private constructor( this.replacesPriceId = replacesPriceId } - fun unitWithProrationConfig(unitWithProrationConfig: UnitWithProrationConfig) = - unitWithProrationConfig(JsonField.of(unitWithProrationConfig)) - - /** - * Sets [Builder.unitWithProrationConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.unitWithProrationConfig] with a well-typed - * [UnitWithProrationConfig] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun unitWithProrationConfig( - unitWithProrationConfig: JsonField - ) = apply { this.unitWithProrationConfig = unitWithProrationConfig } - fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -35170,7 +56139,7 @@ private constructor( } /** - * Returns an immutable instance of [UnitWithProration]. + * Returns an immutable instance of [GroupedWithMeteredMinimum]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -35179,7 +56148,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -35188,6 +56159,7 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() + * .groupedWithMeteredMinimumConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -35199,17 +56171,20 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .unitWithProrationConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): UnitWithProration = - UnitWithProration( + fun build(): GroupedWithMeteredMinimum = + GroupedWithMeteredMinimum( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -35218,6 +56193,10 @@ private constructor( checkRequired("discount", discount), checkRequired("externalPriceId", externalPriceId), checkRequired("fixedPriceQuantity", fixedPriceQuantity), + checkRequired( + "groupedWithMeteredMinimumConfig", + groupedWithMeteredMinimumConfig, + ), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), checkRequired("maximum", maximum), @@ -35230,7 +56209,6 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), - checkRequired("unitWithProrationConfig", unitWithProrationConfig), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -35238,7 +56216,7 @@ private constructor( private var validated: Boolean = false - fun validate(): UnitWithProration = apply { + fun validate(): GroupedWithMeteredMinimum = apply { if (validated) { return@apply } @@ -35246,7 +56224,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -35255,6 +56235,7 @@ private constructor( discount()?.validate() externalPriceId() fixedPriceQuantity() + groupedWithMeteredMinimumConfig().validate() invoicingCycleConfiguration()?.validate() item().validate() maximum()?.validate() @@ -35263,7 +56244,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("unit_with_proration")) { + if (it != JsonValue.from("grouped_with_metered_minimum")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -35271,7 +56252,6 @@ private constructor( planPhaseOrder() priceType().validate() replacesPriceId() - unitWithProrationConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -35294,7 +56274,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -35303,6 +56285,7 @@ private constructor( (discount.asKnown()?.validity() ?: 0) + (if (externalPriceId.asKnown() == null) 0 else 1) + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (groupedWithMeteredMinimumConfig.asKnown()?.validity() ?: 0) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + @@ -35310,14 +56293,144 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("unit_with_proration")) 1 else 0 } + + modelType.let { + if (it == JsonValue.from("grouped_with_metered_minimum")) 1 else 0 + } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + - (unitWithProrationConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -35333,191 +56446,1080 @@ private constructor( companion object { - val ONE_TIME = of("one_time") + val ONE_TIME = of("one_time") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val SEMI_ANNUAL = of("semi_annual") + + val ANNUAL = of("annual") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ONE_TIME, + MONTHLY, + QUARTERLY, + SEMI_ANNUAL, + ANNUAL, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ONE_TIME, + MONTHLY, + QUARTERLY, + SEMI_ANNUAL, + ANNUAL, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ONE_TIME -> Value.ONE_TIME + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + SEMI_ANNUAL -> Value.SEMI_ANNUAL + ANNUAL -> Value.ANNUAL + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ONE_TIME -> Known.ONE_TIME + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + SEMI_ANNUAL -> Known.SEMI_ANNUAL + ANNUAL -> Known.ANNUAL + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @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 [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - val MONTHLY = of("monthly") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - val QUARTERLY = of("quarterly") + return other is Operator && value == other.value + } - val SEMI_ANNUAL = of("semi_annual") + override fun hashCode() = value.hashCode() - val ANNUAL = of("annual") + override fun toString() = value.toString() + } - val CUSTOM = of("custom") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun of(value: String) = Cadence(JsonField.of(value)) + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties } - /** An enum containing [Cadence]'s known values. */ - enum class Known { - ONE_TIME, - MONTHLY, - QUARTERLY, - SEMI_ANNUAL, - ANNUAL, - CUSTOM, + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) } + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + + /** Configuration for grouped_with_metered_minimum pricing */ + class GroupedWithMeteredMinimumConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val minimumUnitAmount: JsonField, + private val pricingKey: JsonField, + private val scalingFactors: JsonField>, + private val scalingKey: JsonField, + private val unitAmounts: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("minimum_unit_amount") + @ExcludeMissing + minimumUnitAmount: JsonField = JsonMissing.of(), + @JsonProperty("pricing_key") + @ExcludeMissing + pricingKey: JsonField = JsonMissing.of(), + @JsonProperty("scaling_factors") + @ExcludeMissing + scalingFactors: JsonField> = JsonMissing.of(), + @JsonProperty("scaling_key") + @ExcludeMissing + scalingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amounts") + @ExcludeMissing + unitAmounts: JsonField> = JsonMissing.of(), + ) : this( + groupingKey, + minimumUnitAmount, + pricingKey, + scalingFactors, + scalingKey, + unitAmounts, + mutableMapOf(), + ) + /** - * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * Used to partition the usage into groups. The minimum amount is applied to each group. * - * An instance of [Cadence] 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. + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). */ - enum class Value { - ONE_TIME, - MONTHLY, - QUARTERLY, - SEMI_ANNUAL, - ANNUAL, - CUSTOM, - /** - * An enum member indicating that [Cadence] was instantiated with an unknown value. - */ - _UNKNOWN, - } + fun groupingKey(): String = groupingKey.getRequired("grouping_key") /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * The minimum amount to charge per group per unit * - * Use the [known] method instead if you're certain the value is always known or if you - * want to throw for the unknown case. + * @throws OrbInvalidDataException if 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(): Value = - when (this) { - ONE_TIME -> Value.ONE_TIME - MONTHLY -> Value.MONTHLY - QUARTERLY -> Value.QUARTERLY - SEMI_ANNUAL -> Value.SEMI_ANNUAL - ANNUAL -> Value.ANNUAL - CUSTOM -> Value.CUSTOM - else -> Value._UNKNOWN - } + fun minimumUnitAmount(): String = minimumUnitAmount.getRequired("minimum_unit_amount") /** - * Returns an enum member corresponding to this class instance's value. + * Used to determine the unit rate * - * 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 OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun pricingKey(): String = pricingKey.getRequired("pricing_key") + + /** + * Scale the unit rates by the scaling factor. * - * @throws OrbInvalidDataException if this class instance's value is a not a known - * member. + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). */ - fun known(): Known = - when (this) { - ONE_TIME -> Known.ONE_TIME - MONTHLY -> Known.MONTHLY - QUARTERLY -> Known.QUARTERLY - SEMI_ANNUAL -> Known.SEMI_ANNUAL - ANNUAL -> Known.ANNUAL - CUSTOM -> Known.CUSTOM - else -> throw OrbInvalidDataException("Unknown Cadence: $value") - } + fun scalingFactors(): List = + scalingFactors.getRequired("scaling_factors") /** - * Returns this class instance's primitive wire representation. + * Used to determine the unit rate scaling factor * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingKey(): String = scalingKey.getRequired("scaling_key") + + /** + * Apply per unit pricing to each pricing value. The minimum amount is applied any + * unmatched usage. * - * @throws OrbInvalidDataException if this class instance's value does not have the - * expected primitive type. + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + fun unitAmounts(): List = unitAmounts.getRequired("unit_amounts") - private var validated: Boolean = false + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey - fun validate(): Cadence = apply { - if (validated) { - return@apply - } + /** + * Returns the raw JSON value of [minimumUnitAmount]. + * + * Unlike [minimumUnitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_unit_amount") + @ExcludeMissing + fun _minimumUnitAmount(): JsonField = minimumUnitAmount - known() - validated = true - } + /** + * Returns the raw JSON value of [pricingKey]. + * + * Unlike [pricingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pricing_key") + @ExcludeMissing + fun _pricingKey(): JsonField = pricingKey - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Returns the raw JSON value of [scalingFactors]. + * + * Unlike [scalingFactors], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("scaling_factors") + @ExcludeMissing + fun _scalingFactors(): JsonField> = scalingFactors /** - * Returns a score indicating how many valid values are contained in this object - * recursively. + * Returns the raw JSON value of [scalingKey]. * - * Used for best match union deserialization. + * Unlike [scalingKey], this method doesn't throw if the JSON field has an unexpected + * type. */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + @JsonProperty("scaling_key") + @ExcludeMissing + fun _scalingKey(): JsonField = scalingKey - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns the raw JSON value of [unitAmounts]. + * + * Unlike [unitAmounts], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amounts") + @ExcludeMissing + fun _unitAmounts(): JsonField> = unitAmounts - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - override fun hashCode() = value.hashCode() + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - override fun toString() = value.toString() - } + fun toBuilder() = Builder().from(this) - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig - private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, - ) { + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [GroupedWithMeteredMinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimumUnitAmount() + * .pricingKey() + * .scalingFactors() + * .scalingKey() + * .unitAmounts() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMeteredMinimumConfig]. */ + class Builder internal constructor() { - fun unit(): UnitConversionRateConfig? = unit + private var groupingKey: JsonField? = null + private var minimumUnitAmount: JsonField? = null + private var pricingKey: JsonField? = null + private var scalingFactors: JsonField>? = null + private var scalingKey: JsonField? = null + private var unitAmounts: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun tiered(): TieredConversionRateConfig? = tiered + internal fun from( + groupedWithMeteredMinimumConfig: GroupedWithMeteredMinimumConfig + ) = apply { + groupingKey = groupedWithMeteredMinimumConfig.groupingKey + minimumUnitAmount = groupedWithMeteredMinimumConfig.minimumUnitAmount + pricingKey = groupedWithMeteredMinimumConfig.pricingKey + scalingFactors = + groupedWithMeteredMinimumConfig.scalingFactors.map { it.toMutableList() } + scalingKey = groupedWithMeteredMinimumConfig.scalingKey + unitAmounts = + groupedWithMeteredMinimumConfig.unitAmounts.map { it.toMutableList() } + additionalProperties = + groupedWithMeteredMinimumConfig.additionalProperties.toMutableMap() + } - fun isUnit(): Boolean = unit != null + /** + * Used to partition the usage into groups. The minimum amount is applied to each + * group. + */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) - fun isTiered(): Boolean = tiered != null + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** The minimum amount to charge per group per unit */ + fun minimumUnitAmount(minimumUnitAmount: String) = + minimumUnitAmount(JsonField.of(minimumUnitAmount)) - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** + * Sets [Builder.minimumUnitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumUnitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun minimumUnitAmount(minimumUnitAmount: JsonField) = apply { + this.minimumUnitAmount = minimumUnitAmount + } - fun _json(): JsonValue? = _json + /** Used to determine the unit rate */ + fun pricingKey(pricingKey: String) = pricingKey(JsonField.of(pricingKey)) - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + /** + * Sets [Builder.pricingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.pricingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun pricingKey(pricingKey: JsonField) = apply { + this.pricingKey = pricingKey } - private var validated: Boolean = false + /** Scale the unit rates by the scaling factor. */ + fun scalingFactors(scalingFactors: List) = + scalingFactors(JsonField.of(scalingFactors)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.scalingFactors] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactors] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun scalingFactors(scalingFactors: JsonField>) = apply { + this.scalingFactors = scalingFactors.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [ScalingFactor] to [scalingFactors]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addScalingFactor(scalingFactor: ScalingFactor) = apply { + scalingFactors = + (scalingFactors ?: JsonField.of(mutableListOf())).also { + checkKnown("scalingFactors", it).add(scalingFactor) } + } + + /** Used to determine the unit rate scaling factor */ + fun scalingKey(scalingKey: String) = scalingKey(JsonField.of(scalingKey)) - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() + /** + * Sets [Builder.scalingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun scalingKey(scalingKey: JsonField) = apply { + this.scalingKey = scalingKey + } + + /** + * Apply per unit pricing to each pricing value. The minimum amount is applied any + * unmatched usage. + */ + fun unitAmounts(unitAmounts: List) = + unitAmounts(JsonField.of(unitAmounts)) + + /** + * Sets [Builder.unitAmounts] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmounts] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun unitAmounts(unitAmounts: JsonField>) = apply { + this.unitAmounts = unitAmounts.map { it.toMutableList() } + } + + /** + * Adds a single [UnitAmount] to [unitAmounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUnitAmount(unitAmount: UnitAmount) = apply { + unitAmounts = + (unitAmounts ?: JsonField.of(mutableListOf())).also { + checkKnown("unitAmounts", it).add(unitAmount) } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMeteredMinimumConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .minimumUnitAmount() + * .pricingKey() + * .scalingFactors() + * .scalingKey() + * .unitAmounts() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMeteredMinimumConfig = + GroupedWithMeteredMinimumConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("minimumUnitAmount", minimumUnitAmount), + checkRequired("pricingKey", pricingKey), + checkRequired("scalingFactors", scalingFactors).map { it.toImmutable() }, + checkRequired("scalingKey", scalingKey), + checkRequired("unitAmounts", unitAmounts).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMeteredMinimumConfig = apply { + if (validated) { + return@apply + } + + groupingKey() + minimumUnitAmount() + pricingKey() + scalingFactors().forEach { it.validate() } + scalingKey() + unitAmounts().forEach { it.validate() } validated = true } @@ -35536,112 +57538,483 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (minimumUnitAmount.asKnown() == null) 0 else 1) + + (if (pricingKey.asKnown() == null) 0 else 1) + + (scalingFactors.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (scalingKey.asKnown() == null) 0 else 1) + + (unitAmounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a scaling factor */ + class ScalingFactor + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val scalingFactor: JsonField, + private val scalingValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("scaling_factor") + @ExcludeMissing + scalingFactor: JsonField = JsonMissing.of(), + @JsonProperty("scaling_value") + @ExcludeMissing + scalingValue: JsonField = JsonMissing.of(), + ) : this(scalingFactor, scalingValue, mutableMapOf()) + + /** + * Scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingFactor(): String = scalingFactor.getRequired("scaling_factor") + + /** + * Scaling value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingValue(): String = scalingValue.getRequired("scaling_value") + + /** + * Returns the raw JSON value of [scalingFactor]. + * + * Unlike [scalingFactor], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("scaling_factor") + @ExcludeMissing + fun _scalingFactor(): JsonField = scalingFactor + + /** + * Returns the raw JSON value of [scalingValue]. + * + * Unlike [scalingValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("scaling_value") + @ExcludeMissing + fun _scalingValue(): JsonField = scalingValue + + @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 [ScalingFactor]. + * + * The following fields are required: + * ```kotlin + * .scalingFactor() + * .scalingValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ScalingFactor]. */ + class Builder internal constructor() { - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + private var scalingFactor: JsonField? = null + private var scalingValue: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - override fun unknown(json: JsonValue?) = 0 + internal fun from(scalingFactor: ScalingFactor) = apply { + this.scalingFactor = scalingFactor.scalingFactor + scalingValue = scalingFactor.scalingValue + additionalProperties = scalingFactor.additionalProperties.toMutableMap() } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** Scaling factor */ + fun scalingFactor(scalingFactor: String) = + scalingFactor(JsonField.of(scalingFactor)) + + /** + * Sets [Builder.scalingFactor] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactor] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun scalingFactor(scalingFactor: JsonField) = apply { + this.scalingFactor = scalingFactor + } + + /** Scaling value */ + fun scalingValue(scalingValue: String) = + scalingValue(JsonField.of(scalingValue)) + + /** + * Sets [Builder.scalingValue] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun scalingValue(scalingValue: JsonField) = apply { + this.scalingValue = scalingValue + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ScalingFactor]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .scalingFactor() + * .scalingValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ScalingFactor = + ScalingFactor( + checkRequired("scalingFactor", scalingFactor), + checkRequired("scalingValue", scalingValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ScalingFactor = apply { + if (validated) { + return@apply + } + + scalingFactor() + scalingValue() + validated = true } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (scalingFactor.asKnown() == null) 0 else 1) + + (if (scalingValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + return other is ScalingFactor && + scalingFactor == other.scalingFactor && + scalingValue == other.scalingValue && + additionalProperties == other.additionalProperties } - companion object { + private val hashCode: Int by lazy { + Objects.hash(scalingFactor, scalingValue, additionalProperties) + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + override fun hashCode(): Int = hashCode - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) + override fun toString() = + "ScalingFactor{scalingFactor=$scalingFactor, scalingValue=$scalingValue, additionalProperties=$additionalProperties}" } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + /** Configuration for a unit amount */ + class UnitAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val pricingValue: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("pricing_value") + @ExcludeMissing + pricingValue: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(pricingValue, unitAmount, mutableMapOf()) - fun visitUnit(unit: UnitConversionRateConfig): T + /** + * Pricing value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun pricingValue(): String = pricingValue.getRequired("pricing_value") - fun visitTiered(tiered: TieredConversionRateConfig): T + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns the raw JSON value of [pricingValue]. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * Unlike [pricingValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("pricing_value") + @ExcludeMissing + fun _pricingValue(): JsonField = pricingValue + + /** + * Returns the raw JSON value of [unitAmount]. * - * @throws OrbInvalidDataException in the default implementation. + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + fun toBuilder() = Builder().from(this) - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) + companion object { + + /** + * Returns a mutable builder for constructing an instance of [UnitAmount]. + * + * The following fields are required: + * ```kotlin + * .pricingValue() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [UnitAmount]. */ + class Builder internal constructor() { + + private var pricingValue: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(unitAmount: UnitAmount) = apply { + pricingValue = unitAmount.pricingValue + this.unitAmount = unitAmount.unitAmount + additionalProperties = unitAmount.additionalProperties.toMutableMap() + } + + /** Pricing value */ + fun pricingValue(pricingValue: String) = + pricingValue(JsonField.of(pricingValue)) + + /** + * Sets [Builder.pricingValue] to an arbitrary JSON value. + * + * You should usually call [Builder.pricingValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun pricingValue(pricingValue: JsonField) = apply { + this.pricingValue = pricingValue + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UnitAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .pricingValue() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnitAmount = + UnitAmount( + checkRequired("pricingValue", pricingValue), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): UnitAmount = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + pricingValue() + unitAmount() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (pricingValue.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is UnitAmount && + pricingValue == other.pricingValue && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(pricingValue, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UnitAmount{pricingValue=$pricingValue, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is GroupedWithMeteredMinimumConfig && + groupingKey == other.groupingKey && + minimumUnitAmount == other.minimumUnitAmount && + pricingKey == other.pricingKey && + scalingFactors == other.scalingFactors && + scalingKey == other.scalingKey && + unitAmounts == other.unitAmounts && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + minimumUnitAmount, + pricingKey, + scalingFactors, + scalingKey, + unitAmounts, + additionalProperties, + ) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMeteredMinimumConfig{groupingKey=$groupingKey, minimumUnitAmount=$minimumUnitAmount, pricingKey=$pricingKey, scalingFactors=$scalingFactors, scalingKey=$scalingKey, unitAmounts=$unitAmounts, additionalProperties=$additionalProperties}" } /** @@ -35739,12 +58112,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -35770,6 +58141,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -35777,6 +58150,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -35791,6 +58165,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -35809,6 +58184,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -35825,6 +58201,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -35872,7 +58249,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -35880,138 +58257,92 @@ private constructor( override fun toString() = value.toString() } - class UnitWithProrationConfig - @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 - * [UnitWithProrationConfig]. - */ - fun builder() = Builder() - } - - /** A builder for [UnitWithProrationConfig]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(unitWithProrationConfig: UnitWithProrationConfig) = apply { - additionalProperties = - unitWithProrationConfig.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 [UnitWithProrationConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): UnitWithProrationConfig = - UnitWithProrationConfig(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): UnitWithProrationConfig = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is UnitWithProrationConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "UnitWithProrationConfig{additionalProperties=$additionalProperties}" - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is UnitWithProration && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && unitWithProrationConfig == other.unitWithProrationConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedWithMeteredMinimum && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + groupedWithMeteredMinimumConfig == other.groupedWithMeteredMinimumConfig && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, unitWithProrationConfig, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + groupedWithMeteredMinimumConfig, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "UnitWithProration{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, unitWithProrationConfig=$unitWithProrationConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "GroupedWithMeteredMinimum{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, groupedWithMeteredMinimumConfig=$groupedWithMeteredMinimumConfig, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class GroupedAllocation + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -36020,7 +58351,7 @@ private constructor( private val discount: JsonField, private val externalPriceId: JsonField, private val fixedPriceQuantity: JsonField, - private val groupedAllocationConfig: JsonField, + private val groupedWithMinMaxThresholdsConfig: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, private val maximum: JsonField, @@ -36046,7 +58377,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -36071,9 +58408,10 @@ private constructor( @JsonProperty("fixed_price_quantity") @ExcludeMissing fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("grouped_allocation_config") + @JsonProperty("grouped_with_min_max_thresholds_config") @ExcludeMissing - groupedAllocationConfig: JsonField = JsonMissing.of(), + groupedWithMinMaxThresholdsConfig: JsonField = + JsonMissing.of(), @JsonProperty("invoicing_cycle_configuration") @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @@ -36108,7 +58446,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -36117,7 +58457,7 @@ private constructor( discount, externalPriceId, fixedPriceQuantity, - groupedAllocationConfig, + groupedWithMinMaxThresholdsConfig, invoicingCycleConfiguration, item, maximum, @@ -36153,12 +58493,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -36209,11 +58562,13 @@ private constructor( fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") /** + * Configuration for grouped_with_min_max_thresholds pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun groupedAllocationConfig(): GroupedAllocationConfig = - groupedAllocationConfig.getRequired("grouped_allocation_config") + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired("grouped_with_min_max_thresholds_config") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -36223,6 +58578,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -36265,9 +58623,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("grouped_allocation") + * JsonValue.from("grouped_with_min_max_thresholds") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -36337,6 +58697,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -36344,6 +58713,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -36421,14 +58800,15 @@ private constructor( fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity /** - * Returns the raw JSON value of [groupedAllocationConfig]. + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. * - * Unlike [groupedAllocationConfig], this method doesn't throw if the JSON field has an - * unexpected type. + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON field + * has an unexpected type. */ - @JsonProperty("grouped_allocation_config") + @JsonProperty("grouped_with_min_max_thresholds_config") @ExcludeMissing - fun _groupedAllocationConfig(): JsonField = groupedAllocationConfig + fun _groupedWithMinMaxThresholdsConfig(): JsonField = + groupedWithMinMaxThresholdsConfig /** * Returns the raw JSON value of [invoicingCycleConfiguration]. @@ -36559,14 +58939,17 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [GroupedAllocation]. + * Returns a mutable builder for constructing an instance of + * [GroupedWithMinMaxThresholds]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -36575,7 +58958,7 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() - * .groupedAllocationConfig() + * .groupedWithMinMaxThresholdsConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -36592,13 +58975,15 @@ private constructor( fun builder() = Builder() } - /** A builder for [GroupedAllocation]. */ + /** A builder for [GroupedWithMinMaxThresholds]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -36607,7 +58992,9 @@ private constructor( private var discount: JsonField? = null private var externalPriceId: JsonField? = null private var fixedPriceQuantity: JsonField? = null - private var groupedAllocationConfig: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null private var maximum: JsonField? = null @@ -36615,7 +59002,7 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("grouped_allocation") + private var modelType: JsonValue = JsonValue.from("grouped_with_min_max_thresholds") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null @@ -36624,34 +59011,41 @@ private constructor( JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(groupedAllocation: GroupedAllocation) = apply { - id = groupedAllocation.id - billableMetric = groupedAllocation.billableMetric - billingCycleConfiguration = groupedAllocation.billingCycleConfiguration - cadence = groupedAllocation.cadence - conversionRate = groupedAllocation.conversionRate - conversionRateConfig = groupedAllocation.conversionRateConfig - createdAt = groupedAllocation.createdAt - creditAllocation = groupedAllocation.creditAllocation - currency = groupedAllocation.currency - discount = groupedAllocation.discount - externalPriceId = groupedAllocation.externalPriceId - fixedPriceQuantity = groupedAllocation.fixedPriceQuantity - groupedAllocationConfig = groupedAllocation.groupedAllocationConfig - invoicingCycleConfiguration = groupedAllocation.invoicingCycleConfiguration - item = groupedAllocation.item - maximum = groupedAllocation.maximum - maximumAmount = groupedAllocation.maximumAmount - metadata = groupedAllocation.metadata - minimum = groupedAllocation.minimum - minimumAmount = groupedAllocation.minimumAmount - modelType = groupedAllocation.modelType - name = groupedAllocation.name - planPhaseOrder = groupedAllocation.planPhaseOrder - priceType = groupedAllocation.priceType - replacesPriceId = groupedAllocation.replacesPriceId - dimensionalPriceConfiguration = groupedAllocation.dimensionalPriceConfiguration - additionalProperties = groupedAllocation.additionalProperties.toMutableMap() + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = apply { + id = groupedWithMinMaxThresholds.id + billableMetric = groupedWithMinMaxThresholds.billableMetric + billingCycleConfiguration = groupedWithMinMaxThresholds.billingCycleConfiguration + billingMode = groupedWithMinMaxThresholds.billingMode + cadence = groupedWithMinMaxThresholds.cadence + compositePriceFilters = + groupedWithMinMaxThresholds.compositePriceFilters.map { it.toMutableList() } + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + createdAt = groupedWithMinMaxThresholds.createdAt + creditAllocation = groupedWithMinMaxThresholds.creditAllocation + currency = groupedWithMinMaxThresholds.currency + discount = groupedWithMinMaxThresholds.discount + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + item = groupedWithMinMaxThresholds.item + maximum = groupedWithMinMaxThresholds.maximum + maximumAmount = groupedWithMinMaxThresholds.maximumAmount + metadata = groupedWithMinMaxThresholds.metadata + minimum = groupedWithMinMaxThresholds.minimum + minimumAmount = groupedWithMinMaxThresholds.minimumAmount + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + planPhaseOrder = groupedWithMinMaxThresholds.planPhaseOrder + priceType = groupedWithMinMaxThresholds.priceType + replacesPriceId = groupedWithMinMaxThresholds.replacesPriceId + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -36693,6 +59087,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -36704,6 +59111,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -36945,19 +59380,21 @@ private constructor( this.fixedPriceQuantity = fixedPriceQuantity } - fun groupedAllocationConfig(groupedAllocationConfig: GroupedAllocationConfig) = - groupedAllocationConfig(JsonField.of(groupedAllocationConfig)) + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = groupedWithMinMaxThresholdsConfig(JsonField.of(groupedWithMinMaxThresholdsConfig)) /** - * Sets [Builder.groupedAllocationConfig] to an arbitrary JSON value. + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. * - * You should usually call [Builder.groupedAllocationConfig] with a well-typed - * [GroupedAllocationConfig] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a well-typed + * [GroupedWithMinMaxThresholdsConfig] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. */ - fun groupedAllocationConfig( - groupedAllocationConfig: JsonField - ) = apply { this.groupedAllocationConfig = groupedAllocationConfig } + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: JsonField + ) = apply { this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig } fun invoicingCycleConfiguration( invoicingCycleConfiguration: BillingCycleConfiguration? @@ -36974,6 +59411,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -37065,7 +59506,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("grouped_allocation") + * JsonValue.from("grouped_with_min_max_thresholds") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -37169,7 +59610,7 @@ private constructor( } /** - * Returns an immutable instance of [GroupedAllocation]. + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -37178,7 +59619,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -37187,7 +59630,7 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() - * .groupedAllocationConfig() + * .groupedWithMinMaxThresholdsConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -37203,12 +59646,16 @@ private constructor( * * @throws IllegalStateException if any required field is unset. */ - fun build(): GroupedAllocation = - GroupedAllocation( + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -37217,7 +59664,10 @@ private constructor( checkRequired("discount", discount), checkRequired("externalPriceId", externalPriceId), checkRequired("fixedPriceQuantity", fixedPriceQuantity), - checkRequired("groupedAllocationConfig", groupedAllocationConfig), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), checkRequired("maximum", maximum), @@ -37237,7 +59687,7 @@ private constructor( private var validated: Boolean = false - fun validate(): GroupedAllocation = apply { + fun validate(): GroupedWithMinMaxThresholds = apply { if (validated) { return@apply } @@ -37245,7 +59695,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -37254,7 +59706,7 @@ private constructor( discount()?.validate() externalPriceId() fixedPriceQuantity() - groupedAllocationConfig().validate() + groupedWithMinMaxThresholdsConfig().validate() invoicingCycleConfiguration()?.validate() item().validate() maximum()?.validate() @@ -37263,7 +59715,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("grouped_allocation")) { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -37293,7 +59745,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -37302,7 +59756,7 @@ private constructor( (discount.asKnown()?.validity() ?: 0) + (if (externalPriceId.asKnown() == null) 0 else 1) + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (groupedAllocationConfig.asKnown()?.validity() ?: 0) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + @@ -37310,13 +59764,144 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("grouped_allocation")) 1 else 0 } + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -37461,7 +60046,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -37469,54 +60054,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun tiered(): TieredConversionRateConfig? = tiered + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") - fun isUnit(): Boolean = unit != null + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") - fun isTiered(): Boolean = tiered != null + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values - fun _json(): JsonValue? = _json + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -37535,124 +60290,422 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() - fun visitUnit(unit: UnitConversionRateConfig): T + override fun toString() = value.toString() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + private var validated: Boolean = false - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } - class GroupedAllocationConfig - @JsonCreator + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -37660,19 +60713,95 @@ private constructor( /** * Returns a mutable builder for constructing an instance of - * [GroupedAllocationConfig]. + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` */ fun builder() = Builder() } - /** A builder for [GroupedAllocationConfig]. */ + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(groupedAllocationConfig: GroupedAllocationConfig) = apply { + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate additionalProperties = - groupedAllocationConfig.additionalProperties.toMutableMap() + groupedWithMinMaxThresholdsConfig.additionalProperties.toMutableMap() + } + + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } + + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } + + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate } fun additionalProperties(additionalProperties: Map) = apply { @@ -37698,21 +60827,41 @@ private constructor( } /** - * Returns an immutable instance of [GroupedAllocationConfig]. + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): GroupedAllocationConfig = - GroupedAllocationConfig(additionalProperties.toImmutable()) + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): GroupedAllocationConfig = apply { + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { if (validated) { return@apply } + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() validated = true } @@ -37731,24 +60880,38 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedAllocationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedAllocationConfig{additionalProperties=$additionalProperties}" + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" } /** @@ -37846,12 +61009,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -37877,6 +61038,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -37884,6 +61047,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -37898,6 +61062,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -37916,6 +61081,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -37932,6 +61098,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -37979,7 +61146,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -37992,25 +61159,87 @@ private constructor( return true } - return /* spotless:off */ other is GroupedAllocation && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && groupedAllocationConfig == other.groupedAllocationConfig && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedWithMinMaxThresholds && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + groupedWithMinMaxThresholdsConfig == other.groupedWithMinMaxThresholdsConfig && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, groupedAllocationConfig, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + groupedWithMinMaxThresholdsConfig, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedAllocation{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, groupedAllocationConfig=$groupedAllocationConfig, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "GroupedWithMinMaxThresholds{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class GroupedWithProratedMinimum + class MatrixWithDisplayName + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -38019,9 +61248,9 @@ private constructor( private val discount: JsonField, private val externalPriceId: JsonField, private val fixedPriceQuantity: JsonField, - private val groupedWithProratedMinimumConfig: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, + private val matrixWithDisplayNameConfig: JsonField, private val maximum: JsonField, private val maximumAmount: JsonField, private val metadata: JsonField, @@ -38045,7 +61274,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -38070,14 +61305,13 @@ private constructor( @JsonProperty("fixed_price_quantity") @ExcludeMissing fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("grouped_with_prorated_minimum_config") - @ExcludeMissing - groupedWithProratedMinimumConfig: JsonField = - JsonMissing.of(), @JsonProperty("invoicing_cycle_configuration") @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @JsonProperty("item") @ExcludeMissing item: JsonField = JsonMissing.of(), + @JsonProperty("matrix_with_display_name_config") + @ExcludeMissing + matrixWithDisplayNameConfig: JsonField = JsonMissing.of(), @JsonProperty("maximum") @ExcludeMissing maximum: JsonField = JsonMissing.of(), @JsonProperty("maximum_amount") @ExcludeMissing @@ -38108,7 +61342,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -38117,9 +61353,9 @@ private constructor( discount, externalPriceId, fixedPriceQuantity, - groupedWithProratedMinimumConfig, invoicingCycleConfiguration, item, + matrixWithDisplayNameConfig, maximum, maximumAmount, metadata, @@ -38153,12 +61389,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -38208,13 +61457,6 @@ private constructor( */ fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun groupedWithProratedMinimumConfig(): GroupedWithProratedMinimumConfig = - groupedWithProratedMinimumConfig.getRequired("grouped_with_prorated_minimum_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -38223,11 +61465,23 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun item(): ItemSlim = item.getRequired("item") + /** + * Configuration for matrix_with_display_name pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun matrixWithDisplayNameConfig(): MatrixWithDisplayNameConfig = + matrixWithDisplayNameConfig.getRequired("matrix_with_display_name_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -38265,9 +61519,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("grouped_with_prorated_minimum") + * JsonValue.from("matrix_with_display_name") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -38337,6 +61593,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -38344,6 +61609,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -38420,17 +61695,6 @@ private constructor( @ExcludeMissing fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - /** - * Returns the raw JSON value of [groupedWithProratedMinimumConfig]. - * - * Unlike [groupedWithProratedMinimumConfig], this method doesn't throw if the JSON field - * has an unexpected type. - */ - @JsonProperty("grouped_with_prorated_minimum_config") - @ExcludeMissing - fun _groupedWithProratedMinimumConfig(): JsonField = - groupedWithProratedMinimumConfig - /** * Returns the raw JSON value of [invoicingCycleConfiguration]. * @@ -38449,6 +61713,17 @@ private constructor( */ @JsonProperty("item") @ExcludeMissing fun _item(): JsonField = item + /** + * Returns the raw JSON value of [matrixWithDisplayNameConfig]. + * + * Unlike [matrixWithDisplayNameConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("matrix_with_display_name_config") + @ExcludeMissing + fun _matrixWithDisplayNameConfig(): JsonField = + matrixWithDisplayNameConfig + /** * Returns the raw JSON value of [maximum]. * @@ -38560,15 +61835,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of - * [GroupedWithProratedMinimum]. + * Returns a mutable builder for constructing an instance of [MatrixWithDisplayName]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -38577,9 +61853,9 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() - * .groupedWithProratedMinimumConfig() * .invoicingCycleConfiguration() * .item() + * .matrixWithDisplayNameConfig() * .maximum() * .maximumAmount() * .metadata() @@ -38594,13 +61870,15 @@ private constructor( fun builder() = Builder() } - /** A builder for [GroupedWithProratedMinimum]. */ + /** A builder for [MatrixWithDisplayName]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -38609,17 +61887,15 @@ private constructor( private var discount: JsonField? = null private var externalPriceId: JsonField? = null private var fixedPriceQuantity: JsonField? = null - private var groupedWithProratedMinimumConfig: - JsonField? = - null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null + private var matrixWithDisplayNameConfig: JsonField? = null private var maximum: JsonField? = null private var maximumAmount: JsonField? = null private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("grouped_with_prorated_minimum") + private var modelType: JsonValue = JsonValue.from("matrix_with_display_name") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null @@ -38628,37 +61904,37 @@ private constructor( JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(groupedWithProratedMinimum: GroupedWithProratedMinimum) = apply { - id = groupedWithProratedMinimum.id - billableMetric = groupedWithProratedMinimum.billableMetric - billingCycleConfiguration = groupedWithProratedMinimum.billingCycleConfiguration - cadence = groupedWithProratedMinimum.cadence - conversionRate = groupedWithProratedMinimum.conversionRate - conversionRateConfig = groupedWithProratedMinimum.conversionRateConfig - createdAt = groupedWithProratedMinimum.createdAt - creditAllocation = groupedWithProratedMinimum.creditAllocation - currency = groupedWithProratedMinimum.currency - discount = groupedWithProratedMinimum.discount - externalPriceId = groupedWithProratedMinimum.externalPriceId - fixedPriceQuantity = groupedWithProratedMinimum.fixedPriceQuantity - groupedWithProratedMinimumConfig = - groupedWithProratedMinimum.groupedWithProratedMinimumConfig - invoicingCycleConfiguration = groupedWithProratedMinimum.invoicingCycleConfiguration - item = groupedWithProratedMinimum.item - maximum = groupedWithProratedMinimum.maximum - maximumAmount = groupedWithProratedMinimum.maximumAmount - metadata = groupedWithProratedMinimum.metadata - minimum = groupedWithProratedMinimum.minimum - minimumAmount = groupedWithProratedMinimum.minimumAmount - modelType = groupedWithProratedMinimum.modelType - name = groupedWithProratedMinimum.name - planPhaseOrder = groupedWithProratedMinimum.planPhaseOrder - priceType = groupedWithProratedMinimum.priceType - replacesPriceId = groupedWithProratedMinimum.replacesPriceId - dimensionalPriceConfiguration = - groupedWithProratedMinimum.dimensionalPriceConfiguration - additionalProperties = - groupedWithProratedMinimum.additionalProperties.toMutableMap() + internal fun from(matrixWithDisplayName: MatrixWithDisplayName) = apply { + id = matrixWithDisplayName.id + billableMetric = matrixWithDisplayName.billableMetric + billingCycleConfiguration = matrixWithDisplayName.billingCycleConfiguration + billingMode = matrixWithDisplayName.billingMode + cadence = matrixWithDisplayName.cadence + compositePriceFilters = + matrixWithDisplayName.compositePriceFilters.map { it.toMutableList() } + conversionRate = matrixWithDisplayName.conversionRate + conversionRateConfig = matrixWithDisplayName.conversionRateConfig + createdAt = matrixWithDisplayName.createdAt + creditAllocation = matrixWithDisplayName.creditAllocation + currency = matrixWithDisplayName.currency + discount = matrixWithDisplayName.discount + externalPriceId = matrixWithDisplayName.externalPriceId + fixedPriceQuantity = matrixWithDisplayName.fixedPriceQuantity + invoicingCycleConfiguration = matrixWithDisplayName.invoicingCycleConfiguration + item = matrixWithDisplayName.item + matrixWithDisplayNameConfig = matrixWithDisplayName.matrixWithDisplayNameConfig + maximum = matrixWithDisplayName.maximum + maximumAmount = matrixWithDisplayName.maximumAmount + metadata = matrixWithDisplayName.metadata + minimum = matrixWithDisplayName.minimum + minimumAmount = matrixWithDisplayName.minimumAmount + modelType = matrixWithDisplayName.modelType + name = matrixWithDisplayName.name + planPhaseOrder = matrixWithDisplayName.planPhaseOrder + priceType = matrixWithDisplayName.priceType + replacesPriceId = matrixWithDisplayName.replacesPriceId + dimensionalPriceConfiguration = matrixWithDisplayName.dimensionalPriceConfiguration + additionalProperties = matrixWithDisplayName.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -38700,6 +61976,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -38711,6 +62000,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -38952,21 +62269,6 @@ private constructor( this.fixedPriceQuantity = fixedPriceQuantity } - fun groupedWithProratedMinimumConfig( - groupedWithProratedMinimumConfig: GroupedWithProratedMinimumConfig - ) = groupedWithProratedMinimumConfig(JsonField.of(groupedWithProratedMinimumConfig)) - - /** - * Sets [Builder.groupedWithProratedMinimumConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.groupedWithProratedMinimumConfig] with a well-typed - * [GroupedWithProratedMinimumConfig] value instead. This method is primarily for - * setting the field to an undocumented or not yet supported value. - */ - fun groupedWithProratedMinimumConfig( - groupedWithProratedMinimumConfig: JsonField - ) = apply { this.groupedWithProratedMinimumConfig = groupedWithProratedMinimumConfig } - fun invoicingCycleConfiguration( invoicingCycleConfiguration: BillingCycleConfiguration? ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) @@ -38982,6 +62284,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -38993,6 +62299,22 @@ private constructor( */ fun item(item: JsonField) = apply { this.item = item } + /** Configuration for matrix_with_display_name pricing */ + fun matrixWithDisplayNameConfig( + matrixWithDisplayNameConfig: MatrixWithDisplayNameConfig + ) = matrixWithDisplayNameConfig(JsonField.of(matrixWithDisplayNameConfig)) + + /** + * Sets [Builder.matrixWithDisplayNameConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.matrixWithDisplayNameConfig] with a well-typed + * [MatrixWithDisplayNameConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun matrixWithDisplayNameConfig( + matrixWithDisplayNameConfig: JsonField + ) = apply { this.matrixWithDisplayNameConfig = matrixWithDisplayNameConfig } + @Deprecated("deprecated") fun maximum(maximum: Maximum?) = maximum(JsonField.ofNullable(maximum)) @@ -39073,7 +62395,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("grouped_with_prorated_minimum") + * JsonValue.from("matrix_with_display_name") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -39177,7 +62499,7 @@ private constructor( } /** - * Returns an immutable instance of [GroupedWithProratedMinimum]. + * Returns an immutable instance of [MatrixWithDisplayName]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -39186,7 +62508,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -39195,9 +62519,9 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() - * .groupedWithProratedMinimumConfig() * .invoicingCycleConfiguration() * .item() + * .matrixWithDisplayNameConfig() * .maximum() * .maximumAmount() * .metadata() @@ -39211,12 +62535,16 @@ private constructor( * * @throws IllegalStateException if any required field is unset. */ - fun build(): GroupedWithProratedMinimum = - GroupedWithProratedMinimum( + fun build(): MatrixWithDisplayName = + MatrixWithDisplayName( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -39225,12 +62553,9 @@ private constructor( checkRequired("discount", discount), checkRequired("externalPriceId", externalPriceId), checkRequired("fixedPriceQuantity", fixedPriceQuantity), - checkRequired( - "groupedWithProratedMinimumConfig", - groupedWithProratedMinimumConfig, - ), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), + checkRequired("matrixWithDisplayNameConfig", matrixWithDisplayNameConfig), checkRequired("maximum", maximum), checkRequired("maximumAmount", maximumAmount), checkRequired("metadata", metadata), @@ -39248,7 +62573,7 @@ private constructor( private var validated: Boolean = false - fun validate(): GroupedWithProratedMinimum = apply { + fun validate(): MatrixWithDisplayName = apply { if (validated) { return@apply } @@ -39256,7 +62581,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -39265,16 +62592,16 @@ private constructor( discount()?.validate() externalPriceId() fixedPriceQuantity() - groupedWithProratedMinimumConfig().validate() invoicingCycleConfiguration()?.validate() item().validate() + matrixWithDisplayNameConfig().validate() maximum()?.validate() maximumAmount() metadata().validate() minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("grouped_with_prorated_minimum")) { + if (it != JsonValue.from("matrix_with_display_name")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -39304,7 +62631,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -39313,23 +62642,150 @@ private constructor( (discount.asKnown()?.validity() ?: 0) + (if (externalPriceId.asKnown() == null) 0 else 1) + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (groupedWithProratedMinimumConfig.asKnown()?.validity() ?: 0) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + + (matrixWithDisplayNameConfig.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + (if (maximumAmount.asKnown() == null) 0 else 1) + (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { - if (it == JsonValue.from("grouped_with_prorated_minimum")) 1 else 0 - } + + modelType.let { if (it == JsonValue.from("matrix_with_display_name")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -39474,7 +62930,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -39482,54 +62938,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun tiered(): TieredConversionRateConfig? = tiered + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values - fun isUnit(): Boolean = unit != null + @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) - fun isTiered(): Boolean = tiered != null + companion object { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -39548,124 +63174,376 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun validate(): Field = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() - fun visitUnit(unit: UnitConversionRateConfig): T + override fun toString() = value.toString() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + else -> Value._UNKNOWN + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } - class GroupedWithProratedMinimumConfig - @JsonCreator + /** Configuration for matrix_with_display_name pricing */ + class MatrixWithDisplayNameConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val dimension: JsonField, + private val unitAmounts: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("dimension") + @ExcludeMissing + dimension: JsonField = JsonMissing.of(), + @JsonProperty("unit_amounts") + @ExcludeMissing + unitAmounts: JsonField> = JsonMissing.of(), + ) : this(dimension, unitAmounts, mutableMapOf()) + + /** + * Used to determine the unit rate + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun dimension(): String = dimension.getRequired("dimension") + + /** + * Apply per unit pricing to each dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmounts(): List = unitAmounts.getRequired("unit_amounts") + + /** + * Returns the raw JSON value of [dimension]. + * + * Unlike [dimension], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("dimension") + @ExcludeMissing + fun _dimension(): JsonField = dimension + + /** + * Returns the raw JSON value of [unitAmounts]. + * + * Unlike [unitAmounts], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_amounts") + @ExcludeMissing + fun _unitAmounts(): JsonField> = unitAmounts + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -39673,21 +63551,70 @@ private constructor( /** * Returns a mutable builder for constructing an instance of - * [GroupedWithProratedMinimumConfig]. + * [MatrixWithDisplayNameConfig]. + * + * The following fields are required: + * ```kotlin + * .dimension() + * .unitAmounts() + * ``` */ fun builder() = Builder() } - /** A builder for [GroupedWithProratedMinimumConfig]. */ + /** A builder for [MatrixWithDisplayNameConfig]. */ class Builder internal constructor() { + private var dimension: JsonField? = null + private var unitAmounts: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() - internal fun from( - groupedWithProratedMinimumConfig: GroupedWithProratedMinimumConfig - ) = apply { - additionalProperties = - groupedWithProratedMinimumConfig.additionalProperties.toMutableMap() + internal fun from(matrixWithDisplayNameConfig: MatrixWithDisplayNameConfig) = + apply { + dimension = matrixWithDisplayNameConfig.dimension + unitAmounts = + matrixWithDisplayNameConfig.unitAmounts.map { it.toMutableList() } + additionalProperties = + matrixWithDisplayNameConfig.additionalProperties.toMutableMap() + } + + /** Used to determine the unit rate */ + fun dimension(dimension: String) = dimension(JsonField.of(dimension)) + + /** + * Sets [Builder.dimension] to an arbitrary JSON value. + * + * You should usually call [Builder.dimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun dimension(dimension: JsonField) = apply { this.dimension = dimension } + + /** Apply per unit pricing to each dimension value */ + fun unitAmounts(unitAmounts: List) = + unitAmounts(JsonField.of(unitAmounts)) + + /** + * Sets [Builder.unitAmounts] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmounts] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun unitAmounts(unitAmounts: JsonField>) = apply { + this.unitAmounts = unitAmounts.map { it.toMutableList() } + } + + /** + * Adds a single [UnitAmount] to [unitAmounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addUnitAmount(unitAmount: UnitAmount) = apply { + unitAmounts = + (unitAmounts ?: JsonField.of(mutableListOf())).also { + checkKnown("unitAmounts", it).add(unitAmount) + } } fun additionalProperties(additionalProperties: Map) = apply { @@ -39713,21 +63640,35 @@ private constructor( } /** - * Returns an immutable instance of [GroupedWithProratedMinimumConfig]. + * Returns an immutable instance of [MatrixWithDisplayNameConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .dimension() + * .unitAmounts() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): GroupedWithProratedMinimumConfig = - GroupedWithProratedMinimumConfig(additionalProperties.toImmutable()) + fun build(): MatrixWithDisplayNameConfig = + MatrixWithDisplayNameConfig( + checkRequired("dimension", dimension), + checkRequired("unitAmounts", unitAmounts).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): GroupedWithProratedMinimumConfig = apply { + fun validate(): MatrixWithDisplayNameConfig = apply { if (validated) { return@apply } + dimension() + unitAmounts().forEach { it.validate() } validated = true } @@ -39746,24 +63687,292 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (dimension.asKnown() == null) 0 else 1) + + (unitAmounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a unit amount item */ + class UnitAmount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val dimensionValue: JsonField, + private val displayName: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("dimension_value") + @ExcludeMissing + dimensionValue: JsonField = JsonMissing.of(), + @JsonProperty("display_name") + @ExcludeMissing + displayName: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(dimensionValue, displayName, unitAmount, mutableMapOf()) + + /** + * The dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun dimensionValue(): String = dimensionValue.getRequired("dimension_value") + + /** + * Display name for this dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun displayName(): String = displayName.getRequired("display_name") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [dimensionValue]. + * + * Unlike [dimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("dimension_value") + @ExcludeMissing + fun _dimensionValue(): JsonField = dimensionValue + + /** + * Returns the raw JSON value of [displayName]. + * + * Unlike [displayName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("display_name") + @ExcludeMissing + fun _displayName(): JsonField = displayName + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 [UnitAmount]. + * + * The following fields are required: + * ```kotlin + * .dimensionValue() + * .displayName() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [UnitAmount]. */ + class Builder internal constructor() { + + private var dimensionValue: JsonField? = null + private var displayName: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(unitAmount: UnitAmount) = apply { + dimensionValue = unitAmount.dimensionValue + displayName = unitAmount.displayName + this.unitAmount = unitAmount.unitAmount + additionalProperties = unitAmount.additionalProperties.toMutableMap() + } + + /** The dimension value */ + fun dimensionValue(dimensionValue: String) = + dimensionValue(JsonField.of(dimensionValue)) + + /** + * Sets [Builder.dimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionValue] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun dimensionValue(dimensionValue: JsonField) = apply { + this.dimensionValue = dimensionValue + } + + /** Display name for this dimension value */ + fun displayName(displayName: String) = displayName(JsonField.of(displayName)) + + /** + * Sets [Builder.displayName] to an arbitrary JSON value. + * + * You should usually call [Builder.displayName] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun displayName(displayName: JsonField) = apply { + this.displayName = displayName + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UnitAmount]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .dimensionValue() + * .displayName() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnitAmount = + UnitAmount( + checkRequired("dimensionValue", dimensionValue), + checkRequired("displayName", displayName), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): UnitAmount = apply { + if (validated) { + return@apply + } + + dimensionValue() + displayName() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (dimensionValue.asKnown() == null) 0 else 1) + + (if (displayName.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnitAmount && + dimensionValue == other.dimensionValue && + displayName == other.displayName && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(dimensionValue, displayName, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UnitAmount{dimensionValue=$dimensionValue, displayName=$displayName, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedWithProratedMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MatrixWithDisplayNameConfig && + dimension == other.dimension && + unitAmounts == other.unitAmounts && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(dimension, unitAmounts, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedWithProratedMinimumConfig{additionalProperties=$additionalProperties}" + "MatrixWithDisplayNameConfig{dimension=$dimension, unitAmounts=$unitAmounts, additionalProperties=$additionalProperties}" } /** @@ -39861,12 +64070,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -39892,6 +64099,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -39899,6 +64108,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -39913,6 +64123,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -39931,6 +64142,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -39947,6 +64159,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -39994,7 +64207,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -40007,25 +64220,87 @@ private constructor( return true } - return /* spotless:off */ other is GroupedWithProratedMinimum && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && groupedWithProratedMinimumConfig == other.groupedWithProratedMinimumConfig && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MatrixWithDisplayName && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + matrixWithDisplayNameConfig == other.matrixWithDisplayNameConfig && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, groupedWithProratedMinimumConfig, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + matrixWithDisplayNameConfig, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedWithProratedMinimum{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, groupedWithProratedMinimumConfig=$groupedWithProratedMinimumConfig, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "MatrixWithDisplayName{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, matrixWithDisplayNameConfig=$matrixWithDisplayNameConfig, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class GroupedWithMeteredMinimum + class GroupedTieredPackage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -40034,7 +64309,7 @@ private constructor( private val discount: JsonField, private val externalPriceId: JsonField, private val fixedPriceQuantity: JsonField, - private val groupedWithMeteredMinimumConfig: JsonField, + private val groupedTieredPackageConfig: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, private val maximum: JsonField, @@ -40060,7 +64335,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -40085,10 +64366,9 @@ private constructor( @JsonProperty("fixed_price_quantity") @ExcludeMissing fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("grouped_with_metered_minimum_config") + @JsonProperty("grouped_tiered_package_config") @ExcludeMissing - groupedWithMeteredMinimumConfig: JsonField = - JsonMissing.of(), + groupedTieredPackageConfig: JsonField = JsonMissing.of(), @JsonProperty("invoicing_cycle_configuration") @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @@ -40123,7 +64403,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -40132,7 +64414,7 @@ private constructor( discount, externalPriceId, fixedPriceQuantity, - groupedWithMeteredMinimumConfig, + groupedTieredPackageConfig, invoicingCycleConfiguration, item, maximum, @@ -40168,12 +64450,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -40224,11 +64519,13 @@ private constructor( fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") /** + * Configuration for grouped_tiered_package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun groupedWithMeteredMinimumConfig(): GroupedWithMeteredMinimumConfig = - groupedWithMeteredMinimumConfig.getRequired("grouped_with_metered_minimum_config") + fun groupedTieredPackageConfig(): GroupedTieredPackageConfig = + groupedTieredPackageConfig.getRequired("grouped_tiered_package_config") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -40238,6 +64535,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -40280,9 +64580,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("grouped_with_metered_minimum") + * JsonValue.from("grouped_tiered_package") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -40352,6 +64654,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -40359,6 +64670,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -40436,15 +64757,15 @@ private constructor( fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity /** - * Returns the raw JSON value of [groupedWithMeteredMinimumConfig]. + * Returns the raw JSON value of [groupedTieredPackageConfig]. * - * Unlike [groupedWithMeteredMinimumConfig], this method doesn't throw if the JSON field has - * an unexpected type. + * Unlike [groupedTieredPackageConfig], this method doesn't throw if the JSON field has an + * unexpected type. */ - @JsonProperty("grouped_with_metered_minimum_config") + @JsonProperty("grouped_tiered_package_config") @ExcludeMissing - fun _groupedWithMeteredMinimumConfig(): JsonField = - groupedWithMeteredMinimumConfig + fun _groupedTieredPackageConfig(): JsonField = + groupedTieredPackageConfig /** * Returns the raw JSON value of [invoicingCycleConfiguration]. @@ -40575,15 +64896,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of - * [GroupedWithMeteredMinimum]. + * Returns a mutable builder for constructing an instance of [GroupedTieredPackage]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -40592,7 +64914,7 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() - * .groupedWithMeteredMinimumConfig() + * .groupedTieredPackageConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -40609,13 +64931,15 @@ private constructor( fun builder() = Builder() } - /** A builder for [GroupedWithMeteredMinimum]. */ + /** A builder for [GroupedTieredPackage]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -40624,9 +64948,7 @@ private constructor( private var discount: JsonField? = null private var externalPriceId: JsonField? = null private var fixedPriceQuantity: JsonField? = null - private var groupedWithMeteredMinimumConfig: - JsonField? = - null + private var groupedTieredPackageConfig: JsonField? = null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null private var maximum: JsonField? = null @@ -40634,7 +64956,7 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("grouped_with_metered_minimum") + private var modelType: JsonValue = JsonValue.from("grouped_tiered_package") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null @@ -40643,36 +64965,37 @@ private constructor( JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(groupedWithMeteredMinimum: GroupedWithMeteredMinimum) = apply { - id = groupedWithMeteredMinimum.id - billableMetric = groupedWithMeteredMinimum.billableMetric - billingCycleConfiguration = groupedWithMeteredMinimum.billingCycleConfiguration - cadence = groupedWithMeteredMinimum.cadence - conversionRate = groupedWithMeteredMinimum.conversionRate - conversionRateConfig = groupedWithMeteredMinimum.conversionRateConfig - createdAt = groupedWithMeteredMinimum.createdAt - creditAllocation = groupedWithMeteredMinimum.creditAllocation - currency = groupedWithMeteredMinimum.currency - discount = groupedWithMeteredMinimum.discount - externalPriceId = groupedWithMeteredMinimum.externalPriceId - fixedPriceQuantity = groupedWithMeteredMinimum.fixedPriceQuantity - groupedWithMeteredMinimumConfig = - groupedWithMeteredMinimum.groupedWithMeteredMinimumConfig - invoicingCycleConfiguration = groupedWithMeteredMinimum.invoicingCycleConfiguration - item = groupedWithMeteredMinimum.item - maximum = groupedWithMeteredMinimum.maximum - maximumAmount = groupedWithMeteredMinimum.maximumAmount - metadata = groupedWithMeteredMinimum.metadata - minimum = groupedWithMeteredMinimum.minimum - minimumAmount = groupedWithMeteredMinimum.minimumAmount - modelType = groupedWithMeteredMinimum.modelType - name = groupedWithMeteredMinimum.name - planPhaseOrder = groupedWithMeteredMinimum.planPhaseOrder - priceType = groupedWithMeteredMinimum.priceType - replacesPriceId = groupedWithMeteredMinimum.replacesPriceId - dimensionalPriceConfiguration = - groupedWithMeteredMinimum.dimensionalPriceConfiguration - additionalProperties = groupedWithMeteredMinimum.additionalProperties.toMutableMap() + internal fun from(groupedTieredPackage: GroupedTieredPackage) = apply { + id = groupedTieredPackage.id + billableMetric = groupedTieredPackage.billableMetric + billingCycleConfiguration = groupedTieredPackage.billingCycleConfiguration + billingMode = groupedTieredPackage.billingMode + cadence = groupedTieredPackage.cadence + compositePriceFilters = + groupedTieredPackage.compositePriceFilters.map { it.toMutableList() } + conversionRate = groupedTieredPackage.conversionRate + conversionRateConfig = groupedTieredPackage.conversionRateConfig + createdAt = groupedTieredPackage.createdAt + creditAllocation = groupedTieredPackage.creditAllocation + currency = groupedTieredPackage.currency + discount = groupedTieredPackage.discount + externalPriceId = groupedTieredPackage.externalPriceId + fixedPriceQuantity = groupedTieredPackage.fixedPriceQuantity + groupedTieredPackageConfig = groupedTieredPackage.groupedTieredPackageConfig + invoicingCycleConfiguration = groupedTieredPackage.invoicingCycleConfiguration + item = groupedTieredPackage.item + maximum = groupedTieredPackage.maximum + maximumAmount = groupedTieredPackage.maximumAmount + metadata = groupedTieredPackage.metadata + minimum = groupedTieredPackage.minimum + minimumAmount = groupedTieredPackage.minimumAmount + modelType = groupedTieredPackage.modelType + name = groupedTieredPackage.name + planPhaseOrder = groupedTieredPackage.planPhaseOrder + priceType = groupedTieredPackage.priceType + replacesPriceId = groupedTieredPackage.replacesPriceId + dimensionalPriceConfiguration = groupedTieredPackage.dimensionalPriceConfiguration + additionalProperties = groupedTieredPackage.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -40714,6 +65037,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -40725,6 +65061,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -40966,20 +65330,20 @@ private constructor( this.fixedPriceQuantity = fixedPriceQuantity } - fun groupedWithMeteredMinimumConfig( - groupedWithMeteredMinimumConfig: GroupedWithMeteredMinimumConfig - ) = groupedWithMeteredMinimumConfig(JsonField.of(groupedWithMeteredMinimumConfig)) + /** Configuration for grouped_tiered_package pricing */ + fun groupedTieredPackageConfig(groupedTieredPackageConfig: GroupedTieredPackageConfig) = + groupedTieredPackageConfig(JsonField.of(groupedTieredPackageConfig)) /** - * Sets [Builder.groupedWithMeteredMinimumConfig] to an arbitrary JSON value. + * Sets [Builder.groupedTieredPackageConfig] to an arbitrary JSON value. * - * You should usually call [Builder.groupedWithMeteredMinimumConfig] with a well-typed - * [GroupedWithMeteredMinimumConfig] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. + * You should usually call [Builder.groupedTieredPackageConfig] with a well-typed + * [GroupedTieredPackageConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. */ - fun groupedWithMeteredMinimumConfig( - groupedWithMeteredMinimumConfig: JsonField - ) = apply { this.groupedWithMeteredMinimumConfig = groupedWithMeteredMinimumConfig } + fun groupedTieredPackageConfig( + groupedTieredPackageConfig: JsonField + ) = apply { this.groupedTieredPackageConfig = groupedTieredPackageConfig } fun invoicingCycleConfiguration( invoicingCycleConfiguration: BillingCycleConfiguration? @@ -40996,6 +65360,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -41087,7 +65455,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("grouped_with_metered_minimum") + * JsonValue.from("grouped_tiered_package") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -41191,7 +65559,7 @@ private constructor( } /** - * Returns an immutable instance of [GroupedWithMeteredMinimum]. + * Returns an immutable instance of [GroupedTieredPackage]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -41200,7 +65568,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -41209,7 +65579,7 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() - * .groupedWithMeteredMinimumConfig() + * .groupedTieredPackageConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -41225,12 +65595,16 @@ private constructor( * * @throws IllegalStateException if any required field is unset. */ - fun build(): GroupedWithMeteredMinimum = - GroupedWithMeteredMinimum( + fun build(): GroupedTieredPackage = + GroupedTieredPackage( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -41239,10 +65613,7 @@ private constructor( checkRequired("discount", discount), checkRequired("externalPriceId", externalPriceId), checkRequired("fixedPriceQuantity", fixedPriceQuantity), - checkRequired( - "groupedWithMeteredMinimumConfig", - groupedWithMeteredMinimumConfig, - ), + checkRequired("groupedTieredPackageConfig", groupedTieredPackageConfig), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), checkRequired("maximum", maximum), @@ -41262,7 +65633,7 @@ private constructor( private var validated: Boolean = false - fun validate(): GroupedWithMeteredMinimum = apply { + fun validate(): GroupedTieredPackage = apply { if (validated) { return@apply } @@ -41270,7 +65641,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -41279,7 +65652,7 @@ private constructor( discount()?.validate() externalPriceId() fixedPriceQuantity() - groupedWithMeteredMinimumConfig().validate() + groupedTieredPackageConfig().validate() invoicingCycleConfiguration()?.validate() item().validate() maximum()?.validate() @@ -41288,7 +65661,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("grouped_with_metered_minimum")) { + if (it != JsonValue.from("grouped_tiered_package")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -41318,7 +65691,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -41327,7 +65702,7 @@ private constructor( (discount.asKnown()?.validity() ?: 0) + (if (externalPriceId.asKnown() == null) 0 else 1) + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (groupedWithMeteredMinimumConfig.asKnown()?.validity() ?: 0) + + (groupedTieredPackageConfig.asKnown()?.validity() ?: 0) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + @@ -41335,15 +65710,142 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { - if (it == JsonValue.from("grouped_with_metered_minimum")) 1 else 0 - } + + modelType.let { if (it == JsonValue.from("grouped_tiered_package")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -41488,7 +65990,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -41496,54 +65998,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun tiered(): TieredConversionRateConfig? = tiered + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") - fun isUnit(): Boolean = unit != null + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") - fun isTiered(): Boolean = tiered != null + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values - fun _json(): JsonValue? = _json + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -41562,124 +66234,397 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() - fun visitUnit(unit: UnitConversionRateConfig): T + override fun toString() = value.toString() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + else -> Value._UNKNOWN + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } - class GroupedWithMeteredMinimumConfig - @JsonCreator + /** Configuration for grouped_tiered_package pricing */ + class GroupedTieredPackageConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(groupingKey, packageSize, tiers, mutableMapOf()) + + /** + * The event property used to group before tiering + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers are + * defined using exclusive lower bounds. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -41687,21 +66632,89 @@ private constructor( /** * Returns a mutable builder for constructing an instance of - * [GroupedWithMeteredMinimumConfig]. + * [GroupedTieredPackageConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` */ fun builder() = Builder() } - /** A builder for [GroupedWithMeteredMinimumConfig]. */ + /** A builder for [GroupedTieredPackageConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() - internal fun from( - groupedWithMeteredMinimumConfig: GroupedWithMeteredMinimumConfig - ) = apply { + internal fun from(groupedTieredPackageConfig: GroupedTieredPackageConfig) = apply { + groupingKey = groupedTieredPackageConfig.groupingKey + packageSize = groupedTieredPackageConfig.packageSize + tiers = groupedTieredPackageConfig.tiers.map { it.toMutableList() } additionalProperties = - groupedWithMeteredMinimumConfig.additionalProperties.toMutableMap() + groupedTieredPackageConfig.additionalProperties.toMutableMap() + } + + /** The event property used to group before tiering */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** + * Apply tiered pricing after rounding up the quantity to the package size. Tiers + * are defined using exclusive lower bounds. + */ + 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 { @@ -41727,21 +66740,38 @@ private constructor( } /** - * Returns an immutable instance of [GroupedWithMeteredMinimumConfig]. + * Returns an immutable instance of [GroupedTieredPackageConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): GroupedWithMeteredMinimumConfig = - GroupedWithMeteredMinimumConfig(additionalProperties.toImmutable()) + fun build(): GroupedTieredPackageConfig = + GroupedTieredPackageConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): GroupedWithMeteredMinimumConfig = apply { + fun validate(): GroupedTieredPackageConfig = apply { if (validated) { return@apply } + groupingKey() + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -41760,24 +66790,247 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val perUnit: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("per_unit") + @ExcludeMissing + perUnit: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(perUnit, tierLowerBound, mutableMapOf()) + + /** + * Price per package + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnit(): String = perUnit.getRequired("per_unit") + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Returns the raw JSON value of [perUnit]. + * + * Unlike [perUnit], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("per_unit") + @ExcludeMissing + fun _perUnit(): JsonField = perUnit + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var perUnit: JsonField? = null + private var tierLowerBound: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + perUnit = tier.perUnit + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Price per package */ + fun perUnit(perUnit: String) = perUnit(JsonField.of(perUnit)) + + /** + * Sets [Builder.perUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnit] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun perUnit(perUnit: JsonField) = apply { this.perUnit = perUnit } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .perUnit() + * .tierLowerBound() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("perUnit", perUnit), + checkRequired("tierLowerBound", tierLowerBound), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + perUnit() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (perUnit.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + perUnit == other.perUnit && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(perUnit, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{perUnit=$perUnit, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedWithMeteredMinimumConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedTieredPackageConfig && + groupingKey == other.groupingKey && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(groupingKey, packageSize, tiers, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedWithMeteredMinimumConfig{additionalProperties=$additionalProperties}" + "GroupedTieredPackageConfig{groupingKey=$groupingKey, packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } /** @@ -41875,12 +67128,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -41906,6 +67157,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -41913,6 +67166,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -41927,6 +67181,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -41945,6 +67200,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -41961,6 +67217,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -42008,7 +67265,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -42021,25 +67278,87 @@ private constructor( return true } - return /* spotless:off */ other is GroupedWithMeteredMinimum && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && groupedWithMeteredMinimumConfig == other.groupedWithMeteredMinimumConfig && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedTieredPackage && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + groupedTieredPackageConfig == other.groupedTieredPackageConfig && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, groupedWithMeteredMinimumConfig, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + groupedTieredPackageConfig, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedWithMeteredMinimum{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, groupedWithMeteredMinimumConfig=$groupedWithMeteredMinimumConfig, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "GroupedTieredPackage{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, groupedTieredPackageConfig=$groupedTieredPackageConfig, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class MatrixWithDisplayName + class MaxGroupTieredPackage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -42050,7 +67369,7 @@ private constructor( private val fixedPriceQuantity: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, - private val matrixWithDisplayNameConfig: JsonField, + private val maxGroupTieredPackageConfig: JsonField, private val maximum: JsonField, private val maximumAmount: JsonField, private val metadata: JsonField, @@ -42074,7 +67393,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -42103,9 +67428,9 @@ private constructor( @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @JsonProperty("item") @ExcludeMissing item: JsonField = JsonMissing.of(), - @JsonProperty("matrix_with_display_name_config") + @JsonProperty("max_group_tiered_package_config") @ExcludeMissing - matrixWithDisplayNameConfig: JsonField = JsonMissing.of(), + maxGroupTieredPackageConfig: JsonField = JsonMissing.of(), @JsonProperty("maximum") @ExcludeMissing maximum: JsonField = JsonMissing.of(), @JsonProperty("maximum_amount") @ExcludeMissing @@ -42136,7 +67461,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -42147,7 +67474,7 @@ private constructor( fixedPriceQuantity, invoicingCycleConfiguration, item, - matrixWithDisplayNameConfig, + maxGroupTieredPackageConfig, maximum, maximumAmount, metadata, @@ -42181,12 +67508,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -42244,17 +67584,22 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun item(): ItemSlim = item.getRequired("item") /** + * Configuration for max_group_tiered_package pricing + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun matrixWithDisplayNameConfig(): MatrixWithDisplayNameConfig = - matrixWithDisplayNameConfig.getRequired("matrix_with_display_name_config") + fun maxGroupTieredPackageConfig(): MaxGroupTieredPackageConfig = + maxGroupTieredPackageConfig.getRequired("max_group_tiered_package_config") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -42293,9 +67638,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("matrix_with_display_name") + * JsonValue.from("max_group_tiered_package") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -42365,6 +67712,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -42372,6 +67728,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -42467,15 +67833,15 @@ private constructor( @JsonProperty("item") @ExcludeMissing fun _item(): JsonField = item /** - * Returns the raw JSON value of [matrixWithDisplayNameConfig]. + * Returns the raw JSON value of [maxGroupTieredPackageConfig]. * - * Unlike [matrixWithDisplayNameConfig], this method doesn't throw if the JSON field has an + * Unlike [maxGroupTieredPackageConfig], this method doesn't throw if the JSON field has an * unexpected type. */ - @JsonProperty("matrix_with_display_name_config") + @JsonProperty("max_group_tiered_package_config") @ExcludeMissing - fun _matrixWithDisplayNameConfig(): JsonField = - matrixWithDisplayNameConfig + fun _maxGroupTieredPackageConfig(): JsonField = + maxGroupTieredPackageConfig /** * Returns the raw JSON value of [maximum]. @@ -42588,14 +67954,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [MatrixWithDisplayName]. + * Returns a mutable builder for constructing an instance of [MaxGroupTieredPackage]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -42606,7 +67974,7 @@ private constructor( * .fixedPriceQuantity() * .invoicingCycleConfiguration() * .item() - * .matrixWithDisplayNameConfig() + * .maxGroupTieredPackageConfig() * .maximum() * .maximumAmount() * .metadata() @@ -42621,13 +67989,15 @@ private constructor( fun builder() = Builder() } - /** A builder for [MatrixWithDisplayName]. */ + /** A builder for [MaxGroupTieredPackage]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -42638,13 +68008,13 @@ private constructor( private var fixedPriceQuantity: JsonField? = null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null - private var matrixWithDisplayNameConfig: JsonField? = null + private var maxGroupTieredPackageConfig: JsonField? = null private var maximum: JsonField? = null private var maximumAmount: JsonField? = null private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("matrix_with_display_name") + private var modelType: JsonValue = JsonValue.from("max_group_tiered_package") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null @@ -42653,34 +68023,37 @@ private constructor( JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(matrixWithDisplayName: MatrixWithDisplayName) = apply { - id = matrixWithDisplayName.id - billableMetric = matrixWithDisplayName.billableMetric - billingCycleConfiguration = matrixWithDisplayName.billingCycleConfiguration - cadence = matrixWithDisplayName.cadence - conversionRate = matrixWithDisplayName.conversionRate - conversionRateConfig = matrixWithDisplayName.conversionRateConfig - createdAt = matrixWithDisplayName.createdAt - creditAllocation = matrixWithDisplayName.creditAllocation - currency = matrixWithDisplayName.currency - discount = matrixWithDisplayName.discount - externalPriceId = matrixWithDisplayName.externalPriceId - fixedPriceQuantity = matrixWithDisplayName.fixedPriceQuantity - invoicingCycleConfiguration = matrixWithDisplayName.invoicingCycleConfiguration - item = matrixWithDisplayName.item - matrixWithDisplayNameConfig = matrixWithDisplayName.matrixWithDisplayNameConfig - maximum = matrixWithDisplayName.maximum - maximumAmount = matrixWithDisplayName.maximumAmount - metadata = matrixWithDisplayName.metadata - minimum = matrixWithDisplayName.minimum - minimumAmount = matrixWithDisplayName.minimumAmount - modelType = matrixWithDisplayName.modelType - name = matrixWithDisplayName.name - planPhaseOrder = matrixWithDisplayName.planPhaseOrder - priceType = matrixWithDisplayName.priceType - replacesPriceId = matrixWithDisplayName.replacesPriceId - dimensionalPriceConfiguration = matrixWithDisplayName.dimensionalPriceConfiguration - additionalProperties = matrixWithDisplayName.additionalProperties.toMutableMap() + internal fun from(maxGroupTieredPackage: MaxGroupTieredPackage) = apply { + id = maxGroupTieredPackage.id + billableMetric = maxGroupTieredPackage.billableMetric + billingCycleConfiguration = maxGroupTieredPackage.billingCycleConfiguration + billingMode = maxGroupTieredPackage.billingMode + cadence = maxGroupTieredPackage.cadence + compositePriceFilters = + maxGroupTieredPackage.compositePriceFilters.map { it.toMutableList() } + conversionRate = maxGroupTieredPackage.conversionRate + conversionRateConfig = maxGroupTieredPackage.conversionRateConfig + createdAt = maxGroupTieredPackage.createdAt + creditAllocation = maxGroupTieredPackage.creditAllocation + currency = maxGroupTieredPackage.currency + discount = maxGroupTieredPackage.discount + externalPriceId = maxGroupTieredPackage.externalPriceId + fixedPriceQuantity = maxGroupTieredPackage.fixedPriceQuantity + invoicingCycleConfiguration = maxGroupTieredPackage.invoicingCycleConfiguration + item = maxGroupTieredPackage.item + maxGroupTieredPackageConfig = maxGroupTieredPackage.maxGroupTieredPackageConfig + maximum = maxGroupTieredPackage.maximum + maximumAmount = maxGroupTieredPackage.maximumAmount + metadata = maxGroupTieredPackage.metadata + minimum = maxGroupTieredPackage.minimum + minimumAmount = maxGroupTieredPackage.minimumAmount + modelType = maxGroupTieredPackage.modelType + name = maxGroupTieredPackage.name + planPhaseOrder = maxGroupTieredPackage.planPhaseOrder + priceType = maxGroupTieredPackage.priceType + replacesPriceId = maxGroupTieredPackage.replacesPriceId + dimensionalPriceConfiguration = maxGroupTieredPackage.dimensionalPriceConfiguration + additionalProperties = maxGroupTieredPackage.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -42722,6 +68095,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -42733,6 +68119,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -42989,6 +68403,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -43000,20 +68418,21 @@ private constructor( */ fun item(item: JsonField) = apply { this.item = item } - fun matrixWithDisplayNameConfig( - matrixWithDisplayNameConfig: MatrixWithDisplayNameConfig - ) = matrixWithDisplayNameConfig(JsonField.of(matrixWithDisplayNameConfig)) + /** Configuration for max_group_tiered_package pricing */ + fun maxGroupTieredPackageConfig( + maxGroupTieredPackageConfig: MaxGroupTieredPackageConfig + ) = maxGroupTieredPackageConfig(JsonField.of(maxGroupTieredPackageConfig)) /** - * Sets [Builder.matrixWithDisplayNameConfig] to an arbitrary JSON value. + * Sets [Builder.maxGroupTieredPackageConfig] to an arbitrary JSON value. * - * You should usually call [Builder.matrixWithDisplayNameConfig] with a well-typed - * [MatrixWithDisplayNameConfig] value instead. This method is primarily for setting the + * You should usually call [Builder.maxGroupTieredPackageConfig] with a well-typed + * [MaxGroupTieredPackageConfig] value instead. This method is primarily for setting the * field to an undocumented or not yet supported value. */ - fun matrixWithDisplayNameConfig( - matrixWithDisplayNameConfig: JsonField - ) = apply { this.matrixWithDisplayNameConfig = matrixWithDisplayNameConfig } + fun maxGroupTieredPackageConfig( + maxGroupTieredPackageConfig: JsonField + ) = apply { this.maxGroupTieredPackageConfig = maxGroupTieredPackageConfig } @Deprecated("deprecated") fun maximum(maximum: Maximum?) = maximum(JsonField.ofNullable(maximum)) @@ -43095,7 +68514,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("matrix_with_display_name") + * JsonValue.from("max_group_tiered_package") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -43199,7 +68618,7 @@ private constructor( } /** - * Returns an immutable instance of [MatrixWithDisplayName]. + * Returns an immutable instance of [MaxGroupTieredPackage]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -43208,7 +68627,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -43219,7 +68640,7 @@ private constructor( * .fixedPriceQuantity() * .invoicingCycleConfiguration() * .item() - * .matrixWithDisplayNameConfig() + * .maxGroupTieredPackageConfig() * .maximum() * .maximumAmount() * .metadata() @@ -43233,12 +68654,16 @@ private constructor( * * @throws IllegalStateException if any required field is unset. */ - fun build(): MatrixWithDisplayName = - MatrixWithDisplayName( + fun build(): MaxGroupTieredPackage = + MaxGroupTieredPackage( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -43249,7 +68674,7 @@ private constructor( checkRequired("fixedPriceQuantity", fixedPriceQuantity), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), - checkRequired("matrixWithDisplayNameConfig", matrixWithDisplayNameConfig), + checkRequired("maxGroupTieredPackageConfig", maxGroupTieredPackageConfig), checkRequired("maximum", maximum), checkRequired("maximumAmount", maximumAmount), checkRequired("metadata", metadata), @@ -43267,7 +68692,7 @@ private constructor( private var validated: Boolean = false - fun validate(): MatrixWithDisplayName = apply { + fun validate(): MaxGroupTieredPackage = apply { if (validated) { return@apply } @@ -43275,7 +68700,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -43286,14 +68713,14 @@ private constructor( fixedPriceQuantity() invoicingCycleConfiguration()?.validate() item().validate() - matrixWithDisplayNameConfig().validate() + maxGroupTieredPackageConfig().validate() maximum()?.validate() maximumAmount() metadata().validate() minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("matrix_with_display_name")) { + if (it != JsonValue.from("max_group_tiered_package")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -43323,7 +68750,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -43334,19 +68763,148 @@ private constructor( (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + - (matrixWithDisplayNameConfig.asKnown()?.validity() ?: 0) + + (maxGroupTieredPackageConfig.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + (if (maximumAmount.asKnown() == null) 0 else 1) + (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("matrix_with_display_name")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("max_group_tiered_package")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -43491,7 +69049,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -43499,54 +69057,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun tiered(): TieredConversionRateConfig? = tiered + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values - fun isUnit(): Boolean = unit != null + @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) - fun isTiered(): Boolean = tiered != null + companion object { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -43565,124 +69293,396 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } - fun visitUnit(unit: UnitConversionRateConfig): T + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + private var validated: Boolean = false - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } - class MatrixWithDisplayNameConfig - @JsonCreator + /** Configuration for max_group_tiered_package pricing */ + class MaxGroupTieredPackageConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val groupingKey: JsonField, + private val packageSize: JsonField, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("package_size") + @ExcludeMissing + packageSize: JsonField = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(groupingKey, packageSize, tiers, mutableMapOf()) + + /** + * The event property used to group before tiering the group with the highest value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Package size + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun packageSize(): String = packageSize.getRequired("package_size") + + /** + * Apply tiered pricing to the largest group after grouping with the provided key. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [packageSize]. + * + * Unlike [packageSize], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("package_size") + @ExcludeMissing + fun _packageSize(): JsonField = packageSize + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -43690,22 +69690,93 @@ private constructor( /** * Returns a mutable builder for constructing an instance of - * [MatrixWithDisplayNameConfig]. + * [MaxGroupTieredPackageConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` */ fun builder() = Builder() } - /** A builder for [MatrixWithDisplayNameConfig]. */ + /** A builder for [MaxGroupTieredPackageConfig]. */ class Builder internal constructor() { + private var groupingKey: JsonField? = null + private var packageSize: JsonField? = null + private var tiers: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(matrixWithDisplayNameConfig: MatrixWithDisplayNameConfig) = + internal fun from(maxGroupTieredPackageConfig: MaxGroupTieredPackageConfig) = apply { + groupingKey = maxGroupTieredPackageConfig.groupingKey + packageSize = maxGroupTieredPackageConfig.packageSize + tiers = maxGroupTieredPackageConfig.tiers.map { it.toMutableList() } additionalProperties = - matrixWithDisplayNameConfig.additionalProperties.toMutableMap() + maxGroupTieredPackageConfig.additionalProperties.toMutableMap() } + /** + * The event property used to group before tiering the group with the highest value + */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Package size */ + fun packageSize(packageSize: String) = packageSize(JsonField.of(packageSize)) + + /** + * Sets [Builder.packageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.packageSize] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun packageSize(packageSize: JsonField) = apply { + this.packageSize = packageSize + } + + /** + * Apply tiered pricing to the largest group after grouping with the provided key. + */ + 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) @@ -43729,21 +69800,38 @@ private constructor( } /** - * Returns an immutable instance of [MatrixWithDisplayNameConfig]. + * Returns an immutable instance of [MaxGroupTieredPackageConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .packageSize() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): MatrixWithDisplayNameConfig = - MatrixWithDisplayNameConfig(additionalProperties.toImmutable()) + fun build(): MaxGroupTieredPackageConfig = + MaxGroupTieredPackageConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("packageSize", packageSize), + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): MatrixWithDisplayNameConfig = apply { + fun validate(): MaxGroupTieredPackageConfig = apply { if (validated) { return@apply } + groupingKey() + packageSize() + tiers().forEach { it.validate() } validated = true } @@ -43762,24 +69850,249 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (packageSize.asKnown() == null) 0 else 1) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MatrixWithDisplayNameConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MaxGroupTieredPackageConfig && + groupingKey == other.groupingKey && + packageSize == other.packageSize && + tiers == other.tiers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(groupingKey, packageSize, tiers, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "MatrixWithDisplayNameConfig{additionalProperties=$additionalProperties}" + "MaxGroupTieredPackageConfig{groupingKey=$groupingKey, packageSize=$packageSize, tiers=$tiers, additionalProperties=$additionalProperties}" } /** @@ -43877,12 +70190,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -43908,6 +70219,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -43915,6 +70228,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -43929,6 +70243,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -43947,6 +70262,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -43963,6 +70279,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -44010,7 +70327,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -44023,26 +70340,87 @@ private constructor( return true } - return /* spotless:off */ other is MatrixWithDisplayName && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && matrixWithDisplayNameConfig == other.matrixWithDisplayNameConfig && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MaxGroupTieredPackage && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maxGroupTieredPackageConfig == other.maxGroupTieredPackageConfig && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, matrixWithDisplayNameConfig, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maxGroupTieredPackageConfig, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "MatrixWithDisplayName{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, matrixWithDisplayNameConfig=$matrixWithDisplayNameConfig, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "MaxGroupTieredPackage{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maxGroupTieredPackageConfig=$maxGroupTieredPackageConfig, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class BulkWithProration + class ScalableMatrixWithUnitPricing + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, - private val bulkWithProrationConfig: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -44063,6 +70441,8 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, + private val scalableMatrixWithUnitPricingConfig: + JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -44076,10 +70456,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), - @JsonProperty("bulk_with_proration_config") + @JsonProperty("billing_mode") @ExcludeMissing - bulkWithProrationConfig: JsonField = JsonMissing.of(), + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -44130,6 +70513,10 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), + @JsonProperty("scalable_matrix_with_unit_pricing_config") + @ExcludeMissing + scalableMatrixWithUnitPricingConfig: JsonField = + JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -44138,8 +70525,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, - bulkWithProrationConfig, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -44160,6 +70548,7 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, + scalableMatrixWithUnitPricingConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -44187,8 +70576,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun bulkWithProrationConfig(): BulkWithProrationConfig = - bulkWithProrationConfig.getRequired("bulk_with_proration_config") + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is @@ -44196,6 +70584,13 @@ private constructor( */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -44253,6 +70648,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -44295,9 +70693,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("bulk_with_proration") + * JsonValue.from("scalable_matrix_with_unit_pricing") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -44332,6 +70732,17 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") + /** + * Configuration for scalable_matrix_with_unit_pricing pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun scalableMatrixWithUnitPricingConfig(): ScalableMatrixWithUnitPricingConfig = + scalableMatrixWithUnitPricingConfig.getRequired( + "scalable_matrix_with_unit_pricing_config" + ) + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -44368,14 +70779,13 @@ private constructor( billingCycleConfiguration /** - * Returns the raw JSON value of [bulkWithProrationConfig]. + * Returns the raw JSON value of [billingMode]. * - * Unlike [bulkWithProrationConfig], this method doesn't throw if the JSON field has an - * unexpected type. + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("bulk_with_proration_config") + @JsonProperty("billing_mode") @ExcludeMissing - fun _bulkWithProrationConfig(): JsonField = bulkWithProrationConfig + fun _billingMode(): JsonField = billingMode /** * Returns the raw JSON value of [cadence]. @@ -44384,6 +70794,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -44563,6 +70983,17 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId + /** + * Returns the raw JSON value of [scalableMatrixWithUnitPricingConfig]. + * + * Unlike [scalableMatrixWithUnitPricingConfig], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("scalable_matrix_with_unit_pricing_config") + @ExcludeMissing + fun _scalableMatrixWithUnitPricingConfig(): JsonField = + scalableMatrixWithUnitPricingConfig + /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -44589,15 +71020,17 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [BulkWithProration]. + * Returns a mutable builder for constructing an instance of + * [ScalableMatrixWithUnitPricing]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() - * .bulkWithProrationConfig() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -44617,19 +71050,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .scalableMatrixWithUnitPricingConfig() * ``` */ fun builder() = Builder() } - /** A builder for [BulkWithProration]. */ + /** A builder for [ScalableMatrixWithUnitPricing]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null - private var bulkWithProrationConfig: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -44645,44 +71080,58 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("bulk_with_proration") + private var modelType: JsonValue = JsonValue.from("scalable_matrix_with_unit_pricing") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null + private var scalableMatrixWithUnitPricingConfig: + JsonField? = + null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(bulkWithProration: BulkWithProration) = apply { - id = bulkWithProration.id - billableMetric = bulkWithProration.billableMetric - billingCycleConfiguration = bulkWithProration.billingCycleConfiguration - bulkWithProrationConfig = bulkWithProration.bulkWithProrationConfig - cadence = bulkWithProration.cadence - conversionRate = bulkWithProration.conversionRate - conversionRateConfig = bulkWithProration.conversionRateConfig - createdAt = bulkWithProration.createdAt - creditAllocation = bulkWithProration.creditAllocation - currency = bulkWithProration.currency - discount = bulkWithProration.discount - externalPriceId = bulkWithProration.externalPriceId - fixedPriceQuantity = bulkWithProration.fixedPriceQuantity - invoicingCycleConfiguration = bulkWithProration.invoicingCycleConfiguration - item = bulkWithProration.item - maximum = bulkWithProration.maximum - maximumAmount = bulkWithProration.maximumAmount - metadata = bulkWithProration.metadata - minimum = bulkWithProration.minimum - minimumAmount = bulkWithProration.minimumAmount - modelType = bulkWithProration.modelType - name = bulkWithProration.name - planPhaseOrder = bulkWithProration.planPhaseOrder - priceType = bulkWithProration.priceType - replacesPriceId = bulkWithProration.replacesPriceId - dimensionalPriceConfiguration = bulkWithProration.dimensionalPriceConfiguration - additionalProperties = bulkWithProration.additionalProperties.toMutableMap() - } + internal fun from(scalableMatrixWithUnitPricing: ScalableMatrixWithUnitPricing) = + apply { + id = scalableMatrixWithUnitPricing.id + billableMetric = scalableMatrixWithUnitPricing.billableMetric + billingCycleConfiguration = + scalableMatrixWithUnitPricing.billingCycleConfiguration + billingMode = scalableMatrixWithUnitPricing.billingMode + cadence = scalableMatrixWithUnitPricing.cadence + compositePriceFilters = + scalableMatrixWithUnitPricing.compositePriceFilters.map { + it.toMutableList() + } + conversionRate = scalableMatrixWithUnitPricing.conversionRate + conversionRateConfig = scalableMatrixWithUnitPricing.conversionRateConfig + createdAt = scalableMatrixWithUnitPricing.createdAt + creditAllocation = scalableMatrixWithUnitPricing.creditAllocation + currency = scalableMatrixWithUnitPricing.currency + discount = scalableMatrixWithUnitPricing.discount + externalPriceId = scalableMatrixWithUnitPricing.externalPriceId + fixedPriceQuantity = scalableMatrixWithUnitPricing.fixedPriceQuantity + invoicingCycleConfiguration = + scalableMatrixWithUnitPricing.invoicingCycleConfiguration + item = scalableMatrixWithUnitPricing.item + maximum = scalableMatrixWithUnitPricing.maximum + maximumAmount = scalableMatrixWithUnitPricing.maximumAmount + metadata = scalableMatrixWithUnitPricing.metadata + minimum = scalableMatrixWithUnitPricing.minimum + minimumAmount = scalableMatrixWithUnitPricing.minimumAmount + modelType = scalableMatrixWithUnitPricing.modelType + name = scalableMatrixWithUnitPricing.name + planPhaseOrder = scalableMatrixWithUnitPricing.planPhaseOrder + priceType = scalableMatrixWithUnitPricing.priceType + replacesPriceId = scalableMatrixWithUnitPricing.replacesPriceId + scalableMatrixWithUnitPricingConfig = + scalableMatrixWithUnitPricing.scalableMatrixWithUnitPricingConfig + dimensionalPriceConfiguration = + scalableMatrixWithUnitPricing.dimensionalPriceConfiguration + additionalProperties = + scalableMatrixWithUnitPricing.additionalProperties.toMutableMap() + } fun id(id: String) = id(JsonField.of(id)) @@ -44723,19 +71172,18 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } - fun bulkWithProrationConfig(bulkWithProrationConfig: BulkWithProrationConfig) = - bulkWithProrationConfig(JsonField.of(bulkWithProrationConfig)) + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) /** - * Sets [Builder.bulkWithProrationConfig] to an arbitrary JSON value. + * Sets [Builder.billingMode] to an arbitrary JSON value. * - * You should usually call [Builder.bulkWithProrationConfig] with a well-typed - * [BulkWithProrationConfig] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun bulkWithProrationConfig( - bulkWithProrationConfig: JsonField - ) = apply { this.bulkWithProrationConfig = bulkWithProrationConfig } + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) @@ -44748,6 +71196,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -45004,6 +71480,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -45095,7 +71575,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("bulk_with_proration") + * JsonValue.from("scalable_matrix_with_unit_pricing") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -45164,6 +71644,27 @@ private constructor( this.replacesPriceId = replacesPriceId } + /** Configuration for scalable_matrix_with_unit_pricing pricing */ + fun scalableMatrixWithUnitPricingConfig( + scalableMatrixWithUnitPricingConfig: ScalableMatrixWithUnitPricingConfig + ) = + scalableMatrixWithUnitPricingConfig( + JsonField.of(scalableMatrixWithUnitPricingConfig) + ) + + /** + * Sets [Builder.scalableMatrixWithUnitPricingConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.scalableMatrixWithUnitPricingConfig] with a + * well-typed [ScalableMatrixWithUnitPricingConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun scalableMatrixWithUnitPricingConfig( + scalableMatrixWithUnitPricingConfig: JsonField + ) = apply { + this.scalableMatrixWithUnitPricingConfig = scalableMatrixWithUnitPricingConfig + } + fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -45199,7 +71700,7 @@ private constructor( } /** - * Returns an immutable instance of [BulkWithProration]. + * Returns an immutable instance of [ScalableMatrixWithUnitPricing]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -45208,8 +71709,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() - * .bulkWithProrationConfig() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -45229,17 +71731,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .scalableMatrixWithUnitPricingConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): BulkWithProration = - BulkWithProration( + fun build(): ScalableMatrixWithUnitPricing = + ScalableMatrixWithUnitPricing( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), - checkRequired("bulkWithProrationConfig", bulkWithProrationConfig), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -45260,6 +71766,10 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), + checkRequired( + "scalableMatrixWithUnitPricingConfig", + scalableMatrixWithUnitPricingConfig, + ), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -45267,7 +71777,7 @@ private constructor( private var validated: Boolean = false - fun validate(): BulkWithProration = apply { + fun validate(): ScalableMatrixWithUnitPricing = apply { if (validated) { return@apply } @@ -45275,8 +71785,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() - bulkWithProrationConfig().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -45293,7 +71804,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("bulk_with_proration")) { + if (it != JsonValue.from("scalable_matrix_with_unit_pricing")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -45301,6 +71812,7 @@ private constructor( planPhaseOrder() priceType().validate() replacesPriceId() + scalableMatrixWithUnitPricingConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -45323,8 +71835,9 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (bulkWithProrationConfig.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + @@ -45340,83 +71853,113 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("bulk_with_proration")) 1 else 0 } + + modelType.let { + if (it == JsonValue.from("scalable_matrix_with_unit_pricing")) 1 else 0 + } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (scalableMatrixWithUnitPricingConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) - class BulkWithProrationConfig - @JsonCreator - private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map - ) { - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + class BillingMode @JsonCreator private constructor(private val value: JsonField) : + Enum { - fun toBuilder() = Builder().from(this) + /** + * 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 { - /** - * Returns a mutable builder for constructing an instance of - * [BulkWithProrationConfig]. - */ - fun builder() = Builder() - } - - /** A builder for [BulkWithProrationConfig]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() + val IN_ADVANCE = of("in_advance") - internal fun from(bulkWithProrationConfig: BulkWithProrationConfig) = apply { - additionalProperties = - bulkWithProrationConfig.additionalProperties.toMutableMap() - } + val IN_ARREAR = of("in_arrear") - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun of(value: String) = BillingMode(JsonField.of(value)) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) + /** + * 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + else -> Value._UNKNOWN } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $value") } - /** - * Returns an immutable instance of [BulkWithProrationConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): BulkWithProrationConfig = - BulkWithProrationConfig(additionalProperties.toImmutable()) - } + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") private var validated: Boolean = false - fun validate(): BulkWithProrationConfig = apply { + fun validate(): BillingMode = apply { if (validated) { return@apply } + known() validated = true } @@ -45434,25 +71977,19 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is BulkWithProrationConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BillingMode && value == other.value } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode + override fun hashCode() = value.hashCode() - override fun toString() = - "BulkWithProrationConfig{additionalProperties=$additionalProperties}" + override fun toString() = value.toString() } class Cadence @JsonCreator private constructor(private val value: JsonField) : @@ -45599,7 +72136,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -45607,54 +72144,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator - fun tiered(): TieredConversionRateConfig? = tiered + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values - fun isUnit(): Boolean = unit != null + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun isTiered(): Boolean = tiered != null + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + fun toBuilder() = Builder().from(this) - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + companion object { - fun _json(): JsonValue? = _json + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -45673,112 +72380,308 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + private var validated: Boolean = false - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } - fun visitUnit(unit: UnitConversionRateConfig): T + override fun hashCode() = value.hashCode() - fun visitTiered(tiered: TieredConversionRateConfig): T + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + else -> Value._UNKNOWN + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } /** @@ -45876,12 +72779,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -45907,6 +72808,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -45914,6 +72817,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -45928,6 +72832,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -45946,6 +72851,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -45962,6 +72868,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -46009,7 +72916,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -46017,30 +72924,753 @@ private constructor( override fun toString() = value.toString() } + /** Configuration for scalable_matrix_with_unit_pricing pricing */ + class ScalableMatrixWithUnitPricingConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val firstDimension: JsonField, + private val matrixScalingFactors: JsonField>, + private val unitPrice: JsonField, + private val prorate: JsonField, + private val secondDimension: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("first_dimension") + @ExcludeMissing + firstDimension: JsonField = JsonMissing.of(), + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + matrixScalingFactors: JsonField> = JsonMissing.of(), + @JsonProperty("unit_price") + @ExcludeMissing + unitPrice: JsonField = JsonMissing.of(), + @JsonProperty("prorate") + @ExcludeMissing + prorate: JsonField = JsonMissing.of(), + @JsonProperty("second_dimension") + @ExcludeMissing + secondDimension: JsonField = JsonMissing.of(), + ) : this( + firstDimension, + matrixScalingFactors, + unitPrice, + prorate, + secondDimension, + mutableMapOf(), + ) + + /** + * Used to determine the unit rate + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun firstDimension(): String = firstDimension.getRequired("first_dimension") + + /** + * Apply a scaling factor to each dimension + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun matrixScalingFactors(): List = + matrixScalingFactors.getRequired("matrix_scaling_factors") + + /** + * The final unit price to rate against the output of the matrix + * + * @throws OrbInvalidDataException if 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(): String = unitPrice.getRequired("unit_price") + + /** + * If true, the unit price will be prorated to the billing period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorate(): Boolean? = prorate.getNullable("prorate") + + /** + * Used to determine the unit rate (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimension(): String? = secondDimension.getNullable("second_dimension") + + /** + * Returns the raw JSON value of [firstDimension]. + * + * Unlike [firstDimension], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("first_dimension") + @ExcludeMissing + fun _firstDimension(): JsonField = firstDimension + + /** + * Returns the raw JSON value of [matrixScalingFactors]. + * + * Unlike [matrixScalingFactors], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + fun _matrixScalingFactors(): JsonField> = matrixScalingFactors + + /** + * 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 [prorate]. + * + * Unlike [prorate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorate") @ExcludeMissing fun _prorate(): JsonField = prorate + + /** + * Returns the raw JSON value of [secondDimension]. + * + * Unlike [secondDimension], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("second_dimension") + @ExcludeMissing + fun _secondDimension(): JsonField = secondDimension + + @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 + * [ScalableMatrixWithUnitPricingConfig]. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .unitPrice() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ScalableMatrixWithUnitPricingConfig]. */ + class Builder internal constructor() { + + private var firstDimension: JsonField? = null + private var matrixScalingFactors: JsonField>? = + null + private var unitPrice: JsonField? = null + private var prorate: JsonField = JsonMissing.of() + private var secondDimension: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from( + scalableMatrixWithUnitPricingConfig: ScalableMatrixWithUnitPricingConfig + ) = apply { + firstDimension = scalableMatrixWithUnitPricingConfig.firstDimension + matrixScalingFactors = + scalableMatrixWithUnitPricingConfig.matrixScalingFactors.map { + it.toMutableList() + } + unitPrice = scalableMatrixWithUnitPricingConfig.unitPrice + prorate = scalableMatrixWithUnitPricingConfig.prorate + secondDimension = scalableMatrixWithUnitPricingConfig.secondDimension + additionalProperties = + scalableMatrixWithUnitPricingConfig.additionalProperties.toMutableMap() + } + + /** Used to determine the unit rate */ + fun firstDimension(firstDimension: String) = + firstDimension(JsonField.of(firstDimension)) + + /** + * Sets [Builder.firstDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun firstDimension(firstDimension: JsonField) = apply { + this.firstDimension = firstDimension + } + + /** Apply a scaling factor to each dimension */ + fun matrixScalingFactors(matrixScalingFactors: List) = + matrixScalingFactors(JsonField.of(matrixScalingFactors)) + + /** + * Sets [Builder.matrixScalingFactors] to an arbitrary JSON value. + * + * You should usually call [Builder.matrixScalingFactors] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun matrixScalingFactors( + matrixScalingFactors: JsonField> + ) = apply { + this.matrixScalingFactors = matrixScalingFactors.map { it.toMutableList() } + } + + /** + * Adds a single [MatrixScalingFactor] to [matrixScalingFactors]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMatrixScalingFactor(matrixScalingFactor: MatrixScalingFactor) = apply { + matrixScalingFactors = + (matrixScalingFactors ?: JsonField.of(mutableListOf())).also { + checkKnown("matrixScalingFactors", it).add(matrixScalingFactor) + } + } + + /** The final unit price to rate against the output of the matrix */ + fun unitPrice(unitPrice: String) = unitPrice(JsonField.of(unitPrice)) + + /** + * Sets [Builder.unitPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.unitPrice] with a well-typed [String] 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 } + + /** If true, the unit price will be prorated to the billing period */ + fun prorate(prorate: Boolean?) = prorate(JsonField.ofNullable(prorate)) + + /** + * Alias for [Builder.prorate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun prorate(prorate: Boolean) = prorate(prorate as Boolean?) + + /** + * Sets [Builder.prorate] to an arbitrary JSON value. + * + * You should usually call [Builder.prorate] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun prorate(prorate: JsonField) = apply { this.prorate = prorate } + + /** Used to determine the unit rate (optional) */ + fun secondDimension(secondDimension: String?) = + secondDimension(JsonField.ofNullable(secondDimension)) + + /** + * Sets [Builder.secondDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimension] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun secondDimension(secondDimension: JsonField) = apply { + this.secondDimension = secondDimension + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ScalableMatrixWithUnitPricingConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .unitPrice() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ScalableMatrixWithUnitPricingConfig = + ScalableMatrixWithUnitPricingConfig( + checkRequired("firstDimension", firstDimension), + checkRequired("matrixScalingFactors", matrixScalingFactors).map { + it.toImmutable() + }, + checkRequired("unitPrice", unitPrice), + prorate, + secondDimension, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ScalableMatrixWithUnitPricingConfig = apply { + if (validated) { + return@apply + } + + firstDimension() + matrixScalingFactors().forEach { it.validate() } + unitPrice() + prorate() + secondDimension() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (firstDimension.asKnown() == null) 0 else 1) + + (matrixScalingFactors.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (unitPrice.asKnown() == null) 0 else 1) + + (if (prorate.asKnown() == null) 0 else 1) + + (if (secondDimension.asKnown() == null) 0 else 1) + + /** Configuration for a single matrix scaling factor */ + class MatrixScalingFactor + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val firstDimensionValue: JsonField, + private val scalingFactor: JsonField, + private val secondDimensionValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("first_dimension_value") + @ExcludeMissing + firstDimensionValue: JsonField = JsonMissing.of(), + @JsonProperty("scaling_factor") + @ExcludeMissing + scalingFactor: JsonField = JsonMissing.of(), + @JsonProperty("second_dimension_value") + @ExcludeMissing + secondDimensionValue: JsonField = JsonMissing.of(), + ) : this(firstDimensionValue, scalingFactor, secondDimensionValue, mutableMapOf()) + + /** + * First dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun firstDimensionValue(): String = + firstDimensionValue.getRequired("first_dimension_value") + + /** + * Scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingFactor(): String = scalingFactor.getRequired("scaling_factor") + + /** + * Second dimension value (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun secondDimensionValue(): String? = + secondDimensionValue.getNullable("second_dimension_value") + + /** + * Returns the raw JSON value of [firstDimensionValue]. + * + * Unlike [firstDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("first_dimension_value") + @ExcludeMissing + fun _firstDimensionValue(): JsonField = firstDimensionValue + + /** + * Returns the raw JSON value of [scalingFactor]. + * + * Unlike [scalingFactor], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("scaling_factor") + @ExcludeMissing + fun _scalingFactor(): JsonField = scalingFactor + + /** + * Returns the raw JSON value of [secondDimensionValue]. + * + * Unlike [secondDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("second_dimension_value") + @ExcludeMissing + fun _secondDimensionValue(): JsonField = secondDimensionValue + + @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 + * [MatrixScalingFactor]. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [MatrixScalingFactor]. */ + class Builder internal constructor() { + + private var firstDimensionValue: JsonField? = null + private var scalingFactor: JsonField? = null + private var secondDimensionValue: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(matrixScalingFactor: MatrixScalingFactor) = apply { + firstDimensionValue = matrixScalingFactor.firstDimensionValue + scalingFactor = matrixScalingFactor.scalingFactor + secondDimensionValue = matrixScalingFactor.secondDimensionValue + additionalProperties = + matrixScalingFactor.additionalProperties.toMutableMap() + } + + /** First dimension value */ + fun firstDimensionValue(firstDimensionValue: String) = + firstDimensionValue(JsonField.of(firstDimensionValue)) + + /** + * Sets [Builder.firstDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimensionValue] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun firstDimensionValue(firstDimensionValue: JsonField) = apply { + this.firstDimensionValue = firstDimensionValue + } + + /** Scaling factor */ + fun scalingFactor(scalingFactor: String) = + scalingFactor(JsonField.of(scalingFactor)) + + /** + * Sets [Builder.scalingFactor] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactor] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun scalingFactor(scalingFactor: JsonField) = apply { + this.scalingFactor = scalingFactor + } + + /** Second dimension value (optional) */ + fun secondDimensionValue(secondDimensionValue: String?) = + secondDimensionValue(JsonField.ofNullable(secondDimensionValue)) + + /** + * Sets [Builder.secondDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimensionValue] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun secondDimensionValue(secondDimensionValue: JsonField) = apply { + this.secondDimensionValue = secondDimensionValue + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [MatrixScalingFactor]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MatrixScalingFactor = + MatrixScalingFactor( + checkRequired("firstDimensionValue", firstDimensionValue), + checkRequired("scalingFactor", scalingFactor), + secondDimensionValue, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MatrixScalingFactor = apply { + if (validated) { + return@apply + } + + firstDimensionValue() + scalingFactor() + secondDimensionValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (firstDimensionValue.asKnown() == null) 0 else 1) + + (if (scalingFactor.asKnown() == null) 0 else 1) + + (if (secondDimensionValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MatrixScalingFactor && + firstDimensionValue == other.firstDimensionValue && + scalingFactor == other.scalingFactor && + secondDimensionValue == other.secondDimensionValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + firstDimensionValue, + scalingFactor, + secondDimensionValue, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MatrixScalingFactor{firstDimensionValue=$firstDimensionValue, scalingFactor=$scalingFactor, secondDimensionValue=$secondDimensionValue, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ScalableMatrixWithUnitPricingConfig && + firstDimension == other.firstDimension && + matrixScalingFactors == other.matrixScalingFactors && + unitPrice == other.unitPrice && + prorate == other.prorate && + secondDimension == other.secondDimension && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + firstDimension, + matrixScalingFactors, + unitPrice, + prorate, + secondDimension, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScalableMatrixWithUnitPricingConfig{firstDimension=$firstDimension, matrixScalingFactors=$matrixScalingFactors, unitPrice=$unitPrice, prorate=$prorate, secondDimension=$secondDimension, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is BulkWithProration && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && bulkWithProrationConfig == other.bulkWithProrationConfig && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ScalableMatrixWithUnitPricing && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + scalableMatrixWithUnitPricingConfig == other.scalableMatrixWithUnitPricingConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, bulkWithProrationConfig, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + scalableMatrixWithUnitPricingConfig, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "BulkWithProration{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, bulkWithProrationConfig=$bulkWithProrationConfig, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "ScalableMatrixWithUnitPricing{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, scalableMatrixWithUnitPricingConfig=$scalableMatrixWithUnitPricingConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class GroupedTieredPackage + class ScalableMatrixWithTieredPricing + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -46049,7 +73679,6 @@ private constructor( private val discount: JsonField, private val externalPriceId: JsonField, private val fixedPriceQuantity: JsonField, - private val groupedTieredPackageConfig: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, private val maximum: JsonField, @@ -46062,6 +73691,8 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, + private val scalableMatrixWithTieredPricingConfig: + JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -46075,7 +73706,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -46100,9 +73737,6 @@ private constructor( @JsonProperty("fixed_price_quantity") @ExcludeMissing fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("grouped_tiered_package_config") - @ExcludeMissing - groupedTieredPackageConfig: JsonField = JsonMissing.of(), @JsonProperty("invoicing_cycle_configuration") @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @@ -46129,6 +73763,11 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), + @JsonProperty("scalable_matrix_with_tiered_pricing_config") + @ExcludeMissing + scalableMatrixWithTieredPricingConfig: + JsonField = + JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -46137,7 +73776,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -46146,7 +73787,6 @@ private constructor( discount, externalPriceId, fixedPriceQuantity, - groupedTieredPackageConfig, invoicingCycleConfiguration, item, maximum, @@ -46159,6 +73799,7 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, + scalableMatrixWithTieredPricingConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -46182,12 +73823,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -46237,13 +73891,6 @@ private constructor( */ fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun groupedTieredPackageConfig(): GroupedTieredPackageConfig = - groupedTieredPackageConfig.getRequired("grouped_tiered_package_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -46252,6 +73899,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -46294,9 +73944,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("grouped_tiered_package") + * JsonValue.from("scalable_matrix_with_tiered_pricing") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -46331,6 +73983,17 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") + /** + * Configuration for scalable_matrix_with_tiered_pricing pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun scalableMatrixWithTieredPricingConfig(): ScalableMatrixWithTieredPricingConfig = + scalableMatrixWithTieredPricingConfig.getRequired( + "scalable_matrix_with_tiered_pricing_config" + ) + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -46366,6 +74029,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -46373,6 +74045,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -46449,17 +74131,6 @@ private constructor( @ExcludeMissing fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - /** - * Returns the raw JSON value of [groupedTieredPackageConfig]. - * - * Unlike [groupedTieredPackageConfig], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("grouped_tiered_package_config") - @ExcludeMissing - fun _groupedTieredPackageConfig(): JsonField = - groupedTieredPackageConfig - /** * Returns the raw JSON value of [invoicingCycleConfiguration]. * @@ -46563,6 +74234,17 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId + /** + * Returns the raw JSON value of [scalableMatrixWithTieredPricingConfig]. + * + * Unlike [scalableMatrixWithTieredPricingConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("scalable_matrix_with_tiered_pricing_config") + @ExcludeMissing + fun _scalableMatrixWithTieredPricingConfig(): + JsonField = scalableMatrixWithTieredPricingConfig + /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -46589,14 +74271,17 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [GroupedTieredPackage]. + * Returns a mutable builder for constructing an instance of + * [ScalableMatrixWithTieredPricing]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -46605,7 +74290,6 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() - * .groupedTieredPackageConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -46617,18 +74301,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .scalableMatrixWithTieredPricingConfig() * ``` */ fun builder() = Builder() } - /** A builder for [GroupedTieredPackage]. */ + /** A builder for [ScalableMatrixWithTieredPricing]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -46637,7 +74324,6 @@ private constructor( private var discount: JsonField? = null private var externalPriceId: JsonField? = null private var fixedPriceQuantity: JsonField? = null - private var groupedTieredPackageConfig: JsonField? = null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null private var maximum: JsonField? = null @@ -46645,44 +74331,58 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("grouped_tiered_package") + private var modelType: JsonValue = JsonValue.from("scalable_matrix_with_tiered_pricing") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null + private var scalableMatrixWithTieredPricingConfig: + JsonField? = + null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(groupedTieredPackage: GroupedTieredPackage) = apply { - id = groupedTieredPackage.id - billableMetric = groupedTieredPackage.billableMetric - billingCycleConfiguration = groupedTieredPackage.billingCycleConfiguration - cadence = groupedTieredPackage.cadence - conversionRate = groupedTieredPackage.conversionRate - conversionRateConfig = groupedTieredPackage.conversionRateConfig - createdAt = groupedTieredPackage.createdAt - creditAllocation = groupedTieredPackage.creditAllocation - currency = groupedTieredPackage.currency - discount = groupedTieredPackage.discount - externalPriceId = groupedTieredPackage.externalPriceId - fixedPriceQuantity = groupedTieredPackage.fixedPriceQuantity - groupedTieredPackageConfig = groupedTieredPackage.groupedTieredPackageConfig - invoicingCycleConfiguration = groupedTieredPackage.invoicingCycleConfiguration - item = groupedTieredPackage.item - maximum = groupedTieredPackage.maximum - maximumAmount = groupedTieredPackage.maximumAmount - metadata = groupedTieredPackage.metadata - minimum = groupedTieredPackage.minimum - minimumAmount = groupedTieredPackage.minimumAmount - modelType = groupedTieredPackage.modelType - name = groupedTieredPackage.name - planPhaseOrder = groupedTieredPackage.planPhaseOrder - priceType = groupedTieredPackage.priceType - replacesPriceId = groupedTieredPackage.replacesPriceId - dimensionalPriceConfiguration = groupedTieredPackage.dimensionalPriceConfiguration - additionalProperties = groupedTieredPackage.additionalProperties.toMutableMap() - } + internal fun from(scalableMatrixWithTieredPricing: ScalableMatrixWithTieredPricing) = + apply { + id = scalableMatrixWithTieredPricing.id + billableMetric = scalableMatrixWithTieredPricing.billableMetric + billingCycleConfiguration = + scalableMatrixWithTieredPricing.billingCycleConfiguration + billingMode = scalableMatrixWithTieredPricing.billingMode + cadence = scalableMatrixWithTieredPricing.cadence + compositePriceFilters = + scalableMatrixWithTieredPricing.compositePriceFilters.map { + it.toMutableList() + } + conversionRate = scalableMatrixWithTieredPricing.conversionRate + conversionRateConfig = scalableMatrixWithTieredPricing.conversionRateConfig + createdAt = scalableMatrixWithTieredPricing.createdAt + creditAllocation = scalableMatrixWithTieredPricing.creditAllocation + currency = scalableMatrixWithTieredPricing.currency + discount = scalableMatrixWithTieredPricing.discount + externalPriceId = scalableMatrixWithTieredPricing.externalPriceId + fixedPriceQuantity = scalableMatrixWithTieredPricing.fixedPriceQuantity + invoicingCycleConfiguration = + scalableMatrixWithTieredPricing.invoicingCycleConfiguration + item = scalableMatrixWithTieredPricing.item + maximum = scalableMatrixWithTieredPricing.maximum + maximumAmount = scalableMatrixWithTieredPricing.maximumAmount + metadata = scalableMatrixWithTieredPricing.metadata + minimum = scalableMatrixWithTieredPricing.minimum + minimumAmount = scalableMatrixWithTieredPricing.minimumAmount + modelType = scalableMatrixWithTieredPricing.modelType + name = scalableMatrixWithTieredPricing.name + planPhaseOrder = scalableMatrixWithTieredPricing.planPhaseOrder + priceType = scalableMatrixWithTieredPricing.priceType + replacesPriceId = scalableMatrixWithTieredPricing.replacesPriceId + scalableMatrixWithTieredPricingConfig = + scalableMatrixWithTieredPricing.scalableMatrixWithTieredPricingConfig + dimensionalPriceConfiguration = + scalableMatrixWithTieredPricing.dimensionalPriceConfiguration + additionalProperties = + scalableMatrixWithTieredPricing.additionalProperties.toMutableMap() + } fun id(id: String) = id(JsonField.of(id)) @@ -46723,6 +74423,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -46734,6 +74447,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -46975,20 +74716,6 @@ private constructor( this.fixedPriceQuantity = fixedPriceQuantity } - fun groupedTieredPackageConfig(groupedTieredPackageConfig: GroupedTieredPackageConfig) = - groupedTieredPackageConfig(JsonField.of(groupedTieredPackageConfig)) - - /** - * Sets [Builder.groupedTieredPackageConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.groupedTieredPackageConfig] with a well-typed - * [GroupedTieredPackageConfig] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun groupedTieredPackageConfig( - groupedTieredPackageConfig: JsonField - ) = apply { this.groupedTieredPackageConfig = groupedTieredPackageConfig } - fun invoicingCycleConfiguration( invoicingCycleConfiguration: BillingCycleConfiguration? ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) @@ -47004,6 +74731,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -47095,7 +74826,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("grouped_tiered_package") + * JsonValue.from("scalable_matrix_with_tiered_pricing") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -47164,6 +74895,28 @@ private constructor( this.replacesPriceId = replacesPriceId } + /** Configuration for scalable_matrix_with_tiered_pricing pricing */ + fun scalableMatrixWithTieredPricingConfig( + scalableMatrixWithTieredPricingConfig: ScalableMatrixWithTieredPricingConfig + ) = + scalableMatrixWithTieredPricingConfig( + JsonField.of(scalableMatrixWithTieredPricingConfig) + ) + + /** + * Sets [Builder.scalableMatrixWithTieredPricingConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.scalableMatrixWithTieredPricingConfig] with a + * well-typed [ScalableMatrixWithTieredPricingConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun scalableMatrixWithTieredPricingConfig( + scalableMatrixWithTieredPricingConfig: + JsonField + ) = apply { + this.scalableMatrixWithTieredPricingConfig = scalableMatrixWithTieredPricingConfig + } + fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -47199,7 +74952,7 @@ private constructor( } /** - * Returns an immutable instance of [GroupedTieredPackage]. + * Returns an immutable instance of [ScalableMatrixWithTieredPricing]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -47208,7 +74961,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -47217,7 +74972,6 @@ private constructor( * .discount() * .externalPriceId() * .fixedPriceQuantity() - * .groupedTieredPackageConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -47229,16 +74983,21 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() + * .scalableMatrixWithTieredPricingConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): GroupedTieredPackage = - GroupedTieredPackage( + fun build(): ScalableMatrixWithTieredPricing = + ScalableMatrixWithTieredPricing( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -47247,7 +75006,6 @@ private constructor( checkRequired("discount", discount), checkRequired("externalPriceId", externalPriceId), checkRequired("fixedPriceQuantity", fixedPriceQuantity), - checkRequired("groupedTieredPackageConfig", groupedTieredPackageConfig), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), checkRequired("maximum", maximum), @@ -47260,6 +75018,10 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), + checkRequired( + "scalableMatrixWithTieredPricingConfig", + scalableMatrixWithTieredPricingConfig, + ), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -47267,7 +75029,7 @@ private constructor( private var validated: Boolean = false - fun validate(): GroupedTieredPackage = apply { + fun validate(): ScalableMatrixWithTieredPricing = apply { if (validated) { return@apply } @@ -47275,7 +75037,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -47284,7 +75048,6 @@ private constructor( discount()?.validate() externalPriceId() fixedPriceQuantity() - groupedTieredPackageConfig().validate() invoicingCycleConfiguration()?.validate() item().validate() maximum()?.validate() @@ -47293,59 +75056,193 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("grouped_tiered_package")) { + if (it != JsonValue.from("scalable_matrix_with_tiered_pricing")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } - } - name() - planPhaseOrder() - priceType().validate() - replacesPriceId() - dimensionalPriceConfiguration()?.validate() - validated = true - } + } + name() + planPhaseOrder() + priceType().validate() + replacesPriceId() + scalableMatrixWithTieredPricingConfig().validate() + dimensionalPriceConfiguration()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (id.asKnown() == null) 0 else 1) + + (billableMetric.asKnown()?.validity() ?: 0) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (createdAt.asKnown() == null) 0 else 1) + + (creditAllocation.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (discount.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (item.asKnown()?.validity() ?: 0) + + (maximum.asKnown()?.validity() ?: 0) + + (if (maximumAmount.asKnown() == null) 0 else 1) + + (metadata.asKnown()?.validity() ?: 0) + + (minimum.asKnown()?.validity() ?: 0) + + (if (minimumAmount.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("scalable_matrix_with_tiered_pricing")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + (priceType.asKnown()?.validity() ?: 0) + + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (scalableMatrixWithTieredPricingConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + return other is BillingMode && value == other.value } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (id.asKnown() == null) 0 else 1) + - (billableMetric.asKnown()?.validity() ?: 0) + - (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (cadence.asKnown()?.validity() ?: 0) + - (if (conversionRate.asKnown() == null) 0 else 1) + - (conversionRateConfig.asKnown()?.validity() ?: 0) + - (if (createdAt.asKnown() == null) 0 else 1) + - (creditAllocation.asKnown()?.validity() ?: 0) + - (if (currency.asKnown() == null) 0 else 1) + - (discount.asKnown()?.validity() ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (groupedTieredPackageConfig.asKnown()?.validity() ?: 0) + - (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + - (item.asKnown()?.validity() ?: 0) + - (maximum.asKnown()?.validity() ?: 0) + - (if (maximumAmount.asKnown() == null) 0 else 1) + - (metadata.asKnown()?.validity() ?: 0) + - (minimum.asKnown()?.validity() ?: 0) + - (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("grouped_tiered_package")) 1 else 0 } + - (if (name.asKnown() == null) 0 else 1) + - (if (planPhaseOrder.asKnown() == null) 0 else 1) + - (priceType.asKnown()?.validity() ?: 0) + - (if (replacesPriceId.asKnown() == null) 0 else 1) + - (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -47491,7 +75388,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -47499,54 +75396,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun isUnit(): Boolean = unit != null + fun toBuilder() = Builder().from(this) - fun isTiered(): Boolean = tiered != null + companion object { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -47565,115 +75632,316 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + private var validated: Boolean = false - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } - fun visitUnit(unit: UnitConversionRateConfig): T + override fun hashCode() = value.hashCode() - fun visitTiered(tiered: TieredConversionRateConfig): T + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + else -> Value._UNKNOWN + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } - class GroupedTieredPackageConfig + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and the + * entire metadata mapping can be cleared by setting `metadata` to `null`. + */ + class Metadata @JsonCreator private constructor( @com.fasterxml.jackson.annotation.JsonValue @@ -47688,21 +75956,17 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of - * [GroupedTieredPackageConfig]. - */ + /** Returns a mutable builder for constructing an instance of [Metadata]. */ fun builder() = Builder() } - /** A builder for [GroupedTieredPackageConfig]. */ + /** A builder for [Metadata]. */ class Builder internal constructor() { private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(groupedTieredPackageConfig: GroupedTieredPackageConfig) = apply { - additionalProperties = - groupedTieredPackageConfig.additionalProperties.toMutableMap() + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() } fun additionalProperties(additionalProperties: Map) = apply { @@ -47728,17 +75992,16 @@ private constructor( } /** - * Returns an immutable instance of [GroupedTieredPackageConfig]. + * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): GroupedTieredPackageConfig = - GroupedTieredPackageConfig(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false - fun validate(): GroupedTieredPackageConfig = apply { + fun validate(): Metadata = apply { if (validated) { return@apply } @@ -47768,50 +76031,386 @@ private constructor( return true } - return /* spotless:off */ other is GroupedTieredPackageConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode - override fun toString() = - "GroupedTieredPackageConfig{additionalProperties=$additionalProperties}" + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } - /** - * User specified key-value pairs for the resource. If not present, this defaults to an - * empty dictionary. Individual keys can be removed by setting the value to `null`, and the - * entire metadata mapping can be cleared by setting `metadata` to `null`. - */ - class Metadata - @JsonCreator + class PriceType @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 { + + val USAGE_PRICE = of("usage_price") + + val FIXED_PRICE = of("fixed_price") + + val COMPOSITE_PRICE = of("composite_price") + + fun of(value: String) = PriceType(JsonField.of(value)) + } + + /** An enum containing [PriceType]'s known values. */ + enum class Known { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + } + + /** + * An enum containing [PriceType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [PriceType] 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 { + USAGE_PRICE, + FIXED_PRICE, + COMPOSITE_PRICE, + /** + * An enum member indicating that [PriceType] 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) { + USAGE_PRICE -> Value.USAGE_PRICE + FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USAGE_PRICE -> Known.USAGE_PRICE + FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE + else -> throw OrbInvalidDataException("Unknown PriceType: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): PriceType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 PriceType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for scalable_matrix_with_tiered_pricing pricing */ + class ScalableMatrixWithTieredPricingConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val firstDimension: JsonField, + private val matrixScalingFactors: JsonField>, + private val tiers: JsonField>, + private val secondDimension: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("first_dimension") + @ExcludeMissing + firstDimension: JsonField = JsonMissing.of(), + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + matrixScalingFactors: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + @JsonProperty("second_dimension") + @ExcludeMissing + secondDimension: JsonField = JsonMissing.of(), + ) : this(firstDimension, matrixScalingFactors, tiers, secondDimension, mutableMapOf()) + + /** + * Used for the scalable matrix first dimension + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun firstDimension(): String = firstDimension.getRequired("first_dimension") + + /** + * Apply a scaling factor to each dimension + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun matrixScalingFactors(): List = + matrixScalingFactors.getRequired("matrix_scaling_factors") + + /** + * Tier pricing structure + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Used for the scalable matrix second dimension (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun secondDimension(): String? = secondDimension.getNullable("second_dimension") + + /** + * Returns the raw JSON value of [firstDimension]. + * + * Unlike [firstDimension], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("first_dimension") + @ExcludeMissing + fun _firstDimension(): JsonField = firstDimension + + /** + * Returns the raw JSON value of [matrixScalingFactors]. + * + * Unlike [matrixScalingFactors], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("matrix_scaling_factors") + @ExcludeMissing + fun _matrixScalingFactors(): JsonField> = matrixScalingFactors + + /** + * 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 + + /** + * Returns the raw JSON value of [secondDimension]. + * + * Unlike [secondDimension], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("second_dimension") + @ExcludeMissing + fun _secondDimension(): JsonField = secondDimension + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) companion object { - /** Returns a mutable builder for constructing an instance of [Metadata]. */ + /** + * Returns a mutable builder for constructing an instance of + * [ScalableMatrixWithTieredPricingConfig]. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .tiers() + * ``` + */ fun builder() = Builder() } - /** A builder for [Metadata]. */ + /** A builder for [ScalableMatrixWithTieredPricingConfig]. */ class Builder internal constructor() { + private var firstDimension: JsonField? = null + private var matrixScalingFactors: JsonField>? = + null + private var tiers: JsonField>? = null + private var secondDimension: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.additionalProperties.toMutableMap() + internal fun from( + scalableMatrixWithTieredPricingConfig: ScalableMatrixWithTieredPricingConfig + ) = apply { + firstDimension = scalableMatrixWithTieredPricingConfig.firstDimension + matrixScalingFactors = + scalableMatrixWithTieredPricingConfig.matrixScalingFactors.map { + it.toMutableList() + } + tiers = scalableMatrixWithTieredPricingConfig.tiers.map { it.toMutableList() } + secondDimension = scalableMatrixWithTieredPricingConfig.secondDimension + additionalProperties = + scalableMatrixWithTieredPricingConfig.additionalProperties.toMutableMap() + } + + /** Used for the scalable matrix first dimension */ + fun firstDimension(firstDimension: String) = + firstDimension(JsonField.of(firstDimension)) + + /** + * Sets [Builder.firstDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimension] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun firstDimension(firstDimension: JsonField) = apply { + this.firstDimension = firstDimension + } + + /** Apply a scaling factor to each dimension */ + fun matrixScalingFactors(matrixScalingFactors: List) = + matrixScalingFactors(JsonField.of(matrixScalingFactors)) + + /** + * Sets [Builder.matrixScalingFactors] to an arbitrary JSON value. + * + * You should usually call [Builder.matrixScalingFactors] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun matrixScalingFactors( + matrixScalingFactors: JsonField> + ) = apply { + this.matrixScalingFactors = matrixScalingFactors.map { it.toMutableList() } + } + + /** + * Adds a single [MatrixScalingFactor] to [matrixScalingFactors]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMatrixScalingFactor(matrixScalingFactor: MatrixScalingFactor) = apply { + matrixScalingFactors = + (matrixScalingFactors ?: JsonField.of(mutableListOf())).also { + checkKnown("matrixScalingFactors", it).add(matrixScalingFactor) + } + } + + /** Tier pricing structure */ + 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) + } + } + + /** Used for the scalable matrix second dimension (optional) */ + fun secondDimension(secondDimension: String?) = + secondDimension(JsonField.ofNullable(secondDimension)) + + /** + * Sets [Builder.secondDimension] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimension] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun secondDimension(secondDimension: JsonField) = apply { + this.secondDimension = secondDimension } fun additionalProperties(additionalProperties: Map) = apply { @@ -47837,20 +76436,42 @@ private constructor( } /** - * Returns an immutable instance of [Metadata]. + * Returns an immutable instance of [ScalableMatrixWithTieredPricingConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimension() + * .matrixScalingFactors() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): ScalableMatrixWithTieredPricingConfig = + ScalableMatrixWithTieredPricingConfig( + checkRequired("firstDimension", firstDimension), + checkRequired("matrixScalingFactors", matrixScalingFactors).map { + it.toImmutable() + }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + secondDimension, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): Metadata = apply { + fun validate(): ScalableMatrixWithTieredPricingConfig = apply { if (validated) { return@apply } + firstDimension() + matrixScalingFactors().forEach { it.validate() } + tiers().forEach { it.validate() } + secondDimension() validated = true } @@ -47869,152 +76490,529 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (firstDimension.asKnown() == null) 0 else 1) + + (matrixScalingFactors.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (secondDimension.asKnown() == null) 0 else 1) + + /** Configuration for a single matrix scaling factor */ + class MatrixScalingFactor + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val firstDimensionValue: JsonField, + private val scalingFactor: JsonField, + private val secondDimensionValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("first_dimension_value") + @ExcludeMissing + firstDimensionValue: JsonField = JsonMissing.of(), + @JsonProperty("scaling_factor") + @ExcludeMissing + scalingFactor: JsonField = JsonMissing.of(), + @JsonProperty("second_dimension_value") + @ExcludeMissing + secondDimensionValue: JsonField = JsonMissing.of(), + ) : this(firstDimensionValue, scalingFactor, secondDimensionValue, mutableMapOf()) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** + * First dimension value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun firstDimensionValue(): String = + firstDimensionValue.getRequired("first_dimension_value") + + /** + * Scaling factor + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun scalingFactor(): String = scalingFactor.getRequired("scaling_factor") + + /** + * Second dimension value (optional) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun secondDimensionValue(): String? = + secondDimensionValue.getNullable("second_dimension_value") + + /** + * Returns the raw JSON value of [firstDimensionValue]. + * + * Unlike [firstDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("first_dimension_value") + @ExcludeMissing + fun _firstDimensionValue(): JsonField = firstDimensionValue + + /** + * Returns the raw JSON value of [scalingFactor]. + * + * Unlike [scalingFactor], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("scaling_factor") + @ExcludeMissing + fun _scalingFactor(): JsonField = scalingFactor + + /** + * Returns the raw JSON value of [secondDimensionValue]. + * + * Unlike [secondDimensionValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("second_dimension_value") + @ExcludeMissing + fun _secondDimensionValue(): JsonField = secondDimensionValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + fun toBuilder() = Builder().from(this) - override fun hashCode(): Int = hashCode + companion object { - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } + /** + * Returns a mutable builder for constructing an instance of + * [MatrixScalingFactor]. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + */ + fun builder() = Builder() + } - class PriceType @JsonCreator private constructor(private val value: JsonField) : - Enum { + /** A builder for [MatrixScalingFactor]. */ + class Builder internal constructor() { - /** - * 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 var firstDimensionValue: JsonField? = null + private var scalingFactor: JsonField? = null + private var secondDimensionValue: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - companion object { + internal fun from(matrixScalingFactor: MatrixScalingFactor) = apply { + firstDimensionValue = matrixScalingFactor.firstDimensionValue + scalingFactor = matrixScalingFactor.scalingFactor + secondDimensionValue = matrixScalingFactor.secondDimensionValue + additionalProperties = + matrixScalingFactor.additionalProperties.toMutableMap() + } - val USAGE_PRICE = of("usage_price") + /** First dimension value */ + fun firstDimensionValue(firstDimensionValue: String) = + firstDimensionValue(JsonField.of(firstDimensionValue)) + + /** + * Sets [Builder.firstDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.firstDimensionValue] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun firstDimensionValue(firstDimensionValue: JsonField) = apply { + this.firstDimensionValue = firstDimensionValue + } - val FIXED_PRICE = of("fixed_price") + /** Scaling factor */ + fun scalingFactor(scalingFactor: String) = + scalingFactor(JsonField.of(scalingFactor)) + + /** + * Sets [Builder.scalingFactor] to an arbitrary JSON value. + * + * You should usually call [Builder.scalingFactor] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun scalingFactor(scalingFactor: JsonField) = apply { + this.scalingFactor = scalingFactor + } - fun of(value: String) = PriceType(JsonField.of(value)) - } + /** Second dimension value (optional) */ + fun secondDimensionValue(secondDimensionValue: String?) = + secondDimensionValue(JsonField.ofNullable(secondDimensionValue)) + + /** + * Sets [Builder.secondDimensionValue] to an arbitrary JSON value. + * + * You should usually call [Builder.secondDimensionValue] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun secondDimensionValue(secondDimensionValue: JsonField) = apply { + this.secondDimensionValue = secondDimensionValue + } - /** An enum containing [PriceType]'s known values. */ - enum class Known { - USAGE_PRICE, - FIXED_PRICE, - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [MatrixScalingFactor]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstDimensionValue() + * .scalingFactor() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MatrixScalingFactor = + MatrixScalingFactor( + checkRequired("firstDimensionValue", firstDimensionValue), + checkRequired("scalingFactor", scalingFactor), + secondDimensionValue, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MatrixScalingFactor = apply { + if (validated) { + return@apply + } + + firstDimensionValue() + scalingFactor() + secondDimensionValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** - * An enum containing [PriceType]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [PriceType] 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 { - USAGE_PRICE, - FIXED_PRICE, /** - * An enum member indicating that [PriceType] was instantiated with an unknown - * value. + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. */ - _UNKNOWN, + internal fun validity(): Int = + (if (firstDimensionValue.asKnown() == null) 0 else 1) + + (if (scalingFactor.asKnown() == null) 0 else 1) + + (if (secondDimensionValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MatrixScalingFactor && + firstDimensionValue == other.firstDimensionValue && + scalingFactor == other.scalingFactor && + secondDimensionValue == other.secondDimensionValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + firstDimensionValue, + scalingFactor, + secondDimensionValue, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MatrixScalingFactor{firstDimensionValue=$firstDimensionValue, scalingFactor=$scalingFactor, secondDimensionValue=$secondDimensionValue, additionalProperties=$additionalProperties}" } - /** - * 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) { - USAGE_PRICE -> Value.USAGE_PRICE - FIXED_PRICE -> Value.FIXED_PRICE - else -> Value._UNKNOWN + /** Configuration for a single tier entry with business logic */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Per unit amount + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - /** - * 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 OrbInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - USAGE_PRICE -> Known.USAGE_PRICE - FIXED_PRICE -> Known.FIXED_PRICE - else -> throw OrbInvalidDataException("Unknown PriceType: $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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() } - /** - * 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 OrbInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + /** A builder for [Tier]. */ + class Builder internal constructor() { - private var validated: Boolean = false + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun validate(): PriceType = apply { - if (validated) { - return@apply + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Per unit amount */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true } - known() - validated = true - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is ScalableMatrixWithTieredPricingConfig && + firstDimension == other.firstDimension && + matrixScalingFactors == other.matrixScalingFactors && + tiers == other.tiers && + secondDimension == other.secondDimension && + additionalProperties == other.additionalProperties } - override fun hashCode() = value.hashCode() + private val hashCode: Int by lazy { + Objects.hash( + firstDimension, + matrixScalingFactors, + tiers, + secondDimension, + additionalProperties, + ) + } - override fun toString() = value.toString() + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScalableMatrixWithTieredPricingConfig{firstDimension=$firstDimension, matrixScalingFactors=$matrixScalingFactors, tiers=$tiers, secondDimension=$secondDimension, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -48022,36 +77020,99 @@ private constructor( return true } - return /* spotless:off */ other is GroupedTieredPackage && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && groupedTieredPackageConfig == other.groupedTieredPackageConfig && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ScalableMatrixWithTieredPricing && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + scalableMatrixWithTieredPricingConfig == + other.scalableMatrixWithTieredPricingConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, groupedTieredPackageConfig, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + scalableMatrixWithTieredPricingConfig, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedTieredPackage{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, groupedTieredPackageConfig=$groupedTieredPackageConfig, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "ScalableMatrixWithTieredPricing{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, scalableMatrixWithTieredPricingConfig=$scalableMatrixWithTieredPricingConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class MaxGroupTieredPackage + class CumulativeGroupedBulk + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, private val creditAllocation: JsonField, + private val cumulativeGroupedBulkConfig: JsonField, private val currency: JsonField, private val discount: JsonField, private val externalPriceId: JsonField, private val fixedPriceQuantity: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, - private val maxGroupTieredPackageConfig: JsonField, private val maximum: JsonField, private val maximumAmount: JsonField, private val metadata: JsonField, @@ -48075,7 +77136,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -48088,6 +77155,9 @@ private constructor( @JsonProperty("credit_allocation") @ExcludeMissing creditAllocation: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_bulk_config") + @ExcludeMissing + cumulativeGroupedBulkConfig: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @@ -48104,9 +77174,6 @@ private constructor( @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @JsonProperty("item") @ExcludeMissing item: JsonField = JsonMissing.of(), - @JsonProperty("max_group_tiered_package_config") - @ExcludeMissing - maxGroupTieredPackageConfig: JsonField = JsonMissing.of(), @JsonProperty("maximum") @ExcludeMissing maximum: JsonField = JsonMissing.of(), @JsonProperty("maximum_amount") @ExcludeMissing @@ -48137,18 +77204,20 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, creditAllocation, + cumulativeGroupedBulkConfig, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, - maxGroupTieredPackageConfig, maximum, maximumAmount, metadata, @@ -48182,12 +77251,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -48213,6 +77295,15 @@ private constructor( */ fun creditAllocation(): Allocation? = creditAllocation.getNullable("credit_allocation") + /** + * Configuration for cumulative_grouped_bulk pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun cumulativeGroupedBulkConfig(): CumulativeGroupedBulkConfig = + cumulativeGroupedBulkConfig.getRequired("cumulative_grouped_bulk_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -48245,18 +77336,14 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun item(): ItemSlim = item.getRequired("item") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun maxGroupTieredPackageConfig(): MaxGroupTieredPackageConfig = - maxGroupTieredPackageConfig.getRequired("max_group_tiered_package_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -48294,9 +77381,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("max_group_tiered_package") + * JsonValue.from("cumulative_grouped_bulk") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -48366,6 +77455,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -48373,6 +77471,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -48412,6 +77520,17 @@ private constructor( @ExcludeMissing fun _creditAllocation(): JsonField = creditAllocation + /** + * Returns the raw JSON value of [cumulativeGroupedBulkConfig]. + * + * Unlike [cumulativeGroupedBulkConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("cumulative_grouped_bulk_config") + @ExcludeMissing + fun _cumulativeGroupedBulkConfig(): JsonField = + cumulativeGroupedBulkConfig + /** * Returns the raw JSON value of [currency]. * @@ -48467,17 +77586,6 @@ private constructor( */ @JsonProperty("item") @ExcludeMissing fun _item(): JsonField = item - /** - * Returns the raw JSON value of [maxGroupTieredPackageConfig]. - * - * Unlike [maxGroupTieredPackageConfig], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("max_group_tiered_package_config") - @ExcludeMissing - fun _maxGroupTieredPackageConfig(): JsonField = - maxGroupTieredPackageConfig - /** * Returns the raw JSON value of [maximum]. * @@ -48589,25 +77697,27 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [MaxGroupTieredPackage]. + * Returns a mutable builder for constructing an instance of [CumulativeGroupedBulk]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() * .creditAllocation() + * .cumulativeGroupedBulkConfig() * .currency() * .discount() * .externalPriceId() * .fixedPriceQuantity() * .invoicingCycleConfiguration() * .item() - * .maxGroupTieredPackageConfig() * .maximum() * .maximumAmount() * .metadata() @@ -48622,30 +77732,32 @@ private constructor( fun builder() = Builder() } - /** A builder for [MaxGroupTieredPackage]. */ + /** A builder for [CumulativeGroupedBulk]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null private var creditAllocation: JsonField? = null + private var cumulativeGroupedBulkConfig: JsonField? = null private var currency: JsonField? = null private var discount: JsonField? = null private var externalPriceId: JsonField? = null private var fixedPriceQuantity: JsonField? = null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null - private var maxGroupTieredPackageConfig: JsonField? = null private var maximum: JsonField? = null private var maximumAmount: JsonField? = null private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("max_group_tiered_package") + private var modelType: JsonValue = JsonValue.from("cumulative_grouped_bulk") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null @@ -48654,34 +77766,37 @@ private constructor( JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(maxGroupTieredPackage: MaxGroupTieredPackage) = apply { - id = maxGroupTieredPackage.id - billableMetric = maxGroupTieredPackage.billableMetric - billingCycleConfiguration = maxGroupTieredPackage.billingCycleConfiguration - cadence = maxGroupTieredPackage.cadence - conversionRate = maxGroupTieredPackage.conversionRate - conversionRateConfig = maxGroupTieredPackage.conversionRateConfig - createdAt = maxGroupTieredPackage.createdAt - creditAllocation = maxGroupTieredPackage.creditAllocation - currency = maxGroupTieredPackage.currency - discount = maxGroupTieredPackage.discount - externalPriceId = maxGroupTieredPackage.externalPriceId - fixedPriceQuantity = maxGroupTieredPackage.fixedPriceQuantity - invoicingCycleConfiguration = maxGroupTieredPackage.invoicingCycleConfiguration - item = maxGroupTieredPackage.item - maxGroupTieredPackageConfig = maxGroupTieredPackage.maxGroupTieredPackageConfig - maximum = maxGroupTieredPackage.maximum - maximumAmount = maxGroupTieredPackage.maximumAmount - metadata = maxGroupTieredPackage.metadata - minimum = maxGroupTieredPackage.minimum - minimumAmount = maxGroupTieredPackage.minimumAmount - modelType = maxGroupTieredPackage.modelType - name = maxGroupTieredPackage.name - planPhaseOrder = maxGroupTieredPackage.planPhaseOrder - priceType = maxGroupTieredPackage.priceType - replacesPriceId = maxGroupTieredPackage.replacesPriceId - dimensionalPriceConfiguration = maxGroupTieredPackage.dimensionalPriceConfiguration - additionalProperties = maxGroupTieredPackage.additionalProperties.toMutableMap() + internal fun from(cumulativeGroupedBulk: CumulativeGroupedBulk) = apply { + id = cumulativeGroupedBulk.id + billableMetric = cumulativeGroupedBulk.billableMetric + billingCycleConfiguration = cumulativeGroupedBulk.billingCycleConfiguration + billingMode = cumulativeGroupedBulk.billingMode + cadence = cumulativeGroupedBulk.cadence + compositePriceFilters = + cumulativeGroupedBulk.compositePriceFilters.map { it.toMutableList() } + conversionRate = cumulativeGroupedBulk.conversionRate + conversionRateConfig = cumulativeGroupedBulk.conversionRateConfig + createdAt = cumulativeGroupedBulk.createdAt + creditAllocation = cumulativeGroupedBulk.creditAllocation + cumulativeGroupedBulkConfig = cumulativeGroupedBulk.cumulativeGroupedBulkConfig + currency = cumulativeGroupedBulk.currency + discount = cumulativeGroupedBulk.discount + externalPriceId = cumulativeGroupedBulk.externalPriceId + fixedPriceQuantity = cumulativeGroupedBulk.fixedPriceQuantity + invoicingCycleConfiguration = cumulativeGroupedBulk.invoicingCycleConfiguration + item = cumulativeGroupedBulk.item + maximum = cumulativeGroupedBulk.maximum + maximumAmount = cumulativeGroupedBulk.maximumAmount + metadata = cumulativeGroupedBulk.metadata + minimum = cumulativeGroupedBulk.minimum + minimumAmount = cumulativeGroupedBulk.minimumAmount + modelType = cumulativeGroupedBulk.modelType + name = cumulativeGroupedBulk.name + planPhaseOrder = cumulativeGroupedBulk.planPhaseOrder + priceType = cumulativeGroupedBulk.priceType + replacesPriceId = cumulativeGroupedBulk.replacesPriceId + dimensionalPriceConfiguration = cumulativeGroupedBulk.dimensionalPriceConfiguration + additionalProperties = cumulativeGroupedBulk.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -48723,6 +77838,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -48734,6 +77862,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -48844,6 +78000,22 @@ private constructor( this.creditAllocation = creditAllocation } + /** Configuration for cumulative_grouped_bulk pricing */ + fun cumulativeGroupedBulkConfig( + cumulativeGroupedBulkConfig: CumulativeGroupedBulkConfig + ) = cumulativeGroupedBulkConfig(JsonField.of(cumulativeGroupedBulkConfig)) + + /** + * Sets [Builder.cumulativeGroupedBulkConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedBulkConfig] with a well-typed + * [CumulativeGroupedBulkConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun cumulativeGroupedBulkConfig( + cumulativeGroupedBulkConfig: JsonField + ) = apply { this.cumulativeGroupedBulkConfig = cumulativeGroupedBulkConfig } + fun currency(currency: String) = currency(JsonField.of(currency)) /** @@ -48990,6 +78162,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -49001,21 +78177,6 @@ private constructor( */ fun item(item: JsonField) = apply { this.item = item } - fun maxGroupTieredPackageConfig( - maxGroupTieredPackageConfig: MaxGroupTieredPackageConfig - ) = maxGroupTieredPackageConfig(JsonField.of(maxGroupTieredPackageConfig)) - - /** - * Sets [Builder.maxGroupTieredPackageConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.maxGroupTieredPackageConfig] with a well-typed - * [MaxGroupTieredPackageConfig] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun maxGroupTieredPackageConfig( - maxGroupTieredPackageConfig: JsonField - ) = apply { this.maxGroupTieredPackageConfig = maxGroupTieredPackageConfig } - @Deprecated("deprecated") fun maximum(maximum: Maximum?) = maximum(JsonField.ofNullable(maximum)) @@ -49096,7 +78257,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("max_group_tiered_package") + * JsonValue.from("cumulative_grouped_bulk") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -49200,7 +78361,7 @@ private constructor( } /** - * Returns an immutable instance of [MaxGroupTieredPackage]. + * Returns an immutable instance of [CumulativeGroupedBulk]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -49209,18 +78370,20 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() * .creditAllocation() + * .cumulativeGroupedBulkConfig() * .currency() * .discount() * .externalPriceId() * .fixedPriceQuantity() * .invoicingCycleConfiguration() * .item() - * .maxGroupTieredPackageConfig() * .maximum() * .maximumAmount() * .metadata() @@ -49234,23 +78397,27 @@ private constructor( * * @throws IllegalStateException if any required field is unset. */ - fun build(): MaxGroupTieredPackage = - MaxGroupTieredPackage( + fun build(): CumulativeGroupedBulk = + CumulativeGroupedBulk( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), checkRequired("creditAllocation", creditAllocation), + checkRequired("cumulativeGroupedBulkConfig", cumulativeGroupedBulkConfig), checkRequired("currency", currency), checkRequired("discount", discount), checkRequired("externalPriceId", externalPriceId), checkRequired("fixedPriceQuantity", fixedPriceQuantity), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), - checkRequired("maxGroupTieredPackageConfig", maxGroupTieredPackageConfig), checkRequired("maximum", maximum), checkRequired("maximumAmount", maximumAmount), checkRequired("metadata", metadata), @@ -49268,7 +78435,7 @@ private constructor( private var validated: Boolean = false - fun validate(): MaxGroupTieredPackage = apply { + fun validate(): CumulativeGroupedBulk = apply { if (validated) { return@apply } @@ -49276,25 +78443,27 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() creditAllocation()?.validate() + cumulativeGroupedBulkConfig().validate() currency() discount()?.validate() externalPriceId() fixedPriceQuantity() invoicingCycleConfiguration()?.validate() item().validate() - maxGroupTieredPackageConfig().validate() maximum()?.validate() maximumAmount() metadata().validate() minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("max_group_tiered_package")) { + if (it != JsonValue.from("cumulative_grouped_bulk")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -49324,30 +78493,161 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + (creditAllocation.asKnown()?.validity() ?: 0) + + (cumulativeGroupedBulkConfig.asKnown()?.validity() ?: 0) + (if (currency.asKnown() == null) 0 else 1) + (discount.asKnown()?.validity() ?: 0) + (if (externalPriceId.asKnown() == null) 0 else 1) + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + - (maxGroupTieredPackageConfig.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + (if (maximumAmount.asKnown() == null) 0 else 1) + (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("max_group_tiered_package")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("cumulative_grouped_bulk")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -49492,7 +78792,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -49500,54 +78800,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun tiered(): TieredConversionRateConfig? = tiered + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values - fun isUnit(): Boolean = unit != null + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun isTiered(): Boolean = tiered != null + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -49566,124 +79036,372 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $value") + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } - fun visitUnit(unit: UnitConversionRateConfig): T + override fun hashCode() = value.hashCode() - fun visitTiered(tiered: TieredConversionRateConfig): T + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + else -> Value._UNKNOWN + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } - class MaxGroupTieredPackageConfig - @JsonCreator + /** Configuration for cumulative_grouped_bulk pricing */ + class CumulativeGroupedBulkConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val dimensionValues: JsonField>, + private val group: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("dimension_values") + @ExcludeMissing + dimensionValues: JsonField> = JsonMissing.of(), + @JsonProperty("group") @ExcludeMissing group: JsonField = JsonMissing.of(), + ) : this(dimensionValues, group, mutableMapOf()) + + /** + * Each tier lower bound must have the same group of values. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun dimensionValues(): List = + dimensionValues.getRequired("dimension_values") + + /** + * Grouping key name + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun group(): String = group.getRequired("group") + + /** + * Returns the raw JSON value of [dimensionValues]. + * + * Unlike [dimensionValues], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("dimension_values") + @ExcludeMissing + fun _dimensionValues(): JsonField> = dimensionValues + + /** + * Returns the raw JSON value of [group]. + * + * Unlike [group], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("group") @ExcludeMissing fun _group(): JsonField = group + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) @@ -49691,22 +79409,72 @@ private constructor( /** * Returns a mutable builder for constructing an instance of - * [MaxGroupTieredPackageConfig]. + * [CumulativeGroupedBulkConfig]. + * + * The following fields are required: + * ```kotlin + * .dimensionValues() + * .group() + * ``` */ fun builder() = Builder() } - /** A builder for [MaxGroupTieredPackageConfig]. */ + /** A builder for [CumulativeGroupedBulkConfig]. */ class Builder internal constructor() { + private var dimensionValues: JsonField>? = null + private var group: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(maxGroupTieredPackageConfig: MaxGroupTieredPackageConfig) = + internal fun from(cumulativeGroupedBulkConfig: CumulativeGroupedBulkConfig) = apply { + dimensionValues = + cumulativeGroupedBulkConfig.dimensionValues.map { it.toMutableList() } + group = cumulativeGroupedBulkConfig.group additionalProperties = - maxGroupTieredPackageConfig.additionalProperties.toMutableMap() + cumulativeGroupedBulkConfig.additionalProperties.toMutableMap() } + /** Each tier lower bound must have the same group of values. */ + fun dimensionValues(dimensionValues: List) = + dimensionValues(JsonField.of(dimensionValues)) + + /** + * Sets [Builder.dimensionValues] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionValues] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun dimensionValues(dimensionValues: JsonField>) = apply { + this.dimensionValues = dimensionValues.map { it.toMutableList() } + } + + /** + * Adds a single [DimensionValue] to [dimensionValues]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDimensionValue(dimensionValue: DimensionValue) = apply { + dimensionValues = + (dimensionValues ?: JsonField.of(mutableListOf())).also { + checkKnown("dimensionValues", it).add(dimensionValue) + } + } + + /** Grouping key name */ + fun group(group: String) = group(JsonField.of(group)) + + /** + * Sets [Builder.group] to an arbitrary JSON value. + * + * You should usually call [Builder.group] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun group(group: JsonField) = apply { this.group = group } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -49730,21 +79498,35 @@ private constructor( } /** - * Returns an immutable instance of [MaxGroupTieredPackageConfig]. + * Returns an immutable instance of [CumulativeGroupedBulkConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .dimensionValues() + * .group() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): MaxGroupTieredPackageConfig = - MaxGroupTieredPackageConfig(additionalProperties.toImmutable()) + fun build(): CumulativeGroupedBulkConfig = + CumulativeGroupedBulkConfig( + checkRequired("dimensionValues", dimensionValues).map { it.toImmutable() }, + checkRequired("group", group), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): MaxGroupTieredPackageConfig = apply { + fun validate(): CumulativeGroupedBulkConfig = apply { if (validated) { return@apply } + dimensionValues().forEach { it.validate() } + group() validated = true } @@ -49763,24 +79545,292 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (dimensionValues.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (group.asKnown() == null) 0 else 1) + + /** Configuration for a dimension value entry */ + class DimensionValue + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(groupingKey, tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Grouping key value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * Tier lower bound + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tierLowerBound(): String = tierLowerBound.getRequired("tier_lower_bound") + + /** + * Unit amount for this combination + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 [DimensionValue]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [DimensionValue]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(dimensionValue: DimensionValue) = apply { + groupingKey = dimensionValue.groupingKey + tierLowerBound = dimensionValue.tierLowerBound + unitAmount = dimensionValue.unitAmount + additionalProperties = dimensionValue.additionalProperties.toMutableMap() + } + + /** Grouping key value */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** Tier lower bound */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Unit amount for this combination */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [DimensionValue]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DimensionValue = + DimensionValue( + checkRequired("groupingKey", groupingKey), + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): DimensionValue = apply { + if (validated) { + return@apply + } + + groupingKey() + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DimensionValue && + groupingKey == other.groupingKey && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(groupingKey, tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DimensionValue{groupingKey=$groupingKey, tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is MaxGroupTieredPackageConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CumulativeGroupedBulkConfig && + dimensionValues == other.dimensionValues && + group == other.group && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(dimensionValues, group, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "MaxGroupTieredPackageConfig{additionalProperties=$additionalProperties}" + "CumulativeGroupedBulkConfig{dimensionValues=$dimensionValues, group=$group, additionalProperties=$additionalProperties}" } /** @@ -49878,12 +79928,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -49909,6 +79957,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -49916,6 +79966,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -49930,6 +79981,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -49948,6 +80000,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -49964,6 +80017,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -50011,7 +80065,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -50024,29 +80078,92 @@ private constructor( return true } - return /* spotless:off */ other is MaxGroupTieredPackage && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maxGroupTieredPackageConfig == other.maxGroupTieredPackageConfig && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CumulativeGroupedBulk && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + cumulativeGroupedBulkConfig == other.cumulativeGroupedBulkConfig && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maxGroupTieredPackageConfig, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + cumulativeGroupedBulkConfig, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "MaxGroupTieredPackage{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maxGroupTieredPackageConfig=$maxGroupTieredPackageConfig, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "CumulativeGroupedBulk{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, cumulativeGroupedBulkConfig=$cumulativeGroupedBulkConfig, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class ScalableMatrixWithUnitPricing + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, private val creditAllocation: JsonField, + private val cumulativeGroupedAllocationConfig: JsonField, private val currency: JsonField, private val discount: JsonField, private val externalPriceId: JsonField, @@ -50063,8 +80180,6 @@ private constructor( private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, - private val scalableMatrixWithUnitPricingConfig: - JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -50078,7 +80193,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -50091,6 +80212,10 @@ private constructor( @JsonProperty("credit_allocation") @ExcludeMissing creditAllocation: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: JsonField = + JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @@ -50129,10 +80254,6 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("scalable_matrix_with_unit_pricing_config") - @ExcludeMissing - scalableMatrixWithUnitPricingConfig: JsonField = - JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -50141,11 +80262,14 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, creditAllocation, + cumulativeGroupedAllocationConfig, currency, discount, externalPriceId, @@ -50162,7 +80286,6 @@ private constructor( planPhaseOrder, priceType, replacesPriceId, - scalableMatrixWithUnitPricingConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -50186,12 +80309,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -50217,6 +80353,15 @@ private constructor( */ fun creditAllocation(): Allocation? = creditAllocation.getNullable("credit_allocation") + /** + * Configuration for cumulative_grouped_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired("cumulative_grouped_allocation_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -50249,6 +80394,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -50291,9 +80439,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("scalable_matrix_with_unit_pricing") + * JsonValue.from("cumulative_grouped_allocation") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -50328,15 +80478,6 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun scalableMatrixWithUnitPricingConfig(): ScalableMatrixWithUnitPricingConfig = - scalableMatrixWithUnitPricingConfig.getRequired( - "scalable_matrix_with_unit_pricing_config" - ) - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -50372,6 +80513,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -50379,6 +80529,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -50418,6 +80578,17 @@ private constructor( @ExcludeMissing fun _creditAllocation(): JsonField = creditAllocation + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): JsonField = + cumulativeGroupedAllocationConfig + /** * Returns the raw JSON value of [currency]. * @@ -50558,17 +80729,6 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId - /** - * Returns the raw JSON value of [scalableMatrixWithUnitPricingConfig]. - * - * Unlike [scalableMatrixWithUnitPricingConfig], this method doesn't throw if the JSON field - * has an unexpected type. - */ - @JsonProperty("scalable_matrix_with_unit_pricing_config") - @ExcludeMissing - fun _scalableMatrixWithUnitPricingConfig(): JsonField = - scalableMatrixWithUnitPricingConfig - /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -50596,18 +80756,21 @@ private constructor( /** * Returns a mutable builder for constructing an instance of - * [ScalableMatrixWithUnitPricing]. + * [CumulativeGroupedAllocation]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() * .creditAllocation() + * .cumulativeGroupedAllocationConfig() * .currency() * .discount() * .externalPriceId() @@ -50623,23 +80786,27 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .scalableMatrixWithUnitPricingConfig() * ``` */ fun builder() = Builder() } - /** A builder for [ScalableMatrixWithUnitPricing]. */ + /** A builder for [CumulativeGroupedAllocation]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null private var creditAllocation: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null private var currency: JsonField? = null private var discount: JsonField? = null private var externalPriceId: JsonField? = null @@ -50651,53 +80818,51 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("scalable_matrix_with_unit_pricing") + private var modelType: JsonValue = JsonValue.from("cumulative_grouped_allocation") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null - private var scalableMatrixWithUnitPricingConfig: - JsonField? = - null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(scalableMatrixWithUnitPricing: ScalableMatrixWithUnitPricing) = - apply { - id = scalableMatrixWithUnitPricing.id - billableMetric = scalableMatrixWithUnitPricing.billableMetric - billingCycleConfiguration = - scalableMatrixWithUnitPricing.billingCycleConfiguration - cadence = scalableMatrixWithUnitPricing.cadence - conversionRate = scalableMatrixWithUnitPricing.conversionRate - conversionRateConfig = scalableMatrixWithUnitPricing.conversionRateConfig - createdAt = scalableMatrixWithUnitPricing.createdAt - creditAllocation = scalableMatrixWithUnitPricing.creditAllocation - currency = scalableMatrixWithUnitPricing.currency - discount = scalableMatrixWithUnitPricing.discount - externalPriceId = scalableMatrixWithUnitPricing.externalPriceId - fixedPriceQuantity = scalableMatrixWithUnitPricing.fixedPriceQuantity - invoicingCycleConfiguration = - scalableMatrixWithUnitPricing.invoicingCycleConfiguration - item = scalableMatrixWithUnitPricing.item - maximum = scalableMatrixWithUnitPricing.maximum - maximumAmount = scalableMatrixWithUnitPricing.maximumAmount - metadata = scalableMatrixWithUnitPricing.metadata - minimum = scalableMatrixWithUnitPricing.minimum - minimumAmount = scalableMatrixWithUnitPricing.minimumAmount - modelType = scalableMatrixWithUnitPricing.modelType - name = scalableMatrixWithUnitPricing.name - planPhaseOrder = scalableMatrixWithUnitPricing.planPhaseOrder - priceType = scalableMatrixWithUnitPricing.priceType - replacesPriceId = scalableMatrixWithUnitPricing.replacesPriceId - scalableMatrixWithUnitPricingConfig = - scalableMatrixWithUnitPricing.scalableMatrixWithUnitPricingConfig - dimensionalPriceConfiguration = - scalableMatrixWithUnitPricing.dimensionalPriceConfiguration - additionalProperties = - scalableMatrixWithUnitPricing.additionalProperties.toMutableMap() - } + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = apply { + id = cumulativeGroupedAllocation.id + billableMetric = cumulativeGroupedAllocation.billableMetric + billingCycleConfiguration = cumulativeGroupedAllocation.billingCycleConfiguration + billingMode = cumulativeGroupedAllocation.billingMode + cadence = cumulativeGroupedAllocation.cadence + compositePriceFilters = + cumulativeGroupedAllocation.compositePriceFilters.map { it.toMutableList() } + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + createdAt = cumulativeGroupedAllocation.createdAt + creditAllocation = cumulativeGroupedAllocation.creditAllocation + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + currency = cumulativeGroupedAllocation.currency + discount = cumulativeGroupedAllocation.discount + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + item = cumulativeGroupedAllocation.item + maximum = cumulativeGroupedAllocation.maximum + maximumAmount = cumulativeGroupedAllocation.maximumAmount + metadata = cumulativeGroupedAllocation.metadata + minimum = cumulativeGroupedAllocation.minimum + minimumAmount = cumulativeGroupedAllocation.minimumAmount + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + planPhaseOrder = cumulativeGroupedAllocation.planPhaseOrder + priceType = cumulativeGroupedAllocation.priceType + replacesPriceId = cumulativeGroupedAllocation.replacesPriceId + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } fun id(id: String) = id(JsonField.of(id)) @@ -50738,6 +80903,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -50749,6 +80927,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -50859,6 +81065,22 @@ private constructor( this.creditAllocation = creditAllocation } + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = cumulativeGroupedAllocationConfig(JsonField.of(cumulativeGroupedAllocationConfig)) + + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a well-typed + * [CumulativeGroupedAllocationConfig] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: JsonField + ) = apply { this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig } + fun currency(currency: String) = currency(JsonField.of(currency)) /** @@ -51005,6 +81227,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -51096,7 +81322,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("scalable_matrix_with_unit_pricing") + * JsonValue.from("cumulative_grouped_allocation") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -51165,26 +81391,6 @@ private constructor( this.replacesPriceId = replacesPriceId } - fun scalableMatrixWithUnitPricingConfig( - scalableMatrixWithUnitPricingConfig: ScalableMatrixWithUnitPricingConfig - ) = - scalableMatrixWithUnitPricingConfig( - JsonField.of(scalableMatrixWithUnitPricingConfig) - ) - - /** - * Sets [Builder.scalableMatrixWithUnitPricingConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.scalableMatrixWithUnitPricingConfig] with a - * well-typed [ScalableMatrixWithUnitPricingConfig] value instead. This method is - * primarily for setting the field to an undocumented or not yet supported value. - */ - fun scalableMatrixWithUnitPricingConfig( - scalableMatrixWithUnitPricingConfig: JsonField - ) = apply { - this.scalableMatrixWithUnitPricingConfig = scalableMatrixWithUnitPricingConfig - } - fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -51220,7 +81426,7 @@ private constructor( } /** - * Returns an immutable instance of [ScalableMatrixWithUnitPricing]. + * Returns an immutable instance of [CumulativeGroupedAllocation]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -51229,11 +81435,14 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() * .creditAllocation() + * .cumulativeGroupedAllocationConfig() * .currency() * .discount() * .externalPriceId() @@ -51249,21 +81458,28 @@ private constructor( * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .scalableMatrixWithUnitPricingConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): ScalableMatrixWithUnitPricing = - ScalableMatrixWithUnitPricing( + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), checkRequired("creditAllocation", creditAllocation), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), checkRequired("currency", currency), checkRequired("discount", discount), checkRequired("externalPriceId", externalPriceId), @@ -51280,10 +81496,6 @@ private constructor( checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), - checkRequired( - "scalableMatrixWithUnitPricingConfig", - scalableMatrixWithUnitPricingConfig, - ), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -51291,7 +81503,7 @@ private constructor( private var validated: Boolean = false - fun validate(): ScalableMatrixWithUnitPricing = apply { + fun validate(): CumulativeGroupedAllocation = apply { if (validated) { return@apply } @@ -51299,11 +81511,14 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() creditAllocation()?.validate() + cumulativeGroupedAllocationConfig().validate() currency() discount()?.validate() externalPriceId() @@ -51316,7 +81531,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("scalable_matrix_with_unit_pricing")) { + if (it != JsonValue.from("cumulative_grouped_allocation")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -51324,7 +81539,6 @@ private constructor( planPhaseOrder() priceType().validate() replacesPriceId() - scalableMatrixWithUnitPricingConfig().validate() dimensionalPriceConfiguration()?.validate() validated = true } @@ -51347,11 +81561,14 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + (creditAllocation.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + (if (currency.asKnown() == null) 0 else 1) + (discount.asKnown()?.validity() ?: 0) + (if (externalPriceId.asKnown() == null) 0 else 1) + @@ -51364,15 +81581,143 @@ private constructor( (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + modelType.let { - if (it == JsonValue.from("scalable_matrix_with_unit_pricing")) 1 else 0 + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + - (scalableMatrixWithUnitPricingConfig.asKnown()?.validity() ?: 0) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -51517,7 +81862,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -51525,54 +81870,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun isUnit(): Boolean = unit != null + fun toBuilder() = Builder().from(this) - fun isTiered(): Boolean = tiered != null + companion object { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -51591,112 +82106,629 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** + * 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } - override fun unknown(json: JsonValue?) = 0 + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + override fun hashCode(): Int = hashCode - companion object { + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(cumulativeAllocation, groupAllocation, groupingKey, unitAmount, mutableMapOf()) - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected + * type. */ - interface Visitor { + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun visitUnit(unit: UnitConversionRateConfig): T + fun toBuilder() = Builder().from(this) - fun visitTiered(tiered: TieredConversionRateConfig): T + companion object { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns a mutable builder for constructing an instance of + * [CumulativeGroupedAllocationConfig]. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties.toMutableMap() + } + + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. * - * @throws OrbInvalidDataException in the default implementation. + * You should usually call [Builder.cumulativeAllocation] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } + + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - return ConversionRateConfig(_json = json) + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply } + + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" } /** @@ -51794,12 +82826,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -51825,6 +82855,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -51832,6 +82864,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -51846,6 +82879,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -51864,6 +82898,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -51880,6 +82915,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -51927,7 +82963,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -51935,140 +82971,92 @@ private constructor( override fun toString() = value.toString() } - class ScalableMatrixWithUnitPricingConfig - @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 - * [ScalableMatrixWithUnitPricingConfig]. - */ - fun builder() = Builder() - } - - /** A builder for [ScalableMatrixWithUnitPricingConfig]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from( - scalableMatrixWithUnitPricingConfig: ScalableMatrixWithUnitPricingConfig - ) = apply { - additionalProperties = - scalableMatrixWithUnitPricingConfig.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 [ScalableMatrixWithUnitPricingConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): ScalableMatrixWithUnitPricingConfig = - ScalableMatrixWithUnitPricingConfig(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): ScalableMatrixWithUnitPricingConfig = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ScalableMatrixWithUnitPricingConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ScalableMatrixWithUnitPricingConfig{additionalProperties=$additionalProperties}" - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ScalableMatrixWithUnitPricing && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && scalableMatrixWithUnitPricingConfig == other.scalableMatrixWithUnitPricingConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CumulativeGroupedAllocation && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + cumulativeGroupedAllocationConfig == other.cumulativeGroupedAllocationConfig && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, scalableMatrixWithUnitPricingConfig, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + cumulativeGroupedAllocationConfig, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "ScalableMatrixWithUnitPricing{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, scalableMatrixWithUnitPricingConfig=$scalableMatrixWithUnitPricingConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "CumulativeGroupedAllocation{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class ScalableMatrixWithTieredPricing + class Minimum + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, @@ -52084,13 +83072,12 @@ private constructor( private val metadata: JsonField, private val minimum: JsonField, private val minimumAmount: JsonField, + private val minimumConfig: JsonField, private val modelType: JsonValue, private val name: JsonField, private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, - private val scalableMatrixWithTieredPricingConfig: - JsonField, private val dimensionalPriceConfiguration: JsonField, private val additionalProperties: MutableMap, ) { @@ -52104,7 +83091,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -52144,6 +83137,9 @@ private constructor( @JsonProperty("minimum_amount") @ExcludeMissing minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("minimum_config") + @ExcludeMissing + minimumConfig: JsonField = JsonMissing.of(), @JsonProperty("model_type") @ExcludeMissing modelType: JsonValue = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("plan_phase_order") @@ -52155,11 +83151,6 @@ private constructor( @JsonProperty("replaces_price_id") @ExcludeMissing replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("scalable_matrix_with_tiered_pricing_config") - @ExcludeMissing - scalableMatrixWithTieredPricingConfig: - JsonField = - JsonMissing.of(), @JsonProperty("dimensional_price_configuration") @ExcludeMissing dimensionalPriceConfiguration: JsonField = @@ -52168,7 +83159,9 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, @@ -52184,12 +83177,12 @@ private constructor( metadata, minimum, minimumAmount, + minimumConfig, modelType, name, planPhaseOrder, priceType, replacesPriceId, - scalableMatrixWithTieredPricingConfig, dimensionalPriceConfiguration, mutableMapOf(), ) @@ -52213,12 +83206,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -52276,6 +83282,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -52318,9 +83327,19 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * Configuration for minimum pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun minimumConfig(): MinimumConfig = minimumConfig.getRequired("minimum_config") + + /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("scalable_matrix_with_tiered_pricing") + * JsonValue.from("minimum") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -52355,15 +83374,6 @@ private constructor( */ fun replacesPriceId(): String? = replacesPriceId.getNullable("replaces_price_id") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun scalableMatrixWithTieredPricingConfig(): ScalableMatrixWithTieredPricingConfig = - scalableMatrixWithTieredPricingConfig.getRequired( - "scalable_matrix_with_tiered_pricing_config" - ) - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -52399,6 +83409,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -52406,6 +83425,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -52549,6 +83578,16 @@ private constructor( @ExcludeMissing fun _minimumAmount(): JsonField = minimumAmount + /** + * Returns the raw JSON value of [minimumConfig]. + * + * Unlike [minimumConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_config") + @ExcludeMissing + fun _minimumConfig(): JsonField = minimumConfig + /** * Returns the raw JSON value of [name]. * @@ -52585,17 +83624,6 @@ private constructor( @ExcludeMissing fun _replacesPriceId(): JsonField = replacesPriceId - /** - * Returns the raw JSON value of [scalableMatrixWithTieredPricingConfig]. - * - * Unlike [scalableMatrixWithTieredPricingConfig], this method doesn't throw if the JSON - * field has an unexpected type. - */ - @JsonProperty("scalable_matrix_with_tiered_pricing_config") - @ExcludeMissing - fun _scalableMatrixWithTieredPricingConfig(): - JsonField = scalableMatrixWithTieredPricingConfig - /** * Returns the raw JSON value of [dimensionalPriceConfiguration]. * @@ -52622,15 +83650,16 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of - * [ScalableMatrixWithTieredPricing]. + * Returns a mutable builder for constructing an instance of [Minimum]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -52646,23 +83675,25 @@ private constructor( * .metadata() * .minimum() * .minimumAmount() + * .minimumConfig() * .name() * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .scalableMatrixWithTieredPricingConfig() * ``` */ fun builder() = Builder() } - /** A builder for [ScalableMatrixWithTieredPricing]. */ + /** A builder for [Minimum]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null @@ -52678,53 +83709,47 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("scalable_matrix_with_tiered_pricing") + private var minimumConfig: JsonField? = null + private var modelType: JsonValue = JsonValue.from("minimum") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null - private var scalableMatrixWithTieredPricingConfig: - JsonField? = - null private var dimensionalPriceConfiguration: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(scalableMatrixWithTieredPricing: ScalableMatrixWithTieredPricing) = - apply { - id = scalableMatrixWithTieredPricing.id - billableMetric = scalableMatrixWithTieredPricing.billableMetric - billingCycleConfiguration = - scalableMatrixWithTieredPricing.billingCycleConfiguration - cadence = scalableMatrixWithTieredPricing.cadence - conversionRate = scalableMatrixWithTieredPricing.conversionRate - conversionRateConfig = scalableMatrixWithTieredPricing.conversionRateConfig - createdAt = scalableMatrixWithTieredPricing.createdAt - creditAllocation = scalableMatrixWithTieredPricing.creditAllocation - currency = scalableMatrixWithTieredPricing.currency - discount = scalableMatrixWithTieredPricing.discount - externalPriceId = scalableMatrixWithTieredPricing.externalPriceId - fixedPriceQuantity = scalableMatrixWithTieredPricing.fixedPriceQuantity - invoicingCycleConfiguration = - scalableMatrixWithTieredPricing.invoicingCycleConfiguration - item = scalableMatrixWithTieredPricing.item - maximum = scalableMatrixWithTieredPricing.maximum - maximumAmount = scalableMatrixWithTieredPricing.maximumAmount - metadata = scalableMatrixWithTieredPricing.metadata - minimum = scalableMatrixWithTieredPricing.minimum - minimumAmount = scalableMatrixWithTieredPricing.minimumAmount - modelType = scalableMatrixWithTieredPricing.modelType - name = scalableMatrixWithTieredPricing.name - planPhaseOrder = scalableMatrixWithTieredPricing.planPhaseOrder - priceType = scalableMatrixWithTieredPricing.priceType - replacesPriceId = scalableMatrixWithTieredPricing.replacesPriceId - scalableMatrixWithTieredPricingConfig = - scalableMatrixWithTieredPricing.scalableMatrixWithTieredPricingConfig - dimensionalPriceConfiguration = - scalableMatrixWithTieredPricing.dimensionalPriceConfiguration - additionalProperties = - scalableMatrixWithTieredPricing.additionalProperties.toMutableMap() - } + internal fun from(minimum: Minimum) = apply { + id = minimum.id + billableMetric = minimum.billableMetric + billingCycleConfiguration = minimum.billingCycleConfiguration + billingMode = minimum.billingMode + cadence = minimum.cadence + compositePriceFilters = minimum.compositePriceFilters.map { it.toMutableList() } + conversionRate = minimum.conversionRate + conversionRateConfig = minimum.conversionRateConfig + createdAt = minimum.createdAt + creditAllocation = minimum.creditAllocation + currency = minimum.currency + discount = minimum.discount + externalPriceId = minimum.externalPriceId + fixedPriceQuantity = minimum.fixedPriceQuantity + invoicingCycleConfiguration = minimum.invoicingCycleConfiguration + item = minimum.item + maximum = minimum.maximum + maximumAmount = minimum.maximumAmount + metadata = minimum.metadata + this.minimum = minimum.minimum + minimumAmount = minimum.minimumAmount + minimumConfig = minimum.minimumConfig + modelType = minimum.modelType + name = minimum.name + planPhaseOrder = minimum.planPhaseOrder + priceType = minimum.priceType + replacesPriceId = minimum.replacesPriceId + dimensionalPriceConfiguration = minimum.dimensionalPriceConfiguration + additionalProperties = minimum.additionalProperties.toMutableMap() + } fun id(id: String) = id(JsonField.of(id)) @@ -52765,6 +83790,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -52776,6 +83814,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -53032,6 +84098,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -53117,13 +84187,28 @@ private constructor( this.minimumAmount = minimumAmount } + /** Configuration for minimum pricing */ + fun minimumConfig(minimumConfig: MinimumConfig) = + minimumConfig(JsonField.of(minimumConfig)) + + /** + * Sets [Builder.minimumConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumConfig] with a well-typed [MinimumConfig] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun minimumConfig(minimumConfig: JsonField) = apply { + this.minimumConfig = minimumConfig + } + /** * Sets the field to an arbitrary JSON value. * * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("scalable_matrix_with_tiered_pricing") + * JsonValue.from("minimum") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -53192,27 +84277,6 @@ private constructor( this.replacesPriceId = replacesPriceId } - fun scalableMatrixWithTieredPricingConfig( - scalableMatrixWithTieredPricingConfig: ScalableMatrixWithTieredPricingConfig - ) = - scalableMatrixWithTieredPricingConfig( - JsonField.of(scalableMatrixWithTieredPricingConfig) - ) - - /** - * Sets [Builder.scalableMatrixWithTieredPricingConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.scalableMatrixWithTieredPricingConfig] with a - * well-typed [ScalableMatrixWithTieredPricingConfig] value instead. This method is - * primarily for setting the field to an undocumented or not yet supported value. - */ - fun scalableMatrixWithTieredPricingConfig( - scalableMatrixWithTieredPricingConfig: - JsonField - ) = apply { - this.scalableMatrixWithTieredPricingConfig = scalableMatrixWithTieredPricingConfig - } - fun dimensionalPriceConfiguration( dimensionalPriceConfiguration: DimensionalPriceConfiguration? ) = dimensionalPriceConfiguration(JsonField.ofNullable(dimensionalPriceConfiguration)) @@ -53248,7 +84312,7 @@ private constructor( } /** - * Returns an immutable instance of [ScalableMatrixWithTieredPricing]. + * Returns an immutable instance of [Minimum]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -53257,7 +84321,9 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() @@ -53273,21 +84339,25 @@ private constructor( * .metadata() * .minimum() * .minimumAmount() + * .minimumConfig() * .name() * .planPhaseOrder() * .priceType() * .replacesPriceId() - * .scalableMatrixWithTieredPricingConfig() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): ScalableMatrixWithTieredPricing = - ScalableMatrixWithTieredPricing( + fun build(): Minimum = + Minimum( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), @@ -53303,15 +84373,12 @@ private constructor( checkRequired("metadata", metadata), checkRequired("minimum", minimum), checkRequired("minimumAmount", minimumAmount), + checkRequired("minimumConfig", minimumConfig), modelType, checkRequired("name", name), checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), - checkRequired( - "scalableMatrixWithTieredPricingConfig", - scalableMatrixWithTieredPricingConfig, - ), dimensionalPriceConfiguration, additionalProperties.toMutableMap(), ) @@ -53319,7 +84386,7 @@ private constructor( private var validated: Boolean = false - fun validate(): ScalableMatrixWithTieredPricing = apply { + fun validate(): Minimum = apply { if (validated) { return@apply } @@ -53327,7 +84394,9 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() @@ -53343,63 +84412,192 @@ private constructor( metadata().validate() minimum()?.validate() minimumAmount() + minimumConfig().validate() _modelType().let { - if (it != JsonValue.from("scalable_matrix_with_tiered_pricing")) { + if (it != JsonValue.from("minimum")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } - name() - planPhaseOrder() - priceType().validate() - replacesPriceId() - scalableMatrixWithTieredPricingConfig().validate() - dimensionalPriceConfiguration()?.validate() - validated = true - } + name() + planPhaseOrder() + priceType().validate() + replacesPriceId() + dimensionalPriceConfiguration()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (id.asKnown() == null) 0 else 1) + + (billableMetric.asKnown()?.validity() ?: 0) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (createdAt.asKnown() == null) 0 else 1) + + (creditAllocation.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (discount.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (item.asKnown()?.validity() ?: 0) + + (maximum.asKnown()?.validity() ?: 0) + + (if (maximumAmount.asKnown() == null) 0 else 1) + + (metadata.asKnown()?.validity() ?: 0) + + (minimum.asKnown()?.validity() ?: 0) + + (if (minimumAmount.asKnown() == null) 0 else 1) + + (minimumConfig.asKnown()?.validity() ?: 0) + + modelType.let { if (it == JsonValue.from("minimum")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (planPhaseOrder.asKnown() == null) 0 else 1) + + (priceType.asKnown()?.validity() ?: 0) + + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (id.asKnown() == null) 0 else 1) + - (billableMetric.asKnown()?.validity() ?: 0) + - (billingCycleConfiguration.asKnown()?.validity() ?: 0) + - (cadence.asKnown()?.validity() ?: 0) + - (if (conversionRate.asKnown() == null) 0 else 1) + - (conversionRateConfig.asKnown()?.validity() ?: 0) + - (if (createdAt.asKnown() == null) 0 else 1) + - (creditAllocation.asKnown()?.validity() ?: 0) + - (if (currency.asKnown() == null) 0 else 1) + - (discount.asKnown()?.validity() ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + - (item.asKnown()?.validity() ?: 0) + - (maximum.asKnown()?.validity() ?: 0) + - (if (maximumAmount.asKnown() == null) 0 else 1) + - (metadata.asKnown()?.validity() ?: 0) + - (minimum.asKnown()?.validity() ?: 0) + - (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { - if (it == JsonValue.from("scalable_matrix_with_tiered_pricing")) 1 else 0 - } + - (if (name.asKnown() == null) 0 else 1) + - (if (planPhaseOrder.asKnown() == null) 0 else 1) + - (priceType.asKnown()?.validity() ?: 0) + - (if (replacesPriceId.asKnown() == null) 0 else 1) + - (scalableMatrixWithTieredPricingConfig.asKnown()?.validity() ?: 0) + - (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -53545,7 +84743,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -53553,54 +84751,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun tiered(): TieredConversionRateConfig? = tiered + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun isUnit(): Boolean = unit != null + fun toBuilder() = Builder().from(this) - fun isTiered(): Boolean = tiered != null + companion object { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -53619,112 +84987,308 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + fun validate(): Field = apply { + if (validated) { + return@apply + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } + + override fun hashCode() = value.hashCode() - fun visitUnit(unit: UnitConversionRateConfig): T + override fun toString() = value.toString() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + private var validated: Boolean = false - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } /** @@ -53822,18 +85386,228 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } + /** Configuration for minimum pricing */ + class MinimumConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val minimumAmount: JsonField, + private val prorated: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("prorated") + @ExcludeMissing + prorated: JsonField = JsonMissing.of(), + ) : this(minimumAmount, prorated, mutableMapOf()) + + /** + * The minimum amount to apply + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun minimumAmount(): String = minimumAmount.getRequired("minimum_amount") + + /** + * If true, subtotals from this price are prorated based on the service period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prorated(): Boolean? = prorated.getNullable("prorated") + + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount + + /** + * Returns the raw JSON value of [prorated]. + * + * Unlike [prorated], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("prorated") @ExcludeMissing fun _prorated(): JsonField = prorated + + @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 [MinimumConfig]. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [MinimumConfig]. */ + class Builder internal constructor() { + + private var minimumAmount: JsonField? = null + private var prorated: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(minimumConfig: MinimumConfig) = apply { + minimumAmount = minimumConfig.minimumAmount + prorated = minimumConfig.prorated + additionalProperties = minimumConfig.additionalProperties.toMutableMap() + } + + /** The minimum amount to apply */ + fun minimumAmount(minimumAmount: String) = + minimumAmount(JsonField.of(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } + + /** If true, subtotals from this price are prorated based on the service period */ + fun prorated(prorated: Boolean) = prorated(JsonField.of(prorated)) + + /** + * Sets [Builder.prorated] to an arbitrary JSON value. + * + * You should usually call [Builder.prorated] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun prorated(prorated: JsonField) = apply { this.prorated = prorated } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [MinimumConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .minimumAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MinimumConfig = + MinimumConfig( + checkRequired("minimumAmount", minimumAmount), + prorated, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MinimumConfig = apply { + if (validated) { + return@apply + } + + minimumAmount() + prorated() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (minimumAmount.asKnown() == null) 0 else 1) + + (if (prorated.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MinimumConfig && + minimumAmount == other.minimumAmount && + prorated == other.prorated && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(minimumAmount, prorated, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MinimumConfig{minimumAmount=$minimumAmount, prorated=$prorated, additionalProperties=$additionalProperties}" + } + class PriceType @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -53853,6 +85627,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -53860,6 +85636,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -53874,6 +85651,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -53892,6 +85670,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -53908,6 +85687,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -53955,7 +85735,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -53963,145 +85743,96 @@ private constructor( override fun toString() = value.toString() } - class ScalableMatrixWithTieredPricingConfig - @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 - * [ScalableMatrixWithTieredPricingConfig]. - */ - fun builder() = Builder() - } - - /** A builder for [ScalableMatrixWithTieredPricingConfig]. */ - class Builder internal constructor() { - - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from( - scalableMatrixWithTieredPricingConfig: ScalableMatrixWithTieredPricingConfig - ) = apply { - additionalProperties = - scalableMatrixWithTieredPricingConfig.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 [ScalableMatrixWithTieredPricingConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): ScalableMatrixWithTieredPricingConfig = - ScalableMatrixWithTieredPricingConfig(additionalProperties.toImmutable()) - } - - private var validated: Boolean = false - - fun validate(): ScalableMatrixWithTieredPricingConfig = apply { - if (validated) { - return@apply - } - - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ScalableMatrixWithTieredPricingConfig && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ScalableMatrixWithTieredPricingConfig{additionalProperties=$additionalProperties}" - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ScalableMatrixWithTieredPricing && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && scalableMatrixWithTieredPricingConfig == other.scalableMatrixWithTieredPricingConfig && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Minimum && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + minimumConfig == other.minimumConfig && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, scalableMatrixWithTieredPricingConfig, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + minimumConfig, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "ScalableMatrixWithTieredPricing{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, scalableMatrixWithTieredPricingConfig=$scalableMatrixWithTieredPricingConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "Minimum{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, minimumConfig=$minimumConfig, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class CumulativeGroupedBulk + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, private val creditAllocation: JsonField, - private val cumulativeGroupedBulkConfig: JsonField, private val currency: JsonField, private val discount: JsonField, private val externalPriceId: JsonField, @@ -54115,6 +85846,7 @@ private constructor( private val minimumAmount: JsonField, private val modelType: JsonValue, private val name: JsonField, + private val percentConfig: JsonField, private val planPhaseOrder: JsonField, private val priceType: JsonField, private val replacesPriceId: JsonField, @@ -54131,7 +85863,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -54144,9 +85882,6 @@ private constructor( @JsonProperty("credit_allocation") @ExcludeMissing creditAllocation: JsonField = JsonMissing.of(), - @JsonProperty("cumulative_grouped_bulk_config") - @ExcludeMissing - cumulativeGroupedBulkConfig: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @@ -54176,6 +85911,9 @@ private constructor( minimumAmount: JsonField = JsonMissing.of(), @JsonProperty("model_type") @ExcludeMissing modelType: JsonValue = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), @JsonProperty("plan_phase_order") @ExcludeMissing planPhaseOrder: JsonField = JsonMissing.of(), @@ -54193,12 +85931,13 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, creditAllocation, - cumulativeGroupedBulkConfig, currency, discount, externalPriceId, @@ -54212,6 +85951,7 @@ private constructor( minimumAmount, modelType, name, + percentConfig, planPhaseOrder, priceType, replacesPriceId, @@ -54238,12 +85978,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -54269,13 +86022,6 @@ private constructor( */ fun creditAllocation(): Allocation? = creditAllocation.getNullable("credit_allocation") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun cumulativeGroupedBulkConfig(): CumulativeGroupedBulkConfig = - cumulativeGroupedBulkConfig.getRequired("cumulative_grouped_bulk_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -54308,6 +86054,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -54350,9 +86099,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("cumulative_grouped_bulk") + * JsonValue.from("percent") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -54366,6 +86117,14 @@ private constructor( */ fun name(): String = name.getRequired("name") + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -54422,6 +86181,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -54429,6 +86197,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -54468,17 +86246,6 @@ private constructor( @ExcludeMissing fun _creditAllocation(): JsonField = creditAllocation - /** - * Returns the raw JSON value of [cumulativeGroupedBulkConfig]. - * - * Unlike [cumulativeGroupedBulkConfig], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("cumulative_grouped_bulk_config") - @ExcludeMissing - fun _cumulativeGroupedBulkConfig(): JsonField = - cumulativeGroupedBulkConfig - /** * Returns the raw JSON value of [currency]. * @@ -54590,6 +86357,16 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + /** + * Returns the raw JSON value of [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig + /** * Returns the raw JSON value of [planPhaseOrder]. * @@ -54645,19 +86422,20 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [CumulativeGroupedBulk]. + * Returns a mutable builder for constructing an instance of [Percent]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() * .creditAllocation() - * .cumulativeGroupedBulkConfig() * .currency() * .discount() * .externalPriceId() @@ -54670,6 +86448,7 @@ private constructor( * .minimum() * .minimumAmount() * .name() + * .percentConfig() * .planPhaseOrder() * .priceType() * .replacesPriceId() @@ -54678,18 +86457,19 @@ private constructor( fun builder() = Builder() } - /** A builder for [CumulativeGroupedBulk]. */ + /** A builder for [Percent]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null private var creditAllocation: JsonField? = null - private var cumulativeGroupedBulkConfig: JsonField? = null private var currency: JsonField? = null private var discount: JsonField? = null private var externalPriceId: JsonField? = null @@ -54701,8 +86481,9 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("cumulative_grouped_bulk") + private var modelType: JsonValue = JsonValue.from("percent") private var name: JsonField? = null + private var percentConfig: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null private var replacesPriceId: JsonField? = null @@ -54710,34 +86491,36 @@ private constructor( JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(cumulativeGroupedBulk: CumulativeGroupedBulk) = apply { - id = cumulativeGroupedBulk.id - billableMetric = cumulativeGroupedBulk.billableMetric - billingCycleConfiguration = cumulativeGroupedBulk.billingCycleConfiguration - cadence = cumulativeGroupedBulk.cadence - conversionRate = cumulativeGroupedBulk.conversionRate - conversionRateConfig = cumulativeGroupedBulk.conversionRateConfig - createdAt = cumulativeGroupedBulk.createdAt - creditAllocation = cumulativeGroupedBulk.creditAllocation - cumulativeGroupedBulkConfig = cumulativeGroupedBulk.cumulativeGroupedBulkConfig - currency = cumulativeGroupedBulk.currency - discount = cumulativeGroupedBulk.discount - externalPriceId = cumulativeGroupedBulk.externalPriceId - fixedPriceQuantity = cumulativeGroupedBulk.fixedPriceQuantity - invoicingCycleConfiguration = cumulativeGroupedBulk.invoicingCycleConfiguration - item = cumulativeGroupedBulk.item - maximum = cumulativeGroupedBulk.maximum - maximumAmount = cumulativeGroupedBulk.maximumAmount - metadata = cumulativeGroupedBulk.metadata - minimum = cumulativeGroupedBulk.minimum - minimumAmount = cumulativeGroupedBulk.minimumAmount - modelType = cumulativeGroupedBulk.modelType - name = cumulativeGroupedBulk.name - planPhaseOrder = cumulativeGroupedBulk.planPhaseOrder - priceType = cumulativeGroupedBulk.priceType - replacesPriceId = cumulativeGroupedBulk.replacesPriceId - dimensionalPriceConfiguration = cumulativeGroupedBulk.dimensionalPriceConfiguration - additionalProperties = cumulativeGroupedBulk.additionalProperties.toMutableMap() + internal fun from(percent: Percent) = apply { + id = percent.id + billableMetric = percent.billableMetric + billingCycleConfiguration = percent.billingCycleConfiguration + billingMode = percent.billingMode + cadence = percent.cadence + compositePriceFilters = percent.compositePriceFilters.map { it.toMutableList() } + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + createdAt = percent.createdAt + creditAllocation = percent.creditAllocation + currency = percent.currency + discount = percent.discount + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + item = percent.item + maximum = percent.maximum + maximumAmount = percent.maximumAmount + metadata = percent.metadata + minimum = percent.minimum + minimumAmount = percent.minimumAmount + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + planPhaseOrder = percent.planPhaseOrder + priceType = percent.priceType + replacesPriceId = percent.replacesPriceId + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + additionalProperties = percent.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -54779,6 +86562,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -54790,6 +86586,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -54900,21 +86724,6 @@ private constructor( this.creditAllocation = creditAllocation } - fun cumulativeGroupedBulkConfig( - cumulativeGroupedBulkConfig: CumulativeGroupedBulkConfig - ) = cumulativeGroupedBulkConfig(JsonField.of(cumulativeGroupedBulkConfig)) - - /** - * Sets [Builder.cumulativeGroupedBulkConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.cumulativeGroupedBulkConfig] with a well-typed - * [CumulativeGroupedBulkConfig] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun cumulativeGroupedBulkConfig( - cumulativeGroupedBulkConfig: JsonField - ) = apply { this.cumulativeGroupedBulkConfig = cumulativeGroupedBulkConfig } - fun currency(currency: String) = currency(JsonField.of(currency)) /** @@ -55061,6 +86870,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -55152,7 +86965,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("cumulative_grouped_bulk") + * JsonValue.from("percent") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -55171,6 +86984,21 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed [PercentConfig] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } + fun planPhaseOrder(planPhaseOrder: Long?) = planPhaseOrder(JsonField.ofNullable(planPhaseOrder)) @@ -55256,7 +87084,7 @@ private constructor( } /** - * Returns an immutable instance of [CumulativeGroupedBulk]. + * Returns an immutable instance of [Percent]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -55265,12 +87093,13 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() * .creditAllocation() - * .cumulativeGroupedBulkConfig() * .currency() * .discount() * .externalPriceId() @@ -55283,6 +87112,7 @@ private constructor( * .minimum() * .minimumAmount() * .name() + * .percentConfig() * .planPhaseOrder() * .priceType() * .replacesPriceId() @@ -55290,17 +87120,20 @@ private constructor( * * @throws IllegalStateException if any required field is unset. */ - fun build(): CumulativeGroupedBulk = - CumulativeGroupedBulk( + fun build(): Percent = + Percent( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), checkRequired("creditAllocation", creditAllocation), - checkRequired("cumulativeGroupedBulkConfig", cumulativeGroupedBulkConfig), checkRequired("currency", currency), checkRequired("discount", discount), checkRequired("externalPriceId", externalPriceId), @@ -55314,6 +87147,7 @@ private constructor( checkRequired("minimumAmount", minimumAmount), modelType, checkRequired("name", name), + checkRequired("percentConfig", percentConfig), checkRequired("planPhaseOrder", planPhaseOrder), checkRequired("priceType", priceType), checkRequired("replacesPriceId", replacesPriceId), @@ -55324,7 +87158,7 @@ private constructor( private var validated: Boolean = false - fun validate(): CumulativeGroupedBulk = apply { + fun validate(): Percent = apply { if (validated) { return@apply } @@ -55332,12 +87166,13 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() creditAllocation()?.validate() - cumulativeGroupedBulkConfig().validate() currency() discount()?.validate() externalPriceId() @@ -55350,11 +87185,12 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("cumulative_grouped_bulk")) { + if (it != JsonValue.from("percent")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } name() + percentConfig().validate() planPhaseOrder() priceType().validate() replacesPriceId() @@ -55380,12 +87216,13 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + (creditAllocation.asKnown()?.validity() ?: 0) + - (cumulativeGroupedBulkConfig.asKnown()?.validity() ?: 0) + (if (currency.asKnown() == null) 0 else 1) + (discount.asKnown()?.validity() ?: 0) + (if (externalPriceId.asKnown() == null) 0 else 1) + @@ -55397,13 +87234,143 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { if (it == JsonValue.from("cumulative_grouped_bulk")) 1 else 0 } + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -55548,7 +87515,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -55556,54 +87523,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun tiered(): TieredConversionRateConfig? = tiered + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun isUnit(): Boolean = unit != null + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun isTiered(): Boolean = tiered != null + fun toBuilder() = Builder().from(this) + + companion object { - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns a mutable builder for constructing an instance of [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { - fun _json(): JsonValue? = _json + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -55622,115 +87759,316 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + /** + * 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + return other is Field && value == other.value + } - fun visitUnit(unit: UnitConversionRateConfig): T + override fun hashCode() = value.hashCode() - fun visitTiered(tiered: TieredConversionRateConfig): T + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + private var validated: Boolean = false - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } - class CumulativeGroupedBulkConfig + /** + * User specified key-value pairs for the resource. If not present, this defaults to an + * empty dictionary. Individual keys can be removed by setting the value to `null`, and the + * entire metadata mapping can be cleared by setting `metadata` to `null`. + */ + class Metadata @JsonCreator private constructor( @com.fasterxml.jackson.annotation.JsonValue @@ -55745,23 +88083,18 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of - * [CumulativeGroupedBulkConfig]. - */ + /** Returns a mutable builder for constructing an instance of [Metadata]. */ fun builder() = Builder() } - /** A builder for [CumulativeGroupedBulkConfig]. */ + /** A builder for [Metadata]. */ class Builder internal constructor() { private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(cumulativeGroupedBulkConfig: CumulativeGroupedBulkConfig) = - apply { - additionalProperties = - cumulativeGroupedBulkConfig.additionalProperties.toMutableMap() - } + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -55786,17 +88119,16 @@ private constructor( } /** - * Returns an immutable instance of [CumulativeGroupedBulkConfig]. + * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): CumulativeGroupedBulkConfig = - CumulativeGroupedBulkConfig(additionalProperties.toImmutable()) + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } private var validated: Boolean = false - fun validate(): CumulativeGroupedBulkConfig = apply { + fun validate(): Metadata = apply { if (validated) { return@apply } @@ -55826,52 +88158,95 @@ private constructor( return true } - return /* spotless:off */ other is CumulativeGroupedBulkConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode - override fun toString() = - "CumulativeGroupedBulkConfig{additionalProperties=$additionalProperties}" + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } - /** - * User specified key-value pairs for the resource. If not present, this defaults to an - * empty dictionary. Individual keys can be removed by setting the value to `null`, and the - * entire metadata mapping can be cleared by setting `metadata` to `null`. - */ - class Metadata - @JsonCreator + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val percent: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("percent") @ExcludeMissing fun _percent(): JsonField = percent + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) companion object { - /** Returns a mutable builder for constructing an instance of [Metadata]. */ + /** + * Returns a mutable builder for constructing an instance of [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ fun builder() = Builder() } - /** A builder for [Metadata]. */ + /** A builder for [PercentConfig]. */ class Builder internal constructor() { + private var percent: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.additionalProperties.toMutableMap() + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() } + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -55895,20 +88270,32 @@ private constructor( } /** - * Returns an immutable instance of [Metadata]. + * Returns an immutable instance of [PercentConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): Metadata = apply { + fun validate(): PercentConfig = apply { if (validated) { return@apply } + percent() validated = true } @@ -55926,24 +88313,24 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { Objects.hash(percent, additionalProperties) } override fun hashCode(): Int = hashCode - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" } class PriceType @JsonCreator private constructor(private val value: JsonField) : @@ -55965,6 +88352,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -55972,6 +88361,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -55986,6 +88376,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -56004,6 +88395,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -56020,6 +88412,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -56067,7 +88460,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -56080,34 +88473,96 @@ private constructor( return true } - return /* spotless:off */ other is CumulativeGroupedBulk && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && cumulativeGroupedBulkConfig == other.cumulativeGroupedBulkConfig && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Percent && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, cumulativeGroupedBulkConfig, currency, discount, externalPriceId, fixedPriceQuantity, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + percentConfig, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "CumulativeGroupedBulk{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, cumulativeGroupedBulkConfig=$cumulativeGroupedBulkConfig, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "Percent{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, percentConfig=$percentConfig, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } - class GroupedWithMinMaxThresholds + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billableMetric: JsonField, private val billingCycleConfiguration: JsonField, + private val billingMode: JsonField, private val cadence: JsonField, + private val compositePriceFilters: JsonField>, private val conversionRate: JsonField, private val conversionRateConfig: JsonField, private val createdAt: JsonField, private val creditAllocation: JsonField, private val currency: JsonField, private val discount: JsonField, + private val eventOutputConfig: JsonField, private val externalPriceId: JsonField, private val fixedPriceQuantity: JsonField, - private val groupedWithMinMaxThresholdsConfig: JsonField, private val invoicingCycleConfiguration: JsonField, private val item: JsonField, private val maximum: JsonField, @@ -56133,7 +88588,13 @@ private constructor( @JsonProperty("billing_cycle_configuration") @ExcludeMissing billingCycleConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("billing_mode") + @ExcludeMissing + billingMode: JsonField = JsonMissing.of(), @JsonProperty("cadence") @ExcludeMissing cadence: JsonField = JsonMissing.of(), + @JsonProperty("composite_price_filters") + @ExcludeMissing + compositePriceFilters: JsonField> = JsonMissing.of(), @JsonProperty("conversion_rate") @ExcludeMissing conversionRate: JsonField = JsonMissing.of(), @@ -56152,16 +88613,15 @@ private constructor( @JsonProperty("discount") @ExcludeMissing discount: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), @JsonProperty("external_price_id") @ExcludeMissing externalPriceId: JsonField = JsonMissing.of(), @JsonProperty("fixed_price_quantity") @ExcludeMissing fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("grouped_with_min_max_thresholds_config") - @ExcludeMissing - groupedWithMinMaxThresholdsConfig: JsonField = - JsonMissing.of(), @JsonProperty("invoicing_cycle_configuration") @ExcludeMissing invoicingCycleConfiguration: JsonField = JsonMissing.of(), @@ -56196,16 +88656,18 @@ private constructor( id, billableMetric, billingCycleConfiguration, + billingMode, cadence, + compositePriceFilters, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, + eventOutputConfig, externalPriceId, fixedPriceQuantity, - groupedWithMinMaxThresholdsConfig, invoicingCycleConfiguration, item, maximum, @@ -56241,12 +88703,25 @@ private constructor( fun billingCycleConfiguration(): BillingCycleConfiguration = billingCycleConfiguration.getRequired("billing_cycle_configuration") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun billingMode(): BillingMode = billingMode.getRequired("billing_mode") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun cadence(): Cadence = cadence.getRequired("cadence") + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun compositePriceFilters(): List? = + compositePriceFilters.getNullable("composite_price_filters") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -56284,6 +88759,15 @@ private constructor( */ @Deprecated("deprecated") fun discount(): Discount? = discount.getNullable("discount") + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") + /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -56296,13 +88780,6 @@ private constructor( */ fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = - groupedWithMinMaxThresholdsConfig.getRequired("grouped_with_min_max_thresholds_config") - /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -56311,6 +88788,9 @@ private constructor( invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** + * A minimal representation of an Item containing only the essential identifying + * information. + * * @throws OrbInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -56353,9 +88833,11 @@ private constructor( fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") /** + * The pricing model type + * * Expected to always return the following: * ```kotlin - * JsonValue.from("grouped_with_min_max_thresholds") + * JsonValue.from("event_output") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -56425,6 +88907,15 @@ private constructor( fun _billingCycleConfiguration(): JsonField = billingCycleConfiguration + /** + * Returns the raw JSON value of [billingMode]. + * + * Unlike [billingMode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("billing_mode") + @ExcludeMissing + fun _billingMode(): JsonField = billingMode + /** * Returns the raw JSON value of [cadence]. * @@ -56432,6 +88923,16 @@ private constructor( */ @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + /** + * Returns the raw JSON value of [compositePriceFilters]. + * + * Unlike [compositePriceFilters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("composite_price_filters") + @ExcludeMissing + fun _compositePriceFilters(): JsonField> = compositePriceFilters + /** * Returns the raw JSON value of [conversionRate]. * @@ -56488,6 +88989,16 @@ private constructor( @ExcludeMissing fun _discount(): JsonField = discount + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig + /** * Returns the raw JSON value of [externalPriceId]. * @@ -56508,17 +89019,6 @@ private constructor( @ExcludeMissing fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - /** - * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. - * - * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON field - * has an unexpected type. - */ - @JsonProperty("grouped_with_min_max_thresholds_config") - @ExcludeMissing - fun _groupedWithMinMaxThresholdsConfig(): JsonField = - groupedWithMinMaxThresholdsConfig - /** * Returns the raw JSON value of [invoicingCycleConfiguration]. * @@ -56648,24 +89148,25 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of - * [GroupedWithMinMaxThresholds]. + * Returns a mutable builder for constructing an instance of [EventOutput]. * * The following fields are required: * ```kotlin * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() * .creditAllocation() * .currency() * .discount() + * .eventOutputConfig() * .externalPriceId() * .fixedPriceQuantity() - * .groupedWithMinMaxThresholdsConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -56682,24 +89183,24 @@ private constructor( fun builder() = Builder() } - /** A builder for [GroupedWithMinMaxThresholds]. */ + /** A builder for [EventOutput]. */ class Builder internal constructor() { private var id: JsonField? = null private var billableMetric: JsonField? = null private var billingCycleConfiguration: JsonField? = null + private var billingMode: JsonField? = null private var cadence: JsonField? = null + private var compositePriceFilters: JsonField>? = null private var conversionRate: JsonField? = null private var conversionRateConfig: JsonField? = null private var createdAt: JsonField? = null private var creditAllocation: JsonField? = null private var currency: JsonField? = null private var discount: JsonField? = null + private var eventOutputConfig: JsonField? = null private var externalPriceId: JsonField? = null private var fixedPriceQuantity: JsonField? = null - private var groupedWithMinMaxThresholdsConfig: - JsonField? = - null private var invoicingCycleConfiguration: JsonField? = null private var item: JsonField? = null private var maximum: JsonField? = null @@ -56707,7 +89208,7 @@ private constructor( private var metadata: JsonField? = null private var minimum: JsonField? = null private var minimumAmount: JsonField? = null - private var modelType: JsonValue = JsonValue.from("grouped_with_min_max_thresholds") + private var modelType: JsonValue = JsonValue.from("event_output") private var name: JsonField? = null private var planPhaseOrder: JsonField? = null private var priceType: JsonField? = null @@ -56716,38 +89217,36 @@ private constructor( JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = apply { - id = groupedWithMinMaxThresholds.id - billableMetric = groupedWithMinMaxThresholds.billableMetric - billingCycleConfiguration = groupedWithMinMaxThresholds.billingCycleConfiguration - cadence = groupedWithMinMaxThresholds.cadence - conversionRate = groupedWithMinMaxThresholds.conversionRate - conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig - createdAt = groupedWithMinMaxThresholds.createdAt - creditAllocation = groupedWithMinMaxThresholds.creditAllocation - currency = groupedWithMinMaxThresholds.currency - discount = groupedWithMinMaxThresholds.discount - externalPriceId = groupedWithMinMaxThresholds.externalPriceId - fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity - groupedWithMinMaxThresholdsConfig = - groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig - invoicingCycleConfiguration = - groupedWithMinMaxThresholds.invoicingCycleConfiguration - item = groupedWithMinMaxThresholds.item - maximum = groupedWithMinMaxThresholds.maximum - maximumAmount = groupedWithMinMaxThresholds.maximumAmount - metadata = groupedWithMinMaxThresholds.metadata - minimum = groupedWithMinMaxThresholds.minimum - minimumAmount = groupedWithMinMaxThresholds.minimumAmount - modelType = groupedWithMinMaxThresholds.modelType - name = groupedWithMinMaxThresholds.name - planPhaseOrder = groupedWithMinMaxThresholds.planPhaseOrder - priceType = groupedWithMinMaxThresholds.priceType - replacesPriceId = groupedWithMinMaxThresholds.replacesPriceId - dimensionalPriceConfiguration = - groupedWithMinMaxThresholds.dimensionalPriceConfiguration - additionalProperties = - groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + internal fun from(eventOutput: EventOutput) = apply { + id = eventOutput.id + billableMetric = eventOutput.billableMetric + billingCycleConfiguration = eventOutput.billingCycleConfiguration + billingMode = eventOutput.billingMode + cadence = eventOutput.cadence + compositePriceFilters = eventOutput.compositePriceFilters.map { it.toMutableList() } + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + createdAt = eventOutput.createdAt + creditAllocation = eventOutput.creditAllocation + currency = eventOutput.currency + discount = eventOutput.discount + eventOutputConfig = eventOutput.eventOutputConfig + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + item = eventOutput.item + maximum = eventOutput.maximum + maximumAmount = eventOutput.maximumAmount + metadata = eventOutput.metadata + minimum = eventOutput.minimum + minimumAmount = eventOutput.minimumAmount + modelType = eventOutput.modelType + name = eventOutput.name + planPhaseOrder = eventOutput.planPhaseOrder + priceType = eventOutput.priceType + replacesPriceId = eventOutput.replacesPriceId + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + additionalProperties = eventOutput.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -56789,6 +89288,19 @@ private constructor( billingCycleConfiguration: JsonField ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + fun billingMode(billingMode: BillingMode) = billingMode(JsonField.of(billingMode)) + + /** + * Sets [Builder.billingMode] to an arbitrary JSON value. + * + * You should usually call [Builder.billingMode] with a well-typed [BillingMode] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingMode(billingMode: JsonField) = apply { + this.billingMode = billingMode + } + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) /** @@ -56800,6 +89312,34 @@ private constructor( */ fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + fun compositePriceFilters(compositePriceFilters: List?) = + compositePriceFilters(JsonField.ofNullable(compositePriceFilters)) + + /** + * Sets [Builder.compositePriceFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.compositePriceFilters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun compositePriceFilters( + compositePriceFilters: JsonField> + ) = apply { + this.compositePriceFilters = compositePriceFilters.map { it.toMutableList() } + } + + /** + * Adds a single [CompositePriceFilter] to [compositePriceFilters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCompositePriceFilter(compositePriceFilter: CompositePriceFilter) = apply { + compositePriceFilters = + (compositePriceFilters ?: JsonField.of(mutableListOf())).also { + checkKnown("compositePriceFilters", it).add(compositePriceFilter) + } + } + fun conversionRate(conversionRate: Double?) = conversionRate(JsonField.ofNullable(conversionRate)) @@ -57005,6 +89545,21 @@ private constructor( .build() ) + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } + fun externalPriceId(externalPriceId: String?) = externalPriceId(JsonField.ofNullable(externalPriceId)) @@ -57041,21 +89596,6 @@ private constructor( this.fixedPriceQuantity = fixedPriceQuantity } - fun groupedWithMinMaxThresholdsConfig( - groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig - ) = groupedWithMinMaxThresholdsConfig(JsonField.of(groupedWithMinMaxThresholdsConfig)) - - /** - * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. - * - * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a well-typed - * [GroupedWithMinMaxThresholdsConfig] value instead. This method is primarily for - * setting the field to an undocumented or not yet supported value. - */ - fun groupedWithMinMaxThresholdsConfig( - groupedWithMinMaxThresholdsConfig: JsonField - ) = apply { this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig } - fun invoicingCycleConfiguration( invoicingCycleConfiguration: BillingCycleConfiguration? ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) @@ -57071,6 +89611,10 @@ private constructor( invoicingCycleConfiguration: JsonField ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + /** + * A minimal representation of an Item containing only the essential identifying + * information. + */ fun item(item: ItemSlim) = item(JsonField.of(item)) /** @@ -57162,7 +89706,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```kotlin - * JsonValue.from("grouped_with_min_max_thresholds") + * JsonValue.from("event_output") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -57266,7 +89810,7 @@ private constructor( } /** - * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * Returns an immutable instance of [EventOutput]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -57275,16 +89819,18 @@ private constructor( * .id() * .billableMetric() * .billingCycleConfiguration() + * .billingMode() * .cadence() + * .compositePriceFilters() * .conversionRate() * .conversionRateConfig() * .createdAt() * .creditAllocation() * .currency() * .discount() + * .eventOutputConfig() * .externalPriceId() * .fixedPriceQuantity() - * .groupedWithMinMaxThresholdsConfig() * .invoicingCycleConfiguration() * .item() * .maximum() @@ -57300,24 +89846,25 @@ private constructor( * * @throws IllegalStateException if any required field is unset. */ - fun build(): GroupedWithMinMaxThresholds = - GroupedWithMinMaxThresholds( + fun build(): EventOutput = + EventOutput( checkRequired("id", id), checkRequired("billableMetric", billableMetric), checkRequired("billingCycleConfiguration", billingCycleConfiguration), + checkRequired("billingMode", billingMode), checkRequired("cadence", cadence), + checkRequired("compositePriceFilters", compositePriceFilters).map { + it.toImmutable() + }, checkRequired("conversionRate", conversionRate), checkRequired("conversionRateConfig", conversionRateConfig), checkRequired("createdAt", createdAt), checkRequired("creditAllocation", creditAllocation), checkRequired("currency", currency), checkRequired("discount", discount), + checkRequired("eventOutputConfig", eventOutputConfig), checkRequired("externalPriceId", externalPriceId), checkRequired("fixedPriceQuantity", fixedPriceQuantity), - checkRequired( - "groupedWithMinMaxThresholdsConfig", - groupedWithMinMaxThresholdsConfig, - ), checkRequired("invoicingCycleConfiguration", invoicingCycleConfiguration), checkRequired("item", item), checkRequired("maximum", maximum), @@ -57337,7 +89884,7 @@ private constructor( private var validated: Boolean = false - fun validate(): GroupedWithMinMaxThresholds = apply { + fun validate(): EventOutput = apply { if (validated) { return@apply } @@ -57345,16 +89892,18 @@ private constructor( id() billableMetric()?.validate() billingCycleConfiguration().validate() + billingMode().validate() cadence().validate() + compositePriceFilters()?.forEach { it.validate() } conversionRate() conversionRateConfig()?.validate() createdAt() creditAllocation()?.validate() currency() discount()?.validate() + eventOutputConfig().validate() externalPriceId() fixedPriceQuantity() - groupedWithMinMaxThresholdsConfig().validate() invoicingCycleConfiguration()?.validate() item().validate() maximum()?.validate() @@ -57363,7 +89912,7 @@ private constructor( minimum()?.validate() minimumAmount() _modelType().let { - if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + if (it != JsonValue.from("event_output")) { throw OrbInvalidDataException("'modelType' is invalid, received $it") } } @@ -57393,16 +89942,18 @@ private constructor( (if (id.asKnown() == null) 0 else 1) + (billableMetric.asKnown()?.validity() ?: 0) + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (billingMode.asKnown()?.validity() ?: 0) + (cadence.asKnown()?.validity() ?: 0) + + (compositePriceFilters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (conversionRate.asKnown() == null) 0 else 1) + (conversionRateConfig.asKnown()?.validity() ?: 0) + (if (createdAt.asKnown() == null) 0 else 1) + (creditAllocation.asKnown()?.validity() ?: 0) + (if (currency.asKnown() == null) 0 else 1) + (discount.asKnown()?.validity() ?: 0) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + (if (externalPriceId.asKnown() == null) 0 else 1) + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + (item.asKnown()?.validity() ?: 0) + (maximum.asKnown()?.validity() ?: 0) + @@ -57410,15 +89961,142 @@ private constructor( (metadata.asKnown()?.validity() ?: 0) + (minimum.asKnown()?.validity() ?: 0) + (if (minimumAmount.asKnown() == null) 0 else 1) + - modelType.let { - if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 - } + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + (if (name.asKnown() == null) 0 else 1) + (if (planPhaseOrder.asKnown() == null) 0 else 1) + (priceType.asKnown()?.validity() ?: 0) + (if (replacesPriceId.asKnown() == null) 0 else 1) + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + class BillingMode @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 { + + val IN_ADVANCE = of("in_advance") + + val IN_ARREAR = of("in_arrear") + + fun of(value: String) = BillingMode(JsonField.of(value)) + } + + /** An enum containing [BillingMode]'s known values. */ + enum class Known { + IN_ADVANCE, + IN_ARREAR, + } + + /** + * An enum containing [BillingMode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [BillingMode] 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 { + IN_ADVANCE, + IN_ARREAR, + /** + * An enum member indicating that [BillingMode] 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) { + IN_ADVANCE -> Value.IN_ADVANCE + IN_ARREAR -> Value.IN_ARREAR + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IN_ADVANCE -> Known.IN_ADVANCE + IN_ARREAR -> Known.IN_ARREAR + else -> throw OrbInvalidDataException("Unknown BillingMode: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingMode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingMode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class Cadence @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -57563,7 +90241,7 @@ private constructor( return true } - return /* spotless:off */ other is Cadence && value == other.value /* spotless:on */ + return other is Cadence && value == other.value } override fun hashCode() = value.hashCode() @@ -57571,54 +90249,224 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(using = ConversionRateConfig.Deserializer::class) - @JsonSerialize(using = ConversionRateConfig.Serializer::class) - class ConversionRateConfig + class CompositePriceFilter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val unit: UnitConversionRateConfig? = null, - private val tiered: TieredConversionRateConfig? = null, - private val _json: JsonValue? = null, + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, ) { - fun unit(): UnitConversionRateConfig? = unit + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) - fun tiered(): TieredConversionRateConfig? = tiered + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun field(): Field = field.getRequired("field") - fun isUnit(): Boolean = unit != null + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun operator(): Operator = operator.getRequired("operator") - fun isTiered(): Boolean = tiered != null + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun values(): List = values.getRequired("values") - fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit") + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field - fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered") + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator - fun _json(): JsonValue? = _json + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @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 [CompositePriceFilter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - tiered != null -> visitor.visitTiered(tiered) - else -> visitor.unknown(_json) + /** A builder for [CompositePriceFilter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(compositePriceFilter: CompositePriceFilter) = apply { + field = compositePriceFilter.field + operator = compositePriceFilter.operator + values = compositePriceFilter.values.map { it.toMutableList() } + additionalProperties = compositePriceFilter.additionalProperties.toMutableMap() } - private var validated: Boolean = false + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) - fun validate(): ConversionRateConfig = apply { - if (validated) { - return@apply + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } } - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) { - unit.validate() + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(value) } + } - override fun visitTiered(tiered: TieredConversionRateConfig) { - tiered.validate() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - ) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CompositePriceFilter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CompositePriceFilter = + CompositePriceFilter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CompositePriceFilter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() validated = true } @@ -57637,146 +90485,481 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity() + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) - override fun visitTiered(tiered: TieredConversionRateConfig) = - tiered.validity() + /** The property of the price to filter on. */ + class Field @JsonCreator private constructor(private val value: JsonField) : + Enum { - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * 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 - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + companion object { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) } - return /* spotless:off */ other is ConversionRateConfig && unit == other.unit && tiered == other.tiered /* spotless:on */ - } + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, tiered) /* spotless:on */ + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $value") + } - override fun toString(): String = - when { - unit != null -> "ConversionRateConfig{unit=$unit}" - tiered != null -> "ConversionRateConfig{tiered=$tiered}" - _json != null -> "ConversionRateConfig{_unknown=$_json}" - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true } - companion object { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun ofTiered(tiered: TieredConversionRateConfig) = - ConversionRateConfig(tiered = tiered) - } + return other is Field && value == other.value + } - /** - * An interface that defines how to map each variant of [ConversionRateConfig] to a - * value of type [T]. - */ - interface Visitor { + override fun hashCode() = value.hashCode() - fun visitUnit(unit: UnitConversionRateConfig): T + override fun toString() = value.toString() + } - fun visitTiered(tiered: TieredConversionRateConfig): T + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Maps an unknown variant of [ConversionRateConfig] to a value of type [T]. + * Returns this class instance's raw value. * - * An instance of [ConversionRateConfig] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if the - * SDK is on an older version than the API, then the API may respond with new - * variants that the SDK is unaware of. + * 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 { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. * - * @throws OrbInvalidDataException in the default implementation. + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown ConversionRateConfig: $json") + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown + * value. + */ + _UNKNOWN, } - } - internal class Deserializer : - BaseDeserializer(ConversionRateConfig::class) { + /** + * 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) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + else -> Value._UNKNOWN + } - override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig { - val json = JsonValue.fromJsonNode(node) - val conversionRateType = - json.asObject()?.get("conversion_rate_type")?.asString() + /** + * 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } - when (conversionRateType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { ConversionRateConfig(unit = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { ConversionRateConfig(tiered = it, _json = json) } - ?: ConversionRateConfig(_json = json) - } + /** + * 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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply } - return ConversionRateConfig(_json = json) + known() + validated = true } - } - internal class Serializer : - BaseSerializer(ConversionRateConfig::class) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun serialize( - value: ConversionRateConfig, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.tiered != null -> generator.writeObject(value.tiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid ConversionRateConfig") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is CompositePriceFilter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositePriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" } - class GroupedWithMinMaxThresholdsConfig - @JsonCreator + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not have a + * value for the `unit_rating_key`. If not provided, events missing a unit rate will be + * ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events will also + * be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + @JsonAnyGetter @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) companion object { /** - * Returns a mutable builder for constructing an instance of - * [GroupedWithMinMaxThresholdsConfig]. + * Returns a mutable builder for constructing an instance of [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` */ fun builder() = Builder() } - /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + /** A builder for [EventOutputConfig]. */ class Builder internal constructor() { + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - internal fun from( - groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig - ) = apply { - additionalProperties = - groupedWithMinMaxThresholdsConfig.additionalProperties.toMutableMap() + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = eventOutputConfig.additionalProperties.toMutableMap() + } + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey + } + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a unit + * rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate + } + + /** + * An optional key in the event data to group by (e.g., event ID). All events will + * also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey } fun additionalProperties(additionalProperties: Map) = apply { @@ -57802,21 +90985,36 @@ private constructor( } /** - * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * Returns an immutable instance of [EventOutputConfig]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): GroupedWithMinMaxThresholdsConfig = - GroupedWithMinMaxThresholdsConfig(additionalProperties.toImmutable()) + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + fun validate(): EventOutputConfig = apply { if (validated) { return@apply } + unitRatingKey() + defaultUnitRate() + groupingKey() validated = true } @@ -57835,24 +91033,30 @@ private constructor( * Used for best match union deserialization. */ internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupedWithMinMaxThresholdsConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(unitRatingKey, defaultUnitRate, groupingKey, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedWithMinMaxThresholdsConfig{additionalProperties=$additionalProperties}" + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" } /** @@ -57950,12 +91154,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -57981,6 +91183,8 @@ private constructor( val FIXED_PRICE = of("fixed_price") + val COMPOSITE_PRICE = of("composite_price") + fun of(value: String) = PriceType(JsonField.of(value)) } @@ -57988,6 +91192,7 @@ private constructor( enum class Known { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, } /** @@ -58002,6 +91207,7 @@ private constructor( enum class Value { USAGE_PRICE, FIXED_PRICE, + COMPOSITE_PRICE, /** * An enum member indicating that [PriceType] was instantiated with an unknown * value. @@ -58020,6 +91226,7 @@ private constructor( when (this) { USAGE_PRICE -> Value.USAGE_PRICE FIXED_PRICE -> Value.FIXED_PRICE + COMPOSITE_PRICE -> Value.COMPOSITE_PRICE else -> Value._UNKNOWN } @@ -58036,6 +91243,7 @@ private constructor( when (this) { USAGE_PRICE -> Known.USAGE_PRICE FIXED_PRICE -> Known.FIXED_PRICE + COMPOSITE_PRICE -> Known.COMPOSITE_PRICE else -> throw OrbInvalidDataException("Unknown PriceType: $value") } @@ -58083,7 +91291,7 @@ private constructor( return true } - return /* spotless:off */ other is PriceType && value == other.value /* spotless:on */ + return other is PriceType && value == other.value } override fun hashCode() = value.hashCode() @@ -58096,16 +91304,75 @@ private constructor( return true } - return /* spotless:off */ other is GroupedWithMinMaxThresholds && id == other.id && billableMetric == other.billableMetric && billingCycleConfiguration == other.billingCycleConfiguration && cadence == other.cadence && conversionRate == other.conversionRate && conversionRateConfig == other.conversionRateConfig && createdAt == other.createdAt && creditAllocation == other.creditAllocation && currency == other.currency && discount == other.discount && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && groupedWithMinMaxThresholdsConfig == other.groupedWithMinMaxThresholdsConfig && invoicingCycleConfiguration == other.invoicingCycleConfiguration && item == other.item && maximum == other.maximum && maximumAmount == other.maximumAmount && metadata == other.metadata && minimum == other.minimum && minimumAmount == other.minimumAmount && modelType == other.modelType && name == other.name && planPhaseOrder == other.planPhaseOrder && priceType == other.priceType && replacesPriceId == other.replacesPriceId && dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EventOutput && + id == other.id && + billableMetric == other.billableMetric && + billingCycleConfiguration == other.billingCycleConfiguration && + billingMode == other.billingMode && + cadence == other.cadence && + compositePriceFilters == other.compositePriceFilters && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + createdAt == other.createdAt && + creditAllocation == other.creditAllocation && + currency == other.currency && + discount == other.discount && + eventOutputConfig == other.eventOutputConfig && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + item == other.item && + maximum == other.maximum && + maximumAmount == other.maximumAmount && + metadata == other.metadata && + minimum == other.minimum && + minimumAmount == other.minimumAmount && + modelType == other.modelType && + name == other.name && + planPhaseOrder == other.planPhaseOrder && + priceType == other.priceType && + replacesPriceId == other.replacesPriceId && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billableMetric, billingCycleConfiguration, cadence, conversionRate, conversionRateConfig, createdAt, creditAllocation, currency, discount, externalPriceId, fixedPriceQuantity, groupedWithMinMaxThresholdsConfig, invoicingCycleConfiguration, item, maximum, maximumAmount, metadata, minimum, minimumAmount, modelType, name, planPhaseOrder, priceType, replacesPriceId, dimensionalPriceConfiguration, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billableMetric, + billingCycleConfiguration, + billingMode, + cadence, + compositePriceFilters, + conversionRate, + conversionRateConfig, + createdAt, + creditAllocation, + currency, + discount, + eventOutputConfig, + externalPriceId, + fixedPriceQuantity, + invoicingCycleConfiguration, + item, + maximum, + maximumAmount, + metadata, + minimum, + minimumAmount, + modelType, + name, + planPhaseOrder, + priceType, + replacesPriceId, + dimensionalPriceConfiguration, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "GroupedWithMinMaxThresholds{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, cadence=$cadence, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" + "EventOutput{id=$id, billableMetric=$billableMetric, billingCycleConfiguration=$billingCycleConfiguration, billingMode=$billingMode, cadence=$cadence, compositePriceFilters=$compositePriceFilters, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, createdAt=$createdAt, creditAllocation=$creditAllocation, currency=$currency, discount=$discount, eventOutputConfig=$eventOutputConfig, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoicingCycleConfiguration=$invoicingCycleConfiguration, item=$item, maximum=$maximum, maximumAmount=$maximumAmount, metadata=$metadata, minimum=$minimum, minimumAmount=$minimumAmount, modelType=$modelType, name=$name, planPhaseOrder=$planPhaseOrder, priceType=$priceType, replacesPriceId=$replacesPriceId, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, additionalProperties=$additionalProperties}" } } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceCreateParams.kt index c4d7ff65e..7f2d53df8 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceCreateParams.kt @@ -2,6 +2,10 @@ package com.withorb.api.models +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.core.ObjectCodec import com.fasterxml.jackson.databind.JsonNode @@ -11,13 +15,20 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.withorb.api.core.BaseDeserializer import com.withorb.api.core.BaseSerializer +import com.withorb.api.core.Enum +import com.withorb.api.core.ExcludeMissing +import com.withorb.api.core.JsonField +import com.withorb.api.core.JsonMissing import com.withorb.api.core.JsonValue import com.withorb.api.core.Params +import com.withorb.api.core.checkKnown import com.withorb.api.core.checkRequired import com.withorb.api.core.getOrThrow import com.withorb.api.core.http.Headers import com.withorb.api.core.http.QueryParams +import com.withorb.api.core.toImmutable import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections import java.util.Objects /** @@ -39,6 +50,7 @@ private constructor( private val additionalQueryParams: QueryParams, ) : Params { + /** New floating price request body params. */ fun body(): Body = body /** Additional headers to send with the request. */ @@ -75,35 +87,27 @@ private constructor( additionalQueryParams = priceCreateParams.additionalQueryParams.toBuilder() } + /** New floating price request body params. */ fun body(body: Body) = apply { this.body = body } /** Alias for calling [body] with `Body.ofUnit(unit)`. */ fun body(unit: NewFloatingUnitPrice) = body(Body.ofUnit(unit)) - /** Alias for calling [body] with `Body.ofPackage(package_)`. */ - fun body(package_: NewFloatingPackagePrice) = body(Body.ofPackage(package_)) - - /** Alias for calling [body] with `Body.ofMatrix(matrix)`. */ - fun body(matrix: NewFloatingMatrixPrice) = body(Body.ofMatrix(matrix)) - - /** Alias for calling [body] with `Body.ofMatrixWithAllocation(matrixWithAllocation)`. */ - fun body(matrixWithAllocation: NewFloatingMatrixWithAllocationPrice) = - body(Body.ofMatrixWithAllocation(matrixWithAllocation)) - /** Alias for calling [body] with `Body.ofTiered(tiered)`. */ fun body(tiered: NewFloatingTieredPrice) = body(Body.ofTiered(tiered)) - /** Alias for calling [body] with `Body.ofTieredBps(tieredBps)`. */ - fun body(tieredBps: NewFloatingTieredBpsPrice) = body(Body.ofTieredBps(tieredBps)) + /** Alias for calling [body] with `Body.ofBulk(bulk)`. */ + fun body(bulk: NewFloatingBulkPrice) = body(Body.ofBulk(bulk)) - /** Alias for calling [body] with `Body.ofBps(bps)`. */ - fun body(bps: NewFloatingBpsPrice) = body(Body.ofBps(bps)) + /** Alias for calling [body] with `Body.ofBulkWithFilters(bulkWithFilters)`. */ + fun body(bulkWithFilters: Body.BulkWithFilters) = + body(Body.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [body] with `Body.ofBulkBps(bulkBps)`. */ - fun body(bulkBps: NewFloatingBulkBpsPrice) = body(Body.ofBulkBps(bulkBps)) + /** Alias for calling [body] with `Body.ofPackage(package_)`. */ + fun body(package_: NewFloatingPackagePrice) = body(Body.ofPackage(package_)) - /** Alias for calling [body] with `Body.ofBulk(bulk)`. */ - fun body(bulk: NewFloatingBulkPrice) = body(Body.ofBulk(bulk)) + /** Alias for calling [body] with `Body.ofMatrix(matrix)`. */ + fun body(matrix: NewFloatingMatrixPrice) = body(Body.ofMatrix(matrix)) /** Alias for calling [body] with `Body.ofThresholdTotalAmount(thresholdTotalAmount)`. */ fun body(thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice) = @@ -113,21 +117,13 @@ private constructor( fun body(tieredPackage: NewFloatingTieredPackagePrice) = body(Body.ofTieredPackage(tieredPackage)) - /** Alias for calling [body] with `Body.ofGroupedTiered(groupedTiered)`. */ - fun body(groupedTiered: NewFloatingGroupedTieredPrice) = - body(Body.ofGroupedTiered(groupedTiered)) - - /** Alias for calling [body] with `Body.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. */ - fun body(maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice) = - body(Body.ofMaxGroupTieredPackage(maxGroupTieredPackage)) - /** Alias for calling [body] with `Body.ofTieredWithMinimum(tieredWithMinimum)`. */ fun body(tieredWithMinimum: NewFloatingTieredWithMinimumPrice) = body(Body.ofTieredWithMinimum(tieredWithMinimum)) - /** Alias for calling [body] with `Body.ofPackageWithAllocation(packageWithAllocation)`. */ - fun body(packageWithAllocation: NewFloatingPackageWithAllocationPrice) = - body(Body.ofPackageWithAllocation(packageWithAllocation)) + /** Alias for calling [body] with `Body.ofGroupedTiered(groupedTiered)`. */ + fun body(groupedTiered: NewFloatingGroupedTieredPrice) = + body(Body.ofGroupedTiered(groupedTiered)) /** * Alias for calling [body] with @@ -136,10 +132,18 @@ private constructor( fun body(tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice) = body(Body.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + /** Alias for calling [body] with `Body.ofPackageWithAllocation(packageWithAllocation)`. */ + fun body(packageWithAllocation: NewFloatingPackageWithAllocationPrice) = + body(Body.ofPackageWithAllocation(packageWithAllocation)) + /** Alias for calling [body] with `Body.ofUnitWithPercent(unitWithPercent)`. */ fun body(unitWithPercent: NewFloatingUnitWithPercentPrice) = body(Body.ofUnitWithPercent(unitWithPercent)) + /** Alias for calling [body] with `Body.ofMatrixWithAllocation(matrixWithAllocation)`. */ + fun body(matrixWithAllocation: NewFloatingMatrixWithAllocationPrice) = + body(Body.ofMatrixWithAllocation(matrixWithAllocation)) + /** Alias for calling [body] with `Body.ofTieredWithProration(tieredWithProration)`. */ fun body(tieredWithProration: NewFloatingTieredWithProrationPrice) = body(Body.ofTieredWithProration(tieredWithProration)) @@ -152,6 +156,10 @@ private constructor( fun body(groupedAllocation: NewFloatingGroupedAllocationPrice) = body(Body.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [body] with `Body.ofBulkWithProration(bulkWithProration)`. */ + fun body(bulkWithProration: NewFloatingBulkWithProrationPrice) = + body(Body.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [body] with * `Body.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -166,18 +174,25 @@ private constructor( fun body(groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice) = body(Body.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [body] with + * `Body.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun body(groupedWithMinMaxThresholds: Body.GroupedWithMinMaxThresholds) = + body(Body.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** Alias for calling [body] with `Body.ofMatrixWithDisplayName(matrixWithDisplayName)`. */ fun body(matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice) = body(Body.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [body] with `Body.ofBulkWithProration(bulkWithProration)`. */ - fun body(bulkWithProration: NewFloatingBulkWithProrationPrice) = - body(Body.ofBulkWithProration(bulkWithProration)) - /** Alias for calling [body] with `Body.ofGroupedTieredPackage(groupedTieredPackage)`. */ fun body(groupedTieredPackage: NewFloatingGroupedTieredPackagePrice) = body(Body.ofGroupedTieredPackage(groupedTieredPackage)) + /** Alias for calling [body] with `Body.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. */ + fun body(maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice) = + body(Body.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + /** * Alias for calling [body] with * `Body.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. @@ -196,6 +211,22 @@ private constructor( fun body(cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice) = body(Body.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + /** + * Alias for calling [body] with + * `Body.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. + */ + fun body(cumulativeGroupedAllocation: Body.CumulativeGroupedAllocation) = + body(Body.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [body] with `Body.ofMinimum(minimum)`. */ + fun body(minimum: NewFloatingMinimumCompositePrice) = body(Body.ofMinimum(minimum)) + + /** Alias for calling [body] with `Body.ofPercent(percent)`. */ + fun body(percent: Body.Percent) = body(Body.ofPercent(percent)) + + /** Alias for calling [body] with `Body.ofEventOutput(eventOutput)`. */ + fun body(eventOutput: Body.EventOutput) = body(Body.ofEventOutput(eventOutput)) + fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -320,97 +351,100 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams + /** New floating price request body params. */ @JsonDeserialize(using = Body.Deserializer::class) @JsonSerialize(using = Body.Serializer::class) class Body private constructor( private val unit: NewFloatingUnitPrice? = null, - private val package_: NewFloatingPackagePrice? = null, - private val matrix: NewFloatingMatrixPrice? = null, - private val matrixWithAllocation: NewFloatingMatrixWithAllocationPrice? = null, private val tiered: NewFloatingTieredPrice? = null, - private val tieredBps: NewFloatingTieredBpsPrice? = null, - private val bps: NewFloatingBpsPrice? = null, - private val bulkBps: NewFloatingBulkBpsPrice? = null, private val bulk: NewFloatingBulkPrice? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: NewFloatingPackagePrice? = null, + private val matrix: NewFloatingMatrixPrice? = null, private val thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice? = null, private val tieredPackage: NewFloatingTieredPackagePrice? = null, - private val groupedTiered: NewFloatingGroupedTieredPrice? = null, - private val maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice? = null, private val tieredWithMinimum: NewFloatingTieredWithMinimumPrice? = null, - private val packageWithAllocation: NewFloatingPackageWithAllocationPrice? = null, + private val groupedTiered: NewFloatingGroupedTieredPrice? = null, private val tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice? = null, + private val packageWithAllocation: NewFloatingPackageWithAllocationPrice? = null, private val unitWithPercent: NewFloatingUnitWithPercentPrice? = null, + private val matrixWithAllocation: NewFloatingMatrixWithAllocationPrice? = null, private val tieredWithProration: NewFloatingTieredWithProrationPrice? = null, private val unitWithProration: NewFloatingUnitWithProrationPrice? = null, private val groupedAllocation: NewFloatingGroupedAllocationPrice? = null, + private val bulkWithProration: NewFloatingBulkWithProrationPrice? = null, private val groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice? = null, private val groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice? = null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, private val matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice? = null, - private val bulkWithProration: NewFloatingBulkWithProrationPrice? = null, private val groupedTieredPackage: NewFloatingGroupedTieredPackagePrice? = null, + private val maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice? = null, private val scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice? = null, private val scalableMatrixWithTieredPricing: NewFloatingScalableMatrixWithTieredPricingPrice? = null, private val cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: NewFloatingMinimumCompositePrice? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, private val _json: JsonValue? = null, ) { fun unit(): NewFloatingUnitPrice? = unit - fun package_(): NewFloatingPackagePrice? = package_ - - fun matrix(): NewFloatingMatrixPrice? = matrix - - fun matrixWithAllocation(): NewFloatingMatrixWithAllocationPrice? = matrixWithAllocation - fun tiered(): NewFloatingTieredPrice? = tiered - fun tieredBps(): NewFloatingTieredBpsPrice? = tieredBps + fun bulk(): NewFloatingBulkPrice? = bulk - fun bps(): NewFloatingBpsPrice? = bps + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters - fun bulkBps(): NewFloatingBulkBpsPrice? = bulkBps + fun package_(): NewFloatingPackagePrice? = package_ - fun bulk(): NewFloatingBulkPrice? = bulk + fun matrix(): NewFloatingMatrixPrice? = matrix fun thresholdTotalAmount(): NewFloatingThresholdTotalAmountPrice? = thresholdTotalAmount fun tieredPackage(): NewFloatingTieredPackagePrice? = tieredPackage - fun groupedTiered(): NewFloatingGroupedTieredPrice? = groupedTiered - - fun maxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice? = maxGroupTieredPackage - fun tieredWithMinimum(): NewFloatingTieredWithMinimumPrice? = tieredWithMinimum - fun packageWithAllocation(): NewFloatingPackageWithAllocationPrice? = packageWithAllocation + fun groupedTiered(): NewFloatingGroupedTieredPrice? = groupedTiered fun tieredPackageWithMinimum(): NewFloatingTieredPackageWithMinimumPrice? = tieredPackageWithMinimum + fun packageWithAllocation(): NewFloatingPackageWithAllocationPrice? = packageWithAllocation + fun unitWithPercent(): NewFloatingUnitWithPercentPrice? = unitWithPercent + fun matrixWithAllocation(): NewFloatingMatrixWithAllocationPrice? = matrixWithAllocation + fun tieredWithProration(): NewFloatingTieredWithProrationPrice? = tieredWithProration fun unitWithProration(): NewFloatingUnitWithProrationPrice? = unitWithProration fun groupedAllocation(): NewFloatingGroupedAllocationPrice? = groupedAllocation + fun bulkWithProration(): NewFloatingBulkWithProrationPrice? = bulkWithProration + fun groupedWithProratedMinimum(): NewFloatingGroupedWithProratedMinimumPrice? = groupedWithProratedMinimum fun groupedWithMeteredMinimum(): NewFloatingGroupedWithMeteredMinimumPrice? = groupedWithMeteredMinimum - fun matrixWithDisplayName(): NewFloatingMatrixWithDisplayNamePrice? = matrixWithDisplayName + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = + groupedWithMinMaxThresholds - fun bulkWithProration(): NewFloatingBulkWithProrationPrice? = bulkWithProration + fun matrixWithDisplayName(): NewFloatingMatrixWithDisplayNamePrice? = matrixWithDisplayName fun groupedTieredPackage(): NewFloatingGroupedTieredPackagePrice? = groupedTieredPackage + fun maxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice? = maxGroupTieredPackage + fun scalableMatrixWithUnitPricing(): NewFloatingScalableMatrixWithUnitPricingPrice? = scalableMatrixWithUnitPricing @@ -419,80 +453,88 @@ private constructor( fun cumulativeGroupedBulk(): NewFloatingCumulativeGroupedBulkPrice? = cumulativeGroupedBulk - fun isUnit(): Boolean = unit != null + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = + cumulativeGroupedAllocation - fun isPackage(): Boolean = package_ != null + fun minimum(): NewFloatingMinimumCompositePrice? = minimum - fun isMatrix(): Boolean = matrix != null + fun percent(): Percent? = percent - fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun eventOutput(): EventOutput? = eventOutput + + fun isUnit(): Boolean = unit != null fun isTiered(): Boolean = tiered != null - fun isTieredBps(): Boolean = tieredBps != null + fun isBulk(): Boolean = bulk != null - fun isBps(): Boolean = bps != null + fun isBulkWithFilters(): Boolean = bulkWithFilters != null - fun isBulkBps(): Boolean = bulkBps != null + fun isPackage(): Boolean = package_ != null - fun isBulk(): Boolean = bulk != null + fun isMatrix(): Boolean = matrix != null fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null fun isTieredPackage(): Boolean = tieredPackage != null - fun isGroupedTiered(): Boolean = groupedTiered != null - - fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null - fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null - fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + fun isGroupedTiered(): Boolean = groupedTiered != null fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + fun isUnitWithPercent(): Boolean = unitWithPercent != null + fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isTieredWithProration(): Boolean = tieredWithProration != null fun isUnitWithProration(): Boolean = unitWithProration != null fun isGroupedAllocation(): Boolean = groupedAllocation != null + fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null - fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null + fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null fun isScalableMatrixWithTieredPricing(): Boolean = scalableMatrixWithTieredPricing != null fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null - fun asUnit(): NewFloatingUnitPrice = unit.getOrThrow("unit") + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null - fun asPackage(): NewFloatingPackagePrice = package_.getOrThrow("package_") + fun isMinimum(): Boolean = minimum != null - fun asMatrix(): NewFloatingMatrixPrice = matrix.getOrThrow("matrix") + fun isPercent(): Boolean = percent != null - fun asMatrixWithAllocation(): NewFloatingMatrixWithAllocationPrice = - matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun isEventOutput(): Boolean = eventOutput != null + + fun asUnit(): NewFloatingUnitPrice = unit.getOrThrow("unit") fun asTiered(): NewFloatingTieredPrice = tiered.getOrThrow("tiered") - fun asTieredBps(): NewFloatingTieredBpsPrice = tieredBps.getOrThrow("tieredBps") + fun asBulk(): NewFloatingBulkPrice = bulk.getOrThrow("bulk") - fun asBps(): NewFloatingBpsPrice = bps.getOrThrow("bps") + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") - fun asBulkBps(): NewFloatingBulkBpsPrice = bulkBps.getOrThrow("bulkBps") + fun asPackage(): NewFloatingPackagePrice = package_.getOrThrow("package_") - fun asBulk(): NewFloatingBulkPrice = bulk.getOrThrow("bulk") + fun asMatrix(): NewFloatingMatrixPrice = matrix.getOrThrow("matrix") fun asThresholdTotalAmount(): NewFloatingThresholdTotalAmountPrice = thresholdTotalAmount.getOrThrow("thresholdTotalAmount") @@ -500,24 +542,24 @@ private constructor( fun asTieredPackage(): NewFloatingTieredPackagePrice = tieredPackage.getOrThrow("tieredPackage") - fun asGroupedTiered(): NewFloatingGroupedTieredPrice = - groupedTiered.getOrThrow("groupedTiered") - - fun asMaxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice = - maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") - fun asTieredWithMinimum(): NewFloatingTieredWithMinimumPrice = tieredWithMinimum.getOrThrow("tieredWithMinimum") - fun asPackageWithAllocation(): NewFloatingPackageWithAllocationPrice = - packageWithAllocation.getOrThrow("packageWithAllocation") + fun asGroupedTiered(): NewFloatingGroupedTieredPrice = + groupedTiered.getOrThrow("groupedTiered") fun asTieredPackageWithMinimum(): NewFloatingTieredPackageWithMinimumPrice = tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + fun asPackageWithAllocation(): NewFloatingPackageWithAllocationPrice = + packageWithAllocation.getOrThrow("packageWithAllocation") + fun asUnitWithPercent(): NewFloatingUnitWithPercentPrice = unitWithPercent.getOrThrow("unitWithPercent") + fun asMatrixWithAllocation(): NewFloatingMatrixWithAllocationPrice = + matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun asTieredWithProration(): NewFloatingTieredWithProrationPrice = tieredWithProration.getOrThrow("tieredWithProration") @@ -527,21 +569,27 @@ private constructor( fun asGroupedAllocation(): NewFloatingGroupedAllocationPrice = groupedAllocation.getOrThrow("groupedAllocation") + fun asBulkWithProration(): NewFloatingBulkWithProrationPrice = + bulkWithProration.getOrThrow("bulkWithProration") + fun asGroupedWithProratedMinimum(): NewFloatingGroupedWithProratedMinimumPrice = groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") fun asGroupedWithMeteredMinimum(): NewFloatingGroupedWithMeteredMinimumPrice = groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") + fun asMatrixWithDisplayName(): NewFloatingMatrixWithDisplayNamePrice = matrixWithDisplayName.getOrThrow("matrixWithDisplayName") - fun asBulkWithProration(): NewFloatingBulkWithProrationPrice = - bulkWithProration.getOrThrow("bulkWithProration") - fun asGroupedTieredPackage(): NewFloatingGroupedTieredPackagePrice = groupedTieredPackage.getOrThrow("groupedTieredPackage") + fun asMaxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice = + maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") + fun asScalableMatrixWithUnitPricing(): NewFloatingScalableMatrixWithUnitPricingPrice = scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") @@ -551,50 +599,64 @@ private constructor( fun asCumulativeGroupedBulk(): NewFloatingCumulativeGroupedBulkPrice = cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") + + fun asMinimum(): NewFloatingMinimumCompositePrice = minimum.getOrThrow("minimum") + + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") + fun _json(): JsonValue? = _json fun accept(visitor: Visitor): T = when { unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) - matrixWithAllocation != null -> - visitor.visitMatrixWithAllocation(matrixWithAllocation) tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) thresholdTotalAmount != null -> visitor.visitThresholdTotalAmount(thresholdTotalAmount) tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) - maxGroupTieredPackage != null -> - visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) - packageWithAllocation != null -> - visitor.visitPackageWithAllocation(packageWithAllocation) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) tieredPackageWithMinimum != null -> visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) + packageWithAllocation != null -> + visitor.visitPackageWithAllocation(packageWithAllocation) unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + matrixWithAllocation != null -> + visitor.visitMatrixWithAllocation(matrixWithAllocation) tieredWithProration != null -> visitor.visitTieredWithProration(tieredWithProration) unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedWithProratedMinimum != null -> visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) groupedWithMeteredMinimum != null -> visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) matrixWithDisplayName != null -> visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedTieredPackage != null -> visitor.visitGroupedTieredPackage(groupedTieredPackage) + maxGroupTieredPackage != null -> + visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) scalableMatrixWithUnitPricing != null -> visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) scalableMatrixWithTieredPricing != null -> visitor.visitScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing) cumulativeGroupedBulk != null -> visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) else -> visitor.unknown(_json) } @@ -611,38 +673,24 @@ private constructor( unit.validate() } - override fun visitPackage(package_: NewFloatingPackagePrice) { - package_.validate() - } - - override fun visitMatrix(matrix: NewFloatingMatrixPrice) { - matrix.validate() - } - - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ) { - matrixWithAllocation.validate() - } - override fun visitTiered(tiered: NewFloatingTieredPrice) { tiered.validate() } - override fun visitTieredBps(tieredBps: NewFloatingTieredBpsPrice) { - tieredBps.validate() + override fun visitBulk(bulk: NewFloatingBulkPrice) { + bulk.validate() } - override fun visitBps(bps: NewFloatingBpsPrice) { - bps.validate() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() } - override fun visitBulkBps(bulkBps: NewFloatingBulkBpsPrice) { - bulkBps.validate() + override fun visitPackage(package_: NewFloatingPackagePrice) { + package_.validate() } - override fun visitBulk(bulk: NewFloatingBulkPrice) { - bulk.validate() + override fun visitMatrix(matrix: NewFloatingMatrixPrice) { + matrix.validate() } override fun visitThresholdTotalAmount( @@ -655,26 +703,14 @@ private constructor( tieredPackage.validate() } - override fun visitGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice) { - groupedTiered.validate() - } - - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice - ) { - maxGroupTieredPackage.validate() - } - override fun visitTieredWithMinimum( tieredWithMinimum: NewFloatingTieredWithMinimumPrice ) { tieredWithMinimum.validate() } - override fun visitPackageWithAllocation( - packageWithAllocation: NewFloatingPackageWithAllocationPrice - ) { - packageWithAllocation.validate() + override fun visitGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice) { + groupedTiered.validate() } override fun visitTieredPackageWithMinimum( @@ -683,12 +719,24 @@ private constructor( tieredPackageWithMinimum.validate() } + override fun visitPackageWithAllocation( + packageWithAllocation: NewFloatingPackageWithAllocationPrice + ) { + packageWithAllocation.validate() + } + override fun visitUnitWithPercent( unitWithPercent: NewFloatingUnitWithPercentPrice ) { unitWithPercent.validate() } + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ) { + matrixWithAllocation.validate() + } + override fun visitTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ) { @@ -707,6 +755,12 @@ private constructor( groupedAllocation.validate() } + override fun visitBulkWithProration( + bulkWithProration: NewFloatingBulkWithProrationPrice + ) { + bulkWithProration.validate() + } + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ) { @@ -719,22 +773,28 @@ private constructor( groupedWithMeteredMinimum.validate() } + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) { + groupedWithMinMaxThresholds.validate() + } + override fun visitMatrixWithDisplayName( matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ) { matrixWithDisplayName.validate() } - override fun visitBulkWithProration( - bulkWithProration: NewFloatingBulkWithProrationPrice + override fun visitGroupedTieredPackage( + groupedTieredPackage: NewFloatingGroupedTieredPackagePrice ) { - bulkWithProration.validate() + groupedTieredPackage.validate() } - override fun visitGroupedTieredPackage( - groupedTieredPackage: NewFloatingGroupedTieredPackagePrice + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice ) { - groupedTieredPackage.validate() + maxGroupTieredPackage.validate() } override fun visitScalableMatrixWithUnitPricing( @@ -755,6 +815,24 @@ private constructor( ) { cumulativeGroupedBulk.validate() } + + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) { + cumulativeGroupedAllocation.validate() + } + + override fun visitMinimum(minimum: NewFloatingMinimumCompositePrice) { + minimum.validate() + } + + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() + } } ) validated = true @@ -779,25 +857,17 @@ private constructor( object : Visitor { override fun visitUnit(unit: NewFloatingUnitPrice) = unit.validity() - override fun visitPackage(package_: NewFloatingPackagePrice) = - package_.validity() - - override fun visitMatrix(matrix: NewFloatingMatrixPrice) = matrix.validity() - - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ) = matrixWithAllocation.validity() - override fun visitTiered(tiered: NewFloatingTieredPrice) = tiered.validity() - override fun visitTieredBps(tieredBps: NewFloatingTieredBpsPrice) = - tieredBps.validity() + override fun visitBulk(bulk: NewFloatingBulkPrice) = bulk.validity() - override fun visitBps(bps: NewFloatingBpsPrice) = bps.validity() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() - override fun visitBulkBps(bulkBps: NewFloatingBulkBpsPrice) = bulkBps.validity() + override fun visitPackage(package_: NewFloatingPackagePrice) = + package_.validity() - override fun visitBulk(bulk: NewFloatingBulkPrice) = bulk.validity() + override fun visitMatrix(matrix: NewFloatingMatrixPrice) = matrix.validity() override fun visitThresholdTotalAmount( thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice @@ -806,29 +876,29 @@ private constructor( override fun visitTieredPackage(tieredPackage: NewFloatingTieredPackagePrice) = tieredPackage.validity() - override fun visitGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice) = - groupedTiered.validity() - - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice - ) = maxGroupTieredPackage.validity() - override fun visitTieredWithMinimum( tieredWithMinimum: NewFloatingTieredWithMinimumPrice ) = tieredWithMinimum.validity() - override fun visitPackageWithAllocation( - packageWithAllocation: NewFloatingPackageWithAllocationPrice - ) = packageWithAllocation.validity() + override fun visitGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice) = + groupedTiered.validity() override fun visitTieredPackageWithMinimum( tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice ) = tieredPackageWithMinimum.validity() + override fun visitPackageWithAllocation( + packageWithAllocation: NewFloatingPackageWithAllocationPrice + ) = packageWithAllocation.validity() + override fun visitUnitWithPercent( unitWithPercent: NewFloatingUnitWithPercentPrice ) = unitWithPercent.validity() + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ) = matrixWithAllocation.validity() + override fun visitTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ) = tieredWithProration.validity() @@ -841,6 +911,10 @@ private constructor( groupedAllocation: NewFloatingGroupedAllocationPrice ) = groupedAllocation.validity() + override fun visitBulkWithProration( + bulkWithProration: NewFloatingBulkWithProrationPrice + ) = bulkWithProration.validity() + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ) = groupedWithProratedMinimum.validity() @@ -849,18 +923,22 @@ private constructor( groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice ) = groupedWithMeteredMinimum.validity() + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + override fun visitMatrixWithDisplayName( matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ) = matrixWithDisplayName.validity() - override fun visitBulkWithProration( - bulkWithProration: NewFloatingBulkWithProrationPrice - ) = bulkWithProration.validity() - override fun visitGroupedTieredPackage( groupedTieredPackage: NewFloatingGroupedTieredPackagePrice ) = groupedTieredPackage.validity() + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ) = maxGroupTieredPackage.validity() + override fun visitScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice ) = scalableMatrixWithUnitPricing.validity() @@ -874,6 +952,17 @@ private constructor( cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice ) = cumulativeGroupedBulk.validity() + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() + + override fun visitMinimum(minimum: NewFloatingMinimumCompositePrice) = + minimum.validity() + + override fun visitPercent(percent: Percent) = percent.validity() + + override fun visitEventOutput(eventOutput: EventOutput) = eventOutput.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -883,50 +972,119 @@ private constructor( return true } - return /* spotless:off */ other is Body && unit == other.unit && package_ == other.package_ && matrix == other.matrix && matrixWithAllocation == other.matrixWithAllocation && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && groupedTiered == other.groupedTiered && maxGroupTieredPackage == other.maxGroupTieredPackage && tieredWithMinimum == other.tieredWithMinimum && packageWithAllocation == other.packageWithAllocation && tieredPackageWithMinimum == other.tieredPackageWithMinimum && unitWithPercent == other.unitWithPercent && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && bulkWithProration == other.bulkWithProration && groupedTieredPackage == other.groupedTieredPackage && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk /* spotless:on */ + return other is Body && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, matrixWithAllocation, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, groupedTiered, maxGroupTieredPackage, tieredWithMinimum, packageWithAllocation, tieredPackageWithMinimum, unitWithPercent, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, groupedWithMeteredMinimum, matrixWithDisplayName, bulkWithProration, groupedTieredPackage, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) override fun toString(): String = when { unit != null -> "Body{unit=$unit}" - package_ != null -> "Body{package_=$package_}" - matrix != null -> "Body{matrix=$matrix}" - matrixWithAllocation != null -> "Body{matrixWithAllocation=$matrixWithAllocation}" tiered != null -> "Body{tiered=$tiered}" - tieredBps != null -> "Body{tieredBps=$tieredBps}" - bps != null -> "Body{bps=$bps}" - bulkBps != null -> "Body{bulkBps=$bulkBps}" bulk != null -> "Body{bulk=$bulk}" + bulkWithFilters != null -> "Body{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "Body{package_=$package_}" + matrix != null -> "Body{matrix=$matrix}" thresholdTotalAmount != null -> "Body{thresholdTotalAmount=$thresholdTotalAmount}" tieredPackage != null -> "Body{tieredPackage=$tieredPackage}" - groupedTiered != null -> "Body{groupedTiered=$groupedTiered}" - maxGroupTieredPackage != null -> - "Body{maxGroupTieredPackage=$maxGroupTieredPackage}" tieredWithMinimum != null -> "Body{tieredWithMinimum=$tieredWithMinimum}" - packageWithAllocation != null -> - "Body{packageWithAllocation=$packageWithAllocation}" + groupedTiered != null -> "Body{groupedTiered=$groupedTiered}" tieredPackageWithMinimum != null -> "Body{tieredPackageWithMinimum=$tieredPackageWithMinimum}" + packageWithAllocation != null -> + "Body{packageWithAllocation=$packageWithAllocation}" unitWithPercent != null -> "Body{unitWithPercent=$unitWithPercent}" + matrixWithAllocation != null -> "Body{matrixWithAllocation=$matrixWithAllocation}" tieredWithProration != null -> "Body{tieredWithProration=$tieredWithProration}" unitWithProration != null -> "Body{unitWithProration=$unitWithProration}" groupedAllocation != null -> "Body{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "Body{bulkWithProration=$bulkWithProration}" groupedWithProratedMinimum != null -> "Body{groupedWithProratedMinimum=$groupedWithProratedMinimum}" groupedWithMeteredMinimum != null -> "Body{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "Body{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" matrixWithDisplayName != null -> "Body{matrixWithDisplayName=$matrixWithDisplayName}" - bulkWithProration != null -> "Body{bulkWithProration=$bulkWithProration}" groupedTieredPackage != null -> "Body{groupedTieredPackage=$groupedTieredPackage}" + maxGroupTieredPackage != null -> + "Body{maxGroupTieredPackage=$maxGroupTieredPackage}" scalableMatrixWithUnitPricing != null -> "Body{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" scalableMatrixWithTieredPricing != null -> "Body{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" cumulativeGroupedBulk != null -> "Body{cumulativeGroupedBulk=$cumulativeGroupedBulk}" + cumulativeGroupedAllocation != null -> + "Body{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "Body{minimum=$minimum}" + percent != null -> "Body{percent=$percent}" + eventOutput != null -> "Body{eventOutput=$eventOutput}" _json != null -> "Body{_unknown=$_json}" else -> throw IllegalStateException("Invalid Body") } @@ -935,22 +1093,16 @@ private constructor( fun ofUnit(unit: NewFloatingUnitPrice) = Body(unit = unit) - fun ofPackage(package_: NewFloatingPackagePrice) = Body(package_ = package_) - - fun ofMatrix(matrix: NewFloatingMatrixPrice) = Body(matrix = matrix) - - fun ofMatrixWithAllocation(matrixWithAllocation: NewFloatingMatrixWithAllocationPrice) = - Body(matrixWithAllocation = matrixWithAllocation) - fun ofTiered(tiered: NewFloatingTieredPrice) = Body(tiered = tiered) - fun ofTieredBps(tieredBps: NewFloatingTieredBpsPrice) = Body(tieredBps = tieredBps) + fun ofBulk(bulk: NewFloatingBulkPrice) = Body(bulk = bulk) - fun ofBps(bps: NewFloatingBpsPrice) = Body(bps = bps) + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + Body(bulkWithFilters = bulkWithFilters) - fun ofBulkBps(bulkBps: NewFloatingBulkBpsPrice) = Body(bulkBps = bulkBps) + fun ofPackage(package_: NewFloatingPackagePrice) = Body(package_ = package_) - fun ofBulk(bulk: NewFloatingBulkPrice) = Body(bulk = bulk) + fun ofMatrix(matrix: NewFloatingMatrixPrice) = Body(matrix = matrix) fun ofThresholdTotalAmount(thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice) = Body(thresholdTotalAmount = thresholdTotalAmount) @@ -958,27 +1110,26 @@ private constructor( fun ofTieredPackage(tieredPackage: NewFloatingTieredPackagePrice) = Body(tieredPackage = tieredPackage) - fun ofGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice) = - Body(groupedTiered = groupedTiered) - - fun ofMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice - ) = Body(maxGroupTieredPackage = maxGroupTieredPackage) - fun ofTieredWithMinimum(tieredWithMinimum: NewFloatingTieredWithMinimumPrice) = Body(tieredWithMinimum = tieredWithMinimum) - fun ofPackageWithAllocation( - packageWithAllocation: NewFloatingPackageWithAllocationPrice - ) = Body(packageWithAllocation = packageWithAllocation) + fun ofGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice) = + Body(groupedTiered = groupedTiered) fun ofTieredPackageWithMinimum( tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice ) = Body(tieredPackageWithMinimum = tieredPackageWithMinimum) + fun ofPackageWithAllocation( + packageWithAllocation: NewFloatingPackageWithAllocationPrice + ) = Body(packageWithAllocation = packageWithAllocation) + fun ofUnitWithPercent(unitWithPercent: NewFloatingUnitWithPercentPrice) = Body(unitWithPercent = unitWithPercent) + fun ofMatrixWithAllocation(matrixWithAllocation: NewFloatingMatrixWithAllocationPrice) = + Body(matrixWithAllocation = matrixWithAllocation) + fun ofTieredWithProration(tieredWithProration: NewFloatingTieredWithProrationPrice) = Body(tieredWithProration = tieredWithProration) @@ -988,6 +1139,9 @@ private constructor( fun ofGroupedAllocation(groupedAllocation: NewFloatingGroupedAllocationPrice) = Body(groupedAllocation = groupedAllocation) + fun ofBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice) = + Body(bulkWithProration = bulkWithProration) + fun ofGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ) = Body(groupedWithProratedMinimum = groupedWithProratedMinimum) @@ -996,16 +1150,21 @@ private constructor( groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice ) = Body(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = Body(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + fun ofMatrixWithDisplayName( matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ) = Body(matrixWithDisplayName = matrixWithDisplayName) - fun ofBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice) = - Body(bulkWithProration = bulkWithProration) - fun ofGroupedTieredPackage(groupedTieredPackage: NewFloatingGroupedTieredPackagePrice) = Body(groupedTieredPackage = groupedTieredPackage) + fun ofMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ) = Body(maxGroupTieredPackage = maxGroupTieredPackage) + fun ofScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice ) = Body(scalableMatrixWithUnitPricing = scalableMatrixWithUnitPricing) @@ -1017,6 +1176,16 @@ private constructor( fun ofCumulativeGroupedBulk( cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice ) = Body(cumulativeGroupedBulk = cumulativeGroupedBulk) + + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = Body(cumulativeGroupedAllocation = cumulativeGroupedAllocation) + + fun ofMinimum(minimum: NewFloatingMinimumCompositePrice) = Body(minimum = minimum) + + fun ofPercent(percent: Percent) = Body(percent = percent) + + fun ofEventOutput(eventOutput: EventOutput) = Body(eventOutput = eventOutput) } /** An interface that defines how to map each variant of [Body] to a value of type [T]. */ @@ -1024,23 +1193,15 @@ private constructor( fun visitUnit(unit: NewFloatingUnitPrice): T - fun visitPackage(package_: NewFloatingPackagePrice): T - - fun visitMatrix(matrix: NewFloatingMatrixPrice): T - - fun visitMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ): T - fun visitTiered(tiered: NewFloatingTieredPrice): T - fun visitTieredBps(tieredBps: NewFloatingTieredBpsPrice): T + fun visitBulk(bulk: NewFloatingBulkPrice): T - fun visitBps(bps: NewFloatingBpsPrice): T + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T - fun visitBulkBps(bulkBps: NewFloatingBulkBpsPrice): T + fun visitPackage(package_: NewFloatingPackagePrice): T - fun visitBulk(bulk: NewFloatingBulkPrice): T + fun visitMatrix(matrix: NewFloatingMatrixPrice): T fun visitThresholdTotalAmount( thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice @@ -1048,24 +1209,24 @@ private constructor( fun visitTieredPackage(tieredPackage: NewFloatingTieredPackagePrice): T + fun visitTieredWithMinimum(tieredWithMinimum: NewFloatingTieredWithMinimumPrice): T + fun visitGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice): T - fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice ): T - fun visitTieredWithMinimum(tieredWithMinimum: NewFloatingTieredWithMinimumPrice): T - fun visitPackageWithAllocation( packageWithAllocation: NewFloatingPackageWithAllocationPrice ): T - fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice - ): T - fun visitUnitWithPercent(unitWithPercent: NewFloatingUnitWithPercentPrice): T + fun visitMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ): T + fun visitTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ): T @@ -1074,6 +1235,8 @@ private constructor( fun visitGroupedAllocation(groupedAllocation: NewFloatingGroupedAllocationPrice): T + fun visitBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice): T + fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ): T @@ -1082,16 +1245,22 @@ private constructor( groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice ): T + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ): T + fun visitMatrixWithDisplayName( matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ): T - fun visitBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice): T - fun visitGroupedTieredPackage( groupedTieredPackage: NewFloatingGroupedTieredPackagePrice ): T + fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ): T + fun visitScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice ): T @@ -1104,6 +1273,16 @@ private constructor( cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice ): T + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ): T + + fun visitMinimum(minimum: NewFloatingMinimumCompositePrice): T + + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T + /** * Maps an unknown variant of [Body] to a value of type [T]. * @@ -1130,44 +1309,28 @@ private constructor( Body(unit = it, _json = json) } ?: Body(_json = json) } - "package" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Body(package_ = it, _json = json) } ?: Body(_json = json) - } - "matrix" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Body(matrix = it, _json = json) - } ?: Body(_json = json) - } - "matrix_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Body(matrixWithAllocation = it, _json = json) } - ?: Body(_json = json) - } "tiered" -> { return tryDeserialize(node, jacksonTypeRef())?.let { Body(tiered = it, _json = json) } ?: Body(_json = json) } - "tiered_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Body(tieredBps = it, _json = json) } ?: Body(_json = json) + "bulk" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Body(bulk = it, _json = json) + } ?: Body(_json = json) } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Body(bps = it, _json = json) + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Body(bulkWithFilters = it, _json = json) } ?: Body(_json = json) } - "bulk_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Body(bulkBps = it, _json = json) } ?: Body(_json = json) + "package" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Body(package_ = it, _json = json) } ?: Body(_json = json) } - "bulk" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Body(bulk = it, _json = json) + "matrix" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Body(matrix = it, _json = json) } ?: Body(_json = json) } "threshold_total_amount" -> { @@ -1182,24 +1345,24 @@ private constructor( return tryDeserialize(node, jacksonTypeRef()) ?.let { Body(tieredPackage = it, _json = json) } ?: Body(_json = json) } - "grouped_tiered" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Body(groupedTiered = it, _json = json) } ?: Body(_json = json) - } - "max_group_tiered_package" -> { + "tiered_with_minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Body(maxGroupTieredPackage = it, _json = json) } + ?.let { Body(tieredWithMinimum = it, _json = json) } ?: Body(_json = json) } - "tiered_with_minimum" -> { + "grouped_tiered" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Body(groupedTiered = it, _json = json) } ?: Body(_json = json) + } + "tiered_package_with_minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Body(tieredWithMinimum = it, _json = json) } + ?.let { Body(tieredPackageWithMinimum = it, _json = json) } ?: Body(_json = json) } "package_with_allocation" -> { @@ -1210,20 +1373,20 @@ private constructor( ?.let { Body(packageWithAllocation = it, _json = json) } ?: Body(_json = json) } - "tiered_package_with_minimum" -> { + "unit_with_percent" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Body(tieredPackageWithMinimum = it, _json = json) } - ?: Body(_json = json) + ?.let { Body(unitWithPercent = it, _json = json) } ?: Body(_json = json) } - "unit_with_percent" -> { + "matrix_with_allocation" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Body(unitWithPercent = it, _json = json) } ?: Body(_json = json) + ?.let { Body(matrixWithAllocation = it, _json = json) } + ?: Body(_json = json) } "tiered_with_proration" -> { return tryDeserialize( @@ -1249,6 +1412,14 @@ private constructor( ?.let { Body(groupedAllocation = it, _json = json) } ?: Body(_json = json) } + "bulk_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Body(bulkWithProration = it, _json = json) } + ?: Body(_json = json) + } "grouped_with_prorated_minimum" -> { return tryDeserialize( node, @@ -1265,6 +1436,11 @@ private constructor( ?.let { Body(groupedWithMeteredMinimum = it, _json = json) } ?: Body(_json = json) } + "grouped_with_min_max_thresholds" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Body(groupedWithMinMaxThresholds = it, _json = json) } + ?: Body(_json = json) + } "matrix_with_display_name" -> { return tryDeserialize( node, @@ -1273,14 +1449,6 @@ private constructor( ?.let { Body(matrixWithDisplayName = it, _json = json) } ?: Body(_json = json) } - "bulk_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Body(bulkWithProration = it, _json = json) } - ?: Body(_json = json) - } "grouped_tiered_package" -> { return tryDeserialize( node, @@ -1289,6 +1457,14 @@ private constructor( ?.let { Body(groupedTieredPackage = it, _json = json) } ?: Body(_json = json) } + "max_group_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Body(maxGroupTieredPackage = it, _json = json) } + ?: Body(_json = json) + } "scalable_matrix_with_unit_pricing" -> { return tryDeserialize( node, @@ -1313,6 +1489,28 @@ private constructor( ?.let { Body(cumulativeGroupedBulk = it, _json = json) } ?: Body(_json = json) } + "cumulative_grouped_allocation" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Body(cumulativeGroupedAllocation = it, _json = json) } + ?: Body(_json = json) + } + "minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Body(minimum = it, _json = json) } ?: Body(_json = json) + } + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Body(percent = it, _json = json) + } ?: Body(_json = json) + } + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Body(eventOutput = it, _json = json) + } ?: Body(_json = json) + } } return Body(_json = json) @@ -1328,55 +1526,8190 @@ private constructor( ) { when { value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) - value.matrixWithAllocation != null -> - generator.writeObject(value.matrixWithAllocation) value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) value.thresholdTotalAmount != null -> generator.writeObject(value.thresholdTotalAmount) value.tieredPackage != null -> generator.writeObject(value.tieredPackage) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) - value.maxGroupTieredPackage != null -> - generator.writeObject(value.maxGroupTieredPackage) value.tieredWithMinimum != null -> generator.writeObject(value.tieredWithMinimum) - value.packageWithAllocation != null -> - generator.writeObject(value.packageWithAllocation) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) value.tieredPackageWithMinimum != null -> generator.writeObject(value.tieredPackageWithMinimum) + value.packageWithAllocation != null -> + generator.writeObject(value.packageWithAllocation) value.unitWithPercent != null -> generator.writeObject(value.unitWithPercent) + value.matrixWithAllocation != null -> + generator.writeObject(value.matrixWithAllocation) value.tieredWithProration != null -> generator.writeObject(value.tieredWithProration) value.unitWithProration != null -> generator.writeObject(value.unitWithProration) value.groupedAllocation != null -> generator.writeObject(value.groupedAllocation) + value.bulkWithProration != null -> + generator.writeObject(value.bulkWithProration) value.groupedWithProratedMinimum != null -> generator.writeObject(value.groupedWithProratedMinimum) value.groupedWithMeteredMinimum != null -> generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) value.matrixWithDisplayName != null -> generator.writeObject(value.matrixWithDisplayName) - value.bulkWithProration != null -> - generator.writeObject(value.bulkWithProration) value.groupedTieredPackage != null -> generator.writeObject(value.groupedTieredPackage) + value.maxGroupTieredPackage != null -> + generator.writeObject(value.maxGroupTieredPackage) value.scalableMatrixWithUnitPricing != null -> generator.writeObject(value.scalableMatrixWithUnitPricing) value.scalableMatrixWithTieredPricing != null -> generator.writeObject(value.scalableMatrixWithTieredPricing) value.cumulativeGroupedBulk != null -> generator.writeObject(value.cumulativeGroupedBulk) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Body") } } } + + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bulkWithFiltersConfig: JsonField, + private val cadence: JsonField, + private val currency: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") @ExcludeMissing modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + bulkWithFiltersConfig, + cadence, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this is + * true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. If + * unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed by + * setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = bulkWithFiltersConfig + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [BulkWithFilters]. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .currency() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFilters]. */ + class Builder internal constructor() { + + private var bulkWithFiltersConfig: JsonField? = null + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + currency = bulkWithFilters.currency + itemId = bulkWithFilters.itemId + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + billableMetricId = bulkWithFilters.billableMetricId + billedInAdvance = bulkWithFilters.billedInAdvance + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + dimensionalPriceConfiguration = bulkWithFilters.dimensionalPriceConfiguration + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoiceGroupingKey = bulkWithFilters.invoiceGroupingKey + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + metadata = bulkWithFilters.metadata + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() + } + + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: JsonField) = + apply { + this.bulkWithFiltersConfig = bulkWithFiltersConfig + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** The per unit conversion rate of the price currency to the invoicing currency. */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun conversionRateConfig(conversionRateConfig: JsonField) = + apply { + this.conversionRateConfig = conversionRateConfig + } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed + * [NewDimensionalPriceConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BulkWithFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .currency() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFilters = + BulkWithFilters( + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFilters = apply { + if (validated) { + return@apply + } + + bulkWithFiltersConfig().validate() + cadence().validate() + currency() + itemId() + _modelType().let { + if (it != JsonValue.from("bulk_with_filters")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) + + /** + * Property filters to apply (all must match) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun filters(): List = filters.getRequired("filters") + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [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 + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { + + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithFiltersConfig.additionalProperties.toMutableMap() + } + + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed `List` + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + + /** Bulk tiers for rating based on total usage volume */ + 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 [BulkWithFiltersConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } + + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = + propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + propertyKey() + propertyValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filters, tiers, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** The cadence to bill for this price on. */ + class Cadence @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed by + * setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFilters && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bulkWithFiltersConfig, + cadence, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFilters{bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val currency: JsonField, + private val groupedWithMinMaxThresholdsConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + groupedWithMinMaxThresholdsConfig: JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") @ExcludeMissing modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + currency, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * Configuration for grouped_with_min_max_thresholds pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired( + "grouped_with_min_max_thresholds_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this is + * true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. If + * unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed by + * setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. + * + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + fun _groupedWithMinMaxThresholdsConfig(): JsonField = + groupedWithMinMaxThresholdsConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 + * [GroupedWithMinMaxThresholds]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholds]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("grouped_with_min_max_thresholds") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = + apply { + cadence = groupedWithMinMaxThresholds.cadence + currency = groupedWithMinMaxThresholds.currency + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + itemId = groupedWithMinMaxThresholds.itemId + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + billableMetricId = groupedWithMinMaxThresholds.billableMetricId + billedInAdvance = groupedWithMinMaxThresholds.billedInAdvance + billingCycleConfiguration = + groupedWithMinMaxThresholds.billingCycleConfiguration + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + invoiceGroupingKey = groupedWithMinMaxThresholds.invoiceGroupingKey + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + metadata = groupedWithMinMaxThresholds.metadata + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = + groupedWithMinMaxThresholdsConfig( + JsonField.of(groupedWithMinMaxThresholdsConfig) + ) + + /** + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a + * well-typed [GroupedWithMinMaxThresholdsConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: JsonField + ) = apply { + this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** The per unit conversion rate of the price currency to the invoicing currency. */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun conversionRateConfig(conversionRateConfig: JsonField) = + apply { + this.conversionRateConfig = conversionRateConfig + } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed + * [NewDimensionalPriceConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholds = apply { + if (validated) { + return@apply + } + + cadence().validate() + currency() + groupedWithMinMaxThresholdsConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @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 + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate + additionalProperties = + groupedWithMinMaxThresholdsConfig.additionalProperties.toMutableMap() + } + + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } + + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } + + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + if (validated) { + return@apply + } + + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed by + * setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholds && + cadence == other.cadence && + currency == other.currency && + groupedWithMinMaxThresholdsConfig == other.groupedWithMinMaxThresholdsConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholds{cadence=$cadence, currency=$currency, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val cumulativeGroupedAllocationConfig: + JsonField, + private val currency: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: JsonField = + JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") @ExcludeMissing modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + cumulativeGroupedAllocationConfig, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for cumulative_grouped_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired( + "cumulative_grouped_allocation_config" + ) + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this is + * true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. If + * unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed by + * setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): JsonField = + cumulativeGroupedAllocationConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 + * [CumulativeGroupedAllocation]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .currency() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocation]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null + private var currency: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("cumulative_grouped_allocation") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = + apply { + cadence = cumulativeGroupedAllocation.cadence + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + currency = cumulativeGroupedAllocation.currency + itemId = cumulativeGroupedAllocation.itemId + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + billableMetricId = cumulativeGroupedAllocation.billableMetricId + billedInAdvance = cumulativeGroupedAllocation.billedInAdvance + billingCycleConfiguration = + cumulativeGroupedAllocation.billingCycleConfiguration + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoiceGroupingKey = cumulativeGroupedAllocation.invoiceGroupingKey + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + metadata = cumulativeGroupedAllocation.metadata + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = + cumulativeGroupedAllocationConfig( + JsonField.of(cumulativeGroupedAllocationConfig) + ) + + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a + * well-typed [CumulativeGroupedAllocationConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: JsonField + ) = apply { + this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig + } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** The per unit conversion rate of the price currency to the invoicing currency. */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun conversionRateConfig(conversionRateConfig: JsonField) = + apply { + this.conversionRateConfig = conversionRateConfig + } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed + * [NewDimensionalPriceConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .currency() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( + checkRequired("cadence", cadence), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), + checkRequired("currency", currency), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocation = apply { + if (validated) { + return@apply + } + + cadence().validate() + cumulativeGroupedAllocationConfig().validate() + currency() + itemId() + _modelType().let { + if (it != JsonValue.from("cumulative_grouped_allocation")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + mutableMapOf(), + ) + + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 + * [CumulativeGroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = + cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties.toMutableMap() + } + + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } + + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation + } + + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply + } + + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed by + * setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocation && + cadence == other.cadence && + cumulativeGroupedAllocationConfig == other.cumulativeGroupedAllocationConfig && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedAllocationConfig, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocation{cadence=$cadence, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val currency: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val percentConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") @ExcludeMissing modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + currency, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") + + /** + * The id of the billable metric for the price. Only needed if the price is usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this is + * true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. If + * unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed by + * setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [Percent]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .itemId() + * .name() + * .percentConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Percent]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("percent") + private var name: JsonField? = null + private var percentConfig: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percent: Percent) = apply { + cadence = percent.cadence + currency = percent.currency + itemId = percent.itemId + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + billableMetricId = percent.billableMetricId + billedInAdvance = percent.billedInAdvance + billingCycleConfiguration = percent.billingCycleConfiguration + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoiceGroupingKey = percent.invoiceGroupingKey + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + metadata = percent.metadata + additionalProperties = percent.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed [PercentConfig] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** The per unit conversion rate of the price currency to the invoicing currency. */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun conversionRateConfig(conversionRateConfig: JsonField) = + apply { + this.conversionRateConfig = conversionRateConfig + } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed + * [NewDimensionalPriceConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Percent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .itemId() + * .name() + * .percentConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Percent = + Percent( + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("percentConfig", percentConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Percent = apply { + if (validated) { + return@apply + } + + cadence().validate() + currency() + itemId() + _modelType().let { + if (it != JsonValue.from("percent")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + percentConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("percent") @ExcludeMissing fun _percent(): JsonField = percent + + @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 [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PercentConfig]. */ + class Builder internal constructor() { + + private var percent: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() + } + + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PercentConfig = apply { + if (validated) { + return@apply + } + + percent() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(percent, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed by + * setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Percent && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Percent{cadence=$cadence, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, percentConfig=$percentConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val currency: JsonField, + private val eventOutputConfig: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") @ExcludeMissing modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + currency, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this is + * true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. If + * unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed by + * setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cadence") @ExcludeMissing fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [EventOutput]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutput]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var eventOutputConfig: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("event_output") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutput: EventOutput) = apply { + cadence = eventOutput.cadence + currency = eventOutput.currency + eventOutputConfig = eventOutput.eventOutputConfig + itemId = eventOutput.itemId + modelType = eventOutput.modelType + name = eventOutput.name + billableMetricId = eventOutput.billableMetricId + billedInAdvance = eventOutput.billedInAdvance + billingCycleConfiguration = eventOutput.billingCycleConfiguration + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoiceGroupingKey = eventOutput.invoiceGroupingKey + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + metadata = eventOutput.metadata + additionalProperties = eventOutput.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** The per unit conversion rate of the price currency to the invoicing currency. */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun conversionRateConfig(conversionRateConfig: JsonField) = + apply { + this.conversionRateConfig = conversionRateConfig + } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a well-typed + * [NewDimensionalPriceConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = invoicingCycleConfiguration(JsonField.ofNullable(invoicingCycleConfiguration)) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutput = + EventOutput( + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired("eventOutputConfig", eventOutputConfig), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutput = apply { + if (validated) { + return@apply + } + + cadence().validate() + currency() + eventOutputConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("event_output")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a unit + * rate will be ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events will + * also be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @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 + * [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutputConfig]. */ + class Builder internal constructor() { + + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = eventOutputConfig.additionalProperties.toMutableMap() + } + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey + } + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a + * unit rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate + } + + /** + * An optional key in the event data to group by (e.g., event ID). All events + * will also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutputConfig = apply { + if (validated) { + return@apply + } + + unitRatingKey() + defaultUnitRate() + groupingKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitRatingKey, defaultUnitRate, groupingKey, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed by + * setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutput && + cadence == other.cadence && + currency == other.currency && + eventOutputConfig == other.eventOutputConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutput{cadence=$cadence, currency=$currency, eventOutputConfig=$eventOutputConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } } override fun equals(other: Any?): Boolean { @@ -1384,10 +9717,13 @@ private constructor( return true } - return /* spotless:off */ other is PriceCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PriceCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "PriceCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateMultipleParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateMultipleParams.kt index 329c84a66..b8cdeb8e2 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateMultipleParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateMultipleParams.kt @@ -15,6 +15,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.withorb.api.core.BaseDeserializer import com.withorb.api.core.BaseSerializer +import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing @@ -420,6 +421,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val timeframeEnd: JsonField, private val timeframeStart: JsonField, @@ -758,12 +760,25 @@ private constructor( return true } - return /* spotless:off */ other is Body && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && customerId == other.customerId && externalCustomerId == other.externalCustomerId && priceEvaluations == other.priceEvaluations && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + customerId == other.customerId && + externalCustomerId == other.externalCustomerId && + priceEvaluations == other.priceEvaluations && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(timeframeEnd, timeframeStart, customerId, externalCustomerId, priceEvaluations, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + timeframeEnd, + timeframeStart, + customerId, + externalCustomerId, + priceEvaluations, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -772,6 +787,7 @@ private constructor( } class PriceEvaluation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val externalPriceId: JsonField, private val filter: JsonField, @@ -822,8 +838,7 @@ private constructor( fun groupingKeys(): List? = groupingKeys.getNullable("grouping_keys") /** - * An inline price definition to evaluate, allowing you to test price configurations before - * adding them to Orb. + * New floating price request body params. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -976,10 +991,7 @@ private constructor( } } - /** - * An inline price definition to evaluate, allowing you to test price configurations - * before adding them to Orb. - */ + /** New floating price request body params. */ fun price(price: Price?) = price(JsonField.ofNullable(price)) /** @@ -994,32 +1006,21 @@ private constructor( /** Alias for calling [price] with `Price.ofUnit(unit)`. */ fun price(unit: NewFloatingUnitPrice) = price(Price.ofUnit(unit)) - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: NewFloatingPackagePrice) = price(Price.ofPackage(package_)) - - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: NewFloatingMatrixPrice) = price(Price.ofMatrix(matrix)) - - /** - * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. - */ - fun price(matrixWithAllocation: NewFloatingMatrixWithAllocationPrice) = - price(Price.ofMatrixWithAllocation(matrixWithAllocation)) - /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ fun price(tiered: NewFloatingTieredPrice) = price(Price.ofTiered(tiered)) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: NewFloatingTieredBpsPrice) = price(Price.ofTieredBps(tieredBps)) + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: NewFloatingBulkPrice) = price(Price.ofBulk(bulk)) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: NewFloatingBpsPrice) = price(Price.ofBps(bps)) + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: NewFloatingBulkBpsPrice) = price(Price.ofBulkBps(bulkBps)) + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: NewFloatingPackagePrice) = price(Price.ofPackage(package_)) - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: NewFloatingBulkPrice) = price(Price.ofBulk(bulk)) + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: NewFloatingMatrixPrice) = price(Price.ofMatrix(matrix)) /** * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. @@ -1031,20 +1032,20 @@ private constructor( fun price(tieredPackage: NewFloatingTieredPackagePrice) = price(Price.ofTieredPackage(tieredPackage)) + /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ + fun price(tieredWithMinimum: NewFloatingTieredWithMinimumPrice) = + price(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ fun price(groupedTiered: NewFloatingGroupedTieredPrice) = price(Price.ofGroupedTiered(groupedTiered)) /** * Alias for calling [price] with - * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. + * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. */ - fun price(maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice) = - price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) - - /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ - fun price(tieredWithMinimum: NewFloatingTieredWithMinimumPrice) = - price(Price.ofTieredWithMinimum(tieredWithMinimum)) + fun price(tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice) = + price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) /** * Alias for calling [price] with @@ -1053,17 +1054,16 @@ private constructor( fun price(packageWithAllocation: NewFloatingPackageWithAllocationPrice) = price(Price.ofPackageWithAllocation(packageWithAllocation)) - /** - * Alias for calling [price] with - * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. - */ - fun price(tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice) = - price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) - /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ fun price(unitWithPercent: NewFloatingUnitWithPercentPrice) = price(Price.ofUnitWithPercent(unitWithPercent)) + /** + * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun price(matrixWithAllocation: NewFloatingMatrixWithAllocationPrice) = + price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + /** * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. */ @@ -1078,6 +1078,10 @@ private constructor( fun price(groupedAllocation: NewFloatingGroupedAllocationPrice) = price(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: NewFloatingBulkWithProrationPrice) = + price(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [price] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -1092,6 +1096,13 @@ private constructor( fun price(groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice) = price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** * Alias for calling [price] with * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. @@ -1099,16 +1110,19 @@ private constructor( fun price(matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice) = price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: NewFloatingBulkWithProrationPrice) = - price(Price.ofBulkWithProration(bulkWithProration)) - /** * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. */ fun price(groupedTieredPackage: NewFloatingGroupedTieredPackagePrice) = price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + /** + * Alias for calling [price] with + * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. + */ + fun price(maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice) = + price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + /** * Alias for calling [price] with * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. @@ -1132,6 +1146,22 @@ private constructor( fun price(cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice) = price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + /** + * Alias for calling [price] with + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. + */ + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: NewFloatingMinimumCompositePrice) = price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) + /** The ID of a price to evaluate that exists in your Orb account. */ fun priceId(priceId: String?) = priceId(JsonField.ofNullable(priceId)) @@ -1215,41 +1245,37 @@ private constructor( (price.asKnown()?.validity() ?: 0) + (if (priceId.asKnown() == null) 0 else 1) - /** - * An inline price definition to evaluate, allowing you to test price configurations before - * adding them to Orb. - */ + /** New floating price request body params. */ @JsonDeserialize(using = Price.Deserializer::class) @JsonSerialize(using = Price.Serializer::class) class Price private constructor( private val unit: NewFloatingUnitPrice? = null, - private val package_: NewFloatingPackagePrice? = null, - private val matrix: NewFloatingMatrixPrice? = null, - private val matrixWithAllocation: NewFloatingMatrixWithAllocationPrice? = null, private val tiered: NewFloatingTieredPrice? = null, - private val tieredBps: NewFloatingTieredBpsPrice? = null, - private val bps: NewFloatingBpsPrice? = null, - private val bulkBps: NewFloatingBulkBpsPrice? = null, private val bulk: NewFloatingBulkPrice? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: NewFloatingPackagePrice? = null, + private val matrix: NewFloatingMatrixPrice? = null, private val thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice? = null, private val tieredPackage: NewFloatingTieredPackagePrice? = null, - private val groupedTiered: NewFloatingGroupedTieredPrice? = null, - private val maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice? = null, private val tieredWithMinimum: NewFloatingTieredWithMinimumPrice? = null, - private val packageWithAllocation: NewFloatingPackageWithAllocationPrice? = null, + private val groupedTiered: NewFloatingGroupedTieredPrice? = null, private val tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice? = null, + private val packageWithAllocation: NewFloatingPackageWithAllocationPrice? = null, private val unitWithPercent: NewFloatingUnitWithPercentPrice? = null, + private val matrixWithAllocation: NewFloatingMatrixWithAllocationPrice? = null, private val tieredWithProration: NewFloatingTieredWithProrationPrice? = null, private val unitWithProration: NewFloatingUnitWithProrationPrice? = null, private val groupedAllocation: NewFloatingGroupedAllocationPrice? = null, + private val bulkWithProration: NewFloatingBulkWithProrationPrice? = null, private val groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice? = null, private val groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice? = null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, private val matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice? = null, - private val bulkWithProration: NewFloatingBulkWithProrationPrice? = null, private val groupedTieredPackage: NewFloatingGroupedTieredPackagePrice? = null, + private val maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice? = null, private val scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice? = null, @@ -1257,65 +1283,68 @@ private constructor( NewFloatingScalableMatrixWithTieredPricingPrice? = null, private val cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: NewFloatingMinimumCompositePrice? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, private val _json: JsonValue? = null, ) { fun unit(): NewFloatingUnitPrice? = unit - fun package_(): NewFloatingPackagePrice? = package_ - - fun matrix(): NewFloatingMatrixPrice? = matrix - - fun matrixWithAllocation(): NewFloatingMatrixWithAllocationPrice? = matrixWithAllocation - fun tiered(): NewFloatingTieredPrice? = tiered - fun tieredBps(): NewFloatingTieredBpsPrice? = tieredBps + fun bulk(): NewFloatingBulkPrice? = bulk - fun bps(): NewFloatingBpsPrice? = bps + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters - fun bulkBps(): NewFloatingBulkBpsPrice? = bulkBps + fun package_(): NewFloatingPackagePrice? = package_ - fun bulk(): NewFloatingBulkPrice? = bulk + fun matrix(): NewFloatingMatrixPrice? = matrix fun thresholdTotalAmount(): NewFloatingThresholdTotalAmountPrice? = thresholdTotalAmount fun tieredPackage(): NewFloatingTieredPackagePrice? = tieredPackage - fun groupedTiered(): NewFloatingGroupedTieredPrice? = groupedTiered - - fun maxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice? = - maxGroupTieredPackage - fun tieredWithMinimum(): NewFloatingTieredWithMinimumPrice? = tieredWithMinimum - fun packageWithAllocation(): NewFloatingPackageWithAllocationPrice? = - packageWithAllocation + fun groupedTiered(): NewFloatingGroupedTieredPrice? = groupedTiered fun tieredPackageWithMinimum(): NewFloatingTieredPackageWithMinimumPrice? = tieredPackageWithMinimum + fun packageWithAllocation(): NewFloatingPackageWithAllocationPrice? = + packageWithAllocation + fun unitWithPercent(): NewFloatingUnitWithPercentPrice? = unitWithPercent + fun matrixWithAllocation(): NewFloatingMatrixWithAllocationPrice? = matrixWithAllocation + fun tieredWithProration(): NewFloatingTieredWithProrationPrice? = tieredWithProration fun unitWithProration(): NewFloatingUnitWithProrationPrice? = unitWithProration fun groupedAllocation(): NewFloatingGroupedAllocationPrice? = groupedAllocation + fun bulkWithProration(): NewFloatingBulkWithProrationPrice? = bulkWithProration + fun groupedWithProratedMinimum(): NewFloatingGroupedWithProratedMinimumPrice? = groupedWithProratedMinimum fun groupedWithMeteredMinimum(): NewFloatingGroupedWithMeteredMinimumPrice? = groupedWithMeteredMinimum + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = + groupedWithMinMaxThresholds + fun matrixWithDisplayName(): NewFloatingMatrixWithDisplayNamePrice? = matrixWithDisplayName - fun bulkWithProration(): NewFloatingBulkWithProrationPrice? = bulkWithProration - fun groupedTieredPackage(): NewFloatingGroupedTieredPackagePrice? = groupedTieredPackage + fun maxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice? = + maxGroupTieredPackage + fun scalableMatrixWithUnitPricing(): NewFloatingScalableMatrixWithUnitPricingPrice? = scalableMatrixWithUnitPricing @@ -1325,56 +1354,63 @@ private constructor( fun cumulativeGroupedBulk(): NewFloatingCumulativeGroupedBulkPrice? = cumulativeGroupedBulk - fun isUnit(): Boolean = unit != null + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = + cumulativeGroupedAllocation - fun isPackage(): Boolean = package_ != null + fun minimum(): NewFloatingMinimumCompositePrice? = minimum - fun isMatrix(): Boolean = matrix != null + fun percent(): Percent? = percent - fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun eventOutput(): EventOutput? = eventOutput + + fun isUnit(): Boolean = unit != null fun isTiered(): Boolean = tiered != null - fun isTieredBps(): Boolean = tieredBps != null + fun isBulk(): Boolean = bulk != null - fun isBps(): Boolean = bps != null + fun isBulkWithFilters(): Boolean = bulkWithFilters != null - fun isBulkBps(): Boolean = bulkBps != null + fun isPackage(): Boolean = package_ != null - fun isBulk(): Boolean = bulk != null + fun isMatrix(): Boolean = matrix != null fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null fun isTieredPackage(): Boolean = tieredPackage != null - fun isGroupedTiered(): Boolean = groupedTiered != null - - fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null - fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null - fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + fun isGroupedTiered(): Boolean = groupedTiered != null fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + fun isUnitWithPercent(): Boolean = unitWithPercent != null + fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isTieredWithProration(): Boolean = tieredWithProration != null fun isUnitWithProration(): Boolean = unitWithProration != null fun isGroupedAllocation(): Boolean = groupedAllocation != null + fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null - fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null + fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null fun isScalableMatrixWithTieredPricing(): Boolean = @@ -1382,24 +1418,25 @@ private constructor( fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null - fun asUnit(): NewFloatingUnitPrice = unit.getOrThrow("unit") + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null - fun asPackage(): NewFloatingPackagePrice = package_.getOrThrow("package_") + fun isMinimum(): Boolean = minimum != null - fun asMatrix(): NewFloatingMatrixPrice = matrix.getOrThrow("matrix") + fun isPercent(): Boolean = percent != null - fun asMatrixWithAllocation(): NewFloatingMatrixWithAllocationPrice = - matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun isEventOutput(): Boolean = eventOutput != null + + fun asUnit(): NewFloatingUnitPrice = unit.getOrThrow("unit") fun asTiered(): NewFloatingTieredPrice = tiered.getOrThrow("tiered") - fun asTieredBps(): NewFloatingTieredBpsPrice = tieredBps.getOrThrow("tieredBps") + fun asBulk(): NewFloatingBulkPrice = bulk.getOrThrow("bulk") - fun asBps(): NewFloatingBpsPrice = bps.getOrThrow("bps") + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") - fun asBulkBps(): NewFloatingBulkBpsPrice = bulkBps.getOrThrow("bulkBps") + fun asPackage(): NewFloatingPackagePrice = package_.getOrThrow("package_") - fun asBulk(): NewFloatingBulkPrice = bulk.getOrThrow("bulk") + fun asMatrix(): NewFloatingMatrixPrice = matrix.getOrThrow("matrix") fun asThresholdTotalAmount(): NewFloatingThresholdTotalAmountPrice = thresholdTotalAmount.getOrThrow("thresholdTotalAmount") @@ -1407,24 +1444,24 @@ private constructor( fun asTieredPackage(): NewFloatingTieredPackagePrice = tieredPackage.getOrThrow("tieredPackage") - fun asGroupedTiered(): NewFloatingGroupedTieredPrice = - groupedTiered.getOrThrow("groupedTiered") - - fun asMaxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice = - maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") - fun asTieredWithMinimum(): NewFloatingTieredWithMinimumPrice = tieredWithMinimum.getOrThrow("tieredWithMinimum") - fun asPackageWithAllocation(): NewFloatingPackageWithAllocationPrice = - packageWithAllocation.getOrThrow("packageWithAllocation") + fun asGroupedTiered(): NewFloatingGroupedTieredPrice = + groupedTiered.getOrThrow("groupedTiered") fun asTieredPackageWithMinimum(): NewFloatingTieredPackageWithMinimumPrice = tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + fun asPackageWithAllocation(): NewFloatingPackageWithAllocationPrice = + packageWithAllocation.getOrThrow("packageWithAllocation") + fun asUnitWithPercent(): NewFloatingUnitWithPercentPrice = unitWithPercent.getOrThrow("unitWithPercent") + fun asMatrixWithAllocation(): NewFloatingMatrixWithAllocationPrice = + matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun asTieredWithProration(): NewFloatingTieredWithProrationPrice = tieredWithProration.getOrThrow("tieredWithProration") @@ -1434,21 +1471,27 @@ private constructor( fun asGroupedAllocation(): NewFloatingGroupedAllocationPrice = groupedAllocation.getOrThrow("groupedAllocation") + fun asBulkWithProration(): NewFloatingBulkWithProrationPrice = + bulkWithProration.getOrThrow("bulkWithProration") + fun asGroupedWithProratedMinimum(): NewFloatingGroupedWithProratedMinimumPrice = groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") fun asGroupedWithMeteredMinimum(): NewFloatingGroupedWithMeteredMinimumPrice = groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") + fun asMatrixWithDisplayName(): NewFloatingMatrixWithDisplayNamePrice = matrixWithDisplayName.getOrThrow("matrixWithDisplayName") - fun asBulkWithProration(): NewFloatingBulkWithProrationPrice = - bulkWithProration.getOrThrow("bulkWithProration") - fun asGroupedTieredPackage(): NewFloatingGroupedTieredPackagePrice = groupedTieredPackage.getOrThrow("groupedTieredPackage") + fun asMaxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice = + maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") + fun asScalableMatrixWithUnitPricing(): NewFloatingScalableMatrixWithUnitPricingPrice = scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") @@ -1459,45 +1502,54 @@ private constructor( fun asCumulativeGroupedBulk(): NewFloatingCumulativeGroupedBulkPrice = cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") + + fun asMinimum(): NewFloatingMinimumCompositePrice = minimum.getOrThrow("minimum") + + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") + fun _json(): JsonValue? = _json fun accept(visitor: Visitor): T = when { unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) - matrixWithAllocation != null -> - visitor.visitMatrixWithAllocation(matrixWithAllocation) tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) thresholdTotalAmount != null -> visitor.visitThresholdTotalAmount(thresholdTotalAmount) tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) - maxGroupTieredPackage != null -> - visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) - packageWithAllocation != null -> - visitor.visitPackageWithAllocation(packageWithAllocation) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) tieredPackageWithMinimum != null -> visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) + packageWithAllocation != null -> + visitor.visitPackageWithAllocation(packageWithAllocation) unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + matrixWithAllocation != null -> + visitor.visitMatrixWithAllocation(matrixWithAllocation) tieredWithProration != null -> visitor.visitTieredWithProration(tieredWithProration) unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedWithProratedMinimum != null -> visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) groupedWithMeteredMinimum != null -> visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) matrixWithDisplayName != null -> visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedTieredPackage != null -> visitor.visitGroupedTieredPackage(groupedTieredPackage) + maxGroupTieredPackage != null -> + visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) scalableMatrixWithUnitPricing != null -> visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) scalableMatrixWithTieredPricing != null -> @@ -1506,6 +1558,11 @@ private constructor( ) cumulativeGroupedBulk != null -> visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) else -> visitor.unknown(_json) } @@ -1522,38 +1579,24 @@ private constructor( unit.validate() } - override fun visitPackage(package_: NewFloatingPackagePrice) { - package_.validate() - } - - override fun visitMatrix(matrix: NewFloatingMatrixPrice) { - matrix.validate() - } - - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ) { - matrixWithAllocation.validate() - } - override fun visitTiered(tiered: NewFloatingTieredPrice) { tiered.validate() } - override fun visitTieredBps(tieredBps: NewFloatingTieredBpsPrice) { - tieredBps.validate() + override fun visitBulk(bulk: NewFloatingBulkPrice) { + bulk.validate() } - override fun visitBps(bps: NewFloatingBpsPrice) { - bps.validate() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() } - override fun visitBulkBps(bulkBps: NewFloatingBulkBpsPrice) { - bulkBps.validate() + override fun visitPackage(package_: NewFloatingPackagePrice) { + package_.validate() } - override fun visitBulk(bulk: NewFloatingBulkPrice) { - bulk.validate() + override fun visitMatrix(matrix: NewFloatingMatrixPrice) { + matrix.validate() } override fun visitThresholdTotalAmount( @@ -1568,28 +1611,16 @@ private constructor( tieredPackage.validate() } - override fun visitGroupedTiered( - groupedTiered: NewFloatingGroupedTieredPrice - ) { - groupedTiered.validate() - } - - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice - ) { - maxGroupTieredPackage.validate() - } - override fun visitTieredWithMinimum( tieredWithMinimum: NewFloatingTieredWithMinimumPrice ) { tieredWithMinimum.validate() } - override fun visitPackageWithAllocation( - packageWithAllocation: NewFloatingPackageWithAllocationPrice + override fun visitGroupedTiered( + groupedTiered: NewFloatingGroupedTieredPrice ) { - packageWithAllocation.validate() + groupedTiered.validate() } override fun visitTieredPackageWithMinimum( @@ -1598,12 +1629,24 @@ private constructor( tieredPackageWithMinimum.validate() } - override fun visitUnitWithPercent( - unitWithPercent: NewFloatingUnitWithPercentPrice + override fun visitPackageWithAllocation( + packageWithAllocation: NewFloatingPackageWithAllocationPrice + ) { + packageWithAllocation.validate() + } + + override fun visitUnitWithPercent( + unitWithPercent: NewFloatingUnitWithPercentPrice ) { unitWithPercent.validate() } + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ) { + matrixWithAllocation.validate() + } + override fun visitTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ) { @@ -1622,6 +1665,12 @@ private constructor( groupedAllocation.validate() } + override fun visitBulkWithProration( + bulkWithProration: NewFloatingBulkWithProrationPrice + ) { + bulkWithProration.validate() + } + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ) { @@ -1634,16 +1683,16 @@ private constructor( groupedWithMeteredMinimum.validate() } - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds ) { - matrixWithDisplayName.validate() + groupedWithMinMaxThresholds.validate() } - override fun visitBulkWithProration( - bulkWithProration: NewFloatingBulkWithProrationPrice + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ) { - bulkWithProration.validate() + matrixWithDisplayName.validate() } override fun visitGroupedTieredPackage( @@ -1652,6 +1701,12 @@ private constructor( groupedTieredPackage.validate() } + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ) { + maxGroupTieredPackage.validate() + } + override fun visitScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice @@ -1671,6 +1726,24 @@ private constructor( ) { cumulativeGroupedBulk.validate() } + + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) { + cumulativeGroupedAllocation.validate() + } + + override fun visitMinimum(minimum: NewFloatingMinimumCompositePrice) { + minimum.validate() + } + + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() + } } ) validated = true @@ -1695,26 +1768,17 @@ private constructor( object : Visitor { override fun visitUnit(unit: NewFloatingUnitPrice) = unit.validity() - override fun visitPackage(package_: NewFloatingPackagePrice) = - package_.validity() - - override fun visitMatrix(matrix: NewFloatingMatrixPrice) = matrix.validity() - - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ) = matrixWithAllocation.validity() - override fun visitTiered(tiered: NewFloatingTieredPrice) = tiered.validity() - override fun visitTieredBps(tieredBps: NewFloatingTieredBpsPrice) = - tieredBps.validity() + override fun visitBulk(bulk: NewFloatingBulkPrice) = bulk.validity() - override fun visitBps(bps: NewFloatingBpsPrice) = bps.validity() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() - override fun visitBulkBps(bulkBps: NewFloatingBulkBpsPrice) = - bulkBps.validity() + override fun visitPackage(package_: NewFloatingPackagePrice) = + package_.validity() - override fun visitBulk(bulk: NewFloatingBulkPrice) = bulk.validity() + override fun visitMatrix(matrix: NewFloatingMatrixPrice) = matrix.validity() override fun visitThresholdTotalAmount( thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice @@ -1724,30 +1788,30 @@ private constructor( tieredPackage: NewFloatingTieredPackagePrice ) = tieredPackage.validity() - override fun visitGroupedTiered( - groupedTiered: NewFloatingGroupedTieredPrice - ) = groupedTiered.validity() - - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice - ) = maxGroupTieredPackage.validity() - override fun visitTieredWithMinimum( tieredWithMinimum: NewFloatingTieredWithMinimumPrice ) = tieredWithMinimum.validity() - override fun visitPackageWithAllocation( - packageWithAllocation: NewFloatingPackageWithAllocationPrice - ) = packageWithAllocation.validity() + override fun visitGroupedTiered( + groupedTiered: NewFloatingGroupedTieredPrice + ) = groupedTiered.validity() override fun visitTieredPackageWithMinimum( tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice ) = tieredPackageWithMinimum.validity() + override fun visitPackageWithAllocation( + packageWithAllocation: NewFloatingPackageWithAllocationPrice + ) = packageWithAllocation.validity() + override fun visitUnitWithPercent( unitWithPercent: NewFloatingUnitWithPercentPrice ) = unitWithPercent.validity() + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ) = matrixWithAllocation.validity() + override fun visitTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ) = tieredWithProration.validity() @@ -1760,6 +1824,10 @@ private constructor( groupedAllocation: NewFloatingGroupedAllocationPrice ) = groupedAllocation.validity() + override fun visitBulkWithProration( + bulkWithProration: NewFloatingBulkWithProrationPrice + ) = bulkWithProration.validity() + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ) = groupedWithProratedMinimum.validity() @@ -1768,18 +1836,22 @@ private constructor( groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice ) = groupedWithMeteredMinimum.validity() + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + override fun visitMatrixWithDisplayName( matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ) = matrixWithDisplayName.validity() - override fun visitBulkWithProration( - bulkWithProration: NewFloatingBulkWithProrationPrice - ) = bulkWithProration.validity() - override fun visitGroupedTieredPackage( groupedTieredPackage: NewFloatingGroupedTieredPackagePrice ) = groupedTieredPackage.validity() + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ) = maxGroupTieredPackage.validity() + override fun visitScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice @@ -1794,6 +1866,18 @@ private constructor( cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice ) = cumulativeGroupedBulk.validity() + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() + + override fun visitMinimum(minimum: NewFloatingMinimumCompositePrice) = + minimum.validity() + + override fun visitPercent(percent: Percent) = percent.validity() + + override fun visitEventOutput(eventOutput: EventOutput) = + eventOutput.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -1803,53 +1887,122 @@ private constructor( return true } - return /* spotless:off */ other is Price && unit == other.unit && package_ == other.package_ && matrix == other.matrix && matrixWithAllocation == other.matrixWithAllocation && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && groupedTiered == other.groupedTiered && maxGroupTieredPackage == other.maxGroupTieredPackage && tieredWithMinimum == other.tieredWithMinimum && packageWithAllocation == other.packageWithAllocation && tieredPackageWithMinimum == other.tieredPackageWithMinimum && unitWithPercent == other.unitWithPercent && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && bulkWithProration == other.bulkWithProration && groupedTieredPackage == other.groupedTieredPackage && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk /* spotless:on */ + return other is Price && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, matrixWithAllocation, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, groupedTiered, maxGroupTieredPackage, tieredWithMinimum, packageWithAllocation, tieredPackageWithMinimum, unitWithPercent, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, groupedWithMeteredMinimum, matrixWithDisplayName, bulkWithProration, groupedTieredPackage, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) override fun toString(): String = when { unit != null -> "Price{unit=$unit}" - package_ != null -> "Price{package_=$package_}" - matrix != null -> "Price{matrix=$matrix}" - matrixWithAllocation != null -> - "Price{matrixWithAllocation=$matrixWithAllocation}" tiered != null -> "Price{tiered=$tiered}" - tieredBps != null -> "Price{tieredBps=$tieredBps}" - bps != null -> "Price{bps=$bps}" - bulkBps != null -> "Price{bulkBps=$bulkBps}" bulk != null -> "Price{bulk=$bulk}" + bulkWithFilters != null -> "Price{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "Price{package_=$package_}" + matrix != null -> "Price{matrix=$matrix}" thresholdTotalAmount != null -> "Price{thresholdTotalAmount=$thresholdTotalAmount}" tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" - groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" - maxGroupTieredPackage != null -> - "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" - packageWithAllocation != null -> - "Price{packageWithAllocation=$packageWithAllocation}" + groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" tieredPackageWithMinimum != null -> "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" + packageWithAllocation != null -> + "Price{packageWithAllocation=$packageWithAllocation}" unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + matrixWithAllocation != null -> + "Price{matrixWithAllocation=$matrixWithAllocation}" tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedWithProratedMinimum != null -> "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" groupedWithMeteredMinimum != null -> "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "Price{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" matrixWithDisplayName != null -> "Price{matrixWithDisplayName=$matrixWithDisplayName}" - bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedTieredPackage != null -> "Price{groupedTieredPackage=$groupedTieredPackage}" + maxGroupTieredPackage != null -> + "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" scalableMatrixWithUnitPricing != null -> "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" scalableMatrixWithTieredPricing != null -> "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" cumulativeGroupedBulk != null -> "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" + cumulativeGroupedAllocation != null -> + "Price{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "Price{minimum=$minimum}" + percent != null -> "Price{percent=$percent}" + eventOutput != null -> "Price{eventOutput=$eventOutput}" _json != null -> "Price{_unknown=$_json}" else -> throw IllegalStateException("Invalid Price") } @@ -1858,23 +2011,16 @@ private constructor( fun ofUnit(unit: NewFloatingUnitPrice) = Price(unit = unit) - fun ofPackage(package_: NewFloatingPackagePrice) = Price(package_ = package_) - - fun ofMatrix(matrix: NewFloatingMatrixPrice) = Price(matrix = matrix) - - fun ofMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ) = Price(matrixWithAllocation = matrixWithAllocation) - fun ofTiered(tiered: NewFloatingTieredPrice) = Price(tiered = tiered) - fun ofTieredBps(tieredBps: NewFloatingTieredBpsPrice) = Price(tieredBps = tieredBps) + fun ofBulk(bulk: NewFloatingBulkPrice) = Price(bulk = bulk) - fun ofBps(bps: NewFloatingBpsPrice) = Price(bps = bps) + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + Price(bulkWithFilters = bulkWithFilters) - fun ofBulkBps(bulkBps: NewFloatingBulkBpsPrice) = Price(bulkBps = bulkBps) + fun ofPackage(package_: NewFloatingPackagePrice) = Price(package_ = package_) - fun ofBulk(bulk: NewFloatingBulkPrice) = Price(bulk = bulk) + fun ofMatrix(matrix: NewFloatingMatrixPrice) = Price(matrix = matrix) fun ofThresholdTotalAmount( thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice @@ -1883,27 +2029,27 @@ private constructor( fun ofTieredPackage(tieredPackage: NewFloatingTieredPackagePrice) = Price(tieredPackage = tieredPackage) - fun ofGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice) = - Price(groupedTiered = groupedTiered) - - fun ofMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice - ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) - fun ofTieredWithMinimum(tieredWithMinimum: NewFloatingTieredWithMinimumPrice) = Price(tieredWithMinimum = tieredWithMinimum) - fun ofPackageWithAllocation( - packageWithAllocation: NewFloatingPackageWithAllocationPrice - ) = Price(packageWithAllocation = packageWithAllocation) + fun ofGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice) = + Price(groupedTiered = groupedTiered) fun ofTieredPackageWithMinimum( tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + fun ofPackageWithAllocation( + packageWithAllocation: NewFloatingPackageWithAllocationPrice + ) = Price(packageWithAllocation = packageWithAllocation) + fun ofUnitWithPercent(unitWithPercent: NewFloatingUnitWithPercentPrice) = Price(unitWithPercent = unitWithPercent) + fun ofMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ) = Price(matrixWithAllocation = matrixWithAllocation) + fun ofTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ) = Price(tieredWithProration = tieredWithProration) @@ -1914,6 +2060,9 @@ private constructor( fun ofGroupedAllocation(groupedAllocation: NewFloatingGroupedAllocationPrice) = Price(groupedAllocation = groupedAllocation) + fun ofBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice) = + Price(bulkWithProration = bulkWithProration) + fun ofGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) @@ -1922,17 +2071,22 @@ private constructor( groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = Price(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + fun ofMatrixWithDisplayName( matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ) = Price(matrixWithDisplayName = matrixWithDisplayName) - fun ofBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice) = - Price(bulkWithProration = bulkWithProration) - fun ofGroupedTieredPackage( groupedTieredPackage: NewFloatingGroupedTieredPackagePrice ) = Price(groupedTieredPackage = groupedTieredPackage) + fun ofMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) + fun ofScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice ) = Price(scalableMatrixWithUnitPricing = scalableMatrixWithUnitPricing) @@ -1944,6 +2098,16 @@ private constructor( fun ofCumulativeGroupedBulk( cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) + + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = Price(cumulativeGroupedAllocation = cumulativeGroupedAllocation) + + fun ofMinimum(minimum: NewFloatingMinimumCompositePrice) = Price(minimum = minimum) + + fun ofPercent(percent: Percent) = Price(percent = percent) + + fun ofEventOutput(eventOutput: EventOutput) = Price(eventOutput = eventOutput) } /** @@ -1953,23 +2117,15 @@ private constructor( fun visitUnit(unit: NewFloatingUnitPrice): T - fun visitPackage(package_: NewFloatingPackagePrice): T - - fun visitMatrix(matrix: NewFloatingMatrixPrice): T - - fun visitMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ): T - fun visitTiered(tiered: NewFloatingTieredPrice): T - fun visitTieredBps(tieredBps: NewFloatingTieredBpsPrice): T + fun visitBulk(bulk: NewFloatingBulkPrice): T - fun visitBps(bps: NewFloatingBpsPrice): T + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T - fun visitBulkBps(bulkBps: NewFloatingBulkBpsPrice): T + fun visitPackage(package_: NewFloatingPackagePrice): T - fun visitBulk(bulk: NewFloatingBulkPrice): T + fun visitMatrix(matrix: NewFloatingMatrixPrice): T fun visitThresholdTotalAmount( thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice @@ -1977,24 +2133,24 @@ private constructor( fun visitTieredPackage(tieredPackage: NewFloatingTieredPackagePrice): T + fun visitTieredWithMinimum(tieredWithMinimum: NewFloatingTieredWithMinimumPrice): T + fun visitGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice): T - fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice ): T - fun visitTieredWithMinimum(tieredWithMinimum: NewFloatingTieredWithMinimumPrice): T - fun visitPackageWithAllocation( packageWithAllocation: NewFloatingPackageWithAllocationPrice ): T - fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice - ): T - fun visitUnitWithPercent(unitWithPercent: NewFloatingUnitWithPercentPrice): T + fun visitMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ): T + fun visitTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ): T @@ -2003,6 +2159,8 @@ private constructor( fun visitGroupedAllocation(groupedAllocation: NewFloatingGroupedAllocationPrice): T + fun visitBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice): T + fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ): T @@ -2011,16 +2169,22 @@ private constructor( groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice ): T + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ): T + fun visitMatrixWithDisplayName( matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ): T - fun visitBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice): T - fun visitGroupedTieredPackage( groupedTieredPackage: NewFloatingGroupedTieredPackagePrice ): T + fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ): T + fun visitScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice ): T @@ -2033,6 +2197,16 @@ private constructor( cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice ): T + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ): T + + fun visitMinimum(minimum: NewFloatingMinimumCompositePrice): T + + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T + /** * Maps an unknown variant of [Price] to a value of type [T]. * @@ -2059,42 +2233,27 @@ private constructor( return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(unit = it, _json = json) } ?: Price(_json = json) } - "package" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) - } - "matrix" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) - } - "matrix_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithAllocation = it, _json = json) } - ?: Price(_json = json) - } "tiered" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(tiered = it, _json = json) } ?: Price(_json = json) } - "tiered_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(tieredBps = it, _json = json) } ?: Price(_json = json) - } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bps = it, _json = json) } ?: Price(_json = json) - } - "bulk_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bulkBps = it, _json = json) } ?: Price(_json = json) - } "bulk" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(bulk = it, _json = json) } ?: Price(_json = json) } + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulkWithFilters = it, _json = json) + } ?: Price(_json = json) + } + "package" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) + } + "matrix" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) + } "threshold_total_amount" -> { return tryDeserialize( node, @@ -2111,28 +2270,28 @@ private constructor( ?.let { Price(tieredPackage = it, _json = json) } ?: Price(_json = json) } - "grouped_tiered" -> { + "tiered_with_minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(groupedTiered = it, _json = json) } + ?.let { Price(tieredWithMinimum = it, _json = json) } ?: Price(_json = json) } - "max_group_tiered_package" -> { + "grouped_tiered" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(maxGroupTieredPackage = it, _json = json) } + ?.let { Price(groupedTiered = it, _json = json) } ?: Price(_json = json) } - "tiered_with_minimum" -> { + "tiered_package_with_minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(tieredWithMinimum = it, _json = json) } + ?.let { Price(tieredPackageWithMinimum = it, _json = json) } ?: Price(_json = json) } "package_with_allocation" -> { @@ -2143,20 +2302,20 @@ private constructor( ?.let { Price(packageWithAllocation = it, _json = json) } ?: Price(_json = json) } - "tiered_package_with_minimum" -> { + "unit_with_percent" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(tieredPackageWithMinimum = it, _json = json) } + ?.let { Price(unitWithPercent = it, _json = json) } ?: Price(_json = json) } - "unit_with_percent" -> { + "matrix_with_allocation" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(unitWithPercent = it, _json = json) } + ?.let { Price(matrixWithAllocation = it, _json = json) } ?: Price(_json = json) } "tiered_with_proration" -> { @@ -2183,6 +2342,14 @@ private constructor( ?.let { Price(groupedAllocation = it, _json = json) } ?: Price(_json = json) } + "bulk_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(bulkWithProration = it, _json = json) } + ?: Price(_json = json) + } "grouped_with_prorated_minimum" -> { return tryDeserialize( node, @@ -2199,20 +2366,20 @@ private constructor( ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } ?: Price(_json = json) } - "matrix_with_display_name" -> { + "grouped_with_min_max_thresholds" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(matrixWithDisplayName = it, _json = json) } + ?.let { Price(groupedWithMinMaxThresholds = it, _json = json) } ?: Price(_json = json) } - "bulk_with_proration" -> { + "matrix_with_display_name" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(bulkWithProration = it, _json = json) } + ?.let { Price(matrixWithDisplayName = it, _json = json) } ?: Price(_json = json) } "grouped_tiered_package" -> { @@ -2223,6 +2390,14 @@ private constructor( ?.let { Price(groupedTieredPackage = it, _json = json) } ?: Price(_json = json) } + "max_group_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(maxGroupTieredPackage = it, _json = json) } + ?: Price(_json = json) + } "scalable_matrix_with_unit_pricing" -> { return tryDeserialize( node, @@ -2249,6 +2424,31 @@ private constructor( ?.let { Price(cumulativeGroupedBulk = it, _json = json) } ?: Price(_json = json) } + "cumulative_grouped_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(cumulativeGroupedAllocation = it, _json = json) } + ?: Price(_json = json) + } + "minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(minimum = it, _json = json) } ?: Price(_json = json) + } + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(percent = it, _json = json) + } ?: Price(_json = json) + } + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(eventOutput = it, _json = json) + } ?: Price(_json = json) + } } return Price(_json = json) @@ -2264,69 +2464,8414 @@ private constructor( ) { when { value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) - value.matrixWithAllocation != null -> - generator.writeObject(value.matrixWithAllocation) value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> + generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) value.thresholdTotalAmount != null -> generator.writeObject(value.thresholdTotalAmount) value.tieredPackage != null -> generator.writeObject(value.tieredPackage) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) - value.maxGroupTieredPackage != null -> - generator.writeObject(value.maxGroupTieredPackage) value.tieredWithMinimum != null -> generator.writeObject(value.tieredWithMinimum) - value.packageWithAllocation != null -> - generator.writeObject(value.packageWithAllocation) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) value.tieredPackageWithMinimum != null -> generator.writeObject(value.tieredPackageWithMinimum) + value.packageWithAllocation != null -> + generator.writeObject(value.packageWithAllocation) value.unitWithPercent != null -> generator.writeObject(value.unitWithPercent) + value.matrixWithAllocation != null -> + generator.writeObject(value.matrixWithAllocation) value.tieredWithProration != null -> generator.writeObject(value.tieredWithProration) value.unitWithProration != null -> generator.writeObject(value.unitWithProration) value.groupedAllocation != null -> generator.writeObject(value.groupedAllocation) + value.bulkWithProration != null -> + generator.writeObject(value.bulkWithProration) value.groupedWithProratedMinimum != null -> generator.writeObject(value.groupedWithProratedMinimum) value.groupedWithMeteredMinimum != null -> generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) value.matrixWithDisplayName != null -> generator.writeObject(value.matrixWithDisplayName) - value.bulkWithProration != null -> - generator.writeObject(value.bulkWithProration) value.groupedTieredPackage != null -> generator.writeObject(value.groupedTieredPackage) + value.maxGroupTieredPackage != null -> + generator.writeObject(value.maxGroupTieredPackage) value.scalableMatrixWithUnitPricing != null -> generator.writeObject(value.scalableMatrixWithUnitPricing) value.scalableMatrixWithTieredPricing != null -> generator.writeObject(value.scalableMatrixWithTieredPricing) value.cumulativeGroupedBulk != null -> generator.writeObject(value.cumulativeGroupedBulk) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Price") } } } - } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bulkWithFiltersConfig: JsonField, + private val cadence: JsonField, + private val currency: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + bulkWithFiltersConfig, + cadence, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) - return /* spotless:off */ other is PriceEvaluation && externalPriceId == other.externalPriceId && filter == other.filter && groupingKeys == other.groupingKeys && price == other.price && priceId == other.priceId && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = + bulkWithFiltersConfig + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [BulkWithFilters]. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .currency() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFilters]. */ + class Builder internal constructor() { + + private var bulkWithFiltersConfig: JsonField? = null + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + currency = bulkWithFilters.currency + itemId = bulkWithFilters.itemId + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + billableMetricId = bulkWithFilters.billableMetricId + billedInAdvance = bulkWithFilters.billedInAdvance + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + dimensionalPriceConfiguration = + bulkWithFilters.dimensionalPriceConfiguration + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoiceGroupingKey = bulkWithFilters.invoiceGroupingKey + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + metadata = bulkWithFilters.metadata + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() + } + + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig( + bulkWithFiltersConfig: JsonField + ) = apply { this.bulkWithFiltersConfig = bulkWithFiltersConfig } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BulkWithFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .currency() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFilters = + BulkWithFilters( + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFilters = apply { + if (validated) { + return@apply + } + + bulkWithFiltersConfig().validate() + cadence().validate() + currency() + itemId() + _modelType().let { + if (it != JsonValue.from("bulk_with_filters")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(externalPriceId, filter, groupingKeys, price, priceId, additionalProperties) } - /* spotless:on */ + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) + + /** + * Property filters to apply (all must match) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [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 + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { + + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithFiltersConfig.additionalProperties.toMutableMap() + } + + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + + /** Bulk tiers for rating based on total usage volume */ + 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 [BulkWithFiltersConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } + + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = + propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + propertyKey() + propertyValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = + tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filters, tiers, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFilters && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bulkWithFiltersConfig, + cadence, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFilters{bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val currency: JsonField, + private val groupedWithMinMaxThresholdsConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + groupedWithMinMaxThresholdsConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + currency, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * Configuration for grouped_with_min_max_thresholds pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired( + "grouped_with_min_max_thresholds_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. + * + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + fun _groupedWithMinMaxThresholdsConfig(): + JsonField = groupedWithMinMaxThresholdsConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 + * [GroupedWithMinMaxThresholds]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholds]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("grouped_with_min_max_thresholds") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = + apply { + cadence = groupedWithMinMaxThresholds.cadence + currency = groupedWithMinMaxThresholds.currency + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + itemId = groupedWithMinMaxThresholds.itemId + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + billableMetricId = groupedWithMinMaxThresholds.billableMetricId + billedInAdvance = groupedWithMinMaxThresholds.billedInAdvance + billingCycleConfiguration = + groupedWithMinMaxThresholds.billingCycleConfiguration + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + invoiceGroupingKey = groupedWithMinMaxThresholds.invoiceGroupingKey + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + metadata = groupedWithMinMaxThresholds.metadata + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = + groupedWithMinMaxThresholdsConfig( + JsonField.of(groupedWithMinMaxThresholdsConfig) + ) + + /** + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a + * well-typed [GroupedWithMinMaxThresholdsConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: + JsonField + ) = apply { + this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholds = apply { + if (validated) { + return@apply + } + + cadence().validate() + currency() + groupedWithMinMaxThresholdsConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @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 + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate + additionalProperties = + groupedWithMinMaxThresholdsConfig.additionalProperties + .toMutableMap() + } + + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } + + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } + + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = + perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + if (validated) { + return@apply + } + + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholds && + cadence == other.cadence && + currency == other.currency && + groupedWithMinMaxThresholdsConfig == + other.groupedWithMinMaxThresholdsConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholds{cadence=$cadence, currency=$currency, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val cumulativeGroupedAllocationConfig: + JsonField, + private val currency: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + cumulativeGroupedAllocationConfig, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for cumulative_grouped_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired( + "cumulative_grouped_allocation_config" + ) + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): + JsonField = cumulativeGroupedAllocationConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 + * [CumulativeGroupedAllocation]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .currency() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocation]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null + private var currency: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("cumulative_grouped_allocation") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = + apply { + cadence = cumulativeGroupedAllocation.cadence + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + currency = cumulativeGroupedAllocation.currency + itemId = cumulativeGroupedAllocation.itemId + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + billableMetricId = cumulativeGroupedAllocation.billableMetricId + billedInAdvance = cumulativeGroupedAllocation.billedInAdvance + billingCycleConfiguration = + cumulativeGroupedAllocation.billingCycleConfiguration + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoiceGroupingKey = cumulativeGroupedAllocation.invoiceGroupingKey + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + metadata = cumulativeGroupedAllocation.metadata + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = + cumulativeGroupedAllocationConfig( + JsonField.of(cumulativeGroupedAllocationConfig) + ) + + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a + * well-typed [CumulativeGroupedAllocationConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: + JsonField + ) = apply { + this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig + } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .currency() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( + checkRequired("cadence", cadence), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), + checkRequired("currency", currency), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocation = apply { + if (validated) { + return@apply + } + + cadence().validate() + cumulativeGroupedAllocationConfig().validate() + currency() + itemId() + _modelType().let { + if (it != JsonValue.from("cumulative_grouped_allocation")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + mutableMapOf(), + ) + + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 + * [CumulativeGroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = + cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties + .toMutableMap() + } + + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } + + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation + } + + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply + } + + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocation && + cadence == other.cadence && + cumulativeGroupedAllocationConfig == + other.cumulativeGroupedAllocationConfig && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedAllocationConfig, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocation{cadence=$cadence, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val currency: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val percentConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + currency, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [Percent]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .itemId() + * .name() + * .percentConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Percent]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("percent") + private var name: JsonField? = null + private var percentConfig: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percent: Percent) = apply { + cadence = percent.cadence + currency = percent.currency + itemId = percent.itemId + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + billableMetricId = percent.billableMetricId + billedInAdvance = percent.billedInAdvance + billingCycleConfiguration = percent.billingCycleConfiguration + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoiceGroupingKey = percent.invoiceGroupingKey + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + metadata = percent.metadata + additionalProperties = percent.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed + * [PercentConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Percent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .itemId() + * .name() + * .percentConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Percent = + Percent( + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("percentConfig", percentConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Percent = apply { + if (validated) { + return@apply + } + + cadence().validate() + currency() + itemId() + _modelType().let { + if (it != JsonValue.from("percent")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + percentConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent") + @ExcludeMissing + fun _percent(): JsonField = percent + + @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 + * [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PercentConfig]. */ + class Builder internal constructor() { + + private var percent: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() + } + + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PercentConfig = apply { + if (validated) { + return@apply + } + + percent() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(percent, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Percent && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Percent{cadence=$cadence, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, percentConfig=$percentConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val currency: JsonField, + private val eventOutputConfig: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + currency, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [EventOutput]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutput]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var eventOutputConfig: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("event_output") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutput: EventOutput) = apply { + cadence = eventOutput.cadence + currency = eventOutput.currency + eventOutputConfig = eventOutput.eventOutputConfig + itemId = eventOutput.itemId + modelType = eventOutput.modelType + name = eventOutput.name + billableMetricId = eventOutput.billableMetricId + billedInAdvance = eventOutput.billedInAdvance + billingCycleConfiguration = eventOutput.billingCycleConfiguration + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoiceGroupingKey = eventOutput.invoiceGroupingKey + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + metadata = eventOutput.metadata + additionalProperties = eventOutput.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutput = + EventOutput( + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired("eventOutputConfig", eventOutputConfig), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutput = apply { + if (validated) { + return@apply + } + + cadence().validate() + currency() + eventOutputConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("event_output")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a + * unit rate will be ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = + defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events + * will also be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @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 + * [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutputConfig]. */ + class Builder internal constructor() { + + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = + eventOutputConfig.additionalProperties.toMutableMap() + } + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey + } + + /** + * If provided, this amount will be used as the unit rate when an event does + * not have a value for the `unit_rating_key`. If not provided, events + * missing a unit rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate + } + + /** + * An optional key in the event data to group by (e.g., event ID). All + * events will also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutputConfig = apply { + if (validated) { + return@apply + } + + unitRatingKey() + defaultUnitRate() + groupingKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + unitRatingKey, + defaultUnitRate, + groupingKey, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutput && + cadence == other.cadence && + currency == other.currency && + eventOutputConfig == other.eventOutputConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutput{cadence=$cadence, currency=$currency, eventOutputConfig=$eventOutputConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PriceEvaluation && + externalPriceId == other.externalPriceId && + filter == other.filter && + groupingKeys == other.groupingKeys && + price == other.price && + priceId == other.priceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + externalPriceId, + filter, + groupingKeys, + price, + priceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2339,10 +10884,13 @@ private constructor( return true } - return /* spotless:off */ other is PriceEvaluateMultipleParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PriceEvaluateMultipleParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "PriceEvaluateMultipleParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateMultipleResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateMultipleResponse.kt index 23021b7b0..f4891fd0c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateMultipleResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateMultipleResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class PriceEvaluateMultipleResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val additionalProperties: MutableMap, @@ -167,6 +168,7 @@ private constructor( internal fun validity(): Int = (data.asKnown()?.sumOf { it.validity().toInt() } ?: 0) class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val currency: JsonField, private val priceGroups: JsonField>, @@ -494,12 +496,25 @@ private constructor( return true } - return /* spotless:off */ other is Data && currency == other.currency && priceGroups == other.priceGroups && externalPriceId == other.externalPriceId && inlinePriceIndex == other.inlinePriceIndex && priceId == other.priceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Data && + currency == other.currency && + priceGroups == other.priceGroups && + externalPriceId == other.externalPriceId && + inlinePriceIndex == other.inlinePriceIndex && + priceId == other.priceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(currency, priceGroups, externalPriceId, inlinePriceIndex, priceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + currency, + priceGroups, + externalPriceId, + inlinePriceIndex, + priceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -512,12 +527,12 @@ private constructor( return true } - return /* spotless:off */ other is PriceEvaluateMultipleResponse && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PriceEvaluateMultipleResponse && + data == other.data && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateParams.kt index 6e168fc51..e0731f439 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateParams.kt @@ -450,6 +450,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val timeframeEnd: JsonField, private val timeframeStart: JsonField, @@ -831,13 +832,28 @@ private constructor( return true } - return /* spotless:off */ other is Body && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && customerId == other.customerId && externalCustomerId == other.externalCustomerId && filter == other.filter && groupingKeys == other.groupingKeys && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + customerId == other.customerId && + externalCustomerId == other.externalCustomerId && + filter == other.filter && + groupingKeys == other.groupingKeys && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + timeframeEnd, + timeframeStart, + customerId, + externalCustomerId, + filter, + groupingKeys, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(timeframeEnd, timeframeStart, customerId, externalCustomerId, filter, groupingKeys, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = @@ -849,10 +865,15 @@ private constructor( return true } - return /* spotless:off */ other is PriceEvaluateParams && priceId == other.priceId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PriceEvaluateParams && + priceId == other.priceId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(priceId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(priceId, body, additionalHeaders, additionalQueryParams) override fun toString() = "PriceEvaluateParams{priceId=$priceId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluatePreviewEventsParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluatePreviewEventsParams.kt index a1a78f24c..363446549 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluatePreviewEventsParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluatePreviewEventsParams.kt @@ -15,6 +15,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.withorb.api.core.BaseDeserializer import com.withorb.api.core.BaseSerializer +import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing @@ -448,6 +449,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val timeframeEnd: JsonField, private val timeframeStart: JsonField, @@ -837,12 +839,27 @@ private constructor( return true } - return /* spotless:off */ other is Body && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && customerId == other.customerId && events == other.events && externalCustomerId == other.externalCustomerId && priceEvaluations == other.priceEvaluations && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + customerId == other.customerId && + events == other.events && + externalCustomerId == other.externalCustomerId && + priceEvaluations == other.priceEvaluations && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(timeframeEnd, timeframeStart, customerId, events, externalCustomerId, priceEvaluations, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + timeframeEnd, + timeframeStart, + customerId, + events, + externalCustomerId, + priceEvaluations, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -851,6 +868,7 @@ private constructor( } class Event + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val eventName: JsonField, private val properties: JsonField, @@ -1262,12 +1280,10 @@ private constructor( return true } - return /* spotless:off */ other is Properties && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Properties && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1279,12 +1295,25 @@ private constructor( return true } - return /* spotless:off */ other is Event && eventName == other.eventName && properties == other.properties && timestamp == other.timestamp && customerId == other.customerId && externalCustomerId == other.externalCustomerId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Event && + eventName == other.eventName && + properties == other.properties && + timestamp == other.timestamp && + customerId == other.customerId && + externalCustomerId == other.externalCustomerId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(eventName, properties, timestamp, customerId, externalCustomerId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + eventName, + properties, + timestamp, + customerId, + externalCustomerId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1293,6 +1322,7 @@ private constructor( } class PriceEvaluation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val externalPriceId: JsonField, private val filter: JsonField, @@ -1343,8 +1373,7 @@ private constructor( fun groupingKeys(): List? = groupingKeys.getNullable("grouping_keys") /** - * An inline price definition to evaluate, allowing you to test price configurations before - * adding them to Orb. + * New floating price request body params. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1497,10 +1526,7 @@ private constructor( } } - /** - * An inline price definition to evaluate, allowing you to test price configurations - * before adding them to Orb. - */ + /** New floating price request body params. */ fun price(price: Price?) = price(JsonField.ofNullable(price)) /** @@ -1515,32 +1541,21 @@ private constructor( /** Alias for calling [price] with `Price.ofUnit(unit)`. */ fun price(unit: NewFloatingUnitPrice) = price(Price.ofUnit(unit)) - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: NewFloatingPackagePrice) = price(Price.ofPackage(package_)) - - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: NewFloatingMatrixPrice) = price(Price.ofMatrix(matrix)) - - /** - * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. - */ - fun price(matrixWithAllocation: NewFloatingMatrixWithAllocationPrice) = - price(Price.ofMatrixWithAllocation(matrixWithAllocation)) - /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ fun price(tiered: NewFloatingTieredPrice) = price(Price.ofTiered(tiered)) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: NewFloatingTieredBpsPrice) = price(Price.ofTieredBps(tieredBps)) + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: NewFloatingBulkPrice) = price(Price.ofBulk(bulk)) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: NewFloatingBpsPrice) = price(Price.ofBps(bps)) + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: NewFloatingBulkBpsPrice) = price(Price.ofBulkBps(bulkBps)) + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: NewFloatingPackagePrice) = price(Price.ofPackage(package_)) - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: NewFloatingBulkPrice) = price(Price.ofBulk(bulk)) + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: NewFloatingMatrixPrice) = price(Price.ofMatrix(matrix)) /** * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. @@ -1552,20 +1567,20 @@ private constructor( fun price(tieredPackage: NewFloatingTieredPackagePrice) = price(Price.ofTieredPackage(tieredPackage)) + /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ + fun price(tieredWithMinimum: NewFloatingTieredWithMinimumPrice) = + price(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ fun price(groupedTiered: NewFloatingGroupedTieredPrice) = price(Price.ofGroupedTiered(groupedTiered)) /** * Alias for calling [price] with - * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. + * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. */ - fun price(maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice) = - price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) - - /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ - fun price(tieredWithMinimum: NewFloatingTieredWithMinimumPrice) = - price(Price.ofTieredWithMinimum(tieredWithMinimum)) + fun price(tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice) = + price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) /** * Alias for calling [price] with @@ -1574,17 +1589,16 @@ private constructor( fun price(packageWithAllocation: NewFloatingPackageWithAllocationPrice) = price(Price.ofPackageWithAllocation(packageWithAllocation)) - /** - * Alias for calling [price] with - * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. - */ - fun price(tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice) = - price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) - /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ fun price(unitWithPercent: NewFloatingUnitWithPercentPrice) = price(Price.ofUnitWithPercent(unitWithPercent)) + /** + * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun price(matrixWithAllocation: NewFloatingMatrixWithAllocationPrice) = + price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + /** * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. */ @@ -1599,6 +1613,10 @@ private constructor( fun price(groupedAllocation: NewFloatingGroupedAllocationPrice) = price(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: NewFloatingBulkWithProrationPrice) = + price(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [price] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -1613,6 +1631,13 @@ private constructor( fun price(groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice) = price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** * Alias for calling [price] with * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. @@ -1620,16 +1645,19 @@ private constructor( fun price(matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice) = price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: NewFloatingBulkWithProrationPrice) = - price(Price.ofBulkWithProration(bulkWithProration)) - /** * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. */ fun price(groupedTieredPackage: NewFloatingGroupedTieredPackagePrice) = price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + /** + * Alias for calling [price] with + * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. + */ + fun price(maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice) = + price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + /** * Alias for calling [price] with * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. @@ -1653,6 +1681,22 @@ private constructor( fun price(cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice) = price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + /** + * Alias for calling [price] with + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. + */ + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: NewFloatingMinimumCompositePrice) = price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) + /** The ID of a price to evaluate that exists in your Orb account. */ fun priceId(priceId: String?) = priceId(JsonField.ofNullable(priceId)) @@ -1736,41 +1780,37 @@ private constructor( (price.asKnown()?.validity() ?: 0) + (if (priceId.asKnown() == null) 0 else 1) - /** - * An inline price definition to evaluate, allowing you to test price configurations before - * adding them to Orb. - */ + /** New floating price request body params. */ @JsonDeserialize(using = Price.Deserializer::class) @JsonSerialize(using = Price.Serializer::class) class Price private constructor( private val unit: NewFloatingUnitPrice? = null, - private val package_: NewFloatingPackagePrice? = null, - private val matrix: NewFloatingMatrixPrice? = null, - private val matrixWithAllocation: NewFloatingMatrixWithAllocationPrice? = null, private val tiered: NewFloatingTieredPrice? = null, - private val tieredBps: NewFloatingTieredBpsPrice? = null, - private val bps: NewFloatingBpsPrice? = null, - private val bulkBps: NewFloatingBulkBpsPrice? = null, private val bulk: NewFloatingBulkPrice? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: NewFloatingPackagePrice? = null, + private val matrix: NewFloatingMatrixPrice? = null, private val thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice? = null, private val tieredPackage: NewFloatingTieredPackagePrice? = null, - private val groupedTiered: NewFloatingGroupedTieredPrice? = null, - private val maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice? = null, private val tieredWithMinimum: NewFloatingTieredWithMinimumPrice? = null, - private val packageWithAllocation: NewFloatingPackageWithAllocationPrice? = null, + private val groupedTiered: NewFloatingGroupedTieredPrice? = null, private val tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice? = null, + private val packageWithAllocation: NewFloatingPackageWithAllocationPrice? = null, private val unitWithPercent: NewFloatingUnitWithPercentPrice? = null, + private val matrixWithAllocation: NewFloatingMatrixWithAllocationPrice? = null, private val tieredWithProration: NewFloatingTieredWithProrationPrice? = null, private val unitWithProration: NewFloatingUnitWithProrationPrice? = null, private val groupedAllocation: NewFloatingGroupedAllocationPrice? = null, + private val bulkWithProration: NewFloatingBulkWithProrationPrice? = null, private val groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice? = null, private val groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice? = null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, private val matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice? = null, - private val bulkWithProration: NewFloatingBulkWithProrationPrice? = null, private val groupedTieredPackage: NewFloatingGroupedTieredPackagePrice? = null, + private val maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice? = null, private val scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice? = null, @@ -1778,65 +1818,68 @@ private constructor( NewFloatingScalableMatrixWithTieredPricingPrice? = null, private val cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: NewFloatingMinimumCompositePrice? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, private val _json: JsonValue? = null, ) { fun unit(): NewFloatingUnitPrice? = unit - fun package_(): NewFloatingPackagePrice? = package_ - - fun matrix(): NewFloatingMatrixPrice? = matrix - - fun matrixWithAllocation(): NewFloatingMatrixWithAllocationPrice? = matrixWithAllocation - fun tiered(): NewFloatingTieredPrice? = tiered - fun tieredBps(): NewFloatingTieredBpsPrice? = tieredBps + fun bulk(): NewFloatingBulkPrice? = bulk - fun bps(): NewFloatingBpsPrice? = bps + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters - fun bulkBps(): NewFloatingBulkBpsPrice? = bulkBps + fun package_(): NewFloatingPackagePrice? = package_ - fun bulk(): NewFloatingBulkPrice? = bulk + fun matrix(): NewFloatingMatrixPrice? = matrix fun thresholdTotalAmount(): NewFloatingThresholdTotalAmountPrice? = thresholdTotalAmount fun tieredPackage(): NewFloatingTieredPackagePrice? = tieredPackage - fun groupedTiered(): NewFloatingGroupedTieredPrice? = groupedTiered - - fun maxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice? = - maxGroupTieredPackage - fun tieredWithMinimum(): NewFloatingTieredWithMinimumPrice? = tieredWithMinimum - fun packageWithAllocation(): NewFloatingPackageWithAllocationPrice? = - packageWithAllocation + fun groupedTiered(): NewFloatingGroupedTieredPrice? = groupedTiered fun tieredPackageWithMinimum(): NewFloatingTieredPackageWithMinimumPrice? = tieredPackageWithMinimum + fun packageWithAllocation(): NewFloatingPackageWithAllocationPrice? = + packageWithAllocation + fun unitWithPercent(): NewFloatingUnitWithPercentPrice? = unitWithPercent + fun matrixWithAllocation(): NewFloatingMatrixWithAllocationPrice? = matrixWithAllocation + fun tieredWithProration(): NewFloatingTieredWithProrationPrice? = tieredWithProration fun unitWithProration(): NewFloatingUnitWithProrationPrice? = unitWithProration fun groupedAllocation(): NewFloatingGroupedAllocationPrice? = groupedAllocation + fun bulkWithProration(): NewFloatingBulkWithProrationPrice? = bulkWithProration + fun groupedWithProratedMinimum(): NewFloatingGroupedWithProratedMinimumPrice? = groupedWithProratedMinimum fun groupedWithMeteredMinimum(): NewFloatingGroupedWithMeteredMinimumPrice? = groupedWithMeteredMinimum + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = + groupedWithMinMaxThresholds + fun matrixWithDisplayName(): NewFloatingMatrixWithDisplayNamePrice? = matrixWithDisplayName - fun bulkWithProration(): NewFloatingBulkWithProrationPrice? = bulkWithProration - fun groupedTieredPackage(): NewFloatingGroupedTieredPackagePrice? = groupedTieredPackage + fun maxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice? = + maxGroupTieredPackage + fun scalableMatrixWithUnitPricing(): NewFloatingScalableMatrixWithUnitPricingPrice? = scalableMatrixWithUnitPricing @@ -1846,56 +1889,63 @@ private constructor( fun cumulativeGroupedBulk(): NewFloatingCumulativeGroupedBulkPrice? = cumulativeGroupedBulk - fun isUnit(): Boolean = unit != null + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = + cumulativeGroupedAllocation - fun isPackage(): Boolean = package_ != null + fun minimum(): NewFloatingMinimumCompositePrice? = minimum - fun isMatrix(): Boolean = matrix != null + fun percent(): Percent? = percent - fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun eventOutput(): EventOutput? = eventOutput + + fun isUnit(): Boolean = unit != null fun isTiered(): Boolean = tiered != null - fun isTieredBps(): Boolean = tieredBps != null + fun isBulk(): Boolean = bulk != null - fun isBps(): Boolean = bps != null + fun isBulkWithFilters(): Boolean = bulkWithFilters != null - fun isBulkBps(): Boolean = bulkBps != null + fun isPackage(): Boolean = package_ != null - fun isBulk(): Boolean = bulk != null + fun isMatrix(): Boolean = matrix != null fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null fun isTieredPackage(): Boolean = tieredPackage != null - fun isGroupedTiered(): Boolean = groupedTiered != null - - fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null - fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null - fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + fun isGroupedTiered(): Boolean = groupedTiered != null fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + fun isUnitWithPercent(): Boolean = unitWithPercent != null + fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isTieredWithProration(): Boolean = tieredWithProration != null fun isUnitWithProration(): Boolean = unitWithProration != null fun isGroupedAllocation(): Boolean = groupedAllocation != null + fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null - fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null + fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null fun isScalableMatrixWithTieredPricing(): Boolean = @@ -1903,24 +1953,25 @@ private constructor( fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null - fun asUnit(): NewFloatingUnitPrice = unit.getOrThrow("unit") + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null - fun asPackage(): NewFloatingPackagePrice = package_.getOrThrow("package_") + fun isMinimum(): Boolean = minimum != null - fun asMatrix(): NewFloatingMatrixPrice = matrix.getOrThrow("matrix") + fun isPercent(): Boolean = percent != null - fun asMatrixWithAllocation(): NewFloatingMatrixWithAllocationPrice = - matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun isEventOutput(): Boolean = eventOutput != null + + fun asUnit(): NewFloatingUnitPrice = unit.getOrThrow("unit") fun asTiered(): NewFloatingTieredPrice = tiered.getOrThrow("tiered") - fun asTieredBps(): NewFloatingTieredBpsPrice = tieredBps.getOrThrow("tieredBps") + fun asBulk(): NewFloatingBulkPrice = bulk.getOrThrow("bulk") - fun asBps(): NewFloatingBpsPrice = bps.getOrThrow("bps") + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") - fun asBulkBps(): NewFloatingBulkBpsPrice = bulkBps.getOrThrow("bulkBps") + fun asPackage(): NewFloatingPackagePrice = package_.getOrThrow("package_") - fun asBulk(): NewFloatingBulkPrice = bulk.getOrThrow("bulk") + fun asMatrix(): NewFloatingMatrixPrice = matrix.getOrThrow("matrix") fun asThresholdTotalAmount(): NewFloatingThresholdTotalAmountPrice = thresholdTotalAmount.getOrThrow("thresholdTotalAmount") @@ -1928,24 +1979,24 @@ private constructor( fun asTieredPackage(): NewFloatingTieredPackagePrice = tieredPackage.getOrThrow("tieredPackage") - fun asGroupedTiered(): NewFloatingGroupedTieredPrice = - groupedTiered.getOrThrow("groupedTiered") - - fun asMaxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice = - maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") - fun asTieredWithMinimum(): NewFloatingTieredWithMinimumPrice = tieredWithMinimum.getOrThrow("tieredWithMinimum") - fun asPackageWithAllocation(): NewFloatingPackageWithAllocationPrice = - packageWithAllocation.getOrThrow("packageWithAllocation") + fun asGroupedTiered(): NewFloatingGroupedTieredPrice = + groupedTiered.getOrThrow("groupedTiered") fun asTieredPackageWithMinimum(): NewFloatingTieredPackageWithMinimumPrice = tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + fun asPackageWithAllocation(): NewFloatingPackageWithAllocationPrice = + packageWithAllocation.getOrThrow("packageWithAllocation") + fun asUnitWithPercent(): NewFloatingUnitWithPercentPrice = unitWithPercent.getOrThrow("unitWithPercent") + fun asMatrixWithAllocation(): NewFloatingMatrixWithAllocationPrice = + matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun asTieredWithProration(): NewFloatingTieredWithProrationPrice = tieredWithProration.getOrThrow("tieredWithProration") @@ -1955,21 +2006,27 @@ private constructor( fun asGroupedAllocation(): NewFloatingGroupedAllocationPrice = groupedAllocation.getOrThrow("groupedAllocation") + fun asBulkWithProration(): NewFloatingBulkWithProrationPrice = + bulkWithProration.getOrThrow("bulkWithProration") + fun asGroupedWithProratedMinimum(): NewFloatingGroupedWithProratedMinimumPrice = groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") fun asGroupedWithMeteredMinimum(): NewFloatingGroupedWithMeteredMinimumPrice = groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") + fun asMatrixWithDisplayName(): NewFloatingMatrixWithDisplayNamePrice = matrixWithDisplayName.getOrThrow("matrixWithDisplayName") - fun asBulkWithProration(): NewFloatingBulkWithProrationPrice = - bulkWithProration.getOrThrow("bulkWithProration") - fun asGroupedTieredPackage(): NewFloatingGroupedTieredPackagePrice = groupedTieredPackage.getOrThrow("groupedTieredPackage") + fun asMaxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice = + maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") + fun asScalableMatrixWithUnitPricing(): NewFloatingScalableMatrixWithUnitPricingPrice = scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") @@ -1980,45 +2037,54 @@ private constructor( fun asCumulativeGroupedBulk(): NewFloatingCumulativeGroupedBulkPrice = cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") + + fun asMinimum(): NewFloatingMinimumCompositePrice = minimum.getOrThrow("minimum") + + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") + fun _json(): JsonValue? = _json fun accept(visitor: Visitor): T = when { unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) - matrixWithAllocation != null -> - visitor.visitMatrixWithAllocation(matrixWithAllocation) tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) thresholdTotalAmount != null -> visitor.visitThresholdTotalAmount(thresholdTotalAmount) tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) - maxGroupTieredPackage != null -> - visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) - packageWithAllocation != null -> - visitor.visitPackageWithAllocation(packageWithAllocation) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) tieredPackageWithMinimum != null -> visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) + packageWithAllocation != null -> + visitor.visitPackageWithAllocation(packageWithAllocation) unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + matrixWithAllocation != null -> + visitor.visitMatrixWithAllocation(matrixWithAllocation) tieredWithProration != null -> visitor.visitTieredWithProration(tieredWithProration) unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedWithProratedMinimum != null -> visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) groupedWithMeteredMinimum != null -> visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) matrixWithDisplayName != null -> visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedTieredPackage != null -> visitor.visitGroupedTieredPackage(groupedTieredPackage) + maxGroupTieredPackage != null -> + visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) scalableMatrixWithUnitPricing != null -> visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) scalableMatrixWithTieredPricing != null -> @@ -2027,6 +2093,11 @@ private constructor( ) cumulativeGroupedBulk != null -> visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) else -> visitor.unknown(_json) } @@ -2043,38 +2114,24 @@ private constructor( unit.validate() } - override fun visitPackage(package_: NewFloatingPackagePrice) { - package_.validate() - } - - override fun visitMatrix(matrix: NewFloatingMatrixPrice) { - matrix.validate() - } - - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ) { - matrixWithAllocation.validate() - } - override fun visitTiered(tiered: NewFloatingTieredPrice) { tiered.validate() } - override fun visitTieredBps(tieredBps: NewFloatingTieredBpsPrice) { - tieredBps.validate() + override fun visitBulk(bulk: NewFloatingBulkPrice) { + bulk.validate() } - override fun visitBps(bps: NewFloatingBpsPrice) { - bps.validate() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() } - override fun visitBulkBps(bulkBps: NewFloatingBulkBpsPrice) { - bulkBps.validate() + override fun visitPackage(package_: NewFloatingPackagePrice) { + package_.validate() } - override fun visitBulk(bulk: NewFloatingBulkPrice) { - bulk.validate() + override fun visitMatrix(matrix: NewFloatingMatrixPrice) { + matrix.validate() } override fun visitThresholdTotalAmount( @@ -2089,28 +2146,16 @@ private constructor( tieredPackage.validate() } - override fun visitGroupedTiered( - groupedTiered: NewFloatingGroupedTieredPrice - ) { - groupedTiered.validate() - } - - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice - ) { - maxGroupTieredPackage.validate() - } - override fun visitTieredWithMinimum( tieredWithMinimum: NewFloatingTieredWithMinimumPrice ) { tieredWithMinimum.validate() } - override fun visitPackageWithAllocation( - packageWithAllocation: NewFloatingPackageWithAllocationPrice + override fun visitGroupedTiered( + groupedTiered: NewFloatingGroupedTieredPrice ) { - packageWithAllocation.validate() + groupedTiered.validate() } override fun visitTieredPackageWithMinimum( @@ -2119,12 +2164,24 @@ private constructor( tieredPackageWithMinimum.validate() } - override fun visitUnitWithPercent( - unitWithPercent: NewFloatingUnitWithPercentPrice + override fun visitPackageWithAllocation( + packageWithAllocation: NewFloatingPackageWithAllocationPrice + ) { + packageWithAllocation.validate() + } + + override fun visitUnitWithPercent( + unitWithPercent: NewFloatingUnitWithPercentPrice ) { unitWithPercent.validate() } + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ) { + matrixWithAllocation.validate() + } + override fun visitTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ) { @@ -2143,6 +2200,12 @@ private constructor( groupedAllocation.validate() } + override fun visitBulkWithProration( + bulkWithProration: NewFloatingBulkWithProrationPrice + ) { + bulkWithProration.validate() + } + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ) { @@ -2155,16 +2218,16 @@ private constructor( groupedWithMeteredMinimum.validate() } - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds ) { - matrixWithDisplayName.validate() + groupedWithMinMaxThresholds.validate() } - override fun visitBulkWithProration( - bulkWithProration: NewFloatingBulkWithProrationPrice + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ) { - bulkWithProration.validate() + matrixWithDisplayName.validate() } override fun visitGroupedTieredPackage( @@ -2173,6 +2236,12 @@ private constructor( groupedTieredPackage.validate() } + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ) { + maxGroupTieredPackage.validate() + } + override fun visitScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice @@ -2192,6 +2261,24 @@ private constructor( ) { cumulativeGroupedBulk.validate() } + + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) { + cumulativeGroupedAllocation.validate() + } + + override fun visitMinimum(minimum: NewFloatingMinimumCompositePrice) { + minimum.validate() + } + + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() + } } ) validated = true @@ -2216,26 +2303,17 @@ private constructor( object : Visitor { override fun visitUnit(unit: NewFloatingUnitPrice) = unit.validity() - override fun visitPackage(package_: NewFloatingPackagePrice) = - package_.validity() - - override fun visitMatrix(matrix: NewFloatingMatrixPrice) = matrix.validity() - - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ) = matrixWithAllocation.validity() - override fun visitTiered(tiered: NewFloatingTieredPrice) = tiered.validity() - override fun visitTieredBps(tieredBps: NewFloatingTieredBpsPrice) = - tieredBps.validity() + override fun visitBulk(bulk: NewFloatingBulkPrice) = bulk.validity() - override fun visitBps(bps: NewFloatingBpsPrice) = bps.validity() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() - override fun visitBulkBps(bulkBps: NewFloatingBulkBpsPrice) = - bulkBps.validity() + override fun visitPackage(package_: NewFloatingPackagePrice) = + package_.validity() - override fun visitBulk(bulk: NewFloatingBulkPrice) = bulk.validity() + override fun visitMatrix(matrix: NewFloatingMatrixPrice) = matrix.validity() override fun visitThresholdTotalAmount( thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice @@ -2245,30 +2323,30 @@ private constructor( tieredPackage: NewFloatingTieredPackagePrice ) = tieredPackage.validity() - override fun visitGroupedTiered( - groupedTiered: NewFloatingGroupedTieredPrice - ) = groupedTiered.validity() - - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice - ) = maxGroupTieredPackage.validity() - override fun visitTieredWithMinimum( tieredWithMinimum: NewFloatingTieredWithMinimumPrice ) = tieredWithMinimum.validity() - override fun visitPackageWithAllocation( - packageWithAllocation: NewFloatingPackageWithAllocationPrice - ) = packageWithAllocation.validity() + override fun visitGroupedTiered( + groupedTiered: NewFloatingGroupedTieredPrice + ) = groupedTiered.validity() override fun visitTieredPackageWithMinimum( tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice ) = tieredPackageWithMinimum.validity() + override fun visitPackageWithAllocation( + packageWithAllocation: NewFloatingPackageWithAllocationPrice + ) = packageWithAllocation.validity() + override fun visitUnitWithPercent( unitWithPercent: NewFloatingUnitWithPercentPrice ) = unitWithPercent.validity() + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ) = matrixWithAllocation.validity() + override fun visitTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ) = tieredWithProration.validity() @@ -2281,6 +2359,10 @@ private constructor( groupedAllocation: NewFloatingGroupedAllocationPrice ) = groupedAllocation.validity() + override fun visitBulkWithProration( + bulkWithProration: NewFloatingBulkWithProrationPrice + ) = bulkWithProration.validity() + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ) = groupedWithProratedMinimum.validity() @@ -2289,18 +2371,22 @@ private constructor( groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice ) = groupedWithMeteredMinimum.validity() + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + override fun visitMatrixWithDisplayName( matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ) = matrixWithDisplayName.validity() - override fun visitBulkWithProration( - bulkWithProration: NewFloatingBulkWithProrationPrice - ) = bulkWithProration.validity() - override fun visitGroupedTieredPackage( groupedTieredPackage: NewFloatingGroupedTieredPackagePrice ) = groupedTieredPackage.validity() + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ) = maxGroupTieredPackage.validity() + override fun visitScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice @@ -2315,6 +2401,18 @@ private constructor( cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice ) = cumulativeGroupedBulk.validity() + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() + + override fun visitMinimum(minimum: NewFloatingMinimumCompositePrice) = + minimum.validity() + + override fun visitPercent(percent: Percent) = percent.validity() + + override fun visitEventOutput(eventOutput: EventOutput) = + eventOutput.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -2324,53 +2422,122 @@ private constructor( return true } - return /* spotless:off */ other is Price && unit == other.unit && package_ == other.package_ && matrix == other.matrix && matrixWithAllocation == other.matrixWithAllocation && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && groupedTiered == other.groupedTiered && maxGroupTieredPackage == other.maxGroupTieredPackage && tieredWithMinimum == other.tieredWithMinimum && packageWithAllocation == other.packageWithAllocation && tieredPackageWithMinimum == other.tieredPackageWithMinimum && unitWithPercent == other.unitWithPercent && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && bulkWithProration == other.bulkWithProration && groupedTieredPackage == other.groupedTieredPackage && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk /* spotless:on */ + return other is Price && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, matrixWithAllocation, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, groupedTiered, maxGroupTieredPackage, tieredWithMinimum, packageWithAllocation, tieredPackageWithMinimum, unitWithPercent, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, groupedWithMeteredMinimum, matrixWithDisplayName, bulkWithProration, groupedTieredPackage, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) override fun toString(): String = when { unit != null -> "Price{unit=$unit}" - package_ != null -> "Price{package_=$package_}" - matrix != null -> "Price{matrix=$matrix}" - matrixWithAllocation != null -> - "Price{matrixWithAllocation=$matrixWithAllocation}" tiered != null -> "Price{tiered=$tiered}" - tieredBps != null -> "Price{tieredBps=$tieredBps}" - bps != null -> "Price{bps=$bps}" - bulkBps != null -> "Price{bulkBps=$bulkBps}" bulk != null -> "Price{bulk=$bulk}" + bulkWithFilters != null -> "Price{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "Price{package_=$package_}" + matrix != null -> "Price{matrix=$matrix}" thresholdTotalAmount != null -> "Price{thresholdTotalAmount=$thresholdTotalAmount}" tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" - groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" - maxGroupTieredPackage != null -> - "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" - packageWithAllocation != null -> - "Price{packageWithAllocation=$packageWithAllocation}" + groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" tieredPackageWithMinimum != null -> "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" + packageWithAllocation != null -> + "Price{packageWithAllocation=$packageWithAllocation}" unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + matrixWithAllocation != null -> + "Price{matrixWithAllocation=$matrixWithAllocation}" tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedWithProratedMinimum != null -> "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" groupedWithMeteredMinimum != null -> "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "Price{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" matrixWithDisplayName != null -> "Price{matrixWithDisplayName=$matrixWithDisplayName}" - bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedTieredPackage != null -> "Price{groupedTieredPackage=$groupedTieredPackage}" + maxGroupTieredPackage != null -> + "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" scalableMatrixWithUnitPricing != null -> "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" scalableMatrixWithTieredPricing != null -> "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" cumulativeGroupedBulk != null -> "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" + cumulativeGroupedAllocation != null -> + "Price{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "Price{minimum=$minimum}" + percent != null -> "Price{percent=$percent}" + eventOutput != null -> "Price{eventOutput=$eventOutput}" _json != null -> "Price{_unknown=$_json}" else -> throw IllegalStateException("Invalid Price") } @@ -2379,23 +2546,16 @@ private constructor( fun ofUnit(unit: NewFloatingUnitPrice) = Price(unit = unit) - fun ofPackage(package_: NewFloatingPackagePrice) = Price(package_ = package_) - - fun ofMatrix(matrix: NewFloatingMatrixPrice) = Price(matrix = matrix) - - fun ofMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ) = Price(matrixWithAllocation = matrixWithAllocation) - fun ofTiered(tiered: NewFloatingTieredPrice) = Price(tiered = tiered) - fun ofTieredBps(tieredBps: NewFloatingTieredBpsPrice) = Price(tieredBps = tieredBps) + fun ofBulk(bulk: NewFloatingBulkPrice) = Price(bulk = bulk) - fun ofBps(bps: NewFloatingBpsPrice) = Price(bps = bps) + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + Price(bulkWithFilters = bulkWithFilters) - fun ofBulkBps(bulkBps: NewFloatingBulkBpsPrice) = Price(bulkBps = bulkBps) + fun ofPackage(package_: NewFloatingPackagePrice) = Price(package_ = package_) - fun ofBulk(bulk: NewFloatingBulkPrice) = Price(bulk = bulk) + fun ofMatrix(matrix: NewFloatingMatrixPrice) = Price(matrix = matrix) fun ofThresholdTotalAmount( thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice @@ -2404,27 +2564,27 @@ private constructor( fun ofTieredPackage(tieredPackage: NewFloatingTieredPackagePrice) = Price(tieredPackage = tieredPackage) - fun ofGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice) = - Price(groupedTiered = groupedTiered) - - fun ofMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice - ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) - fun ofTieredWithMinimum(tieredWithMinimum: NewFloatingTieredWithMinimumPrice) = Price(tieredWithMinimum = tieredWithMinimum) - fun ofPackageWithAllocation( - packageWithAllocation: NewFloatingPackageWithAllocationPrice - ) = Price(packageWithAllocation = packageWithAllocation) + fun ofGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice) = + Price(groupedTiered = groupedTiered) fun ofTieredPackageWithMinimum( tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + fun ofPackageWithAllocation( + packageWithAllocation: NewFloatingPackageWithAllocationPrice + ) = Price(packageWithAllocation = packageWithAllocation) + fun ofUnitWithPercent(unitWithPercent: NewFloatingUnitWithPercentPrice) = Price(unitWithPercent = unitWithPercent) + fun ofMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ) = Price(matrixWithAllocation = matrixWithAllocation) + fun ofTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ) = Price(tieredWithProration = tieredWithProration) @@ -2435,6 +2595,9 @@ private constructor( fun ofGroupedAllocation(groupedAllocation: NewFloatingGroupedAllocationPrice) = Price(groupedAllocation = groupedAllocation) + fun ofBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice) = + Price(bulkWithProration = bulkWithProration) + fun ofGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) @@ -2443,17 +2606,22 @@ private constructor( groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = Price(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + fun ofMatrixWithDisplayName( matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ) = Price(matrixWithDisplayName = matrixWithDisplayName) - fun ofBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice) = - Price(bulkWithProration = bulkWithProration) - fun ofGroupedTieredPackage( groupedTieredPackage: NewFloatingGroupedTieredPackagePrice ) = Price(groupedTieredPackage = groupedTieredPackage) + fun ofMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) + fun ofScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice ) = Price(scalableMatrixWithUnitPricing = scalableMatrixWithUnitPricing) @@ -2465,6 +2633,16 @@ private constructor( fun ofCumulativeGroupedBulk( cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) + + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = Price(cumulativeGroupedAllocation = cumulativeGroupedAllocation) + + fun ofMinimum(minimum: NewFloatingMinimumCompositePrice) = Price(minimum = minimum) + + fun ofPercent(percent: Percent) = Price(percent = percent) + + fun ofEventOutput(eventOutput: EventOutput) = Price(eventOutput = eventOutput) } /** @@ -2474,23 +2652,15 @@ private constructor( fun visitUnit(unit: NewFloatingUnitPrice): T - fun visitPackage(package_: NewFloatingPackagePrice): T - - fun visitMatrix(matrix: NewFloatingMatrixPrice): T - - fun visitMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ): T - fun visitTiered(tiered: NewFloatingTieredPrice): T - fun visitTieredBps(tieredBps: NewFloatingTieredBpsPrice): T + fun visitBulk(bulk: NewFloatingBulkPrice): T - fun visitBps(bps: NewFloatingBpsPrice): T + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T - fun visitBulkBps(bulkBps: NewFloatingBulkBpsPrice): T + fun visitPackage(package_: NewFloatingPackagePrice): T - fun visitBulk(bulk: NewFloatingBulkPrice): T + fun visitMatrix(matrix: NewFloatingMatrixPrice): T fun visitThresholdTotalAmount( thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice @@ -2498,24 +2668,24 @@ private constructor( fun visitTieredPackage(tieredPackage: NewFloatingTieredPackagePrice): T + fun visitTieredWithMinimum(tieredWithMinimum: NewFloatingTieredWithMinimumPrice): T + fun visitGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice): T - fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice ): T - fun visitTieredWithMinimum(tieredWithMinimum: NewFloatingTieredWithMinimumPrice): T - fun visitPackageWithAllocation( packageWithAllocation: NewFloatingPackageWithAllocationPrice ): T - fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice - ): T - fun visitUnitWithPercent(unitWithPercent: NewFloatingUnitWithPercentPrice): T + fun visitMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ): T + fun visitTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ): T @@ -2524,6 +2694,8 @@ private constructor( fun visitGroupedAllocation(groupedAllocation: NewFloatingGroupedAllocationPrice): T + fun visitBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice): T + fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ): T @@ -2532,16 +2704,22 @@ private constructor( groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice ): T + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ): T + fun visitMatrixWithDisplayName( matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ): T - fun visitBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice): T - fun visitGroupedTieredPackage( groupedTieredPackage: NewFloatingGroupedTieredPackagePrice ): T + fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ): T + fun visitScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice ): T @@ -2554,6 +2732,16 @@ private constructor( cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice ): T + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ): T + + fun visitMinimum(minimum: NewFloatingMinimumCompositePrice): T + + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T + /** * Maps an unknown variant of [Price] to a value of type [T]. * @@ -2580,42 +2768,27 @@ private constructor( return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(unit = it, _json = json) } ?: Price(_json = json) } - "package" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) - } - "matrix" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) - } - "matrix_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithAllocation = it, _json = json) } - ?: Price(_json = json) - } "tiered" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(tiered = it, _json = json) } ?: Price(_json = json) } - "tiered_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(tieredBps = it, _json = json) } ?: Price(_json = json) - } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bps = it, _json = json) } ?: Price(_json = json) - } - "bulk_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bulkBps = it, _json = json) } ?: Price(_json = json) - } "bulk" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(bulk = it, _json = json) } ?: Price(_json = json) } + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulkWithFilters = it, _json = json) + } ?: Price(_json = json) + } + "package" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) + } + "matrix" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) + } "threshold_total_amount" -> { return tryDeserialize( node, @@ -2632,28 +2805,28 @@ private constructor( ?.let { Price(tieredPackage = it, _json = json) } ?: Price(_json = json) } - "grouped_tiered" -> { + "tiered_with_minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(groupedTiered = it, _json = json) } + ?.let { Price(tieredWithMinimum = it, _json = json) } ?: Price(_json = json) } - "max_group_tiered_package" -> { + "grouped_tiered" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(maxGroupTieredPackage = it, _json = json) } + ?.let { Price(groupedTiered = it, _json = json) } ?: Price(_json = json) } - "tiered_with_minimum" -> { + "tiered_package_with_minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(tieredWithMinimum = it, _json = json) } + ?.let { Price(tieredPackageWithMinimum = it, _json = json) } ?: Price(_json = json) } "package_with_allocation" -> { @@ -2664,20 +2837,20 @@ private constructor( ?.let { Price(packageWithAllocation = it, _json = json) } ?: Price(_json = json) } - "tiered_package_with_minimum" -> { + "unit_with_percent" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(tieredPackageWithMinimum = it, _json = json) } + ?.let { Price(unitWithPercent = it, _json = json) } ?: Price(_json = json) } - "unit_with_percent" -> { + "matrix_with_allocation" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(unitWithPercent = it, _json = json) } + ?.let { Price(matrixWithAllocation = it, _json = json) } ?: Price(_json = json) } "tiered_with_proration" -> { @@ -2704,6 +2877,14 @@ private constructor( ?.let { Price(groupedAllocation = it, _json = json) } ?: Price(_json = json) } + "bulk_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(bulkWithProration = it, _json = json) } + ?: Price(_json = json) + } "grouped_with_prorated_minimum" -> { return tryDeserialize( node, @@ -2720,20 +2901,20 @@ private constructor( ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } ?: Price(_json = json) } - "matrix_with_display_name" -> { + "grouped_with_min_max_thresholds" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(matrixWithDisplayName = it, _json = json) } + ?.let { Price(groupedWithMinMaxThresholds = it, _json = json) } ?: Price(_json = json) } - "bulk_with_proration" -> { + "matrix_with_display_name" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(bulkWithProration = it, _json = json) } + ?.let { Price(matrixWithDisplayName = it, _json = json) } ?: Price(_json = json) } "grouped_tiered_package" -> { @@ -2744,6 +2925,14 @@ private constructor( ?.let { Price(groupedTieredPackage = it, _json = json) } ?: Price(_json = json) } + "max_group_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(maxGroupTieredPackage = it, _json = json) } + ?: Price(_json = json) + } "scalable_matrix_with_unit_pricing" -> { return tryDeserialize( node, @@ -2770,6 +2959,31 @@ private constructor( ?.let { Price(cumulativeGroupedBulk = it, _json = json) } ?: Price(_json = json) } + "cumulative_grouped_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(cumulativeGroupedAllocation = it, _json = json) } + ?: Price(_json = json) + } + "minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(minimum = it, _json = json) } ?: Price(_json = json) + } + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(percent = it, _json = json) + } ?: Price(_json = json) + } + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(eventOutput = it, _json = json) + } ?: Price(_json = json) + } } return Price(_json = json) @@ -2785,69 +2999,8414 @@ private constructor( ) { when { value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) - value.matrixWithAllocation != null -> - generator.writeObject(value.matrixWithAllocation) value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> + generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) value.thresholdTotalAmount != null -> generator.writeObject(value.thresholdTotalAmount) value.tieredPackage != null -> generator.writeObject(value.tieredPackage) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) - value.maxGroupTieredPackage != null -> - generator.writeObject(value.maxGroupTieredPackage) value.tieredWithMinimum != null -> generator.writeObject(value.tieredWithMinimum) - value.packageWithAllocation != null -> - generator.writeObject(value.packageWithAllocation) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) value.tieredPackageWithMinimum != null -> generator.writeObject(value.tieredPackageWithMinimum) + value.packageWithAllocation != null -> + generator.writeObject(value.packageWithAllocation) value.unitWithPercent != null -> generator.writeObject(value.unitWithPercent) + value.matrixWithAllocation != null -> + generator.writeObject(value.matrixWithAllocation) value.tieredWithProration != null -> generator.writeObject(value.tieredWithProration) value.unitWithProration != null -> generator.writeObject(value.unitWithProration) value.groupedAllocation != null -> generator.writeObject(value.groupedAllocation) + value.bulkWithProration != null -> + generator.writeObject(value.bulkWithProration) value.groupedWithProratedMinimum != null -> generator.writeObject(value.groupedWithProratedMinimum) value.groupedWithMeteredMinimum != null -> generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) value.matrixWithDisplayName != null -> generator.writeObject(value.matrixWithDisplayName) - value.bulkWithProration != null -> - generator.writeObject(value.bulkWithProration) value.groupedTieredPackage != null -> generator.writeObject(value.groupedTieredPackage) + value.maxGroupTieredPackage != null -> + generator.writeObject(value.maxGroupTieredPackage) value.scalableMatrixWithUnitPricing != null -> generator.writeObject(value.scalableMatrixWithUnitPricing) value.scalableMatrixWithTieredPricing != null -> generator.writeObject(value.scalableMatrixWithTieredPricing) value.cumulativeGroupedBulk != null -> generator.writeObject(value.cumulativeGroupedBulk) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Price") } } } - } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bulkWithFiltersConfig: JsonField, + private val cadence: JsonField, + private val currency: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + bulkWithFiltersConfig, + cadence, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) - return /* spotless:off */ other is PriceEvaluation && externalPriceId == other.externalPriceId && filter == other.filter && groupingKeys == other.groupingKeys && price == other.price && priceId == other.priceId && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(externalPriceId, filter, groupingKeys, price, priceId, additionalProperties) } - /* spotless:on */ + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = + bulkWithFiltersConfig + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [BulkWithFilters]. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .currency() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFilters]. */ + class Builder internal constructor() { + + private var bulkWithFiltersConfig: JsonField? = null + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + currency = bulkWithFilters.currency + itemId = bulkWithFilters.itemId + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + billableMetricId = bulkWithFilters.billableMetricId + billedInAdvance = bulkWithFilters.billedInAdvance + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + dimensionalPriceConfiguration = + bulkWithFilters.dimensionalPriceConfiguration + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoiceGroupingKey = bulkWithFilters.invoiceGroupingKey + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + metadata = bulkWithFilters.metadata + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() + } + + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig( + bulkWithFiltersConfig: JsonField + ) = apply { this.bulkWithFiltersConfig = bulkWithFiltersConfig } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BulkWithFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .currency() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFilters = + BulkWithFilters( + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFilters = apply { + if (validated) { + return@apply + } + + bulkWithFiltersConfig().validate() + cadence().validate() + currency() + itemId() + _modelType().let { + if (it != JsonValue.from("bulk_with_filters")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) + + /** + * Property filters to apply (all must match) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [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 + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { + + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithFiltersConfig.additionalProperties.toMutableMap() + } + + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + + /** Bulk tiers for rating based on total usage volume */ + 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 [BulkWithFiltersConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } + + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = + propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + propertyKey() + propertyValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = + tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filters, tiers, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFilters && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bulkWithFiltersConfig, + cadence, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFilters{bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val currency: JsonField, + private val groupedWithMinMaxThresholdsConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + groupedWithMinMaxThresholdsConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + currency, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * Configuration for grouped_with_min_max_thresholds pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired( + "grouped_with_min_max_thresholds_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. + * + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + fun _groupedWithMinMaxThresholdsConfig(): + JsonField = groupedWithMinMaxThresholdsConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 + * [GroupedWithMinMaxThresholds]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholds]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("grouped_with_min_max_thresholds") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = + apply { + cadence = groupedWithMinMaxThresholds.cadence + currency = groupedWithMinMaxThresholds.currency + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + itemId = groupedWithMinMaxThresholds.itemId + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + billableMetricId = groupedWithMinMaxThresholds.billableMetricId + billedInAdvance = groupedWithMinMaxThresholds.billedInAdvance + billingCycleConfiguration = + groupedWithMinMaxThresholds.billingCycleConfiguration + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + invoiceGroupingKey = groupedWithMinMaxThresholds.invoiceGroupingKey + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + metadata = groupedWithMinMaxThresholds.metadata + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = + groupedWithMinMaxThresholdsConfig( + JsonField.of(groupedWithMinMaxThresholdsConfig) + ) + + /** + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a + * well-typed [GroupedWithMinMaxThresholdsConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: + JsonField + ) = apply { + this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholds = apply { + if (validated) { + return@apply + } + + cadence().validate() + currency() + groupedWithMinMaxThresholdsConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @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 + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate + additionalProperties = + groupedWithMinMaxThresholdsConfig.additionalProperties + .toMutableMap() + } + + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } + + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } + + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = + perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + if (validated) { + return@apply + } + + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholds && + cadence == other.cadence && + currency == other.currency && + groupedWithMinMaxThresholdsConfig == + other.groupedWithMinMaxThresholdsConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholds{cadence=$cadence, currency=$currency, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val cumulativeGroupedAllocationConfig: + JsonField, + private val currency: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + cumulativeGroupedAllocationConfig, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for cumulative_grouped_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired( + "cumulative_grouped_allocation_config" + ) + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): + JsonField = cumulativeGroupedAllocationConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 + * [CumulativeGroupedAllocation]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .currency() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocation]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null + private var currency: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("cumulative_grouped_allocation") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = + apply { + cadence = cumulativeGroupedAllocation.cadence + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + currency = cumulativeGroupedAllocation.currency + itemId = cumulativeGroupedAllocation.itemId + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + billableMetricId = cumulativeGroupedAllocation.billableMetricId + billedInAdvance = cumulativeGroupedAllocation.billedInAdvance + billingCycleConfiguration = + cumulativeGroupedAllocation.billingCycleConfiguration + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoiceGroupingKey = cumulativeGroupedAllocation.invoiceGroupingKey + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + metadata = cumulativeGroupedAllocation.metadata + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = + cumulativeGroupedAllocationConfig( + JsonField.of(cumulativeGroupedAllocationConfig) + ) + + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a + * well-typed [CumulativeGroupedAllocationConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: + JsonField + ) = apply { + this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig + } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .currency() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( + checkRequired("cadence", cadence), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), + checkRequired("currency", currency), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocation = apply { + if (validated) { + return@apply + } + + cadence().validate() + cumulativeGroupedAllocationConfig().validate() + currency() + itemId() + _modelType().let { + if (it != JsonValue.from("cumulative_grouped_allocation")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + mutableMapOf(), + ) + + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 + * [CumulativeGroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = + cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties + .toMutableMap() + } + + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } + + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation + } + + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply + } + + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocation && + cadence == other.cadence && + cumulativeGroupedAllocationConfig == + other.cumulativeGroupedAllocationConfig && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedAllocationConfig, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocation{cadence=$cadence, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val currency: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val percentConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + currency, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [Percent]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .itemId() + * .name() + * .percentConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Percent]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("percent") + private var name: JsonField? = null + private var percentConfig: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percent: Percent) = apply { + cadence = percent.cadence + currency = percent.currency + itemId = percent.itemId + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + billableMetricId = percent.billableMetricId + billedInAdvance = percent.billedInAdvance + billingCycleConfiguration = percent.billingCycleConfiguration + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoiceGroupingKey = percent.invoiceGroupingKey + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + metadata = percent.metadata + additionalProperties = percent.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed + * [PercentConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Percent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .itemId() + * .name() + * .percentConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Percent = + Percent( + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("percentConfig", percentConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Percent = apply { + if (validated) { + return@apply + } + + cadence().validate() + currency() + itemId() + _modelType().let { + if (it != JsonValue.from("percent")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + percentConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent") + @ExcludeMissing + fun _percent(): JsonField = percent + + @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 + * [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PercentConfig]. */ + class Builder internal constructor() { + + private var percent: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() + } + + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PercentConfig = apply { + if (validated) { + return@apply + } + + percent() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(percent, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Percent && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Percent{cadence=$cadence, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, percentConfig=$percentConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val currency: JsonField, + private val eventOutputConfig: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + currency, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [EventOutput]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutput]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var eventOutputConfig: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("event_output") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutput: EventOutput) = apply { + cadence = eventOutput.cadence + currency = eventOutput.currency + eventOutputConfig = eventOutput.eventOutputConfig + itemId = eventOutput.itemId + modelType = eventOutput.modelType + name = eventOutput.name + billableMetricId = eventOutput.billableMetricId + billedInAdvance = eventOutput.billedInAdvance + billingCycleConfiguration = eventOutput.billingCycleConfiguration + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoiceGroupingKey = eventOutput.invoiceGroupingKey + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + metadata = eventOutput.metadata + additionalProperties = eventOutput.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutput = + EventOutput( + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired("eventOutputConfig", eventOutputConfig), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutput = apply { + if (validated) { + return@apply + } + + cadence().validate() + currency() + eventOutputConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("event_output")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a + * unit rate will be ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = + defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events + * will also be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @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 + * [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutputConfig]. */ + class Builder internal constructor() { + + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = + eventOutputConfig.additionalProperties.toMutableMap() + } + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey + } + + /** + * If provided, this amount will be used as the unit rate when an event does + * not have a value for the `unit_rating_key`. If not provided, events + * missing a unit rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate + } + + /** + * An optional key in the event data to group by (e.g., event ID). All + * events will also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutputConfig = apply { + if (validated) { + return@apply + } + + unitRatingKey() + defaultUnitRate() + groupingKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + unitRatingKey, + defaultUnitRate, + groupingKey, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutput && + cadence == other.cadence && + currency == other.currency && + eventOutputConfig == other.eventOutputConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutput{cadence=$cadence, currency=$currency, eventOutputConfig=$eventOutputConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PriceEvaluation && + externalPriceId == other.externalPriceId && + filter == other.filter && + groupingKeys == other.groupingKeys && + price == other.price && + priceId == other.priceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + externalPriceId, + filter, + groupingKeys, + price, + priceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2860,10 +11419,13 @@ private constructor( return true } - return /* spotless:off */ other is PriceEvaluatePreviewEventsParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PriceEvaluatePreviewEventsParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "PriceEvaluatePreviewEventsParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluatePreviewEventsResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluatePreviewEventsResponse.kt index c29906967..b1b6f3c15 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluatePreviewEventsResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluatePreviewEventsResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class PriceEvaluatePreviewEventsResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val additionalProperties: MutableMap, @@ -169,6 +170,7 @@ private constructor( internal fun validity(): Int = (data.asKnown()?.sumOf { it.validity().toInt() } ?: 0) class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val currency: JsonField, private val priceGroups: JsonField>, @@ -496,12 +498,25 @@ private constructor( return true } - return /* spotless:off */ other is Data && currency == other.currency && priceGroups == other.priceGroups && externalPriceId == other.externalPriceId && inlinePriceIndex == other.inlinePriceIndex && priceId == other.priceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Data && + currency == other.currency && + priceGroups == other.priceGroups && + externalPriceId == other.externalPriceId && + inlinePriceIndex == other.inlinePriceIndex && + priceId == other.priceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(currency, priceGroups, externalPriceId, inlinePriceIndex, priceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + currency, + priceGroups, + externalPriceId, + inlinePriceIndex, + priceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -514,12 +529,12 @@ private constructor( return true } - return /* spotless:off */ other is PriceEvaluatePreviewEventsResponse && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PriceEvaluatePreviewEventsResponse && + data == other.data && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateResponse.kt index f99cc331d..b872f4dbd 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceEvaluateResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class PriceEvaluateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val additionalProperties: MutableMap, @@ -173,12 +174,12 @@ private constructor( return true } - return /* spotless:off */ other is PriceEvaluateResponse && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PriceEvaluateResponse && + data == other.data && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceExternalPriceIdFetchParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceExternalPriceIdFetchParams.kt index cbfbf3315..242c6f86b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceExternalPriceIdFetchParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceExternalPriceIdFetchParams.kt @@ -185,10 +185,14 @@ private constructor( return true } - return /* spotless:off */ other is PriceExternalPriceIdFetchParams && externalPriceId == other.externalPriceId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PriceExternalPriceIdFetchParams && + externalPriceId == other.externalPriceId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalPriceId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(externalPriceId, additionalHeaders, additionalQueryParams) override fun toString() = "PriceExternalPriceIdFetchParams{externalPriceId=$externalPriceId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceExternalPriceIdUpdateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceExternalPriceIdUpdateParams.kt index 9ae4c6efa..bbc17fe46 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceExternalPriceIdUpdateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceExternalPriceIdUpdateParams.kt @@ -260,6 +260,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val metadata: JsonField, private val additionalProperties: MutableMap, @@ -393,12 +394,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -498,12 +499,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -515,10 +514,15 @@ private constructor( return true } - return /* spotless:off */ other is PriceExternalPriceIdUpdateParams && externalPriceId == other.externalPriceId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PriceExternalPriceIdUpdateParams && + externalPriceId == other.externalPriceId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(externalPriceId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(externalPriceId, body, additionalHeaders, additionalQueryParams) override fun toString() = "PriceExternalPriceIdUpdateParams{externalPriceId=$externalPriceId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceFetchParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceFetchParams.kt index 4bc7493fa..2dc891c00 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceFetchParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceFetchParams.kt @@ -170,10 +170,13 @@ private constructor( return true } - return /* spotless:off */ other is PriceFetchParams && priceId == other.priceId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PriceFetchParams && + priceId == other.priceId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(priceId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(priceId, additionalHeaders, additionalQueryParams) override fun toString() = "PriceFetchParams{priceId=$priceId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceInterval.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceInterval.kt index 5e7f032c2..5f1bbada0 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceInterval.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceInterval.kt @@ -23,9 +23,11 @@ import java.util.Objects * subscription. A subscription’s price intervals define its billing behavior. */ class PriceInterval +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val billingCycleDay: JsonField, + private val canDeferBilling: JsonField, private val currentBillingPeriodEndDate: JsonField, private val currentBillingPeriodStartDate: JsonField, private val endDate: JsonField, @@ -43,6 +45,9 @@ private constructor( @JsonProperty("billing_cycle_day") @ExcludeMissing billingCycleDay: JsonField = JsonMissing.of(), + @JsonProperty("can_defer_billing") + @ExcludeMissing + canDeferBilling: JsonField = JsonMissing.of(), @JsonProperty("current_billing_period_end_date") @ExcludeMissing currentBillingPeriodEndDate: JsonField = JsonMissing.of(), @@ -66,6 +71,7 @@ private constructor( ) : this( id, billingCycleDay, + canDeferBilling, currentBillingPeriodEndDate, currentBillingPeriodStartDate, endDate, @@ -91,6 +97,15 @@ private constructor( */ fun billingCycleDay(): Long = billingCycleDay.getRequired("billing_cycle_day") + /** + * For in-arrears prices. If true, and the price interval ends mid-cycle, the final line item + * will be deferred to the next scheduled invoice instead of being billed mid-cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun canDeferBilling(): Boolean = canDeferBilling.getRequired("can_defer_billing") + /** * The end of the current billing period. This is an exclusive timestamp, such that the instant * returned is exactly the end of the billing period. Set to null if this price interval is not @@ -190,6 +205,15 @@ private constructor( @ExcludeMissing fun _billingCycleDay(): JsonField = billingCycleDay + /** + * Returns the raw JSON value of [canDeferBilling]. + * + * Unlike [canDeferBilling], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("can_defer_billing") + @ExcludeMissing + fun _canDeferBilling(): JsonField = canDeferBilling + /** * Returns the raw JSON value of [currentBillingPeriodEndDate]. * @@ -282,6 +306,7 @@ private constructor( * ```kotlin * .id() * .billingCycleDay() + * .canDeferBilling() * .currentBillingPeriodEndDate() * .currentBillingPeriodStartDate() * .endDate() @@ -300,6 +325,7 @@ private constructor( private var id: JsonField? = null private var billingCycleDay: JsonField? = null + private var canDeferBilling: JsonField? = null private var currentBillingPeriodEndDate: JsonField? = null private var currentBillingPeriodStartDate: JsonField? = null private var endDate: JsonField? = null @@ -315,6 +341,7 @@ private constructor( internal fun from(priceInterval: PriceInterval) = apply { id = priceInterval.id billingCycleDay = priceInterval.billingCycleDay + canDeferBilling = priceInterval.canDeferBilling currentBillingPeriodEndDate = priceInterval.currentBillingPeriodEndDate currentBillingPeriodStartDate = priceInterval.currentBillingPeriodStartDate endDate = priceInterval.endDate @@ -351,6 +378,24 @@ private constructor( this.billingCycleDay = billingCycleDay } + /** + * For in-arrears prices. If true, and the price interval ends mid-cycle, the final line + * item will be deferred to the next scheduled invoice instead of being billed mid-cycle. + */ + fun canDeferBilling(canDeferBilling: Boolean) = + canDeferBilling(JsonField.of(canDeferBilling)) + + /** + * Sets [Builder.canDeferBilling] to an arbitrary JSON value. + * + * You should usually call [Builder.canDeferBilling] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun canDeferBilling(canDeferBilling: JsonField) = apply { + this.canDeferBilling = canDeferBilling + } + /** * The end of the current billing period. This is an exclusive timestamp, such that the * instant returned is exactly the end of the billing period. Set to null if this price @@ -475,28 +520,23 @@ private constructor( fun price(price: JsonField) = apply { this.price = price } /** Alias for calling [price] with `Price.ofUnit(unit)`. */ - fun price(unit: Price.Unit) = price(Price.ofUnit(unit)) - - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: Price.Package) = price(Price.ofPackage(package_)) - - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: Price.Matrix) = price(Price.ofMatrix(matrix)) + fun price(unit: Price.UnitPrice) = price(Price.ofUnit(unit)) /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ fun price(tiered: Price.Tiered) = price(Price.ofTiered(tiered)) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: Price.TieredBps) = price(Price.ofTieredBps(tieredBps)) + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: Price.Bulk) = price(Price.ofBulk(bulk)) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: Price.Bps) = price(Price.ofBps(bps)) + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: Price.BulkBps) = price(Price.ofBulkBps(bulkBps)) + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: Price.Package) = price(Price.ofPackage(package_)) - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: Price.Bulk) = price(Price.ofBulk(bulk)) + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: Price.Matrix) = price(Price.ofMatrix(matrix)) /** Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. */ fun price(thresholdTotalAmount: Price.ThresholdTotalAmount) = @@ -505,13 +545,13 @@ private constructor( /** Alias for calling [price] with `Price.ofTieredPackage(tieredPackage)`. */ fun price(tieredPackage: Price.TieredPackage) = price(Price.ofTieredPackage(tieredPackage)) - /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: Price.GroupedTiered) = price(Price.ofGroupedTiered(groupedTiered)) - /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ fun price(tieredWithMinimum: Price.TieredWithMinimum) = price(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: Price.GroupedTiered) = price(Price.ofGroupedTiered(groupedTiered)) + /** * Alias for calling [price] with * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. @@ -545,6 +585,10 @@ private constructor( fun price(groupedAllocation: Price.GroupedAllocation) = price(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: Price.BulkWithProration) = + price(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [price] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -559,16 +603,19 @@ private constructor( fun price(groupedWithMeteredMinimum: Price.GroupedWithMeteredMinimum) = price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** * Alias for calling [price] with `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. */ fun price(matrixWithDisplayName: Price.MatrixWithDisplayName) = price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: Price.BulkWithProration) = - price(Price.ofBulkWithProration(bulkWithProration)) - /** Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. */ fun price(groupedTieredPackage: Price.GroupedTieredPackage) = price(Price.ofGroupedTieredPackage(groupedTieredPackage)) @@ -601,10 +648,19 @@ private constructor( /** * Alias for calling [price] with - * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. */ - fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = - price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: Price.Minimum) = price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) /** * The start date of the price interval. This is the date that Orb starts billing for this @@ -679,6 +735,7 @@ private constructor( * ```kotlin * .id() * .billingCycleDay() + * .canDeferBilling() * .currentBillingPeriodEndDate() * .currentBillingPeriodStartDate() * .endDate() @@ -695,6 +752,7 @@ private constructor( PriceInterval( checkRequired("id", id), checkRequired("billingCycleDay", billingCycleDay), + checkRequired("canDeferBilling", canDeferBilling), checkRequired("currentBillingPeriodEndDate", currentBillingPeriodEndDate), checkRequired("currentBillingPeriodStartDate", currentBillingPeriodStartDate), checkRequired("endDate", endDate), @@ -718,6 +776,7 @@ private constructor( id() billingCycleDay() + canDeferBilling() currentBillingPeriodEndDate() currentBillingPeriodStartDate() endDate() @@ -745,6 +804,7 @@ private constructor( internal fun validity(): Int = (if (id.asKnown() == null) 0 else 1) + (if (billingCycleDay.asKnown() == null) 0 else 1) + + (if (canDeferBilling.asKnown() == null) 0 else 1) + (if (currentBillingPeriodEndDate.asKnown() == null) 0 else 1) + (if (currentBillingPeriodStartDate.asKnown() == null) 0 else 1) + (if (endDate.asKnown() == null) 0 else 1) + @@ -759,15 +819,40 @@ private constructor( return true } - return /* spotless:off */ other is PriceInterval && id == other.id && billingCycleDay == other.billingCycleDay && currentBillingPeriodEndDate == other.currentBillingPeriodEndDate && currentBillingPeriodStartDate == other.currentBillingPeriodStartDate && endDate == other.endDate && filter == other.filter && fixedFeeQuantityTransitions == other.fixedFeeQuantityTransitions && price == other.price && startDate == other.startDate && usageCustomerIds == other.usageCustomerIds && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PriceInterval && + id == other.id && + billingCycleDay == other.billingCycleDay && + canDeferBilling == other.canDeferBilling && + currentBillingPeriodEndDate == other.currentBillingPeriodEndDate && + currentBillingPeriodStartDate == other.currentBillingPeriodStartDate && + endDate == other.endDate && + filter == other.filter && + fixedFeeQuantityTransitions == other.fixedFeeQuantityTransitions && + price == other.price && + startDate == other.startDate && + usageCustomerIds == other.usageCustomerIds && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, billingCycleDay, currentBillingPeriodEndDate, currentBillingPeriodStartDate, endDate, filter, fixedFeeQuantityTransitions, price, startDate, usageCustomerIds, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + billingCycleDay, + canDeferBilling, + currentBillingPeriodEndDate, + currentBillingPeriodStartDate, + endDate, + filter, + fixedFeeQuantityTransitions, + price, + startDate, + usageCustomerIds, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "PriceInterval{id=$id, billingCycleDay=$billingCycleDay, currentBillingPeriodEndDate=$currentBillingPeriodEndDate, currentBillingPeriodStartDate=$currentBillingPeriodStartDate, endDate=$endDate, filter=$filter, fixedFeeQuantityTransitions=$fixedFeeQuantityTransitions, price=$price, startDate=$startDate, usageCustomerIds=$usageCustomerIds, additionalProperties=$additionalProperties}" + "PriceInterval{id=$id, billingCycleDay=$billingCycleDay, canDeferBilling=$canDeferBilling, currentBillingPeriodEndDate=$currentBillingPeriodEndDate, currentBillingPeriodStartDate=$currentBillingPeriodStartDate, endDate=$endDate, filter=$filter, fixedFeeQuantityTransitions=$fixedFeeQuantityTransitions, price=$price, startDate=$startDate, usageCustomerIds=$usageCustomerIds, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListPage.kt index b19828ad9..c2f41ce9c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListPage.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is PriceListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is PriceListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "PriceListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListPageAsync.kt index 8309ab8db..5f0df3759 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListPageAsync.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is PriceListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is PriceListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "PriceListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListPageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListPageResponse.kt index 36c714258..f957c0dad 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListPageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListPageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class PriceListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -127,28 +128,23 @@ private constructor( } /** Alias for calling [addData] with `Price.ofUnit(unit)`. */ - fun addData(unit: Price.Unit) = addData(Price.ofUnit(unit)) - - /** Alias for calling [addData] with `Price.ofPackage(package_)`. */ - fun addData(package_: Price.Package) = addData(Price.ofPackage(package_)) - - /** Alias for calling [addData] with `Price.ofMatrix(matrix)`. */ - fun addData(matrix: Price.Matrix) = addData(Price.ofMatrix(matrix)) + fun addData(unit: Price.UnitPrice) = addData(Price.ofUnit(unit)) /** Alias for calling [addData] with `Price.ofTiered(tiered)`. */ fun addData(tiered: Price.Tiered) = addData(Price.ofTiered(tiered)) - /** Alias for calling [addData] with `Price.ofTieredBps(tieredBps)`. */ - fun addData(tieredBps: Price.TieredBps) = addData(Price.ofTieredBps(tieredBps)) + /** Alias for calling [addData] with `Price.ofBulk(bulk)`. */ + fun addData(bulk: Price.Bulk) = addData(Price.ofBulk(bulk)) - /** Alias for calling [addData] with `Price.ofBps(bps)`. */ - fun addData(bps: Price.Bps) = addData(Price.ofBps(bps)) + /** Alias for calling [addData] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun addData(bulkWithFilters: Price.BulkWithFilters) = + addData(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [addData] with `Price.ofBulkBps(bulkBps)`. */ - fun addData(bulkBps: Price.BulkBps) = addData(Price.ofBulkBps(bulkBps)) + /** Alias for calling [addData] with `Price.ofPackage(package_)`. */ + fun addData(package_: Price.Package) = addData(Price.ofPackage(package_)) - /** Alias for calling [addData] with `Price.ofBulk(bulk)`. */ - fun addData(bulk: Price.Bulk) = addData(Price.ofBulk(bulk)) + /** Alias for calling [addData] with `Price.ofMatrix(matrix)`. */ + fun addData(matrix: Price.Matrix) = addData(Price.ofMatrix(matrix)) /** * Alias for calling [addData] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. @@ -160,14 +156,14 @@ private constructor( fun addData(tieredPackage: Price.TieredPackage) = addData(Price.ofTieredPackage(tieredPackage)) - /** Alias for calling [addData] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun addData(groupedTiered: Price.GroupedTiered) = - addData(Price.ofGroupedTiered(groupedTiered)) - /** Alias for calling [addData] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ fun addData(tieredWithMinimum: Price.TieredWithMinimum) = addData(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** Alias for calling [addData] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun addData(groupedTiered: Price.GroupedTiered) = + addData(Price.ofGroupedTiered(groupedTiered)) + /** * Alias for calling [addData] with * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. @@ -203,6 +199,10 @@ private constructor( fun addData(groupedAllocation: Price.GroupedAllocation) = addData(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [addData] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun addData(bulkWithProration: Price.BulkWithProration) = + addData(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [addData] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -217,16 +217,19 @@ private constructor( fun addData(groupedWithMeteredMinimum: Price.GroupedWithMeteredMinimum) = addData(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [addData] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun addData(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + addData(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** * Alias for calling [addData] with `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. */ fun addData(matrixWithDisplayName: Price.MatrixWithDisplayName) = addData(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [addData] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun addData(bulkWithProration: Price.BulkWithProration) = - addData(Price.ofBulkWithProration(bulkWithProration)) - /** * Alias for calling [addData] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. */ @@ -261,10 +264,19 @@ private constructor( /** * Alias for calling [addData] with - * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. */ - fun addData(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = - addData(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + fun addData(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + addData(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [addData] with `Price.ofMinimum(minimum)`. */ + fun addData(minimum: Price.Minimum) = addData(Price.ofMinimum(minimum)) + + /** Alias for calling [addData] with `Price.ofPercent(percent)`. */ + fun addData(percent: Price.Percent) = addData(Price.ofPercent(percent)) + + /** Alias for calling [addData] with `Price.ofEventOutput(eventOutput)`. */ + fun addData(eventOutput: Price.EventOutput) = addData(Price.ofEventOutput(eventOutput)) fun paginationMetadata(paginationMetadata: PaginationMetadata) = paginationMetadata(JsonField.of(paginationMetadata)) @@ -354,12 +366,15 @@ private constructor( return true } - return /* spotless:off */ other is PriceListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PriceListPageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListParams.kt index 7a2ff0656..7680106d9 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceListParams.kt @@ -198,10 +198,15 @@ private constructor( return true } - return /* spotless:off */ other is PriceListParams && cursor == other.cursor && limit == other.limit && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PriceListParams && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(cursor, limit, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(cursor, limit, additionalHeaders, additionalQueryParams) override fun toString() = "PriceListParams{cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceUpdateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceUpdateParams.kt index d20558d61..e283530e6 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceUpdateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/PriceUpdateParams.kt @@ -253,6 +253,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val metadata: JsonField, private val additionalProperties: MutableMap, @@ -386,12 +387,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -491,12 +492,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -508,10 +507,15 @@ private constructor( return true } - return /* spotless:off */ other is PriceUpdateParams && priceId == other.priceId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PriceUpdateParams && + priceId == other.priceId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(priceId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(priceId, body, additionalHeaders, additionalQueryParams) override fun toString() = "PriceUpdateParams{priceId=$priceId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubLineItemGrouping.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubLineItemGrouping.kt index 17edb202d..6abe60f1d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubLineItemGrouping.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubLineItemGrouping.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class SubLineItemGrouping +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val key: JsonField, private val value: JsonField, @@ -189,12 +190,13 @@ private constructor( return true } - return /* spotless:off */ other is SubLineItemGrouping && key == other.key && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SubLineItemGrouping && + key == other.key && + value == other.value && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(key, value, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubLineItemMatrixConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubLineItemMatrixConfig.kt index 34f0cef2d..7f6bb8b4d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubLineItemMatrixConfig.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubLineItemMatrixConfig.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class SubLineItemMatrixConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val dimensionValues: JsonField>, private val additionalProperties: MutableMap, @@ -180,12 +181,12 @@ private constructor( return true } - return /* spotless:off */ other is SubLineItemMatrixConfig && dimensionValues == other.dimensionValues && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SubLineItemMatrixConfig && + dimensionValues == other.dimensionValues && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(dimensionValues, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Subscription.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Subscription.kt index 60528e901..91585358b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Subscription.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Subscription.kt @@ -47,6 +47,7 @@ import java.util.Objects * a recurring fee for the following period. */ class Subscription +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val activePlanPhaseOrder: JsonField, @@ -1595,10 +1596,13 @@ private constructor( return true } - return /* spotless:off */ other is DiscountInterval && amount == other.amount && percentage == other.percentage && usage == other.usage /* spotless:on */ + return other is DiscountInterval && + amount == other.amount && + percentage == other.percentage && + usage == other.usage } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(amount, percentage, usage) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(amount, percentage, usage) override fun toString(): String = when { @@ -1784,12 +1788,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1918,7 +1920,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -1931,12 +1933,69 @@ private constructor( return true } - return /* spotless:off */ other is Subscription && id == other.id && activePlanPhaseOrder == other.activePlanPhaseOrder && adjustmentIntervals == other.adjustmentIntervals && autoCollection == other.autoCollection && billingCycleAnchorConfiguration == other.billingCycleAnchorConfiguration && billingCycleDay == other.billingCycleDay && createdAt == other.createdAt && currentBillingPeriodEndDate == other.currentBillingPeriodEndDate && currentBillingPeriodStartDate == other.currentBillingPeriodStartDate && customer == other.customer && defaultInvoiceMemo == other.defaultInvoiceMemo && discountIntervals == other.discountIntervals && endDate == other.endDate && fixedFeeQuantitySchedule == other.fixedFeeQuantitySchedule && invoicingThreshold == other.invoicingThreshold && maximumIntervals == other.maximumIntervals && metadata == other.metadata && minimumIntervals == other.minimumIntervals && name == other.name && netTerms == other.netTerms && pendingSubscriptionChange == other.pendingSubscriptionChange && plan == other.plan && priceIntervals == other.priceIntervals && redeemedCoupon == other.redeemedCoupon && startDate == other.startDate && status == other.status && trialInfo == other.trialInfo && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Subscription && + id == other.id && + activePlanPhaseOrder == other.activePlanPhaseOrder && + adjustmentIntervals == other.adjustmentIntervals && + autoCollection == other.autoCollection && + billingCycleAnchorConfiguration == other.billingCycleAnchorConfiguration && + billingCycleDay == other.billingCycleDay && + createdAt == other.createdAt && + currentBillingPeriodEndDate == other.currentBillingPeriodEndDate && + currentBillingPeriodStartDate == other.currentBillingPeriodStartDate && + customer == other.customer && + defaultInvoiceMemo == other.defaultInvoiceMemo && + discountIntervals == other.discountIntervals && + endDate == other.endDate && + fixedFeeQuantitySchedule == other.fixedFeeQuantitySchedule && + invoicingThreshold == other.invoicingThreshold && + maximumIntervals == other.maximumIntervals && + metadata == other.metadata && + minimumIntervals == other.minimumIntervals && + name == other.name && + netTerms == other.netTerms && + pendingSubscriptionChange == other.pendingSubscriptionChange && + plan == other.plan && + priceIntervals == other.priceIntervals && + redeemedCoupon == other.redeemedCoupon && + startDate == other.startDate && + status == other.status && + trialInfo == other.trialInfo && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, activePlanPhaseOrder, adjustmentIntervals, autoCollection, billingCycleAnchorConfiguration, billingCycleDay, createdAt, currentBillingPeriodEndDate, currentBillingPeriodStartDate, customer, defaultInvoiceMemo, discountIntervals, endDate, fixedFeeQuantitySchedule, invoicingThreshold, maximumIntervals, metadata, minimumIntervals, name, netTerms, pendingSubscriptionChange, plan, priceIntervals, redeemedCoupon, startDate, status, trialInfo, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + activePlanPhaseOrder, + adjustmentIntervals, + autoCollection, + billingCycleAnchorConfiguration, + billingCycleDay, + createdAt, + currentBillingPeriodEndDate, + currentBillingPeriodStartDate, + customer, + defaultInvoiceMemo, + discountIntervals, + endDate, + fixedFeeQuantitySchedule, + invoicingThreshold, + maximumIntervals, + metadata, + minimumIntervals, + name, + netTerms, + pendingSubscriptionChange, + plan, + priceIntervals, + redeemedCoupon, + startDate, + status, + trialInfo, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionCancelParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionCancelParams.kt index 6810cd1da..328f96d37 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionCancelParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionCancelParams.kt @@ -63,7 +63,6 @@ import java.util.Objects * `end_date` equal to the `start_date` upon cancellation. * * ## Backdated cancellations - * * Orb allows you to cancel a subscription in the past as long as there are no paid invoices between * the `requested_date` and the current time. If the cancellation is after the latest issued * invoice, Orb will generate a balance refund for the current period. If the cancellation is before @@ -394,6 +393,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cancelOption: JsonField, private val allowInvoiceCreditOrVoid: JsonField, @@ -648,12 +648,21 @@ private constructor( return true } - return /* spotless:off */ other is Body && cancelOption == other.cancelOption && allowInvoiceCreditOrVoid == other.allowInvoiceCreditOrVoid && cancellationDate == other.cancellationDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + cancelOption == other.cancelOption && + allowInvoiceCreditOrVoid == other.allowInvoiceCreditOrVoid && + cancellationDate == other.cancellationDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cancelOption, allowInvoiceCreditOrVoid, cancellationDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + cancelOption, + allowInvoiceCreditOrVoid, + cancellationDate, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -787,7 +796,7 @@ private constructor( return true } - return /* spotless:off */ other is CancelOption && value == other.value /* spotless:on */ + return other is CancelOption && value == other.value } override fun hashCode() = value.hashCode() @@ -800,10 +809,15 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionCancelParams && subscriptionId == other.subscriptionId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionCancelParams && + subscriptionId == other.subscriptionId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) override fun toString() = "SubscriptionCancelParams{subscriptionId=$subscriptionId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeApplyParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeApplyParams.kt index b4e1d8218..3fd39e573 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeApplyParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeApplyParams.kt @@ -14,6 +14,7 @@ import com.withorb.api.core.Params import com.withorb.api.core.http.Headers import com.withorb.api.core.http.QueryParams import com.withorb.api.errors.OrbInvalidDataException +import java.time.LocalDate import java.util.Collections import java.util.Objects @@ -41,7 +42,43 @@ private constructor( fun description(): String? = body.description() /** - * Amount already collected to apply to the customer's balance. + * Mark all pending invoices that are payable as paid. If amount is also provided, mark as paid + * and credit the difference to the customer's balance. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun markAsPaid(): Boolean? = body.markAsPaid() + + /** + * An optional external ID to associate with the payment. Only applicable when mark_as_paid is + * true. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun paymentExternalId(): String? = body.paymentExternalId() + + /** + * Optional notes about the payment. Only applicable when mark_as_paid is true. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun paymentNotes(): String? = body.paymentNotes() + + /** + * A date string to specify the date the payment was received. Only applicable when mark_as_paid + * is true. If not provided, defaults to the current date. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun paymentReceivedDate(): LocalDate? = body.paymentReceivedDate() + + /** + * Amount already collected to apply to the customer's balance. If mark_as_paid is also + * provided, credit the difference to the customer's balance. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -55,6 +92,36 @@ private constructor( */ fun _description(): JsonField = body._description() + /** + * Returns the raw JSON value of [markAsPaid]. + * + * Unlike [markAsPaid], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _markAsPaid(): JsonField = body._markAsPaid() + + /** + * Returns the raw JSON value of [paymentExternalId]. + * + * Unlike [paymentExternalId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _paymentExternalId(): JsonField = body._paymentExternalId() + + /** + * Returns the raw JSON value of [paymentNotes]. + * + * Unlike [paymentNotes], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _paymentNotes(): JsonField = body._paymentNotes() + + /** + * Returns the raw JSON value of [paymentReceivedDate]. + * + * Unlike [paymentReceivedDate], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _paymentReceivedDate(): JsonField = body._paymentReceivedDate() + /** * Returns the raw JSON value of [previouslyCollectedAmount]. * @@ -109,7 +176,11 @@ private constructor( * 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: * - [description] - * - [previouslyCollectedAmount] + * - [markAsPaid] + * - [paymentExternalId] + * - [paymentNotes] + * - [paymentReceivedDate] + * - etc. */ fun body(body: Body) = apply { this.body = body.toBuilder() } @@ -125,7 +196,84 @@ private constructor( */ fun description(description: JsonField) = apply { body.description(description) } - /** Amount already collected to apply to the customer's balance. */ + /** + * Mark all pending invoices that are payable as paid. If amount is also provided, mark as + * paid and credit the difference to the customer's balance. + */ + fun markAsPaid(markAsPaid: Boolean?) = apply { body.markAsPaid(markAsPaid) } + + /** + * Alias for [Builder.markAsPaid]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun markAsPaid(markAsPaid: Boolean) = markAsPaid(markAsPaid as Boolean?) + + /** + * Sets [Builder.markAsPaid] to an arbitrary JSON value. + * + * You should usually call [Builder.markAsPaid] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun markAsPaid(markAsPaid: JsonField) = apply { body.markAsPaid(markAsPaid) } + + /** + * An optional external ID to associate with the payment. Only applicable when mark_as_paid + * is true. + */ + fun paymentExternalId(paymentExternalId: String?) = apply { + body.paymentExternalId(paymentExternalId) + } + + /** + * Sets [Builder.paymentExternalId] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentExternalId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun paymentExternalId(paymentExternalId: JsonField) = apply { + body.paymentExternalId(paymentExternalId) + } + + /** Optional notes about the payment. Only applicable when mark_as_paid is true. */ + fun paymentNotes(paymentNotes: String?) = apply { body.paymentNotes(paymentNotes) } + + /** + * Sets [Builder.paymentNotes] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentNotes] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun paymentNotes(paymentNotes: JsonField) = apply { + body.paymentNotes(paymentNotes) + } + + /** + * A date string to specify the date the payment was received. Only applicable when + * mark_as_paid is true. If not provided, defaults to the current date. + */ + fun paymentReceivedDate(paymentReceivedDate: LocalDate?) = apply { + body.paymentReceivedDate(paymentReceivedDate) + } + + /** + * Sets [Builder.paymentReceivedDate] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentReceivedDate] with a well-typed [LocalDate] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun paymentReceivedDate(paymentReceivedDate: JsonField) = apply { + body.paymentReceivedDate(paymentReceivedDate) + } + + /** + * Amount already collected to apply to the customer's balance. If mark_as_paid is also + * provided, credit the difference to the customer's balance. + */ fun previouslyCollectedAmount(previouslyCollectedAmount: String?) = apply { body.previouslyCollectedAmount(previouslyCollectedAmount) } @@ -285,8 +433,13 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val description: JsonField, + private val markAsPaid: JsonField, + private val paymentExternalId: JsonField, + private val paymentNotes: JsonField, + private val paymentReceivedDate: JsonField, private val previouslyCollectedAmount: JsonField, private val additionalProperties: MutableMap, ) { @@ -296,10 +449,30 @@ private constructor( @JsonProperty("description") @ExcludeMissing description: JsonField = JsonMissing.of(), + @JsonProperty("mark_as_paid") + @ExcludeMissing + markAsPaid: JsonField = JsonMissing.of(), + @JsonProperty("payment_external_id") + @ExcludeMissing + paymentExternalId: JsonField = JsonMissing.of(), + @JsonProperty("payment_notes") + @ExcludeMissing + paymentNotes: JsonField = JsonMissing.of(), + @JsonProperty("payment_received_date") + @ExcludeMissing + paymentReceivedDate: JsonField = JsonMissing.of(), @JsonProperty("previously_collected_amount") @ExcludeMissing previouslyCollectedAmount: JsonField = JsonMissing.of(), - ) : this(description, previouslyCollectedAmount, mutableMapOf()) + ) : this( + description, + markAsPaid, + paymentExternalId, + paymentNotes, + paymentReceivedDate, + previouslyCollectedAmount, + mutableMapOf(), + ) /** * Description to apply to the balance transaction representing this credit. @@ -310,7 +483,44 @@ private constructor( fun description(): String? = description.getNullable("description") /** - * Amount already collected to apply to the customer's balance. + * Mark all pending invoices that are payable as paid. If amount is also provided, mark as + * paid and credit the difference to the customer's balance. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun markAsPaid(): Boolean? = markAsPaid.getNullable("mark_as_paid") + + /** + * An optional external ID to associate with the payment. Only applicable when mark_as_paid + * is true. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun paymentExternalId(): String? = paymentExternalId.getNullable("payment_external_id") + + /** + * Optional notes about the payment. Only applicable when mark_as_paid is true. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun paymentNotes(): String? = paymentNotes.getNullable("payment_notes") + + /** + * A date string to specify the date the payment was received. Only applicable when + * mark_as_paid is true. If not provided, defaults to the current date. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun paymentReceivedDate(): LocalDate? = + paymentReceivedDate.getNullable("payment_received_date") + + /** + * Amount already collected to apply to the customer's balance. If mark_as_paid is also + * provided, credit the difference to the customer's balance. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -327,6 +537,45 @@ private constructor( @ExcludeMissing fun _description(): JsonField = description + /** + * Returns the raw JSON value of [markAsPaid]. + * + * Unlike [markAsPaid], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("mark_as_paid") + @ExcludeMissing + fun _markAsPaid(): JsonField = markAsPaid + + /** + * Returns the raw JSON value of [paymentExternalId]. + * + * Unlike [paymentExternalId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("payment_external_id") + @ExcludeMissing + fun _paymentExternalId(): JsonField = paymentExternalId + + /** + * Returns the raw JSON value of [paymentNotes]. + * + * Unlike [paymentNotes], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("payment_notes") + @ExcludeMissing + fun _paymentNotes(): JsonField = paymentNotes + + /** + * Returns the raw JSON value of [paymentReceivedDate]. + * + * Unlike [paymentReceivedDate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("payment_received_date") + @ExcludeMissing + fun _paymentReceivedDate(): JsonField = paymentReceivedDate + /** * Returns the raw JSON value of [previouslyCollectedAmount]. * @@ -359,11 +608,19 @@ private constructor( class Builder internal constructor() { private var description: JsonField = JsonMissing.of() + private var markAsPaid: JsonField = JsonMissing.of() + private var paymentExternalId: JsonField = JsonMissing.of() + private var paymentNotes: JsonField = JsonMissing.of() + private var paymentReceivedDate: JsonField = JsonMissing.of() private var previouslyCollectedAmount: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(body: Body) = apply { description = body.description + markAsPaid = body.markAsPaid + paymentExternalId = body.paymentExternalId + paymentNotes = body.paymentNotes + paymentReceivedDate = body.paymentReceivedDate previouslyCollectedAmount = body.previouslyCollectedAmount additionalProperties = body.additionalProperties.toMutableMap() } @@ -382,7 +639,83 @@ private constructor( this.description = description } - /** Amount already collected to apply to the customer's balance. */ + /** + * Mark all pending invoices that are payable as paid. If amount is also provided, mark + * as paid and credit the difference to the customer's balance. + */ + fun markAsPaid(markAsPaid: Boolean?) = markAsPaid(JsonField.ofNullable(markAsPaid)) + + /** + * Alias for [Builder.markAsPaid]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun markAsPaid(markAsPaid: Boolean) = markAsPaid(markAsPaid as Boolean?) + + /** + * Sets [Builder.markAsPaid] to an arbitrary JSON value. + * + * You should usually call [Builder.markAsPaid] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun markAsPaid(markAsPaid: JsonField) = apply { this.markAsPaid = markAsPaid } + + /** + * An optional external ID to associate with the payment. Only applicable when + * mark_as_paid is true. + */ + fun paymentExternalId(paymentExternalId: String?) = + paymentExternalId(JsonField.ofNullable(paymentExternalId)) + + /** + * Sets [Builder.paymentExternalId] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentExternalId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun paymentExternalId(paymentExternalId: JsonField) = apply { + this.paymentExternalId = paymentExternalId + } + + /** Optional notes about the payment. Only applicable when mark_as_paid is true. */ + fun paymentNotes(paymentNotes: String?) = + paymentNotes(JsonField.ofNullable(paymentNotes)) + + /** + * Sets [Builder.paymentNotes] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentNotes] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun paymentNotes(paymentNotes: JsonField) = apply { + this.paymentNotes = paymentNotes + } + + /** + * A date string to specify the date the payment was received. Only applicable when + * mark_as_paid is true. If not provided, defaults to the current date. + */ + fun paymentReceivedDate(paymentReceivedDate: LocalDate?) = + paymentReceivedDate(JsonField.ofNullable(paymentReceivedDate)) + + /** + * Sets [Builder.paymentReceivedDate] to an arbitrary JSON value. + * + * You should usually call [Builder.paymentReceivedDate] with a well-typed [LocalDate] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun paymentReceivedDate(paymentReceivedDate: JsonField) = apply { + this.paymentReceivedDate = paymentReceivedDate + } + + /** + * Amount already collected to apply to the customer's balance. If mark_as_paid is also + * provided, credit the difference to the customer's balance. + */ fun previouslyCollectedAmount(previouslyCollectedAmount: String?) = previouslyCollectedAmount(JsonField.ofNullable(previouslyCollectedAmount)) @@ -422,7 +755,15 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): Body = - Body(description, previouslyCollectedAmount, additionalProperties.toMutableMap()) + Body( + description, + markAsPaid, + paymentExternalId, + paymentNotes, + paymentReceivedDate, + previouslyCollectedAmount, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -433,6 +774,10 @@ private constructor( } description() + markAsPaid() + paymentExternalId() + paymentNotes() + paymentReceivedDate() previouslyCollectedAmount() validated = true } @@ -453,6 +798,10 @@ private constructor( */ internal fun validity(): Int = (if (description.asKnown() == null) 0 else 1) + + (if (markAsPaid.asKnown() == null) 0 else 1) + + (if (paymentExternalId.asKnown() == null) 0 else 1) + + (if (paymentNotes.asKnown() == null) 0 else 1) + + (if (paymentReceivedDate.asKnown() == null) 0 else 1) + (if (previouslyCollectedAmount.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { @@ -460,17 +809,32 @@ private constructor( return true } - return /* spotless:off */ other is Body && description == other.description && previouslyCollectedAmount == other.previouslyCollectedAmount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + description == other.description && + markAsPaid == other.markAsPaid && + paymentExternalId == other.paymentExternalId && + paymentNotes == other.paymentNotes && + paymentReceivedDate == other.paymentReceivedDate && + previouslyCollectedAmount == other.previouslyCollectedAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + description, + markAsPaid, + paymentExternalId, + paymentNotes, + paymentReceivedDate, + previouslyCollectedAmount, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(description, previouslyCollectedAmount, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = - "Body{description=$description, previouslyCollectedAmount=$previouslyCollectedAmount, additionalProperties=$additionalProperties}" + "Body{description=$description, markAsPaid=$markAsPaid, paymentExternalId=$paymentExternalId, paymentNotes=$paymentNotes, paymentReceivedDate=$paymentReceivedDate, previouslyCollectedAmount=$previouslyCollectedAmount, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -478,10 +842,15 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionChangeApplyParams && subscriptionChangeId == other.subscriptionChangeId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionChangeApplyParams && + subscriptionChangeId == other.subscriptionChangeId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionChangeId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionChangeId, body, additionalHeaders, additionalQueryParams) override fun toString() = "SubscriptionChangeApplyParams{subscriptionChangeId=$subscriptionChangeId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeApplyResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeApplyResponse.kt index 511cf30c2..bd1d8273f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeApplyResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeApplyResponse.kt @@ -23,19 +23,28 @@ import java.util.Objects * changes/creation of invoices (see `subscription.changed_resources`). */ class SubscriptionChangeApplyResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, + private val changeType: JsonField, private val expirationTime: JsonField, private val status: JsonField, private val subscription: JsonField, private val appliedAt: JsonField, + private val billingCycleAlignment: JsonField, private val cancelledAt: JsonField, + private val changeOption: JsonField, + private val effectiveDate: JsonField, + private val planId: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("change_type") + @ExcludeMissing + changeType: JsonField = JsonMissing.of(), @JsonProperty("expiration_time") @ExcludeMissing expirationTime: JsonField = JsonMissing.of(), @@ -46,10 +55,33 @@ private constructor( @JsonProperty("applied_at") @ExcludeMissing appliedAt: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_alignment") + @ExcludeMissing + billingCycleAlignment: JsonField = JsonMissing.of(), @JsonProperty("cancelled_at") @ExcludeMissing cancelledAt: JsonField = JsonMissing.of(), - ) : this(id, expirationTime, status, subscription, appliedAt, cancelledAt, mutableMapOf()) + @JsonProperty("change_option") + @ExcludeMissing + changeOption: JsonField = JsonMissing.of(), + @JsonProperty("effective_date") + @ExcludeMissing + effectiveDate: JsonField = JsonMissing.of(), + @JsonProperty("plan_id") @ExcludeMissing planId: JsonField = JsonMissing.of(), + ) : this( + id, + changeType, + expirationTime, + status, + subscription, + appliedAt, + billingCycleAlignment, + cancelledAt, + changeOption, + effectiveDate, + planId, + mutableMapOf(), + ) /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -57,6 +89,14 @@ private constructor( */ fun id(): String = id.getRequired("id") + /** + * The type of change (e.g., 'schedule_plan_change', 'create_subscription'). + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun changeType(): String = changeType.getRequired("change_type") + /** * Subscription change will be cancelled at this time and can no longer be applied. * @@ -85,6 +125,15 @@ private constructor( */ fun appliedAt(): OffsetDateTime? = appliedAt.getNullable("applied_at") + /** + * Billing cycle alignment for plan changes. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun billingCycleAlignment(): String? = + billingCycleAlignment.getNullable("billing_cycle_alignment") + /** * When this change was cancelled. * @@ -93,6 +142,31 @@ private constructor( */ fun cancelledAt(): OffsetDateTime? = cancelledAt.getNullable("cancelled_at") + /** + * How the change is scheduled (e.g., 'immediate', 'end_of_subscription_term', + * 'requested_date'). + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun changeOption(): String? = changeOption.getNullable("change_option") + + /** + * When this change will take effect. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun effectiveDate(): OffsetDateTime? = effectiveDate.getNullable("effective_date") + + /** + * The target plan ID for plan changes. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun planId(): String? = planId.getNullable("plan_id") + /** * Returns the raw JSON value of [id]. * @@ -100,6 +174,13 @@ private constructor( */ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + /** + * Returns the raw JSON value of [changeType]. + * + * Unlike [changeType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("change_type") @ExcludeMissing fun _changeType(): JsonField = changeType + /** * Returns the raw JSON value of [expirationTime]. * @@ -134,6 +215,16 @@ private constructor( @ExcludeMissing fun _appliedAt(): JsonField = appliedAt + /** + * Returns the raw JSON value of [billingCycleAlignment]. + * + * Unlike [billingCycleAlignment], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("billing_cycle_alignment") + @ExcludeMissing + fun _billingCycleAlignment(): JsonField = billingCycleAlignment + /** * Returns the raw JSON value of [cancelledAt]. * @@ -143,6 +234,31 @@ private constructor( @ExcludeMissing fun _cancelledAt(): JsonField = cancelledAt + /** + * Returns the raw JSON value of [changeOption]. + * + * Unlike [changeOption], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("change_option") + @ExcludeMissing + fun _changeOption(): JsonField = changeOption + + /** + * Returns the raw JSON value of [effectiveDate]. + * + * Unlike [effectiveDate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("effective_date") + @ExcludeMissing + fun _effectiveDate(): JsonField = effectiveDate + + /** + * Returns the raw JSON value of [planId]. + * + * Unlike [planId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("plan_id") @ExcludeMissing fun _planId(): JsonField = planId + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -164,6 +280,7 @@ private constructor( * The following fields are required: * ```kotlin * .id() + * .changeType() * .expirationTime() * .status() * .subscription() @@ -176,21 +293,31 @@ private constructor( class Builder internal constructor() { private var id: JsonField? = null + private var changeType: JsonField? = null private var expirationTime: JsonField? = null private var status: JsonField? = null private var subscription: JsonField? = null private var appliedAt: JsonField = JsonMissing.of() + private var billingCycleAlignment: JsonField = JsonMissing.of() private var cancelledAt: JsonField = JsonMissing.of() + private var changeOption: JsonField = JsonMissing.of() + private var effectiveDate: JsonField = JsonMissing.of() + private var planId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(subscriptionChangeApplyResponse: SubscriptionChangeApplyResponse) = apply { id = subscriptionChangeApplyResponse.id + changeType = subscriptionChangeApplyResponse.changeType expirationTime = subscriptionChangeApplyResponse.expirationTime status = subscriptionChangeApplyResponse.status subscription = subscriptionChangeApplyResponse.subscription appliedAt = subscriptionChangeApplyResponse.appliedAt + billingCycleAlignment = subscriptionChangeApplyResponse.billingCycleAlignment cancelledAt = subscriptionChangeApplyResponse.cancelledAt + changeOption = subscriptionChangeApplyResponse.changeOption + effectiveDate = subscriptionChangeApplyResponse.effectiveDate + planId = subscriptionChangeApplyResponse.planId additionalProperties = subscriptionChangeApplyResponse.additionalProperties.toMutableMap() } @@ -205,6 +332,18 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } + /** The type of change (e.g., 'schedule_plan_change', 'create_subscription'). */ + fun changeType(changeType: String) = changeType(JsonField.of(changeType)) + + /** + * Sets [Builder.changeType] to an arbitrary JSON value. + * + * You should usually call [Builder.changeType] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun changeType(changeType: JsonField) = apply { this.changeType = changeType } + /** Subscription change will be cancelled at this time and can no longer be applied. */ fun expirationTime(expirationTime: OffsetDateTime) = expirationTime(JsonField.of(expirationTime)) @@ -256,6 +395,21 @@ private constructor( */ fun appliedAt(appliedAt: JsonField) = apply { this.appliedAt = appliedAt } + /** Billing cycle alignment for plan changes. */ + fun billingCycleAlignment(billingCycleAlignment: String?) = + billingCycleAlignment(JsonField.ofNullable(billingCycleAlignment)) + + /** + * Sets [Builder.billingCycleAlignment] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleAlignment] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingCycleAlignment(billingCycleAlignment: JsonField) = apply { + this.billingCycleAlignment = billingCycleAlignment + } + /** When this change was cancelled. */ fun cancelledAt(cancelledAt: OffsetDateTime?) = cancelledAt(JsonField.ofNullable(cancelledAt)) @@ -271,6 +425,49 @@ private constructor( this.cancelledAt = cancelledAt } + /** + * How the change is scheduled (e.g., 'immediate', 'end_of_subscription_term', + * 'requested_date'). + */ + fun changeOption(changeOption: String?) = changeOption(JsonField.ofNullable(changeOption)) + + /** + * Sets [Builder.changeOption] to an arbitrary JSON value. + * + * You should usually call [Builder.changeOption] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun changeOption(changeOption: JsonField) = apply { + this.changeOption = changeOption + } + + /** When this change will take effect. */ + fun effectiveDate(effectiveDate: OffsetDateTime?) = + effectiveDate(JsonField.ofNullable(effectiveDate)) + + /** + * Sets [Builder.effectiveDate] to an arbitrary JSON value. + * + * You should usually call [Builder.effectiveDate] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun effectiveDate(effectiveDate: JsonField) = apply { + this.effectiveDate = effectiveDate + } + + /** The target plan ID for plan changes. */ + fun planId(planId: String?) = planId(JsonField.ofNullable(planId)) + + /** + * Sets [Builder.planId] to an arbitrary JSON value. + * + * You should usually call [Builder.planId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun planId(planId: JsonField) = apply { this.planId = planId } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -298,6 +495,7 @@ private constructor( * The following fields are required: * ```kotlin * .id() + * .changeType() * .expirationTime() * .status() * .subscription() @@ -308,11 +506,16 @@ private constructor( fun build(): SubscriptionChangeApplyResponse = SubscriptionChangeApplyResponse( checkRequired("id", id), + checkRequired("changeType", changeType), checkRequired("expirationTime", expirationTime), checkRequired("status", status), checkRequired("subscription", subscription), appliedAt, + billingCycleAlignment, cancelledAt, + changeOption, + effectiveDate, + planId, additionalProperties.toMutableMap(), ) } @@ -325,11 +528,16 @@ private constructor( } id() + changeType() expirationTime() status().validate() subscription()?.validate() appliedAt() + billingCycleAlignment() cancelledAt() + changeOption() + effectiveDate() + planId() validated = true } @@ -348,11 +556,16 @@ private constructor( */ internal fun validity(): Int = (if (id.asKnown() == null) 0 else 1) + + (if (changeType.asKnown() == null) 0 else 1) + (if (expirationTime.asKnown() == null) 0 else 1) + (status.asKnown()?.validity() ?: 0) + (subscription.asKnown()?.validity() ?: 0) + (if (appliedAt.asKnown() == null) 0 else 1) + - (if (cancelledAt.asKnown() == null) 0 else 1) + (if (billingCycleAlignment.asKnown() == null) 0 else 1) + + (if (cancelledAt.asKnown() == null) 0 else 1) + + (if (changeOption.asKnown() == null) 0 else 1) + + (if (effectiveDate.asKnown() == null) 0 else 1) + + (if (planId.asKnown() == null) 0 else 1) class Status @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -476,7 +689,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -489,15 +702,40 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionChangeApplyResponse && id == other.id && expirationTime == other.expirationTime && status == other.status && subscription == other.subscription && appliedAt == other.appliedAt && cancelledAt == other.cancelledAt && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SubscriptionChangeApplyResponse && + id == other.id && + changeType == other.changeType && + expirationTime == other.expirationTime && + status == other.status && + subscription == other.subscription && + appliedAt == other.appliedAt && + billingCycleAlignment == other.billingCycleAlignment && + cancelledAt == other.cancelledAt && + changeOption == other.changeOption && + effectiveDate == other.effectiveDate && + planId == other.planId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, expirationTime, status, subscription, appliedAt, cancelledAt, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + changeType, + expirationTime, + status, + subscription, + appliedAt, + billingCycleAlignment, + cancelledAt, + changeOption, + effectiveDate, + planId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "SubscriptionChangeApplyResponse{id=$id, expirationTime=$expirationTime, status=$status, subscription=$subscription, appliedAt=$appliedAt, cancelledAt=$cancelledAt, additionalProperties=$additionalProperties}" + "SubscriptionChangeApplyResponse{id=$id, changeType=$changeType, expirationTime=$expirationTime, status=$status, subscription=$subscription, appliedAt=$appliedAt, billingCycleAlignment=$billingCycleAlignment, cancelledAt=$cancelledAt, changeOption=$changeOption, effectiveDate=$effectiveDate, planId=$planId, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeCancelParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeCancelParams.kt index 581cedb61..46e8aa5f4 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeCancelParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeCancelParams.kt @@ -217,10 +217,20 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionChangeCancelParams && subscriptionChangeId == other.subscriptionChangeId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is SubscriptionChangeCancelParams && + subscriptionChangeId == other.subscriptionChangeId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionChangeId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + subscriptionChangeId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) override fun toString() = "SubscriptionChangeCancelParams{subscriptionChangeId=$subscriptionChangeId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeCancelResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeCancelResponse.kt index b9410635d..bcc8ee807 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeCancelResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeCancelResponse.kt @@ -23,19 +23,28 @@ import java.util.Objects * changes/creation of invoices (see `subscription.changed_resources`). */ class SubscriptionChangeCancelResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, + private val changeType: JsonField, private val expirationTime: JsonField, private val status: JsonField, private val subscription: JsonField, private val appliedAt: JsonField, + private val billingCycleAlignment: JsonField, private val cancelledAt: JsonField, + private val changeOption: JsonField, + private val effectiveDate: JsonField, + private val planId: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("change_type") + @ExcludeMissing + changeType: JsonField = JsonMissing.of(), @JsonProperty("expiration_time") @ExcludeMissing expirationTime: JsonField = JsonMissing.of(), @@ -46,10 +55,33 @@ private constructor( @JsonProperty("applied_at") @ExcludeMissing appliedAt: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_alignment") + @ExcludeMissing + billingCycleAlignment: JsonField = JsonMissing.of(), @JsonProperty("cancelled_at") @ExcludeMissing cancelledAt: JsonField = JsonMissing.of(), - ) : this(id, expirationTime, status, subscription, appliedAt, cancelledAt, mutableMapOf()) + @JsonProperty("change_option") + @ExcludeMissing + changeOption: JsonField = JsonMissing.of(), + @JsonProperty("effective_date") + @ExcludeMissing + effectiveDate: JsonField = JsonMissing.of(), + @JsonProperty("plan_id") @ExcludeMissing planId: JsonField = JsonMissing.of(), + ) : this( + id, + changeType, + expirationTime, + status, + subscription, + appliedAt, + billingCycleAlignment, + cancelledAt, + changeOption, + effectiveDate, + planId, + mutableMapOf(), + ) /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -57,6 +89,14 @@ private constructor( */ fun id(): String = id.getRequired("id") + /** + * The type of change (e.g., 'schedule_plan_change', 'create_subscription'). + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun changeType(): String = changeType.getRequired("change_type") + /** * Subscription change will be cancelled at this time and can no longer be applied. * @@ -85,6 +125,15 @@ private constructor( */ fun appliedAt(): OffsetDateTime? = appliedAt.getNullable("applied_at") + /** + * Billing cycle alignment for plan changes. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun billingCycleAlignment(): String? = + billingCycleAlignment.getNullable("billing_cycle_alignment") + /** * When this change was cancelled. * @@ -93,6 +142,31 @@ private constructor( */ fun cancelledAt(): OffsetDateTime? = cancelledAt.getNullable("cancelled_at") + /** + * How the change is scheduled (e.g., 'immediate', 'end_of_subscription_term', + * 'requested_date'). + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun changeOption(): String? = changeOption.getNullable("change_option") + + /** + * When this change will take effect. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun effectiveDate(): OffsetDateTime? = effectiveDate.getNullable("effective_date") + + /** + * The target plan ID for plan changes. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun planId(): String? = planId.getNullable("plan_id") + /** * Returns the raw JSON value of [id]. * @@ -100,6 +174,13 @@ private constructor( */ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + /** + * Returns the raw JSON value of [changeType]. + * + * Unlike [changeType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("change_type") @ExcludeMissing fun _changeType(): JsonField = changeType + /** * Returns the raw JSON value of [expirationTime]. * @@ -134,6 +215,16 @@ private constructor( @ExcludeMissing fun _appliedAt(): JsonField = appliedAt + /** + * Returns the raw JSON value of [billingCycleAlignment]. + * + * Unlike [billingCycleAlignment], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("billing_cycle_alignment") + @ExcludeMissing + fun _billingCycleAlignment(): JsonField = billingCycleAlignment + /** * Returns the raw JSON value of [cancelledAt]. * @@ -143,6 +234,31 @@ private constructor( @ExcludeMissing fun _cancelledAt(): JsonField = cancelledAt + /** + * Returns the raw JSON value of [changeOption]. + * + * Unlike [changeOption], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("change_option") + @ExcludeMissing + fun _changeOption(): JsonField = changeOption + + /** + * Returns the raw JSON value of [effectiveDate]. + * + * Unlike [effectiveDate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("effective_date") + @ExcludeMissing + fun _effectiveDate(): JsonField = effectiveDate + + /** + * Returns the raw JSON value of [planId]. + * + * Unlike [planId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("plan_id") @ExcludeMissing fun _planId(): JsonField = planId + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -164,6 +280,7 @@ private constructor( * The following fields are required: * ```kotlin * .id() + * .changeType() * .expirationTime() * .status() * .subscription() @@ -176,21 +293,31 @@ private constructor( class Builder internal constructor() { private var id: JsonField? = null + private var changeType: JsonField? = null private var expirationTime: JsonField? = null private var status: JsonField? = null private var subscription: JsonField? = null private var appliedAt: JsonField = JsonMissing.of() + private var billingCycleAlignment: JsonField = JsonMissing.of() private var cancelledAt: JsonField = JsonMissing.of() + private var changeOption: JsonField = JsonMissing.of() + private var effectiveDate: JsonField = JsonMissing.of() + private var planId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(subscriptionChangeCancelResponse: SubscriptionChangeCancelResponse) = apply { id = subscriptionChangeCancelResponse.id + changeType = subscriptionChangeCancelResponse.changeType expirationTime = subscriptionChangeCancelResponse.expirationTime status = subscriptionChangeCancelResponse.status subscription = subscriptionChangeCancelResponse.subscription appliedAt = subscriptionChangeCancelResponse.appliedAt + billingCycleAlignment = subscriptionChangeCancelResponse.billingCycleAlignment cancelledAt = subscriptionChangeCancelResponse.cancelledAt + changeOption = subscriptionChangeCancelResponse.changeOption + effectiveDate = subscriptionChangeCancelResponse.effectiveDate + planId = subscriptionChangeCancelResponse.planId additionalProperties = subscriptionChangeCancelResponse.additionalProperties.toMutableMap() } @@ -205,6 +332,18 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } + /** The type of change (e.g., 'schedule_plan_change', 'create_subscription'). */ + fun changeType(changeType: String) = changeType(JsonField.of(changeType)) + + /** + * Sets [Builder.changeType] to an arbitrary JSON value. + * + * You should usually call [Builder.changeType] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun changeType(changeType: JsonField) = apply { this.changeType = changeType } + /** Subscription change will be cancelled at this time and can no longer be applied. */ fun expirationTime(expirationTime: OffsetDateTime) = expirationTime(JsonField.of(expirationTime)) @@ -256,6 +395,21 @@ private constructor( */ fun appliedAt(appliedAt: JsonField) = apply { this.appliedAt = appliedAt } + /** Billing cycle alignment for plan changes. */ + fun billingCycleAlignment(billingCycleAlignment: String?) = + billingCycleAlignment(JsonField.ofNullable(billingCycleAlignment)) + + /** + * Sets [Builder.billingCycleAlignment] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleAlignment] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingCycleAlignment(billingCycleAlignment: JsonField) = apply { + this.billingCycleAlignment = billingCycleAlignment + } + /** When this change was cancelled. */ fun cancelledAt(cancelledAt: OffsetDateTime?) = cancelledAt(JsonField.ofNullable(cancelledAt)) @@ -271,6 +425,49 @@ private constructor( this.cancelledAt = cancelledAt } + /** + * How the change is scheduled (e.g., 'immediate', 'end_of_subscription_term', + * 'requested_date'). + */ + fun changeOption(changeOption: String?) = changeOption(JsonField.ofNullable(changeOption)) + + /** + * Sets [Builder.changeOption] to an arbitrary JSON value. + * + * You should usually call [Builder.changeOption] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun changeOption(changeOption: JsonField) = apply { + this.changeOption = changeOption + } + + /** When this change will take effect. */ + fun effectiveDate(effectiveDate: OffsetDateTime?) = + effectiveDate(JsonField.ofNullable(effectiveDate)) + + /** + * Sets [Builder.effectiveDate] to an arbitrary JSON value. + * + * You should usually call [Builder.effectiveDate] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun effectiveDate(effectiveDate: JsonField) = apply { + this.effectiveDate = effectiveDate + } + + /** The target plan ID for plan changes. */ + fun planId(planId: String?) = planId(JsonField.ofNullable(planId)) + + /** + * Sets [Builder.planId] to an arbitrary JSON value. + * + * You should usually call [Builder.planId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun planId(planId: JsonField) = apply { this.planId = planId } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -298,6 +495,7 @@ private constructor( * The following fields are required: * ```kotlin * .id() + * .changeType() * .expirationTime() * .status() * .subscription() @@ -308,11 +506,16 @@ private constructor( fun build(): SubscriptionChangeCancelResponse = SubscriptionChangeCancelResponse( checkRequired("id", id), + checkRequired("changeType", changeType), checkRequired("expirationTime", expirationTime), checkRequired("status", status), checkRequired("subscription", subscription), appliedAt, + billingCycleAlignment, cancelledAt, + changeOption, + effectiveDate, + planId, additionalProperties.toMutableMap(), ) } @@ -325,11 +528,16 @@ private constructor( } id() + changeType() expirationTime() status().validate() subscription()?.validate() appliedAt() + billingCycleAlignment() cancelledAt() + changeOption() + effectiveDate() + planId() validated = true } @@ -348,11 +556,16 @@ private constructor( */ internal fun validity(): Int = (if (id.asKnown() == null) 0 else 1) + + (if (changeType.asKnown() == null) 0 else 1) + (if (expirationTime.asKnown() == null) 0 else 1) + (status.asKnown()?.validity() ?: 0) + (subscription.asKnown()?.validity() ?: 0) + (if (appliedAt.asKnown() == null) 0 else 1) + - (if (cancelledAt.asKnown() == null) 0 else 1) + (if (billingCycleAlignment.asKnown() == null) 0 else 1) + + (if (cancelledAt.asKnown() == null) 0 else 1) + + (if (changeOption.asKnown() == null) 0 else 1) + + (if (effectiveDate.asKnown() == null) 0 else 1) + + (if (planId.asKnown() == null) 0 else 1) class Status @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -476,7 +689,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -489,15 +702,40 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionChangeCancelResponse && id == other.id && expirationTime == other.expirationTime && status == other.status && subscription == other.subscription && appliedAt == other.appliedAt && cancelledAt == other.cancelledAt && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SubscriptionChangeCancelResponse && + id == other.id && + changeType == other.changeType && + expirationTime == other.expirationTime && + status == other.status && + subscription == other.subscription && + appliedAt == other.appliedAt && + billingCycleAlignment == other.billingCycleAlignment && + cancelledAt == other.cancelledAt && + changeOption == other.changeOption && + effectiveDate == other.effectiveDate && + planId == other.planId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, expirationTime, status, subscription, appliedAt, cancelledAt, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + changeType, + expirationTime, + status, + subscription, + appliedAt, + billingCycleAlignment, + cancelledAt, + changeOption, + effectiveDate, + planId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "SubscriptionChangeCancelResponse{id=$id, expirationTime=$expirationTime, status=$status, subscription=$subscription, appliedAt=$appliedAt, cancelledAt=$cancelledAt, additionalProperties=$additionalProperties}" + "SubscriptionChangeCancelResponse{id=$id, changeType=$changeType, expirationTime=$expirationTime, status=$status, subscription=$subscription, appliedAt=$appliedAt, billingCycleAlignment=$billingCycleAlignment, cancelledAt=$cancelledAt, changeOption=$changeOption, effectiveDate=$effectiveDate, planId=$planId, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeMinified.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeMinified.kt index 5c84d2659..0dcaddf53 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeMinified.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeMinified.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class SubscriptionChangeMinified +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val additionalProperties: MutableMap, @@ -151,12 +152,12 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionChangeMinified && id == other.id && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SubscriptionChangeMinified && + id == other.id && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeRetrieveParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeRetrieveParams.kt index 4be798700..0be99bdeb 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeRetrieveParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeRetrieveParams.kt @@ -189,10 +189,14 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionChangeRetrieveParams && subscriptionChangeId == other.subscriptionChangeId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionChangeRetrieveParams && + subscriptionChangeId == other.subscriptionChangeId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionChangeId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionChangeId, additionalHeaders, additionalQueryParams) override fun toString() = "SubscriptionChangeRetrieveParams{subscriptionChangeId=$subscriptionChangeId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeRetrieveResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeRetrieveResponse.kt index 0c9dc6815..e6e297e23 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeRetrieveResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionChangeRetrieveResponse.kt @@ -23,19 +23,28 @@ import java.util.Objects * changes/creation of invoices (see `subscription.changed_resources`). */ class SubscriptionChangeRetrieveResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, + private val changeType: JsonField, private val expirationTime: JsonField, private val status: JsonField, private val subscription: JsonField, private val appliedAt: JsonField, + private val billingCycleAlignment: JsonField, private val cancelledAt: JsonField, + private val changeOption: JsonField, + private val effectiveDate: JsonField, + private val planId: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("change_type") + @ExcludeMissing + changeType: JsonField = JsonMissing.of(), @JsonProperty("expiration_time") @ExcludeMissing expirationTime: JsonField = JsonMissing.of(), @@ -46,10 +55,33 @@ private constructor( @JsonProperty("applied_at") @ExcludeMissing appliedAt: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_alignment") + @ExcludeMissing + billingCycleAlignment: JsonField = JsonMissing.of(), @JsonProperty("cancelled_at") @ExcludeMissing cancelledAt: JsonField = JsonMissing.of(), - ) : this(id, expirationTime, status, subscription, appliedAt, cancelledAt, mutableMapOf()) + @JsonProperty("change_option") + @ExcludeMissing + changeOption: JsonField = JsonMissing.of(), + @JsonProperty("effective_date") + @ExcludeMissing + effectiveDate: JsonField = JsonMissing.of(), + @JsonProperty("plan_id") @ExcludeMissing planId: JsonField = JsonMissing.of(), + ) : this( + id, + changeType, + expirationTime, + status, + subscription, + appliedAt, + billingCycleAlignment, + cancelledAt, + changeOption, + effectiveDate, + planId, + mutableMapOf(), + ) /** * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly @@ -57,6 +89,14 @@ private constructor( */ fun id(): String = id.getRequired("id") + /** + * The type of change (e.g., 'schedule_plan_change', 'create_subscription'). + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun changeType(): String = changeType.getRequired("change_type") + /** * Subscription change will be cancelled at this time and can no longer be applied. * @@ -85,6 +125,15 @@ private constructor( */ fun appliedAt(): OffsetDateTime? = appliedAt.getNullable("applied_at") + /** + * Billing cycle alignment for plan changes. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun billingCycleAlignment(): String? = + billingCycleAlignment.getNullable("billing_cycle_alignment") + /** * When this change was cancelled. * @@ -93,6 +142,31 @@ private constructor( */ fun cancelledAt(): OffsetDateTime? = cancelledAt.getNullable("cancelled_at") + /** + * How the change is scheduled (e.g., 'immediate', 'end_of_subscription_term', + * 'requested_date'). + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun changeOption(): String? = changeOption.getNullable("change_option") + + /** + * When this change will take effect. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun effectiveDate(): OffsetDateTime? = effectiveDate.getNullable("effective_date") + + /** + * The target plan ID for plan changes. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun planId(): String? = planId.getNullable("plan_id") + /** * Returns the raw JSON value of [id]. * @@ -100,6 +174,13 @@ private constructor( */ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + /** + * Returns the raw JSON value of [changeType]. + * + * Unlike [changeType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("change_type") @ExcludeMissing fun _changeType(): JsonField = changeType + /** * Returns the raw JSON value of [expirationTime]. * @@ -134,6 +215,16 @@ private constructor( @ExcludeMissing fun _appliedAt(): JsonField = appliedAt + /** + * Returns the raw JSON value of [billingCycleAlignment]. + * + * Unlike [billingCycleAlignment], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("billing_cycle_alignment") + @ExcludeMissing + fun _billingCycleAlignment(): JsonField = billingCycleAlignment + /** * Returns the raw JSON value of [cancelledAt]. * @@ -143,6 +234,31 @@ private constructor( @ExcludeMissing fun _cancelledAt(): JsonField = cancelledAt + /** + * Returns the raw JSON value of [changeOption]. + * + * Unlike [changeOption], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("change_option") + @ExcludeMissing + fun _changeOption(): JsonField = changeOption + + /** + * Returns the raw JSON value of [effectiveDate]. + * + * Unlike [effectiveDate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("effective_date") + @ExcludeMissing + fun _effectiveDate(): JsonField = effectiveDate + + /** + * Returns the raw JSON value of [planId]. + * + * Unlike [planId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("plan_id") @ExcludeMissing fun _planId(): JsonField = planId + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -164,6 +280,7 @@ private constructor( * The following fields are required: * ```kotlin * .id() + * .changeType() * .expirationTime() * .status() * .subscription() @@ -176,21 +293,31 @@ private constructor( class Builder internal constructor() { private var id: JsonField? = null + private var changeType: JsonField? = null private var expirationTime: JsonField? = null private var status: JsonField? = null private var subscription: JsonField? = null private var appliedAt: JsonField = JsonMissing.of() + private var billingCycleAlignment: JsonField = JsonMissing.of() private var cancelledAt: JsonField = JsonMissing.of() + private var changeOption: JsonField = JsonMissing.of() + private var effectiveDate: JsonField = JsonMissing.of() + private var planId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(subscriptionChangeRetrieveResponse: SubscriptionChangeRetrieveResponse) = apply { id = subscriptionChangeRetrieveResponse.id + changeType = subscriptionChangeRetrieveResponse.changeType expirationTime = subscriptionChangeRetrieveResponse.expirationTime status = subscriptionChangeRetrieveResponse.status subscription = subscriptionChangeRetrieveResponse.subscription appliedAt = subscriptionChangeRetrieveResponse.appliedAt + billingCycleAlignment = subscriptionChangeRetrieveResponse.billingCycleAlignment cancelledAt = subscriptionChangeRetrieveResponse.cancelledAt + changeOption = subscriptionChangeRetrieveResponse.changeOption + effectiveDate = subscriptionChangeRetrieveResponse.effectiveDate + planId = subscriptionChangeRetrieveResponse.planId additionalProperties = subscriptionChangeRetrieveResponse.additionalProperties.toMutableMap() } @@ -205,6 +332,18 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } + /** The type of change (e.g., 'schedule_plan_change', 'create_subscription'). */ + fun changeType(changeType: String) = changeType(JsonField.of(changeType)) + + /** + * Sets [Builder.changeType] to an arbitrary JSON value. + * + * You should usually call [Builder.changeType] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun changeType(changeType: JsonField) = apply { this.changeType = changeType } + /** Subscription change will be cancelled at this time and can no longer be applied. */ fun expirationTime(expirationTime: OffsetDateTime) = expirationTime(JsonField.of(expirationTime)) @@ -256,6 +395,21 @@ private constructor( */ fun appliedAt(appliedAt: JsonField) = apply { this.appliedAt = appliedAt } + /** Billing cycle alignment for plan changes. */ + fun billingCycleAlignment(billingCycleAlignment: String?) = + billingCycleAlignment(JsonField.ofNullable(billingCycleAlignment)) + + /** + * Sets [Builder.billingCycleAlignment] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleAlignment] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun billingCycleAlignment(billingCycleAlignment: JsonField) = apply { + this.billingCycleAlignment = billingCycleAlignment + } + /** When this change was cancelled. */ fun cancelledAt(cancelledAt: OffsetDateTime?) = cancelledAt(JsonField.ofNullable(cancelledAt)) @@ -271,6 +425,49 @@ private constructor( this.cancelledAt = cancelledAt } + /** + * How the change is scheduled (e.g., 'immediate', 'end_of_subscription_term', + * 'requested_date'). + */ + fun changeOption(changeOption: String?) = changeOption(JsonField.ofNullable(changeOption)) + + /** + * Sets [Builder.changeOption] to an arbitrary JSON value. + * + * You should usually call [Builder.changeOption] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun changeOption(changeOption: JsonField) = apply { + this.changeOption = changeOption + } + + /** When this change will take effect. */ + fun effectiveDate(effectiveDate: OffsetDateTime?) = + effectiveDate(JsonField.ofNullable(effectiveDate)) + + /** + * Sets [Builder.effectiveDate] to an arbitrary JSON value. + * + * You should usually call [Builder.effectiveDate] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun effectiveDate(effectiveDate: JsonField) = apply { + this.effectiveDate = effectiveDate + } + + /** The target plan ID for plan changes. */ + fun planId(planId: String?) = planId(JsonField.ofNullable(planId)) + + /** + * Sets [Builder.planId] to an arbitrary JSON value. + * + * You should usually call [Builder.planId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun planId(planId: JsonField) = apply { this.planId = planId } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -298,6 +495,7 @@ private constructor( * The following fields are required: * ```kotlin * .id() + * .changeType() * .expirationTime() * .status() * .subscription() @@ -308,11 +506,16 @@ private constructor( fun build(): SubscriptionChangeRetrieveResponse = SubscriptionChangeRetrieveResponse( checkRequired("id", id), + checkRequired("changeType", changeType), checkRequired("expirationTime", expirationTime), checkRequired("status", status), checkRequired("subscription", subscription), appliedAt, + billingCycleAlignment, cancelledAt, + changeOption, + effectiveDate, + planId, additionalProperties.toMutableMap(), ) } @@ -325,11 +528,16 @@ private constructor( } id() + changeType() expirationTime() status().validate() subscription()?.validate() appliedAt() + billingCycleAlignment() cancelledAt() + changeOption() + effectiveDate() + planId() validated = true } @@ -348,11 +556,16 @@ private constructor( */ internal fun validity(): Int = (if (id.asKnown() == null) 0 else 1) + + (if (changeType.asKnown() == null) 0 else 1) + (if (expirationTime.asKnown() == null) 0 else 1) + (status.asKnown()?.validity() ?: 0) + (subscription.asKnown()?.validity() ?: 0) + (if (appliedAt.asKnown() == null) 0 else 1) + - (if (cancelledAt.asKnown() == null) 0 else 1) + (if (billingCycleAlignment.asKnown() == null) 0 else 1) + + (if (cancelledAt.asKnown() == null) 0 else 1) + + (if (changeOption.asKnown() == null) 0 else 1) + + (if (effectiveDate.asKnown() == null) 0 else 1) + + (if (planId.asKnown() == null) 0 else 1) class Status @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -476,7 +689,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -489,15 +702,40 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionChangeRetrieveResponse && id == other.id && expirationTime == other.expirationTime && status == other.status && subscription == other.subscription && appliedAt == other.appliedAt && cancelledAt == other.cancelledAt && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SubscriptionChangeRetrieveResponse && + id == other.id && + changeType == other.changeType && + expirationTime == other.expirationTime && + status == other.status && + subscription == other.subscription && + appliedAt == other.appliedAt && + billingCycleAlignment == other.billingCycleAlignment && + cancelledAt == other.cancelledAt && + changeOption == other.changeOption && + effectiveDate == other.effectiveDate && + planId == other.planId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, expirationTime, status, subscription, appliedAt, cancelledAt, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + changeType, + expirationTime, + status, + subscription, + appliedAt, + billingCycleAlignment, + cancelledAt, + changeOption, + effectiveDate, + planId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "SubscriptionChangeRetrieveResponse{id=$id, expirationTime=$expirationTime, status=$status, subscription=$subscription, appliedAt=$appliedAt, cancelledAt=$cancelledAt, additionalProperties=$additionalProperties}" + "SubscriptionChangeRetrieveResponse{id=$id, changeType=$changeType, expirationTime=$expirationTime, status=$status, subscription=$subscription, appliedAt=$appliedAt, billingCycleAlignment=$billingCycleAlignment, cancelledAt=$cancelledAt, changeOption=$changeOption, effectiveDate=$effectiveDate, planId=$planId, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionCreateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionCreateParams.kt index 64cec9a04..19616bd6d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionCreateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionCreateParams.kt @@ -168,7 +168,6 @@ import java.util.Objects * the billable metric, cadence, type, and name of a price can not be overridden. * * ### Maximums and Minimums - * * Minimums and maximums, much like price overrides, can be useful when a new customer has * negotiated a new or different minimum or maximum spend cap than the default for a given price. If * one exists for a price and null is provided for the minimum/maximum override on creation, then @@ -213,7 +212,6 @@ import java.util.Objects * ``` * * ### Discounts - * * Discounts, like price overrides, can be useful when a new customer has negotiated a new or * different discount than the default for a price. If a discount exists for a price and a null * discount is provided on creation, then there will be no discount on the new subscription. @@ -263,6 +261,9 @@ import java.util.Objects * threshold billing, pass in an `invoicing_threshold`, which is specified in the subscription's * invoicing currency, when creating a subscription. E.g. pass in `10.00` to issue an invoice when * usage amounts hit \$10.00 for a subscription that invoices in USD. + * + * ## Limits + * By default, Orb limits the number of subscriptions per customer to 100. */ class SubscriptionCreateParams private constructor( @@ -1653,6 +1654,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val addAdjustments: JsonField>, private val addPrices: JsonField>, @@ -3376,12 +3378,82 @@ private constructor( return true } - return /* spotless:off */ other is Body && addAdjustments == other.addAdjustments && addPrices == other.addPrices && alignBillingWithSubscriptionStartDate == other.alignBillingWithSubscriptionStartDate && autoCollection == other.autoCollection && awsRegion == other.awsRegion && billingCycleAnchorConfiguration == other.billingCycleAnchorConfiguration && couponRedemptionCode == other.couponRedemptionCode && creditsOverageRate == other.creditsOverageRate && currency == other.currency && customerId == other.customerId && defaultInvoiceMemo == other.defaultInvoiceMemo && endDate == other.endDate && externalCustomerId == other.externalCustomerId && externalMarketplace == other.externalMarketplace && externalMarketplaceReportingId == other.externalMarketplaceReportingId && externalPlanId == other.externalPlanId && filter == other.filter && initialPhaseOrder == other.initialPhaseOrder && invoicingThreshold == other.invoicingThreshold && metadata == other.metadata && name == other.name && netTerms == other.netTerms && perCreditOverageAmount == other.perCreditOverageAmount && planId == other.planId && planVersionNumber == other.planVersionNumber && priceOverrides == other.priceOverrides && removeAdjustments == other.removeAdjustments && removePrices == other.removePrices && replaceAdjustments == other.replaceAdjustments && replacePrices == other.replacePrices && startDate == other.startDate && trialDurationDays == other.trialDurationDays && usageCustomerIds == other.usageCustomerIds && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + addAdjustments == other.addAdjustments && + addPrices == other.addPrices && + alignBillingWithSubscriptionStartDate == + other.alignBillingWithSubscriptionStartDate && + autoCollection == other.autoCollection && + awsRegion == other.awsRegion && + billingCycleAnchorConfiguration == other.billingCycleAnchorConfiguration && + couponRedemptionCode == other.couponRedemptionCode && + creditsOverageRate == other.creditsOverageRate && + currency == other.currency && + customerId == other.customerId && + defaultInvoiceMemo == other.defaultInvoiceMemo && + endDate == other.endDate && + externalCustomerId == other.externalCustomerId && + externalMarketplace == other.externalMarketplace && + externalMarketplaceReportingId == other.externalMarketplaceReportingId && + externalPlanId == other.externalPlanId && + filter == other.filter && + initialPhaseOrder == other.initialPhaseOrder && + invoicingThreshold == other.invoicingThreshold && + metadata == other.metadata && + name == other.name && + netTerms == other.netTerms && + perCreditOverageAmount == other.perCreditOverageAmount && + planId == other.planId && + planVersionNumber == other.planVersionNumber && + priceOverrides == other.priceOverrides && + removeAdjustments == other.removeAdjustments && + removePrices == other.removePrices && + replaceAdjustments == other.replaceAdjustments && + replacePrices == other.replacePrices && + startDate == other.startDate && + trialDurationDays == other.trialDurationDays && + usageCustomerIds == other.usageCustomerIds && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(addAdjustments, addPrices, alignBillingWithSubscriptionStartDate, autoCollection, awsRegion, billingCycleAnchorConfiguration, couponRedemptionCode, creditsOverageRate, currency, customerId, defaultInvoiceMemo, endDate, externalCustomerId, externalMarketplace, externalMarketplaceReportingId, externalPlanId, filter, initialPhaseOrder, invoicingThreshold, metadata, name, netTerms, perCreditOverageAmount, planId, planVersionNumber, priceOverrides, removeAdjustments, removePrices, replaceAdjustments, replacePrices, startDate, trialDurationDays, usageCustomerIds, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + addAdjustments, + addPrices, + alignBillingWithSubscriptionStartDate, + autoCollection, + awsRegion, + billingCycleAnchorConfiguration, + couponRedemptionCode, + creditsOverageRate, + currency, + customerId, + defaultInvoiceMemo, + endDate, + externalCustomerId, + externalMarketplace, + externalMarketplaceReportingId, + externalPlanId, + filter, + initialPhaseOrder, + invoicingThreshold, + metadata, + name, + netTerms, + perCreditOverageAmount, + planId, + planVersionNumber, + priceOverrides, + removeAdjustments, + removePrices, + replaceAdjustments, + replacePrices, + startDate, + trialDurationDays, + usageCustomerIds, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -3390,6 +3462,7 @@ private constructor( } class AddAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val adjustment: JsonField, private val endDate: JsonField, @@ -3895,10 +3968,16 @@ private constructor( return true } - return /* spotless:off */ other is Adjustment && percentageDiscount == other.percentageDiscount && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ + return other is Adjustment && + percentageDiscount == other.percentageDiscount && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + minimum == other.minimum && + maximum == other.maximum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) override fun toString(): String = when { @@ -4023,12 +4102,17 @@ private constructor( return true } - return /* spotless:off */ other is AddAdjustment && adjustment == other.adjustment && endDate == other.endDate && planPhaseOrder == other.planPhaseOrder && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AddAdjustment && + adjustment == other.adjustment && + endDate == other.endDate && + planPhaseOrder == other.planPhaseOrder && + startDate == other.startDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustment, endDate, planPhaseOrder, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(adjustment, endDate, planPhaseOrder, startDate, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -4037,6 +4121,7 @@ private constructor( } class AddPrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val allocationPrice: JsonField, private val discounts: JsonField>, @@ -4156,7 +4241,7 @@ private constructor( fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") /** - * The definition of a new price to create and add to the subscription. + * New subscription price request body params. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -4461,7 +4546,7 @@ private constructor( this.planPhaseOrder = planPhaseOrder } - /** The definition of a new price to create and add to the subscription. */ + /** New subscription price request body params. */ fun price(price: Price?) = price(JsonField.ofNullable(price)) /** @@ -4476,27 +4561,21 @@ private constructor( /** Alias for calling [price] with `Price.ofUnit(unit)`. */ fun price(unit: NewSubscriptionUnitPrice) = price(Price.ofUnit(unit)) - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: NewSubscriptionPackagePrice) = price(Price.ofPackage(package_)) - - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: NewSubscriptionMatrixPrice) = price(Price.ofMatrix(matrix)) - /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ fun price(tiered: NewSubscriptionTieredPrice) = price(Price.ofTiered(tiered)) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: NewSubscriptionTieredBpsPrice) = - price(Price.ofTieredBps(tieredBps)) + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: NewSubscriptionBulkPrice) = price(Price.ofBulk(bulk)) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: NewSubscriptionBpsPrice) = price(Price.ofBps(bps)) + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: NewSubscriptionBulkBpsPrice) = price(Price.ofBulkBps(bulkBps)) + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: NewSubscriptionPackagePrice) = price(Price.ofPackage(package_)) - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: NewSubscriptionBulkPrice) = price(Price.ofBulk(bulk)) + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: NewSubscriptionMatrixPrice) = price(Price.ofMatrix(matrix)) /** * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. @@ -4512,9 +4591,16 @@ private constructor( fun price(tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice) = price(Price.ofTieredWithMinimum(tieredWithMinimum)) - /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ - fun price(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = - price(Price.ofUnitWithPercent(unitWithPercent)) + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: NewSubscriptionGroupedTieredPrice) = + price(Price.ofGroupedTiered(groupedTiered)) + + /** + * Alias for calling [price] with + * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + */ + fun price(tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice) = + price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) /** * Alias for calling [price] with @@ -4523,10 +4609,20 @@ private constructor( fun price(packageWithAllocation: NewSubscriptionPackageWithAllocationPrice) = price(Price.ofPackageWithAllocation(packageWithAllocation)) + /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ + fun price(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = + price(Price.ofUnitWithPercent(unitWithPercent)) + + /** + * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun price(matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice) = + price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + /** * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. */ - fun price(tieredWithProration: NewSubscriptionTierWithProrationPrice) = + fun price(tieredWithProration: Price.TieredWithProration) = price(Price.ofTieredWithProration(tieredWithProration)) /** Alias for calling [price] with `Price.ofUnitWithProration(unitWithProration)`. */ @@ -4537,6 +4633,10 @@ private constructor( fun price(groupedAllocation: NewSubscriptionGroupedAllocationPrice) = price(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = + price(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [price] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -4544,32 +4644,32 @@ private constructor( fun price(groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice) = price(Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)) - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = - price(Price.ofBulkWithProration(bulkWithProration)) - /** * Alias for calling [price] with - * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. + * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. */ - fun price( - scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice - ) = price(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) + fun price(groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice) = + price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) /** * Alias for calling [price] with - * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. */ - fun price( - scalableMatrixWithTieredPricing: NewSubscriptionScalableMatrixWithTieredPricingPrice - ) = price(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) /** * Alias for calling [price] with - * `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. + * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. */ - fun price(cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice) = - price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + fun price(matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice) = + price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) + + /** + * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. + */ + fun price(groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice) = + price(Price.ofGroupedTieredPackage(groupedTieredPackage)) /** * Alias for calling [price] with @@ -4580,40 +4680,43 @@ private constructor( /** * Alias for calling [price] with - * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. + * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. */ - fun price(groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice) = - price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + fun price( + scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice + ) = price(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) /** * Alias for calling [price] with - * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. - */ - fun price(matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice) = - price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - - /** - * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. + * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. */ - fun price(groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice) = - price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + fun price( + scalableMatrixWithTieredPricing: NewSubscriptionScalableMatrixWithTieredPricingPrice + ) = price(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) /** - * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + * Alias for calling [price] with + * `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. */ - fun price(matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice) = - price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + fun price(cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice) = + price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) /** * Alias for calling [price] with - * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. */ - fun price(tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice) = - price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) - /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: NewSubscriptionGroupedTieredPrice) = - price(Price.ofGroupedTiered(groupedTiered)) + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: NewSubscriptionMinimumCompositePrice) = + price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) /** The id of the price to add to the subscription. */ fun priceId(priceId: String?) = priceId(JsonField.ofNullable(priceId)) @@ -4731,31 +4834,39 @@ private constructor( (if (priceId.asKnown() == null) 0 else 1) + (if (startDate.asKnown() == null) 0 else 1) - /** The definition of a new price to create and add to the subscription. */ + /** New subscription price request body params. */ @JsonDeserialize(using = Price.Deserializer::class) @JsonSerialize(using = Price.Serializer::class) class Price private constructor( private val unit: NewSubscriptionUnitPrice? = null, - private val package_: NewSubscriptionPackagePrice? = null, - private val matrix: NewSubscriptionMatrixPrice? = null, private val tiered: NewSubscriptionTieredPrice? = null, - private val tieredBps: NewSubscriptionTieredBpsPrice? = null, - private val bps: NewSubscriptionBpsPrice? = null, - private val bulkBps: NewSubscriptionBulkBpsPrice? = null, private val bulk: NewSubscriptionBulkPrice? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: NewSubscriptionPackagePrice? = null, + private val matrix: NewSubscriptionMatrixPrice? = null, private val thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice? = null, private val tieredPackage: NewSubscriptionTieredPackagePrice? = null, private val tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice? = null, - private val unitWithPercent: NewSubscriptionUnitWithPercentPrice? = null, + private val groupedTiered: NewSubscriptionGroupedTieredPrice? = null, + private val tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice? = + null, private val packageWithAllocation: NewSubscriptionPackageWithAllocationPrice? = null, - private val tieredWithProration: NewSubscriptionTierWithProrationPrice? = null, + private val unitWithPercent: NewSubscriptionUnitWithPercentPrice? = null, + private val matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice? = null, + private val tieredWithProration: TieredWithProration? = null, private val unitWithProration: NewSubscriptionUnitWithProrationPrice? = null, private val groupedAllocation: NewSubscriptionGroupedAllocationPrice? = null, + private val bulkWithProration: NewSubscriptionBulkWithProrationPrice? = null, private val groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice? = null, - private val bulkWithProration: NewSubscriptionBulkWithProrationPrice? = null, + private val groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice? = + null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, + private val matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice? = null, + private val groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice? = null, + private val maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice? = null, private val scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice? = null, @@ -4763,33 +4874,24 @@ private constructor( NewSubscriptionScalableMatrixWithTieredPricingPrice? = null, private val cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice? = null, - private val maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice? = null, - private val groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice? = - null, - private val matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice? = null, - private val groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice? = null, - private val matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice? = null, - private val tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice? = - null, - private val groupedTiered: NewSubscriptionGroupedTieredPrice? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: NewSubscriptionMinimumCompositePrice? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, private val _json: JsonValue? = null, ) { fun unit(): NewSubscriptionUnitPrice? = unit - fun package_(): NewSubscriptionPackagePrice? = package_ - - fun matrix(): NewSubscriptionMatrixPrice? = matrix - fun tiered(): NewSubscriptionTieredPrice? = tiered - fun tieredBps(): NewSubscriptionTieredBpsPrice? = tieredBps + fun bulk(): NewSubscriptionBulkPrice? = bulk - fun bps(): NewSubscriptionBpsPrice? = bps + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters - fun bulkBps(): NewSubscriptionBulkBpsPrice? = bulkBps + fun package_(): NewSubscriptionPackagePrice? = package_ - fun bulk(): NewSubscriptionBulkPrice? = bulk + fun matrix(): NewSubscriptionMatrixPrice? = matrix fun thresholdTotalAmount(): NewSubscriptionThresholdTotalAmountPrice? = thresholdTotalAmount @@ -4798,21 +4900,44 @@ private constructor( fun tieredWithMinimum(): NewSubscriptionTieredWithMinimumPrice? = tieredWithMinimum - fun unitWithPercent(): NewSubscriptionUnitWithPercentPrice? = unitWithPercent + fun groupedTiered(): NewSubscriptionGroupedTieredPrice? = groupedTiered + + fun tieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice? = + tieredPackageWithMinimum fun packageWithAllocation(): NewSubscriptionPackageWithAllocationPrice? = packageWithAllocation - fun tieredWithProration(): NewSubscriptionTierWithProrationPrice? = tieredWithProration + fun unitWithPercent(): NewSubscriptionUnitWithPercentPrice? = unitWithPercent + + fun matrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice? = + matrixWithAllocation + + fun tieredWithProration(): TieredWithProration? = tieredWithProration fun unitWithProration(): NewSubscriptionUnitWithProrationPrice? = unitWithProration fun groupedAllocation(): NewSubscriptionGroupedAllocationPrice? = groupedAllocation + fun bulkWithProration(): NewSubscriptionBulkWithProrationPrice? = bulkWithProration + fun groupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice? = groupedWithProratedMinimum - fun bulkWithProration(): NewSubscriptionBulkWithProrationPrice? = bulkWithProration + fun groupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice? = + groupedWithMeteredMinimum + + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = + groupedWithMinMaxThresholds + + fun matrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice? = + matrixWithDisplayName + + fun groupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice? = + groupedTieredPackage + + fun maxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice? = + maxGroupTieredPackage fun scalableMatrixWithUnitPricing(): NewSubscriptionScalableMatrixWithUnitPricingPrice? = scalableMatrixWithUnitPricing @@ -4824,41 +4949,26 @@ private constructor( fun cumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice? = cumulativeGroupedBulk - fun maxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice? = - maxGroupTieredPackage - - fun groupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice? = - groupedWithMeteredMinimum - - fun matrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice? = - matrixWithDisplayName - - fun groupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice? = - groupedTieredPackage + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = + cumulativeGroupedAllocation - fun matrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice? = - matrixWithAllocation + fun minimum(): NewSubscriptionMinimumCompositePrice? = minimum - fun tieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice? = - tieredPackageWithMinimum + fun percent(): Percent? = percent - fun groupedTiered(): NewSubscriptionGroupedTieredPrice? = groupedTiered + fun eventOutput(): EventOutput? = eventOutput fun isUnit(): Boolean = unit != null - fun isPackage(): Boolean = package_ != null - - fun isMatrix(): Boolean = matrix != null - fun isTiered(): Boolean = tiered != null - fun isTieredBps(): Boolean = tieredBps != null + fun isBulk(): Boolean = bulk != null - fun isBps(): Boolean = bps != null + fun isBulkWithFilters(): Boolean = bulkWithFilters != null - fun isBulkBps(): Boolean = bulkBps != null + fun isPackage(): Boolean = package_ != null - fun isBulk(): Boolean = bulk != null + fun isMatrix(): Boolean = matrix != null fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null @@ -4866,56 +4976,62 @@ private constructor( fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null - fun isUnitWithPercent(): Boolean = unitWithPercent != null + fun isGroupedTiered(): Boolean = groupedTiered != null + + fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + fun isUnitWithPercent(): Boolean = unitWithPercent != null + + fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isTieredWithProration(): Boolean = tieredWithProration != null fun isUnitWithProration(): Boolean = unitWithProration != null fun isGroupedAllocation(): Boolean = groupedAllocation != null + fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null - fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null - fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null - fun isScalableMatrixWithTieredPricing(): Boolean = - scalableMatrixWithTieredPricing != null + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null - fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null + fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null - fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null - - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null - fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + fun isScalableMatrixWithTieredPricing(): Boolean = + scalableMatrixWithTieredPricing != null - fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null - fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null - fun isGroupedTiered(): Boolean = groupedTiered != null + fun isMinimum(): Boolean = minimum != null - fun asUnit(): NewSubscriptionUnitPrice = unit.getOrThrow("unit") + fun isPercent(): Boolean = percent != null - fun asPackage(): NewSubscriptionPackagePrice = package_.getOrThrow("package_") + fun isEventOutput(): Boolean = eventOutput != null - fun asMatrix(): NewSubscriptionMatrixPrice = matrix.getOrThrow("matrix") + fun asUnit(): NewSubscriptionUnitPrice = unit.getOrThrow("unit") fun asTiered(): NewSubscriptionTieredPrice = tiered.getOrThrow("tiered") - fun asTieredBps(): NewSubscriptionTieredBpsPrice = tieredBps.getOrThrow("tieredBps") + fun asBulk(): NewSubscriptionBulkPrice = bulk.getOrThrow("bulk") - fun asBps(): NewSubscriptionBpsPrice = bps.getOrThrow("bps") + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") - fun asBulkBps(): NewSubscriptionBulkBpsPrice = bulkBps.getOrThrow("bulkBps") + fun asPackage(): NewSubscriptionPackagePrice = package_.getOrThrow("package_") - fun asBulk(): NewSubscriptionBulkPrice = bulk.getOrThrow("bulk") + fun asMatrix(): NewSubscriptionMatrixPrice = matrix.getOrThrow("matrix") fun asThresholdTotalAmount(): NewSubscriptionThresholdTotalAmountPrice = thresholdTotalAmount.getOrThrow("thresholdTotalAmount") @@ -4926,13 +5042,22 @@ private constructor( fun asTieredWithMinimum(): NewSubscriptionTieredWithMinimumPrice = tieredWithMinimum.getOrThrow("tieredWithMinimum") - fun asUnitWithPercent(): NewSubscriptionUnitWithPercentPrice = - unitWithPercent.getOrThrow("unitWithPercent") + fun asGroupedTiered(): NewSubscriptionGroupedTieredPrice = + groupedTiered.getOrThrow("groupedTiered") + + fun asTieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice = + tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") fun asPackageWithAllocation(): NewSubscriptionPackageWithAllocationPrice = packageWithAllocation.getOrThrow("packageWithAllocation") - fun asTieredWithProration(): NewSubscriptionTierWithProrationPrice = + fun asUnitWithPercent(): NewSubscriptionUnitWithPercentPrice = + unitWithPercent.getOrThrow("unitWithPercent") + + fun asMatrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice = + matrixWithAllocation.getOrThrow("matrixWithAllocation") + + fun asTieredWithProration(): TieredWithProration = tieredWithProration.getOrThrow("tieredWithProration") fun asUnitWithProration(): NewSubscriptionUnitWithProrationPrice = @@ -4941,28 +5066,17 @@ private constructor( fun asGroupedAllocation(): NewSubscriptionGroupedAllocationPrice = groupedAllocation.getOrThrow("groupedAllocation") - fun asGroupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice = - groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") - fun asBulkWithProration(): NewSubscriptionBulkWithProrationPrice = bulkWithProration.getOrThrow("bulkWithProration") - fun asScalableMatrixWithUnitPricing(): - NewSubscriptionScalableMatrixWithUnitPricingPrice = - scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") + fun asGroupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice = + groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") - fun asScalableMatrixWithTieredPricing(): - NewSubscriptionScalableMatrixWithTieredPricingPrice = - scalableMatrixWithTieredPricing.getOrThrow("scalableMatrixWithTieredPricing") + fun asGroupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice = + groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") - fun asCumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice = - cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") - - fun asMaxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice = - maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") - - fun asGroupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice = - groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") fun asMatrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice = matrixWithDisplayName.getOrThrow("matrixWithDisplayName") @@ -4970,41 +5084,68 @@ private constructor( fun asGroupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice = groupedTieredPackage.getOrThrow("groupedTieredPackage") - fun asMatrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice = - matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun asMaxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice = + maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") - fun asTieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice = - tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + fun asScalableMatrixWithUnitPricing(): + NewSubscriptionScalableMatrixWithUnitPricingPrice = + scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") - fun asGroupedTiered(): NewSubscriptionGroupedTieredPrice = - groupedTiered.getOrThrow("groupedTiered") + fun asScalableMatrixWithTieredPricing(): + NewSubscriptionScalableMatrixWithTieredPricingPrice = + scalableMatrixWithTieredPricing.getOrThrow("scalableMatrixWithTieredPricing") + + fun asCumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice = + cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") + + fun asMinimum(): NewSubscriptionMinimumCompositePrice = minimum.getOrThrow("minimum") + + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") fun _json(): JsonValue? = _json fun accept(visitor: Visitor): T = when { unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) thresholdTotalAmount != null -> visitor.visitThresholdTotalAmount(thresholdTotalAmount) tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) - unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + tieredPackageWithMinimum != null -> + visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) packageWithAllocation != null -> visitor.visitPackageWithAllocation(packageWithAllocation) + unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + matrixWithAllocation != null -> + visitor.visitMatrixWithAllocation(matrixWithAllocation) tieredWithProration != null -> visitor.visitTieredWithProration(tieredWithProration) unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedWithProratedMinimum != null -> visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) + groupedWithMeteredMinimum != null -> + visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) + matrixWithDisplayName != null -> + visitor.visitMatrixWithDisplayName(matrixWithDisplayName) + groupedTieredPackage != null -> + visitor.visitGroupedTieredPackage(groupedTieredPackage) + maxGroupTieredPackage != null -> + visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) scalableMatrixWithUnitPricing != null -> visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) scalableMatrixWithTieredPricing != null -> @@ -5013,19 +5154,11 @@ private constructor( ) cumulativeGroupedBulk != null -> visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) - maxGroupTieredPackage != null -> - visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) - groupedWithMeteredMinimum != null -> - visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) - matrixWithDisplayName != null -> - visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - groupedTieredPackage != null -> - visitor.visitGroupedTieredPackage(groupedTieredPackage) - matrixWithAllocation != null -> - visitor.visitMatrixWithAllocation(matrixWithAllocation) - tieredPackageWithMinimum != null -> - visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) else -> visitor.unknown(_json) } @@ -5042,32 +5175,24 @@ private constructor( unit.validate() } - override fun visitPackage(package_: NewSubscriptionPackagePrice) { - package_.validate() - } - - override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) { - matrix.validate() - } - override fun visitTiered(tiered: NewSubscriptionTieredPrice) { tiered.validate() } - override fun visitTieredBps(tieredBps: NewSubscriptionTieredBpsPrice) { - tieredBps.validate() + override fun visitBulk(bulk: NewSubscriptionBulkPrice) { + bulk.validate() } - override fun visitBps(bps: NewSubscriptionBpsPrice) { - bps.validate() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() } - override fun visitBulkBps(bulkBps: NewSubscriptionBulkBpsPrice) { - bulkBps.validate() + override fun visitPackage(package_: NewSubscriptionPackagePrice) { + package_.validate() } - override fun visitBulk(bulk: NewSubscriptionBulkPrice) { - bulk.validate() + override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) { + matrix.validate() } override fun visitThresholdTotalAmount( @@ -5088,10 +5213,16 @@ private constructor( tieredWithMinimum.validate() } - override fun visitUnitWithPercent( - unitWithPercent: NewSubscriptionUnitWithPercentPrice + override fun visitGroupedTiered( + groupedTiered: NewSubscriptionGroupedTieredPrice ) { - unitWithPercent.validate() + groupedTiered.validate() + } + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ) { + tieredPackageWithMinimum.validate() } override fun visitPackageWithAllocation( @@ -5100,8 +5231,20 @@ private constructor( packageWithAllocation.validate() } + override fun visitUnitWithPercent( + unitWithPercent: NewSubscriptionUnitWithPercentPrice + ) { + unitWithPercent.validate() + } + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ) { + matrixWithAllocation.validate() + } + override fun visitTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice + tieredWithProration: TieredWithProration ) { tieredWithProration.validate() } @@ -5118,6 +5261,12 @@ private constructor( groupedAllocation.validate() } + override fun visitBulkWithProration( + bulkWithProration: NewSubscriptionBulkWithProrationPrice + ) { + bulkWithProration.validate() + } + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice @@ -5125,30 +5274,28 @@ private constructor( groupedWithProratedMinimum.validate() } - override fun visitBulkWithProration( - bulkWithProration: NewSubscriptionBulkWithProrationPrice + override fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice ) { - bulkWithProration.validate() + groupedWithMeteredMinimum.validate() } - override fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: - NewSubscriptionScalableMatrixWithUnitPricingPrice + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds ) { - scalableMatrixWithUnitPricing.validate() + groupedWithMinMaxThresholds.validate() } - override fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice ) { - scalableMatrixWithTieredPricing.validate() + matrixWithDisplayName.validate() } - override fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice + override fun visitGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice ) { - cumulativeGroupedBulk.validate() + groupedTieredPackage.validate() } override fun visitMaxGroupTieredPackage( @@ -5157,40 +5304,42 @@ private constructor( maxGroupTieredPackage.validate() } - override fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + override fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: + NewSubscriptionScalableMatrixWithUnitPricingPrice ) { - groupedWithMeteredMinimum.validate() + scalableMatrixWithUnitPricing.validate() } - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + override fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice ) { - matrixWithDisplayName.validate() + scalableMatrixWithTieredPricing.validate() } - override fun visitGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + override fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice ) { - groupedTieredPackage.validate() + cumulativeGroupedBulk.validate() } - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation ) { - matrixWithAllocation.validate() + cumulativeGroupedAllocation.validate() } - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ) { - tieredPackageWithMinimum.validate() + override fun visitMinimum(minimum: NewSubscriptionMinimumCompositePrice) { + minimum.validate() } - override fun visitGroupedTiered( - groupedTiered: NewSubscriptionGroupedTieredPrice - ) { - groupedTiered.validate() + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() } } ) @@ -5216,24 +5365,19 @@ private constructor( object : Visitor { override fun visitUnit(unit: NewSubscriptionUnitPrice) = unit.validity() - override fun visitPackage(package_: NewSubscriptionPackagePrice) = - package_.validity() - - override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) = - matrix.validity() - override fun visitTiered(tiered: NewSubscriptionTieredPrice) = tiered.validity() - override fun visitTieredBps(tieredBps: NewSubscriptionTieredBpsPrice) = - tieredBps.validity() + override fun visitBulk(bulk: NewSubscriptionBulkPrice) = bulk.validity() - override fun visitBps(bps: NewSubscriptionBpsPrice) = bps.validity() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() - override fun visitBulkBps(bulkBps: NewSubscriptionBulkBpsPrice) = - bulkBps.validity() + override fun visitPackage(package_: NewSubscriptionPackagePrice) = + package_.validity() - override fun visitBulk(bulk: NewSubscriptionBulkPrice) = bulk.validity() + override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) = + matrix.validity() override fun visitThresholdTotalAmount( thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice @@ -5247,16 +5391,28 @@ private constructor( tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice ) = tieredWithMinimum.validity() - override fun visitUnitWithPercent( - unitWithPercent: NewSubscriptionUnitWithPercentPrice - ) = unitWithPercent.validity() + override fun visitGroupedTiered( + groupedTiered: NewSubscriptionGroupedTieredPrice + ) = groupedTiered.validity() + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ) = tieredPackageWithMinimum.validity() override fun visitPackageWithAllocation( packageWithAllocation: NewSubscriptionPackageWithAllocationPrice ) = packageWithAllocation.validity() + override fun visitUnitWithPercent( + unitWithPercent: NewSubscriptionUnitWithPercentPrice + ) = unitWithPercent.validity() + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ) = matrixWithAllocation.validity() + override fun visitTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice + tieredWithProration: TieredWithProration ) = tieredWithProration.validity() override fun visitUnitWithProration( @@ -5267,14 +5423,34 @@ private constructor( groupedAllocation: NewSubscriptionGroupedAllocationPrice ) = groupedAllocation.validity() + override fun visitBulkWithProration( + bulkWithProration: NewSubscriptionBulkWithProrationPrice + ) = bulkWithProration.validity() + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice ) = groupedWithProratedMinimum.validity() - override fun visitBulkWithProration( - bulkWithProration: NewSubscriptionBulkWithProrationPrice - ) = bulkWithProration.validity() + override fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + ) = groupedWithMeteredMinimum.validity() + + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + ) = matrixWithDisplayName.validity() + + override fun visitGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + ) = groupedTieredPackage.validity() + + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice + ) = maxGroupTieredPackage.validity() override fun visitScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: @@ -5290,33 +5466,17 @@ private constructor( cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice ) = cumulativeGroupedBulk.validity() - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice - ) = maxGroupTieredPackage.validity() - - override fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice - ) = groupedWithMeteredMinimum.validity() - - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice - ) = matrixWithDisplayName.validity() - - override fun visitGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice - ) = groupedTieredPackage.validity() + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice - ) = matrixWithAllocation.validity() + override fun visitMinimum(minimum: NewSubscriptionMinimumCompositePrice) = + minimum.validity() - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ) = tieredPackageWithMinimum.validity() + override fun visitPercent(percent: Percent) = percent.validity() - override fun visitGroupedTiered( - groupedTiered: NewSubscriptionGroupedTieredPrice - ) = groupedTiered.validity() + override fun visitEventOutput(eventOutput: EventOutput) = + eventOutput.validity() override fun unknown(json: JsonValue?) = 0 } @@ -5327,53 +5487,122 @@ private constructor( return true } - return /* spotless:off */ other is Price && unit == other.unit && package_ == other.package_ && matrix == other.matrix && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && tieredWithMinimum == other.tieredWithMinimum && unitWithPercent == other.unitWithPercent && packageWithAllocation == other.packageWithAllocation && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && bulkWithProration == other.bulkWithProration && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk && maxGroupTieredPackage == other.maxGroupTieredPackage && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && groupedTieredPackage == other.groupedTieredPackage && matrixWithAllocation == other.matrixWithAllocation && tieredPackageWithMinimum == other.tieredPackageWithMinimum && groupedTiered == other.groupedTiered /* spotless:on */ + return other is Price && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, tieredWithMinimum, unitWithPercent, packageWithAllocation, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, bulkWithProration, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk, maxGroupTieredPackage, groupedWithMeteredMinimum, matrixWithDisplayName, groupedTieredPackage, matrixWithAllocation, tieredPackageWithMinimum, groupedTiered) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) override fun toString(): String = when { unit != null -> "Price{unit=$unit}" - package_ != null -> "Price{package_=$package_}" - matrix != null -> "Price{matrix=$matrix}" tiered != null -> "Price{tiered=$tiered}" - tieredBps != null -> "Price{tieredBps=$tieredBps}" - bps != null -> "Price{bps=$bps}" - bulkBps != null -> "Price{bulkBps=$bulkBps}" bulk != null -> "Price{bulk=$bulk}" + bulkWithFilters != null -> "Price{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "Price{package_=$package_}" + matrix != null -> "Price{matrix=$matrix}" thresholdTotalAmount != null -> "Price{thresholdTotalAmount=$thresholdTotalAmount}" tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" - unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" + tieredPackageWithMinimum != null -> + "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" packageWithAllocation != null -> "Price{packageWithAllocation=$packageWithAllocation}" + unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + matrixWithAllocation != null -> + "Price{matrixWithAllocation=$matrixWithAllocation}" tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedWithProratedMinimum != null -> "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" - bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" - scalableMatrixWithUnitPricing != null -> - "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" - scalableMatrixWithTieredPricing != null -> - "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" - cumulativeGroupedBulk != null -> - "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" - maxGroupTieredPackage != null -> - "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" groupedWithMeteredMinimum != null -> "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "Price{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" matrixWithDisplayName != null -> "Price{matrixWithDisplayName=$matrixWithDisplayName}" groupedTieredPackage != null -> "Price{groupedTieredPackage=$groupedTieredPackage}" - matrixWithAllocation != null -> - "Price{matrixWithAllocation=$matrixWithAllocation}" - tieredPackageWithMinimum != null -> - "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" - groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" + maxGroupTieredPackage != null -> + "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" + scalableMatrixWithUnitPricing != null -> + "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" + scalableMatrixWithTieredPricing != null -> + "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" + cumulativeGroupedBulk != null -> + "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" + cumulativeGroupedAllocation != null -> + "Price{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "Price{minimum=$minimum}" + percent != null -> "Price{percent=$percent}" + eventOutput != null -> "Price{eventOutput=$eventOutput}" _json != null -> "Price{_unknown=$_json}" else -> throw IllegalStateException("Invalid Price") } @@ -5382,20 +5611,16 @@ private constructor( fun ofUnit(unit: NewSubscriptionUnitPrice) = Price(unit = unit) - fun ofPackage(package_: NewSubscriptionPackagePrice) = Price(package_ = package_) - - fun ofMatrix(matrix: NewSubscriptionMatrixPrice) = Price(matrix = matrix) - fun ofTiered(tiered: NewSubscriptionTieredPrice) = Price(tiered = tiered) - fun ofTieredBps(tieredBps: NewSubscriptionTieredBpsPrice) = - Price(tieredBps = tieredBps) + fun ofBulk(bulk: NewSubscriptionBulkPrice) = Price(bulk = bulk) - fun ofBps(bps: NewSubscriptionBpsPrice) = Price(bps = bps) + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + Price(bulkWithFilters = bulkWithFilters) - fun ofBulkBps(bulkBps: NewSubscriptionBulkBpsPrice) = Price(bulkBps = bulkBps) + fun ofPackage(package_: NewSubscriptionPackagePrice) = Price(package_ = package_) - fun ofBulk(bulk: NewSubscriptionBulkPrice) = Price(bulk = bulk) + fun ofMatrix(matrix: NewSubscriptionMatrixPrice) = Price(matrix = matrix) fun ofThresholdTotalAmount( thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice @@ -5407,16 +5632,26 @@ private constructor( fun ofTieredWithMinimum(tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice) = Price(tieredWithMinimum = tieredWithMinimum) - fun ofUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = - Price(unitWithPercent = unitWithPercent) + fun ofGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice) = + Price(groupedTiered = groupedTiered) + + fun ofTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) fun ofPackageWithAllocation( packageWithAllocation: NewSubscriptionPackageWithAllocationPrice ) = Price(packageWithAllocation = packageWithAllocation) - fun ofTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice - ) = Price(tieredWithProration = tieredWithProration) + fun ofUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = + Price(unitWithPercent = unitWithPercent) + + fun ofMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ) = Price(matrixWithAllocation = matrixWithAllocation) + + fun ofTieredWithProration(tieredWithProration: TieredWithProration) = + Price(tieredWithProration = tieredWithProration) fun ofUnitWithProration(unitWithProration: NewSubscriptionUnitWithProrationPrice) = Price(unitWithProration = unitWithProration) @@ -5424,12 +5659,32 @@ private constructor( fun ofGroupedAllocation(groupedAllocation: NewSubscriptionGroupedAllocationPrice) = Price(groupedAllocation = groupedAllocation) + fun ofBulkWithProration(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = + Price(bulkWithProration = bulkWithProration) + fun ofGroupedWithProratedMinimum( groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) - fun ofBulkWithProration(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = - Price(bulkWithProration = bulkWithProration) + fun ofGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = Price(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + + fun ofMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + ) = Price(matrixWithDisplayName = matrixWithDisplayName) + + fun ofGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + ) = Price(groupedTieredPackage = groupedTieredPackage) + + fun ofMaxGroupTieredPackage( + maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice + ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) fun ofScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice @@ -5444,32 +5699,16 @@ private constructor( cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) - fun ofMaxGroupTieredPackage( - maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice - ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) - - fun ofGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice - ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) - - fun ofMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice - ) = Price(matrixWithDisplayName = matrixWithDisplayName) - - fun ofGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice - ) = Price(groupedTieredPackage = groupedTieredPackage) + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = Price(cumulativeGroupedAllocation = cumulativeGroupedAllocation) - fun ofMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice - ) = Price(matrixWithAllocation = matrixWithAllocation) + fun ofMinimum(minimum: NewSubscriptionMinimumCompositePrice) = + Price(minimum = minimum) - fun ofTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + fun ofPercent(percent: Percent) = Price(percent = percent) - fun ofGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice) = - Price(groupedTiered = groupedTiered) + fun ofEventOutput(eventOutput: EventOutput) = Price(eventOutput = eventOutput) } /** @@ -5479,19 +5718,15 @@ private constructor( fun visitUnit(unit: NewSubscriptionUnitPrice): T - fun visitPackage(package_: NewSubscriptionPackagePrice): T - - fun visitMatrix(matrix: NewSubscriptionMatrixPrice): T - fun visitTiered(tiered: NewSubscriptionTieredPrice): T - fun visitTieredBps(tieredBps: NewSubscriptionTieredBpsPrice): T + fun visitBulk(bulk: NewSubscriptionBulkPrice): T - fun visitBps(bps: NewSubscriptionBpsPrice): T + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T - fun visitBulkBps(bulkBps: NewSubscriptionBulkBpsPrice): T + fun visitPackage(package_: NewSubscriptionPackagePrice): T - fun visitBulk(bulk: NewSubscriptionBulkPrice): T + fun visitMatrix(matrix: NewSubscriptionMatrixPrice): T fun visitThresholdTotalAmount( thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice @@ -5503,16 +5738,24 @@ private constructor( tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice ): T - fun visitUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice): T + fun visitGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice): T + + fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ): T fun visitPackageWithAllocation( packageWithAllocation: NewSubscriptionPackageWithAllocationPrice ): T - fun visitTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice + fun visitUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice): T + + fun visitMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice ): T + fun visitTieredWithProration(tieredWithProration: TieredWithProration): T + fun visitUnitWithProration( unitWithProration: NewSubscriptionUnitWithProrationPrice ): T @@ -5521,52 +5764,56 @@ private constructor( groupedAllocation: NewSubscriptionGroupedAllocationPrice ): T + fun visitBulkWithProration( + bulkWithProration: NewSubscriptionBulkWithProrationPrice + ): T + fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice ): T - fun visitBulkWithProration( - bulkWithProration: NewSubscriptionBulkWithProrationPrice + fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice ): T - fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds ): T - fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice + fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice ): T - fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice + fun visitGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice ): T fun visitMaxGroupTieredPackage( maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice ): T - fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice ): T - fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice ): T - fun visitGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice ): T - fun visitMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation ): T - fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ): T + fun visitMinimum(minimum: NewSubscriptionMinimumCompositePrice): T - fun visitGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice): T + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T /** * Maps an unknown variant of [Price] to a value of type [T]. @@ -5594,20 +5841,6 @@ private constructor( return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(unit = it, _json = json) } ?: Price(_json = json) } - "package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) - } - "matrix" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) - } "tiered" -> { return tryDeserialize( node, @@ -5615,27 +5848,28 @@ private constructor( ) ?.let { Price(tiered = it, _json = json) } ?: Price(_json = json) } - "tiered_bps" -> { + "bulk" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(bulk = it, _json = json) } ?: Price(_json = json) + } + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulkWithFilters = it, _json = json) + } ?: Price(_json = json) + } + "package" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(tieredBps = it, _json = json) } ?: Price(_json = json) - } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bps = it, _json = json) } ?: Price(_json = json) + ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) } - "bulk_bps" -> { + "matrix" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(bulkBps = it, _json = json) } ?: Price(_json = json) - } - "bulk" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bulk = it, _json = json) } ?: Price(_json = json) + ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) } "threshold_total_amount" -> { return tryDeserialize( @@ -5661,12 +5895,20 @@ private constructor( ?.let { Price(tieredWithMinimum = it, _json = json) } ?: Price(_json = json) } - "unit_with_percent" -> { + "grouped_tiered" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(unitWithPercent = it, _json = json) } + ?.let { Price(groupedTiered = it, _json = json) } + ?: Price(_json = json) + } + "tiered_package_with_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tieredPackageWithMinimum = it, _json = json) } ?: Price(_json = json) } "package_with_allocation" -> { @@ -5677,11 +5919,24 @@ private constructor( ?.let { Price(packageWithAllocation = it, _json = json) } ?: Price(_json = json) } - "tiered_with_proration" -> { + "unit_with_percent" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(unitWithPercent = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_allocation" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) + ?.let { Price(matrixWithAllocation = it, _json = json) } + ?: Price(_json = json) + } + "tiered_with_proration" -> { + return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(tieredWithProration = it, _json = json) } ?: Price(_json = json) } @@ -5701,6 +5956,14 @@ private constructor( ?.let { Price(groupedAllocation = it, _json = json) } ?: Price(_json = json) } + "bulk_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(bulkWithProration = it, _json = json) } + ?: Price(_json = json) + } "grouped_with_prorated_minimum" -> { return tryDeserialize( node, @@ -5709,12 +5972,44 @@ private constructor( ?.let { Price(groupedWithProratedMinimum = it, _json = json) } ?: Price(_json = json) } - "bulk_with_proration" -> { + "grouped_with_metered_minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(bulkWithProration = it, _json = json) } + ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_min_max_thresholds" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithMinMaxThresholds = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_display_name" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(matrixWithDisplayName = it, _json = json) } + ?: Price(_json = json) + } + "grouped_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedTieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "max_group_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(maxGroupTieredPackage = it, _json = json) } ?: Price(_json = json) } "scalable_matrix_with_unit_pricing" -> { @@ -5745,61 +6040,30 @@ private constructor( ?.let { Price(cumulativeGroupedBulk = it, _json = json) } ?: Price(_json = json) } - "max_group_tiered_package" -> { + "cumulative_grouped_allocation" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(maxGroupTieredPackage = it, _json = json) } + ?.let { Price(cumulativeGroupedAllocation = it, _json = json) } ?: Price(_json = json) } - "grouped_with_metered_minimum" -> { + "minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } - ?: Price(_json = json) - } - "matrix_with_display_name" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithDisplayName = it, _json = json) } - ?: Price(_json = json) - } - "grouped_tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedTieredPackage = it, _json = json) } - ?: Price(_json = json) - } - "matrix_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithAllocation = it, _json = json) } - ?: Price(_json = json) + ?.let { Price(minimum = it, _json = json) } ?: Price(_json = json) } - "tiered_package_with_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredPackageWithMinimum = it, _json = json) } - ?: Price(_json = json) + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(percent = it, _json = json) + } ?: Price(_json = json) } - "grouped_tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedTiered = it, _json = json) } - ?: Price(_json = json) + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(eventOutput = it, _json = json) + } ?: Price(_json = json) } } @@ -5816,3016 +6080,23934 @@ private constructor( ) { when { value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> + generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) value.thresholdTotalAmount != null -> generator.writeObject(value.thresholdTotalAmount) value.tieredPackage != null -> generator.writeObject(value.tieredPackage) value.tieredWithMinimum != null -> generator.writeObject(value.tieredWithMinimum) - value.unitWithPercent != null -> - generator.writeObject(value.unitWithPercent) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) + value.tieredPackageWithMinimum != null -> + generator.writeObject(value.tieredPackageWithMinimum) value.packageWithAllocation != null -> generator.writeObject(value.packageWithAllocation) + value.unitWithPercent != null -> + generator.writeObject(value.unitWithPercent) + value.matrixWithAllocation != null -> + generator.writeObject(value.matrixWithAllocation) value.tieredWithProration != null -> generator.writeObject(value.tieredWithProration) value.unitWithProration != null -> generator.writeObject(value.unitWithProration) value.groupedAllocation != null -> generator.writeObject(value.groupedAllocation) - value.groupedWithProratedMinimum != null -> - generator.writeObject(value.groupedWithProratedMinimum) value.bulkWithProration != null -> generator.writeObject(value.bulkWithProration) - value.scalableMatrixWithUnitPricing != null -> - generator.writeObject(value.scalableMatrixWithUnitPricing) - value.scalableMatrixWithTieredPricing != null -> - generator.writeObject(value.scalableMatrixWithTieredPricing) - value.cumulativeGroupedBulk != null -> - generator.writeObject(value.cumulativeGroupedBulk) - value.maxGroupTieredPackage != null -> - generator.writeObject(value.maxGroupTieredPackage) + value.groupedWithProratedMinimum != null -> + generator.writeObject(value.groupedWithProratedMinimum) value.groupedWithMeteredMinimum != null -> generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) value.matrixWithDisplayName != null -> generator.writeObject(value.matrixWithDisplayName) value.groupedTieredPackage != null -> generator.writeObject(value.groupedTieredPackage) - value.matrixWithAllocation != null -> - generator.writeObject(value.matrixWithAllocation) - value.tieredPackageWithMinimum != null -> - generator.writeObject(value.tieredPackageWithMinimum) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) + value.maxGroupTieredPackage != null -> + generator.writeObject(value.maxGroupTieredPackage) + value.scalableMatrixWithUnitPricing != null -> + generator.writeObject(value.scalableMatrixWithUnitPricing) + value.scalableMatrixWithTieredPricing != null -> + generator.writeObject(value.scalableMatrixWithTieredPricing) + value.cumulativeGroupedBulk != null -> + generator.writeObject(value.cumulativeGroupedBulk) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Price") } } } - } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bulkWithFiltersConfig: JsonField, + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) - return /* spotless:off */ other is AddPrice && allocationPrice == other.allocationPrice && discounts == other.discounts && endDate == other.endDate && externalPriceId == other.externalPriceId && maximumAmount == other.maximumAmount && minimumAmount == other.minimumAmount && planPhaseOrder == other.planPhaseOrder && price == other.price && priceId == other.priceId && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(allocationPrice, discounts, endDate, externalPriceId, maximumAmount, minimumAmount, planPhaseOrder, price, priceId, startDate, additionalProperties) } - /* spotless:on */ + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - override fun hashCode(): Int = hashCode + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - override fun toString() = - "AddPrice{allocationPrice=$allocationPrice, discounts=$discounts, endDate=$endDate, externalPriceId=$externalPriceId, maximumAmount=$maximumAmount, minimumAmount=$minimumAmount, planPhaseOrder=$planPhaseOrder, price=$price, priceId=$priceId, startDate=$startDate, additionalProperties=$additionalProperties}" - } + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - @Deprecated("deprecated") - class ExternalMarketplace - @JsonCreator - private constructor(private val value: JsonField) : Enum { + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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 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 + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - companion object { + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - val GOOGLE = of("google") + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - val AWS = of("aws") + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - val AZURE = of("azure") + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - fun of(value: String) = ExternalMarketplace(JsonField.of(value)) - } + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - /** An enum containing [ExternalMarketplace]'s known values. */ - enum class Known { - GOOGLE, - AWS, - AZURE, - } + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - /** - * An enum containing [ExternalMarketplace]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [ExternalMarketplace] 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 { - GOOGLE, - AWS, - AZURE, - /** - * An enum member indicating that [ExternalMarketplace] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - /** - * 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) { - GOOGLE -> Value.GOOGLE - AWS -> Value.AWS - AZURE -> Value.AZURE - else -> Value._UNKNOWN - } + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - /** - * 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - GOOGLE -> Known.GOOGLE - AWS -> Known.AWS - AZURE -> Known.AZURE - else -> throw OrbInvalidDataException("Unknown ExternalMarketplace: $value") - } + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - /** - * 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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - private var validated: Boolean = false + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - fun validate(): ExternalMarketplace = apply { - if (validated) { - return@apply - } + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - known() - validated = true - } + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = + bulkWithFiltersConfig - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * 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 - return /* spotless:off */ other is ExternalMarketplace && value == other.value /* spotless:on */ - } + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - override fun hashCode() = value.hashCode() + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - override fun toString() = value.toString() - } + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - /** - * User-specified key/value pairs for the resource. Individual keys can be removed by setting - * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to - * `null`. - */ - class Metadata - @JsonCreator - private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map - ) { + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - fun toBuilder() = Builder().from(this) + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - companion object { + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - /** Returns a mutable builder for constructing an instance of [Metadata]. */ - fun builder() = Builder() - } + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - /** A builder for [Metadata]. */ - class Builder internal constructor() { + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - internal fun from(metadata: Metadata) = apply { - additionalProperties = metadata.additionalProperties.toMutableMap() - } + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + @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 toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [BulkWithFilters]. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** A builder for [BulkWithFilters]. */ + class Builder internal constructor() { + + private var bulkWithFiltersConfig: JsonField? = null + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + itemId = bulkWithFilters.itemId + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + billableMetricId = bulkWithFilters.billableMetricId + billedInAdvance = bulkWithFilters.billedInAdvance + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + currency = bulkWithFilters.currency + dimensionalPriceConfiguration = + bulkWithFilters.dimensionalPriceConfiguration + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoiceGroupingKey = bulkWithFilters.invoiceGroupingKey + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + metadata = bulkWithFilters.metadata + referenceId = bulkWithFilters.referenceId + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() + } - /** - * Returns an immutable instance of [Metadata]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Metadata = Metadata(additionalProperties.toImmutable()) - } + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig( + bulkWithFiltersConfig: JsonField + ) = apply { this.bulkWithFiltersConfig = bulkWithFiltersConfig } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - private var validated: Boolean = false + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - fun validate(): Metadata = apply { - if (validated) { - return@apply - } + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - validated = true - } + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - override fun hashCode(): Int = hashCode + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - override fun toString() = "Metadata{additionalProperties=$additionalProperties}" - } + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - class RemoveAdjustment - private constructor( - private val adjustmentId: JsonField, - private val additionalProperties: MutableMap, - ) { + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - @JsonCreator - private constructor( - @JsonProperty("adjustment_id") - @ExcludeMissing - adjustmentId: JsonField = JsonMissing.of() - ) : this(adjustmentId, mutableMapOf()) + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** - * The id of the adjustment to remove on the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun adjustmentId(): String = adjustmentId.getRequired("adjustment_id") + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** - * Returns the raw JSON value of [adjustmentId]. - * - * Unlike [adjustmentId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("adjustment_id") - @ExcludeMissing - fun _adjustmentId(): JsonField = adjustmentId + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Returns an immutable instance of [BulkWithFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFilters = + BulkWithFilters( + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - fun toBuilder() = Builder().from(this) + private var validated: Boolean = false - companion object { + fun validate(): BulkWithFilters = apply { + if (validated) { + return@apply + } - /** - * Returns a mutable builder for constructing an instance of [RemoveAdjustment]. - * - * The following fields are required: - * ```kotlin - * .adjustmentId() - * ``` - */ - fun builder() = Builder() - } + bulkWithFiltersConfig().validate() + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("bulk_with_filters")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - /** A builder for [RemoveAdjustment]. */ - class Builder internal constructor() { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - private var adjustmentId: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { - internal fun from(removeAdjustment: RemoveAdjustment) = apply { - adjustmentId = removeAdjustment.adjustmentId - additionalProperties = removeAdjustment.additionalProperties.toMutableMap() - } + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) + + /** + * Property filters to apply (all must match) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [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) + } - /** The id of the adjustment to remove on the subscription. */ - fun adjustmentId(adjustmentId: String) = adjustmentId(JsonField.of(adjustmentId)) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() + } - /** - * Sets [Builder.adjustmentId] to an arbitrary JSON value. - * - * You should usually call [Builder.adjustmentId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun adjustmentId(adjustmentId: JsonField) = apply { - this.adjustmentId = adjustmentId - } + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithFiltersConfig.additionalProperties.toMutableMap() + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** Bulk tiers for rating based on total usage volume */ + 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() } + } - /** - * Returns an immutable instance of [RemoveAdjustment]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .adjustmentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): RemoveAdjustment = - RemoveAdjustment( - checkRequired("adjustmentId", adjustmentId), - additionalProperties.toMutableMap(), - ) - } + /** + * 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) + } + } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): RemoveAdjustment = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - adjustmentId() - validated = true - } + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - 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. - */ - internal fun validity(): Int = (if (adjustmentId.asKnown() == null) 0 else 1) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns an immutable instance of [BulkWithFiltersConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } - return /* spotless:off */ other is RemoveAdjustment && adjustmentId == other.adjustmentId && additionalProperties == other.additionalProperties /* spotless:on */ - } + private var validated: Boolean = false - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustmentId, additionalProperties) } - /* spotless:on */ + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } - override fun hashCode(): Int = hashCode + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } - override fun toString() = - "RemoveAdjustment{adjustmentId=$adjustmentId, additionalProperties=$additionalProperties}" - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - class RemovePrice - private constructor( - private val externalPriceId: JsonField, - private val priceId: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - @JsonCreator - private constructor( - @JsonProperty("external_price_id") - @ExcludeMissing - externalPriceId: JsonField = JsonMissing.of(), - @JsonProperty("price_id") @ExcludeMissing priceId: JsonField = JsonMissing.of(), - ) : this(externalPriceId, priceId, mutableMapOf()) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } - /** - * The external price id of the price to remove on the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = + propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } - /** - * The id of the price to remove on the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun priceId(): String? = priceId.getNullable("price_id") + private var validated: Boolean = false - /** - * Returns the raw JSON value of [externalPriceId]. - * - * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("external_price_id") - @ExcludeMissing - fun _externalPriceId(): JsonField = externalPriceId + fun validate(): Filter = apply { + if (validated) { + return@apply + } - /** - * Returns the raw JSON value of [priceId]. - * - * Unlike [priceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("price_id") @ExcludeMissing fun _priceId(): JsonField = priceId + propertyKey() + propertyValue() + validated = true + } - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } - fun toBuilder() = Builder().from(this) + override fun hashCode(): Int = hashCode - companion object { + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } - /** Returns a mutable builder for constructing an instance of [RemovePrice]. */ - fun builder() = Builder() - } + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = + tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** A builder for [RemovePrice]. */ - class Builder internal constructor() { + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - private var externalPriceId: JsonField = JsonMissing.of() - private var priceId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + fun toBuilder() = Builder().from(this) - internal fun from(removePrice: RemovePrice) = apply { - externalPriceId = removePrice.externalPriceId - priceId = removePrice.priceId - additionalProperties = removePrice.additionalProperties.toMutableMap() - } + companion object { - /** The external price id of the price to remove on the subscription. */ - fun externalPriceId(externalPriceId: String?) = - externalPriceId(JsonField.ofNullable(externalPriceId)) + /** + * Returns a mutable builder for constructing an instance of [Tier]. + * + * The following fields are required: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - /** - * Sets [Builder.externalPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.externalPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun externalPriceId(externalPriceId: JsonField) = apply { - this.externalPriceId = externalPriceId - } + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } - /** The id of the price to remove on the subscription. */ - fun priceId(priceId: String?) = priceId(JsonField.ofNullable(priceId)) + private var validated: Boolean = false - /** - * Sets [Builder.priceId] to an arbitrary JSON value. - * - * You should usually call [Builder.priceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun priceId(priceId: JsonField) = apply { this.priceId = priceId } + fun validate(): Tier = apply { + if (validated) { + return@apply + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + unitAmount() + tierLowerBound() + validated = true + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, 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() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } - /** - * Returns an immutable instance of [RemovePrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): RemovePrice = - RemovePrice(externalPriceId, priceId, additionalProperties.toMutableMap()) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - private var validated: Boolean = false + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } - fun validate(): RemovePrice = apply { - if (validated) { - return@apply - } + private val hashCode: Int by lazy { + Objects.hash(filters, tiers, additionalProperties) + } - externalPriceId() - priceId() - validated = true - } + override fun hashCode(): Int = hashCode - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (priceId.asKnown() == null) 0 else 1) + /** The cadence to bill for this price on. */ + class Cadence + @JsonCreator + private constructor(private val value: JsonField) : Enum { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * 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 - return /* spotless:off */ other is RemovePrice && externalPriceId == other.externalPriceId && priceId == other.priceId && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(externalPriceId, priceId, additionalProperties) } - /* spotless:on */ + val ANNUAL = of("annual") - override fun hashCode(): Int = hashCode + val SEMI_ANNUAL = of("semi_annual") - override fun toString() = - "RemovePrice{externalPriceId=$externalPriceId, priceId=$priceId, additionalProperties=$additionalProperties}" - } + val MONTHLY = of("monthly") - class ReplaceAdjustment - private constructor( - private val adjustment: JsonField, - private val replacesAdjustmentId: JsonField, - private val additionalProperties: MutableMap, - ) { + val QUARTERLY = of("quarterly") - @JsonCreator - private constructor( - @JsonProperty("adjustment") - @ExcludeMissing - adjustment: JsonField = JsonMissing.of(), - @JsonProperty("replaces_adjustment_id") - @ExcludeMissing - replacesAdjustmentId: JsonField = JsonMissing.of(), - ) : this(adjustment, replacesAdjustmentId, mutableMapOf()) + val ONE_TIME = of("one_time") - /** - * The definition of a new adjustment to create and add to the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun adjustment(): Adjustment = adjustment.getRequired("adjustment") + val CUSTOM = of("custom") - /** - * The id of the adjustment on the plan to replace in the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun replacesAdjustmentId(): String = - replacesAdjustmentId.getRequired("replaces_adjustment_id") + fun of(value: String) = Cadence(JsonField.of(value)) + } - /** - * Returns the raw JSON value of [adjustment]. - * - * Unlike [adjustment], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("adjustment") - @ExcludeMissing - fun _adjustment(): JsonField = adjustment + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - /** - * Returns the raw JSON value of [replacesAdjustmentId]. - * - * Unlike [replacesAdjustmentId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("replaces_adjustment_id") - @ExcludeMissing - fun _replacesAdjustmentId(): JsonField = replacesAdjustmentId + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } - companion object { + known() + validated = true + } - /** - * Returns a mutable builder for constructing an instance of [ReplaceAdjustment]. - * - * The following fields are required: - * ```kotlin - * .adjustment() - * .replacesAdjustmentId() - * ``` - */ - fun builder() = Builder() - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** A builder for [ReplaceAdjustment]. */ - class Builder internal constructor() { + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - private var adjustment: JsonField? = null - private var replacesAdjustmentId: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() + return other is Cadence && value == other.value + } - internal fun from(replaceAdjustment: ReplaceAdjustment) = apply { - adjustment = replaceAdjustment.adjustment - replacesAdjustmentId = replaceAdjustment.replacesAdjustmentId - additionalProperties = replaceAdjustment.additionalProperties.toMutableMap() - } + override fun hashCode() = value.hashCode() - /** The definition of a new adjustment to create and add to the subscription. */ - fun adjustment(adjustment: Adjustment) = adjustment(JsonField.of(adjustment)) + override fun toString() = value.toString() + } - /** - * Sets [Builder.adjustment] to an arbitrary JSON value. - * - * You should usually call [Builder.adjustment] with a well-typed [Adjustment] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun adjustment(adjustment: JsonField) = apply { - this.adjustment = adjustment - } + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - /** - * Alias for calling [adjustment] with - * `Adjustment.ofPercentageDiscount(percentageDiscount)`. - */ - fun adjustment(percentageDiscount: NewPercentageDiscount) = - adjustment(Adjustment.ofPercentageDiscount(percentageDiscount)) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewPercentageDiscount.builder() - * .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) - * .percentageDiscount(percentageDiscount) - * .build() - * ``` - */ - fun percentageDiscountAdjustment(percentageDiscount: Double) = - adjustment( - NewPercentageDiscount.builder() - .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) - .percentageDiscount(percentageDiscount) - .build() - ) + fun toBuilder() = Builder().from(this) - /** Alias for calling [adjustment] with `Adjustment.ofUsageDiscount(usageDiscount)`. */ - fun adjustment(usageDiscount: NewUsageDiscount) = - adjustment(Adjustment.ofUsageDiscount(usageDiscount)) + companion object { - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewUsageDiscount.builder() - * .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) - * .usageDiscount(usageDiscount) - * .build() - * ``` - */ - fun usageDiscountAdjustment(usageDiscount: Double) = - adjustment( - NewUsageDiscount.builder() - .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) - .usageDiscount(usageDiscount) - .build() - ) + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + fun builder() = Builder() + } - /** - * Alias for calling [adjustment] with `Adjustment.ofAmountDiscount(amountDiscount)`. - */ - fun adjustment(amountDiscount: NewAmountDiscount) = - adjustment(Adjustment.ofAmountDiscount(amountDiscount)) + /** A builder for [Metadata]. */ + class Builder internal constructor() { - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewAmountDiscount.builder() - * .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) - * .amountDiscount(amountDiscount) - * .build() - * ``` - */ - fun amountDiscountAdjustment(amountDiscount: String) = - adjustment( - NewAmountDiscount.builder() - .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) - .amountDiscount(amountDiscount) - .build() - ) + private var additionalProperties: MutableMap = + mutableMapOf() - /** Alias for calling [adjustment] with `Adjustment.ofMinimum(minimum)`. */ - fun adjustment(minimum: NewMinimum) = adjustment(Adjustment.ofMinimum(minimum)) + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } - /** Alias for calling [adjustment] with `Adjustment.ofMaximum(maximum)`. */ - fun adjustment(maximum: NewMaximum) = adjustment(Adjustment.ofMaximum(maximum)) + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewMaximum.builder() - * .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) - * .maximumAmount(maximumAmount) - * .build() - * ``` - */ - fun maximumAdjustment(maximumAmount: String) = - adjustment( - NewMaximum.builder() - .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) - .maximumAmount(maximumAmount) - .build() - ) + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** The id of the adjustment on the plan to replace in the subscription. */ - fun replacesAdjustmentId(replacesAdjustmentId: String) = - replacesAdjustmentId(JsonField.of(replacesAdjustmentId)) + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - /** - * Sets [Builder.replacesAdjustmentId] to an arbitrary JSON value. - * - * You should usually call [Builder.replacesAdjustmentId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun replacesAdjustmentId(replacesAdjustmentId: JsonField) = apply { - this.replacesAdjustmentId = replacesAdjustmentId - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + private var validated: Boolean = false - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun validate(): Metadata = apply { + if (validated) { + return@apply + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + validated = true + } - /** - * Returns an immutable instance of [ReplaceAdjustment]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .adjustment() - * .replacesAdjustmentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ReplaceAdjustment = - ReplaceAdjustment( - checkRequired("adjustment", adjustment), - checkRequired("replacesAdjustmentId", replacesAdjustmentId), - additionalProperties.toMutableMap(), - ) - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - private var validated: Boolean = false + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } - fun validate(): ReplaceAdjustment = apply { - if (validated) { - return@apply - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - adjustment().validate() - replacesAdjustmentId() - validated = true - } + return other is Metadata && + additionalProperties == other.additionalProperties + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (adjustment.asKnown()?.validity() ?: 0) + - (if (replacesAdjustmentId.asKnown() == null) 0 else 1) + override fun hashCode(): Int = hashCode - /** The definition of a new adjustment to create and add to the subscription. */ - @JsonDeserialize(using = Adjustment.Deserializer::class) - @JsonSerialize(using = Adjustment.Serializer::class) - class Adjustment - private constructor( - private val percentageDiscount: NewPercentageDiscount? = null, - private val usageDiscount: NewUsageDiscount? = null, - private val amountDiscount: NewAmountDiscount? = null, - private val minimum: NewMinimum? = null, - private val maximum: NewMaximum? = null, - private val _json: JsonValue? = null, - ) { + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } - fun percentageDiscount(): NewPercentageDiscount? = percentageDiscount + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun usageDiscount(): NewUsageDiscount? = usageDiscount + return other is BulkWithFilters && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } - fun amountDiscount(): NewAmountDiscount? = amountDiscount + private val hashCode: Int by lazy { + Objects.hash( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } - fun minimum(): NewMinimum? = minimum + override fun hashCode(): Int = hashCode - fun maximum(): NewMaximum? = maximum + override fun toString() = + "BulkWithFilters{bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } - fun isPercentageDiscount(): Boolean = percentageDiscount != null + class TieredWithProration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val tieredWithProrationConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + tieredWithProrationConfig: JsonField = + JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) - fun isUsageDiscount(): Boolean = usageDiscount != null + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - fun isAmountDiscount(): Boolean = amountDiscount != null + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - fun isMinimum(): Boolean = minimum != null + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - fun isMaximum(): Boolean = maximum != null + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - fun asPercentageDiscount(): NewPercentageDiscount = - percentageDiscount.getOrThrow("percentageDiscount") + /** + * Configuration for tiered_with_proration pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tieredWithProrationConfig(): TieredWithProrationConfig = + tieredWithProrationConfig.getRequired("tiered_with_proration_config") - fun asUsageDiscount(): NewUsageDiscount = usageDiscount.getOrThrow("usageDiscount") + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - fun asAmountDiscount(): NewAmountDiscount = amountDiscount.getOrThrow("amountDiscount") + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - fun asMinimum(): NewMinimum = minimum.getOrThrow("minimum") + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - fun asMaximum(): NewMaximum = maximum.getOrThrow("maximum") + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - fun _json(): JsonValue? = _json + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - fun accept(visitor: Visitor): T = - when { - percentageDiscount != null -> - visitor.visitPercentageDiscount(percentageDiscount) - usageDiscount != null -> visitor.visitUsageDiscount(usageDiscount) - amountDiscount != null -> visitor.visitAmountDiscount(amountDiscount) - minimum != null -> visitor.visitMinimum(minimum) - maximum != null -> visitor.visitMaximum(maximum) - else -> visitor.unknown(_json) - } + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - private var validated: Boolean = false + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - fun validate(): Adjustment = apply { - if (validated) { - return@apply - } + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - accept( - object : Visitor { - override fun visitPercentageDiscount( - percentageDiscount: NewPercentageDiscount - ) { - percentageDiscount.validate() - } + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) { - usageDiscount.validate() - } + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) { - amountDiscount.validate() - } + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - override fun visitMinimum(minimum: NewMinimum) { - minimum.validate() - } + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - override fun visitMaximum(maximum: NewMaximum) { - maximum.validate() - } - } - ) - validated = true - } + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitPercentageDiscount( - percentageDiscount: NewPercentageDiscount - ) = percentageDiscount.validity() + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) = - usageDiscount.validity() + /** + * 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 - override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) = - amountDiscount.validity() + /** + * Returns the raw JSON value of [tieredWithProrationConfig]. + * + * Unlike [tieredWithProrationConfig], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + fun _tieredWithProrationConfig(): JsonField = + tieredWithProrationConfig - override fun visitMinimum(minimum: NewMinimum) = minimum.validity() + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - override fun visitMaximum(maximum: NewMaximum) = maximum.validity() + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - override fun unknown(json: JsonValue?) = 0 - } - ) + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - return /* spotless:off */ other is Adjustment && percentageDiscount == other.percentageDiscount && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ - } + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) /* spotless:on */ + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - override fun toString(): String = - when { - percentageDiscount != null -> - "Adjustment{percentageDiscount=$percentageDiscount}" - usageDiscount != null -> "Adjustment{usageDiscount=$usageDiscount}" - amountDiscount != null -> "Adjustment{amountDiscount=$amountDiscount}" - minimum != null -> "Adjustment{minimum=$minimum}" - maximum != null -> "Adjustment{maximum=$maximum}" - _json != null -> "Adjustment{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Adjustment") - } + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - companion object { + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - fun ofPercentageDiscount(percentageDiscount: NewPercentageDiscount) = - Adjustment(percentageDiscount = percentageDiscount) + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - fun ofUsageDiscount(usageDiscount: NewUsageDiscount) = - Adjustment(usageDiscount = usageDiscount) + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - fun ofAmountDiscount(amountDiscount: NewAmountDiscount) = - Adjustment(amountDiscount = amountDiscount) + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - fun ofMinimum(minimum: NewMinimum) = Adjustment(minimum = minimum) + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - fun ofMaximum(maximum: NewMaximum) = Adjustment(maximum = maximum) - } + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - /** - * An interface that defines how to map each variant of [Adjustment] to a value of type - * [T]. - */ - interface Visitor { + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun visitPercentageDiscount(percentageDiscount: NewPercentageDiscount): T + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [TieredWithProration]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + */ + fun builder() = Builder() + } - fun visitUsageDiscount(usageDiscount: NewUsageDiscount): T + /** A builder for [TieredWithProration]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("tiered_with_proration") + private var name: JsonField? = null + private var tieredWithProrationConfig: JsonField? = + null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tieredWithProration: TieredWithProration) = apply { + cadence = tieredWithProration.cadence + itemId = tieredWithProration.itemId + modelType = tieredWithProration.modelType + name = tieredWithProration.name + tieredWithProrationConfig = tieredWithProration.tieredWithProrationConfig + billableMetricId = tieredWithProration.billableMetricId + billedInAdvance = tieredWithProration.billedInAdvance + billingCycleConfiguration = tieredWithProration.billingCycleConfiguration + conversionRate = tieredWithProration.conversionRate + conversionRateConfig = tieredWithProration.conversionRateConfig + currency = tieredWithProration.currency + dimensionalPriceConfiguration = + tieredWithProration.dimensionalPriceConfiguration + externalPriceId = tieredWithProration.externalPriceId + fixedPriceQuantity = tieredWithProration.fixedPriceQuantity + invoiceGroupingKey = tieredWithProration.invoiceGroupingKey + invoicingCycleConfiguration = + tieredWithProration.invoicingCycleConfiguration + metadata = tieredWithProration.metadata + referenceId = tieredWithProration.referenceId + additionalProperties = + tieredWithProration.additionalProperties.toMutableMap() + } - fun visitAmountDiscount(amountDiscount: NewAmountDiscount): T + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for tiered_with_proration pricing */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: TieredWithProrationConfig + ) = tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) + + /** + * Sets [Builder.tieredWithProrationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.tieredWithProrationConfig] with a well-typed + * [TieredWithProrationConfig] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: JsonField + ) = apply { this.tieredWithProrationConfig = tieredWithProrationConfig } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - fun visitMinimum(minimum: NewMinimum): T + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - fun visitMaximum(maximum: NewMaximum): T + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - /** - * Maps an unknown variant of [Adjustment] to a value of type [T]. - * - * An instance of [Adjustment] can contain an unknown variant if it was deserialized - * from data that doesn't match any known variant. For example, if the SDK is on an - * older version than the API, then the API may respond with new variants that the - * SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown Adjustment: $json") - } - } + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - internal class Deserializer : BaseDeserializer(Adjustment::class) { + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - override fun ObjectCodec.deserialize(node: JsonNode): Adjustment { - val json = JsonValue.fromJsonNode(node) - val adjustmentType = json.asObject()?.get("adjustment_type")?.asString() + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - when (adjustmentType) { - "percentage_discount" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Adjustment(percentageDiscount = it, _json = json) } - ?: Adjustment(_json = json) + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - "usage_discount" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(usageDiscount = it, _json = json) - } ?: Adjustment(_json = json) + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TieredWithProration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProration = + TieredWithProration( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("tieredWithProrationConfig", tieredWithProrationConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProration = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("tiered_with_proration")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") } - "amount_discount" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(amountDiscount = it, _json = json) - } ?: Adjustment(_json = json) + } + name() + tieredWithProrationConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("tiered_with_proration")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (tieredWithProrationConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN } - "minimum" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(minimum = it, _json = json) - } ?: Adjustment(_json = json) + + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") } - "maximum" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(maximum = it, _json = json) - } ?: Adjustment(_json = json) + + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply } + + known() + validated = true } - return Adjustment(_json = json) - } - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - internal class Serializer : BaseSerializer(Adjustment::class) { + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun serialize( - value: Adjustment, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.percentageDiscount != null -> - generator.writeObject(value.percentageDiscount) - value.usageDiscount != null -> generator.writeObject(value.usageDiscount) - value.amountDiscount != null -> generator.writeObject(value.amountDiscount) - value.minimum != null -> generator.writeObject(value.minimum) - value.maximum != null -> generator.writeObject(value.maximum) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Adjustment") + return other is Cadence && value == other.value } - } - } - } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + override fun hashCode() = value.hashCode() - return /* spotless:off */ other is ReplaceAdjustment && adjustment == other.adjustment && replacesAdjustmentId == other.replacesAdjustmentId && additionalProperties == other.additionalProperties /* spotless:on */ - } + override fun toString() = value.toString() + } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustment, replacesAdjustmentId, additionalProperties) } - /* spotless:on */ + /** Configuration for tiered_with_proration pricing */ + class TieredWithProrationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { - override fun hashCode(): Int = hashCode + @JsonCreator + private constructor( + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Tiers for rating based on total usage quantities into the specified tier with + * proration + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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) + } - override fun toString() = - "ReplaceAdjustment{adjustment=$adjustment, replacesAdjustmentId=$replacesAdjustmentId, additionalProperties=$additionalProperties}" - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [TieredWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + */ + fun builder() = Builder() + } - class ReplacePrice - private constructor( - private val replacesPriceId: JsonField, - private val allocationPrice: JsonField, - private val discounts: JsonField>, - private val externalPriceId: JsonField, - private val fixedPriceQuantity: JsonField, - private val maximumAmount: JsonField, - private val minimumAmount: JsonField, - private val price: JsonField, - private val priceId: JsonField, - private val additionalProperties: MutableMap, - ) { + /** A builder for [TieredWithProrationConfig]. */ + class Builder internal constructor() { + + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = + apply { + tiers = tieredWithProrationConfig.tiers.map { it.toMutableList() } + additionalProperties = + tieredWithProrationConfig.additionalProperties.toMutableMap() + } + + /** + * Tiers for rating based on total usage quantities into the specified tier + * with proration + */ + 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() } + } - @JsonCreator - private constructor( - @JsonProperty("replaces_price_id") - @ExcludeMissing - replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("allocation_price") - @ExcludeMissing - allocationPrice: JsonField = JsonMissing.of(), - @JsonProperty("discounts") - @ExcludeMissing - discounts: JsonField> = JsonMissing.of(), - @JsonProperty("external_price_id") - @ExcludeMissing - externalPriceId: JsonField = JsonMissing.of(), - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("maximum_amount") - @ExcludeMissing - maximumAmount: JsonField = JsonMissing.of(), - @JsonProperty("minimum_amount") - @ExcludeMissing - minimumAmount: JsonField = JsonMissing.of(), - @JsonProperty("price") @ExcludeMissing price: JsonField = JsonMissing.of(), - @JsonProperty("price_id") @ExcludeMissing priceId: JsonField = JsonMissing.of(), - ) : this( - replacesPriceId, - allocationPrice, - discounts, - externalPriceId, - fixedPriceQuantity, - maximumAmount, - minimumAmount, - price, - priceId, - mutableMapOf(), - ) + /** + * 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) + } + } - /** - * The id of the price on the plan to replace in the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun replacesPriceId(): String = replacesPriceId.getRequired("replaces_price_id") + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** - * The definition of a new allocation price to create and add to the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun allocationPrice(): NewAllocationPrice? = allocationPrice.getNullable("allocation_price") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** - * [DEPRECATED] Use add_adjustments instead. The subscription's discounts for the - * replacement price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") - fun discounts(): List? = discounts.getNullable("discounts") + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - /** - * The external price id of the price to add to the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - /** - * The new quantity of the price, if the price is a fixed price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** - * [DEPRECATED] Use add_adjustments instead. The subscription's maximum amount for the - * replacement price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") - fun maximumAmount(): String? = maximumAmount.getNullable("maximum_amount") + /** + * Returns an immutable instance of [TieredWithProrationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProrationConfig = + TieredWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } - /** - * [DEPRECATED] Use add_adjustments instead. The subscription's minimum amount for the - * replacement price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") - fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") + private var validated: Boolean = false - /** - * The definition of a new price to create and add to the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun price(): Price? = price.getNullable("price") + fun validate(): TieredWithProrationConfig = apply { + if (validated) { + return@apply + } - /** - * The id of the price to add to the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun priceId(): String? = priceId.getNullable("price_id") + tiers().forEach { it.validate() } + validated = true + } - /** - * Returns the raw JSON value of [replacesPriceId]. - * - * Unlike [replacesPriceId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("replaces_price_id") - @ExcludeMissing - fun _replacesPriceId(): JsonField = replacesPriceId + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** - * Returns the raw JSON value of [allocationPrice]. - * - * Unlike [allocationPrice], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("allocation_price") - @ExcludeMissing - fun _allocationPrice(): JsonField = allocationPrice + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tiered with proration tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Inclusive tier starting value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun tierLowerBound(): String = + tierLowerBound.getRequired("tier_lower_bound") + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** - * Returns the raw JSON value of [discounts]. - * - * Unlike [discounts], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("discounts") - @ExcludeMissing - fun _discounts(): JsonField> = discounts + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - /** - * Returns the raw JSON value of [externalPriceId]. - * - * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("external_price_id") - @ExcludeMissing - fun _externalPriceId(): JsonField = externalPriceId + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Inclusive tier starting value */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } - /** - * Returns the raw JSON value of [fixedPriceQuantity]. - * - * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + private var validated: Boolean = false - /** - * Returns the raw JSON value of [maximumAmount]. - * - * Unlike [maximumAmount], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @Deprecated("deprecated") - @JsonProperty("maximum_amount") - @ExcludeMissing - fun _maximumAmount(): JsonField = maximumAmount + fun validate(): Tier = apply { + if (validated) { + return@apply + } - /** - * Returns the raw JSON value of [minimumAmount]. - * - * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @Deprecated("deprecated") - @JsonProperty("minimum_amount") - @ExcludeMissing - fun _minimumAmount(): JsonField = minimumAmount + tierLowerBound() + unitAmount() + validated = true + } - /** - * 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 + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } - /** - * Returns the raw JSON value of [priceId]. - * - * Unlike [priceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("price_id") @ExcludeMissing fun _priceId(): JsonField = priceId + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + override fun hashCode(): Int = hashCode - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } - fun toBuilder() = Builder().from(this) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - companion object { + return other is TieredWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } - /** - * Returns a mutable builder for constructing an instance of [ReplacePrice]. - * - * The following fields are required: - * ```kotlin - * .replacesPriceId() - * ``` - */ - fun builder() = Builder() - } + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } - /** A builder for [ReplacePrice]. */ - class Builder internal constructor() { + override fun hashCode(): Int = hashCode - private var replacesPriceId: JsonField? = null - private var allocationPrice: JsonField = JsonMissing.of() - private var discounts: JsonField>? = null - private var externalPriceId: JsonField = JsonMissing.of() - private var fixedPriceQuantity: JsonField = JsonMissing.of() - private var maximumAmount: JsonField = JsonMissing.of() - private var minimumAmount: JsonField = JsonMissing.of() - private var price: JsonField = JsonMissing.of() - private var priceId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + override fun toString() = + "TieredWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" + } - internal fun from(replacePrice: ReplacePrice) = apply { - replacesPriceId = replacePrice.replacesPriceId - allocationPrice = replacePrice.allocationPrice - discounts = replacePrice.discounts.map { it.toMutableList() } - externalPriceId = replacePrice.externalPriceId - fixedPriceQuantity = replacePrice.fixedPriceQuantity - maximumAmount = replacePrice.maximumAmount - minimumAmount = replacePrice.minimumAmount - price = replacePrice.price - priceId = replacePrice.priceId - additionalProperties = replacePrice.additionalProperties.toMutableMap() - } + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - /** The id of the price on the plan to replace in the subscription. */ - fun replacesPriceId(replacesPriceId: String) = - replacesPriceId(JsonField.of(replacesPriceId)) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - /** - * Sets [Builder.replacesPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.replacesPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun replacesPriceId(replacesPriceId: JsonField) = apply { - this.replacesPriceId = replacesPriceId - } + fun toBuilder() = Builder().from(this) - /** The definition of a new allocation price to create and add to the subscription. */ - fun allocationPrice(allocationPrice: NewAllocationPrice?) = - allocationPrice(JsonField.ofNullable(allocationPrice)) + companion object { - /** - * Sets [Builder.allocationPrice] to an arbitrary JSON value. - * - * You should usually call [Builder.allocationPrice] with a well-typed - * [NewAllocationPrice] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun allocationPrice(allocationPrice: JsonField) = apply { - this.allocationPrice = allocationPrice - } + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + fun builder() = Builder() + } - /** - * [DEPRECATED] Use add_adjustments instead. The subscription's discounts for the - * replacement price. - */ - @Deprecated("deprecated") - fun discounts(discounts: List?) = - discounts(JsonField.ofNullable(discounts)) + /** A builder for [Metadata]. */ + class Builder internal constructor() { - /** - * Sets [Builder.discounts] to an arbitrary JSON value. - * - * You should usually call [Builder.discounts] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - @Deprecated("deprecated") - fun discounts(discounts: JsonField>) = apply { - this.discounts = discounts.map { it.toMutableList() } - } + private var additionalProperties: MutableMap = + mutableMapOf() - /** - * Adds a single [DiscountOverride] to [discounts]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - @Deprecated("deprecated") - fun addDiscount(discount: DiscountOverride) = apply { - discounts = - (discounts ?: JsonField.of(mutableListOf())).also { - checkKnown("discounts", it).add(discount) + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } - } - /** The external price id of the price to add to the subscription. */ - fun externalPriceId(externalPriceId: String?) = - externalPriceId(JsonField.ofNullable(externalPriceId)) + private var validated: Boolean = false - /** - * Sets [Builder.externalPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.externalPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun externalPriceId(externalPriceId: JsonField) = apply { - this.externalPriceId = externalPriceId - } + fun validate(): Metadata = apply { + if (validated) { + return@apply + } - /** The new quantity of the price, if the price is a fixed price. */ - fun fixedPriceQuantity(fixedPriceQuantity: Double?) = - fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + validated = true + } - /** - * Alias for [Builder.fixedPriceQuantity]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun fixedPriceQuantity(fixedPriceQuantity: Double) = - fixedPriceQuantity(fixedPriceQuantity as Double?) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** - * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. - * - * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { - this.fixedPriceQuantity = fixedPriceQuantity + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProration && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredWithProrationConfig == other.tieredWithProrationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProration{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, tieredWithProrationConfig=$tieredWithProrationConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" } - /** - * [DEPRECATED] Use add_adjustments instead. The subscription's maximum amount for the - * replacement price. - */ - @Deprecated("deprecated") - fun maximumAmount(maximumAmount: String?) = - maximumAmount(JsonField.ofNullable(maximumAmount)) + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val groupedWithMinMaxThresholdsConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + groupedWithMinMaxThresholdsConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for grouped_with_min_max_thresholds pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired( + "grouped_with_min_max_thresholds_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. + * + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + fun _groupedWithMinMaxThresholdsConfig(): + JsonField = groupedWithMinMaxThresholdsConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [GroupedWithMinMaxThresholds]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholds]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("grouped_with_min_max_thresholds") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = + apply { + cadence = groupedWithMinMaxThresholds.cadence + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + itemId = groupedWithMinMaxThresholds.itemId + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + billableMetricId = groupedWithMinMaxThresholds.billableMetricId + billedInAdvance = groupedWithMinMaxThresholds.billedInAdvance + billingCycleConfiguration = + groupedWithMinMaxThresholds.billingCycleConfiguration + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + currency = groupedWithMinMaxThresholds.currency + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + invoiceGroupingKey = groupedWithMinMaxThresholds.invoiceGroupingKey + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + metadata = groupedWithMinMaxThresholds.metadata + referenceId = groupedWithMinMaxThresholds.referenceId + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = + groupedWithMinMaxThresholdsConfig( + JsonField.of(groupedWithMinMaxThresholdsConfig) + ) + + /** + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a + * well-typed [GroupedWithMinMaxThresholdsConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: + JsonField + ) = apply { + this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( + checkRequired("cadence", cadence), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholds = apply { + if (validated) { + return@apply + } + + cadence().validate() + groupedWithMinMaxThresholdsConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @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 + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate + additionalProperties = + groupedWithMinMaxThresholdsConfig.additionalProperties + .toMutableMap() + } + + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } + + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } + + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = + perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + if (validated) { + return@apply + } + + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholds && + cadence == other.cadence && + groupedWithMinMaxThresholdsConfig == + other.groupedWithMinMaxThresholdsConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholds{cadence=$cadence, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val cumulativeGroupedAllocationConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for cumulative_grouped_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired( + "cumulative_grouped_allocation_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): + JsonField = cumulativeGroupedAllocationConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [CumulativeGroupedAllocation]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocation]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("cumulative_grouped_allocation") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = + apply { + cadence = cumulativeGroupedAllocation.cadence + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + itemId = cumulativeGroupedAllocation.itemId + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + billableMetricId = cumulativeGroupedAllocation.billableMetricId + billedInAdvance = cumulativeGroupedAllocation.billedInAdvance + billingCycleConfiguration = + cumulativeGroupedAllocation.billingCycleConfiguration + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + currency = cumulativeGroupedAllocation.currency + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoiceGroupingKey = cumulativeGroupedAllocation.invoiceGroupingKey + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + metadata = cumulativeGroupedAllocation.metadata + referenceId = cumulativeGroupedAllocation.referenceId + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = + cumulativeGroupedAllocationConfig( + JsonField.of(cumulativeGroupedAllocationConfig) + ) + + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a + * well-typed [CumulativeGroupedAllocationConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: + JsonField + ) = apply { + this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( + checkRequired("cadence", cadence), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocation = apply { + if (validated) { + return@apply + } + + cadence().validate() + cumulativeGroupedAllocationConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("cumulative_grouped_allocation")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + mutableMapOf(), + ) + + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 + * [CumulativeGroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = + cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties + .toMutableMap() + } + + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } + + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation + } + + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply + } + + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocation && + cadence == other.cadence && + cumulativeGroupedAllocationConfig == + other.cumulativeGroupedAllocationConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocation{cadence=$cadence, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val percentConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [Percent]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Percent]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("percent") + private var name: JsonField? = null + private var percentConfig: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percent: Percent) = apply { + cadence = percent.cadence + itemId = percent.itemId + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + billableMetricId = percent.billableMetricId + billedInAdvance = percent.billedInAdvance + billingCycleConfiguration = percent.billingCycleConfiguration + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + currency = percent.currency + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoiceGroupingKey = percent.invoiceGroupingKey + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + metadata = percent.metadata + referenceId = percent.referenceId + additionalProperties = percent.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed + * [PercentConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Percent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Percent = + Percent( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("percentConfig", percentConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Percent = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("percent")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + percentConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent") + @ExcludeMissing + fun _percent(): JsonField = percent + + @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 + * [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PercentConfig]. */ + class Builder internal constructor() { + + private var percent: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() + } + + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PercentConfig = apply { + if (validated) { + return@apply + } + + percent() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(percent, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Percent && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Percent{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, percentConfig=$percentConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val eventOutputConfig: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [EventOutput]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutput]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var eventOutputConfig: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("event_output") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutput: EventOutput) = apply { + cadence = eventOutput.cadence + eventOutputConfig = eventOutput.eventOutputConfig + itemId = eventOutput.itemId + modelType = eventOutput.modelType + name = eventOutput.name + billableMetricId = eventOutput.billableMetricId + billedInAdvance = eventOutput.billedInAdvance + billingCycleConfiguration = eventOutput.billingCycleConfiguration + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + currency = eventOutput.currency + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoiceGroupingKey = eventOutput.invoiceGroupingKey + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + metadata = eventOutput.metadata + referenceId = eventOutput.referenceId + additionalProperties = eventOutput.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutput = + EventOutput( + checkRequired("cadence", cadence), + checkRequired("eventOutputConfig", eventOutputConfig), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutput = apply { + if (validated) { + return@apply + } + + cadence().validate() + eventOutputConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("event_output")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a + * unit rate will be ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = + defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events + * will also be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @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 + * [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutputConfig]. */ + class Builder internal constructor() { + + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = + eventOutputConfig.additionalProperties.toMutableMap() + } + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey + } + + /** + * If provided, this amount will be used as the unit rate when an event does + * not have a value for the `unit_rating_key`. If not provided, events + * missing a unit rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate + } + + /** + * An optional key in the event data to group by (e.g., event ID). All + * events will also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutputConfig = apply { + if (validated) { + return@apply + } + + unitRatingKey() + defaultUnitRate() + groupingKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + unitRatingKey, + defaultUnitRate, + groupingKey, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutput && + cadence == other.cadence && + eventOutputConfig == other.eventOutputConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutput{cadence=$cadence, eventOutputConfig=$eventOutputConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddPrice && + allocationPrice == other.allocationPrice && + discounts == other.discounts && + endDate == other.endDate && + externalPriceId == other.externalPriceId && + maximumAmount == other.maximumAmount && + minimumAmount == other.minimumAmount && + planPhaseOrder == other.planPhaseOrder && + price == other.price && + priceId == other.priceId && + startDate == other.startDate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + allocationPrice, + discounts, + endDate, + externalPriceId, + maximumAmount, + minimumAmount, + planPhaseOrder, + price, + priceId, + startDate, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddPrice{allocationPrice=$allocationPrice, discounts=$discounts, endDate=$endDate, externalPriceId=$externalPriceId, maximumAmount=$maximumAmount, minimumAmount=$minimumAmount, planPhaseOrder=$planPhaseOrder, price=$price, priceId=$priceId, startDate=$startDate, additionalProperties=$additionalProperties}" + } + + @Deprecated("deprecated") + class ExternalMarketplace + @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 { + + val GOOGLE = of("google") + + val AWS = of("aws") + + val AZURE = of("azure") + + fun of(value: String) = ExternalMarketplace(JsonField.of(value)) + } + + /** An enum containing [ExternalMarketplace]'s known values. */ + enum class Known { + GOOGLE, + AWS, + AZURE, + } + + /** + * An enum containing [ExternalMarketplace]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ExternalMarketplace] 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 { + GOOGLE, + AWS, + AZURE, + /** + * An enum member indicating that [ExternalMarketplace] 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) { + GOOGLE -> Value.GOOGLE + AWS -> Value.AWS + AZURE -> Value.AZURE + 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 OrbInvalidDataException if this class instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + GOOGLE -> Known.GOOGLE + AWS -> Known.AWS + AZURE -> Known.AZURE + else -> throw OrbInvalidDataException("Unknown ExternalMarketplace: $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 OrbInvalidDataException if this class instance's value does not have the expected + * primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): ExternalMarketplace = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 ExternalMarketplace && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed by setting + * the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to + * `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + class RemoveAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val adjustmentId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("adjustment_id") + @ExcludeMissing + adjustmentId: JsonField = JsonMissing.of() + ) : this(adjustmentId, mutableMapOf()) + + /** + * The id of the adjustment to remove on the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun adjustmentId(): String = adjustmentId.getRequired("adjustment_id") + + /** + * Returns the raw JSON value of [adjustmentId]. + * + * Unlike [adjustmentId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("adjustment_id") + @ExcludeMissing + fun _adjustmentId(): JsonField = adjustmentId + + @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 [RemoveAdjustment]. + * + * The following fields are required: + * ```kotlin + * .adjustmentId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [RemoveAdjustment]. */ + class Builder internal constructor() { + + private var adjustmentId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(removeAdjustment: RemoveAdjustment) = apply { + adjustmentId = removeAdjustment.adjustmentId + additionalProperties = removeAdjustment.additionalProperties.toMutableMap() + } + + /** The id of the adjustment to remove on the subscription. */ + fun adjustmentId(adjustmentId: String) = adjustmentId(JsonField.of(adjustmentId)) + + /** + * Sets [Builder.adjustmentId] to an arbitrary JSON value. + * + * You should usually call [Builder.adjustmentId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun adjustmentId(adjustmentId: JsonField) = apply { + this.adjustmentId = adjustmentId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [RemoveAdjustment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .adjustmentId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RemoveAdjustment = + RemoveAdjustment( + checkRequired("adjustmentId", adjustmentId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RemoveAdjustment = apply { + if (validated) { + return@apply + } + + adjustmentId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (adjustmentId.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RemoveAdjustment && + adjustmentId == other.adjustmentId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(adjustmentId, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemoveAdjustment{adjustmentId=$adjustmentId, additionalProperties=$additionalProperties}" + } + + class RemovePrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val externalPriceId: JsonField, + private val priceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("price_id") @ExcludeMissing priceId: JsonField = JsonMissing.of(), + ) : this(externalPriceId, priceId, mutableMapOf()) + + /** + * The external price id of the price to remove on the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * The id of the price to remove on the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun priceId(): String? = priceId.getNullable("price_id") + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [priceId]. + * + * Unlike [priceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("price_id") @ExcludeMissing fun _priceId(): JsonField = priceId + + @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 [RemovePrice]. */ + fun builder() = Builder() + } + + /** A builder for [RemovePrice]. */ + class Builder internal constructor() { + + private var externalPriceId: JsonField = JsonMissing.of() + private var priceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(removePrice: RemovePrice) = apply { + externalPriceId = removePrice.externalPriceId + priceId = removePrice.priceId + additionalProperties = removePrice.additionalProperties.toMutableMap() + } + + /** The external price id of the price to remove on the subscription. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** The id of the price to remove on the subscription. */ + fun priceId(priceId: String?) = priceId(JsonField.ofNullable(priceId)) + + /** + * Sets [Builder.priceId] to an arbitrary JSON value. + * + * You should usually call [Builder.priceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun priceId(priceId: JsonField) = apply { this.priceId = priceId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [RemovePrice]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RemovePrice = + RemovePrice(externalPriceId, priceId, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): RemovePrice = apply { + if (validated) { + return@apply + } + + externalPriceId() + priceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (priceId.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RemovePrice && + externalPriceId == other.externalPriceId && + priceId == other.priceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(externalPriceId, priceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemovePrice{externalPriceId=$externalPriceId, priceId=$priceId, additionalProperties=$additionalProperties}" + } + + class ReplaceAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val adjustment: JsonField, + private val replacesAdjustmentId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("adjustment") + @ExcludeMissing + adjustment: JsonField = JsonMissing.of(), + @JsonProperty("replaces_adjustment_id") + @ExcludeMissing + replacesAdjustmentId: JsonField = JsonMissing.of(), + ) : this(adjustment, replacesAdjustmentId, mutableMapOf()) + + /** + * The definition of a new adjustment to create and add to the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun adjustment(): Adjustment = adjustment.getRequired("adjustment") + + /** + * The id of the adjustment on the plan to replace in the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun replacesAdjustmentId(): String = + replacesAdjustmentId.getRequired("replaces_adjustment_id") + + /** + * Returns the raw JSON value of [adjustment]. + * + * Unlike [adjustment], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("adjustment") + @ExcludeMissing + fun _adjustment(): JsonField = adjustment + + /** + * Returns the raw JSON value of [replacesAdjustmentId]. + * + * Unlike [replacesAdjustmentId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("replaces_adjustment_id") + @ExcludeMissing + fun _replacesAdjustmentId(): JsonField = replacesAdjustmentId + + @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 [ReplaceAdjustment]. + * + * The following fields are required: + * ```kotlin + * .adjustment() + * .replacesAdjustmentId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ReplaceAdjustment]. */ + class Builder internal constructor() { + + private var adjustment: JsonField? = null + private var replacesAdjustmentId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(replaceAdjustment: ReplaceAdjustment) = apply { + adjustment = replaceAdjustment.adjustment + replacesAdjustmentId = replaceAdjustment.replacesAdjustmentId + additionalProperties = replaceAdjustment.additionalProperties.toMutableMap() + } + + /** The definition of a new adjustment to create and add to the subscription. */ + fun adjustment(adjustment: Adjustment) = adjustment(JsonField.of(adjustment)) + + /** + * Sets [Builder.adjustment] to an arbitrary JSON value. + * + * You should usually call [Builder.adjustment] with a well-typed [Adjustment] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun adjustment(adjustment: JsonField) = apply { + this.adjustment = adjustment + } + + /** + * Alias for calling [adjustment] with + * `Adjustment.ofPercentageDiscount(percentageDiscount)`. + */ + fun adjustment(percentageDiscount: NewPercentageDiscount) = + adjustment(Adjustment.ofPercentageDiscount(percentageDiscount)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewPercentageDiscount.builder() + * .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) + * .percentageDiscount(percentageDiscount) + * .build() + * ``` + */ + fun percentageDiscountAdjustment(percentageDiscount: Double) = + adjustment( + NewPercentageDiscount.builder() + .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) + .percentageDiscount(percentageDiscount) + .build() + ) + + /** Alias for calling [adjustment] with `Adjustment.ofUsageDiscount(usageDiscount)`. */ + fun adjustment(usageDiscount: NewUsageDiscount) = + adjustment(Adjustment.ofUsageDiscount(usageDiscount)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewUsageDiscount.builder() + * .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) + * .usageDiscount(usageDiscount) + * .build() + * ``` + */ + fun usageDiscountAdjustment(usageDiscount: Double) = + adjustment( + NewUsageDiscount.builder() + .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) + .usageDiscount(usageDiscount) + .build() + ) + + /** + * Alias for calling [adjustment] with `Adjustment.ofAmountDiscount(amountDiscount)`. + */ + fun adjustment(amountDiscount: NewAmountDiscount) = + adjustment(Adjustment.ofAmountDiscount(amountDiscount)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewAmountDiscount.builder() + * .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) + * .amountDiscount(amountDiscount) + * .build() + * ``` + */ + fun amountDiscountAdjustment(amountDiscount: String) = + adjustment( + NewAmountDiscount.builder() + .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) + .amountDiscount(amountDiscount) + .build() + ) + + /** Alias for calling [adjustment] with `Adjustment.ofMinimum(minimum)`. */ + fun adjustment(minimum: NewMinimum) = adjustment(Adjustment.ofMinimum(minimum)) + + /** Alias for calling [adjustment] with `Adjustment.ofMaximum(maximum)`. */ + fun adjustment(maximum: NewMaximum) = adjustment(Adjustment.ofMaximum(maximum)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewMaximum.builder() + * .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) + * .maximumAmount(maximumAmount) + * .build() + * ``` + */ + fun maximumAdjustment(maximumAmount: String) = + adjustment( + NewMaximum.builder() + .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) + .maximumAmount(maximumAmount) + .build() + ) + + /** The id of the adjustment on the plan to replace in the subscription. */ + fun replacesAdjustmentId(replacesAdjustmentId: String) = + replacesAdjustmentId(JsonField.of(replacesAdjustmentId)) + + /** + * Sets [Builder.replacesAdjustmentId] to an arbitrary JSON value. + * + * You should usually call [Builder.replacesAdjustmentId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun replacesAdjustmentId(replacesAdjustmentId: JsonField) = apply { + this.replacesAdjustmentId = replacesAdjustmentId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ReplaceAdjustment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .adjustment() + * .replacesAdjustmentId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ReplaceAdjustment = + ReplaceAdjustment( + checkRequired("adjustment", adjustment), + checkRequired("replacesAdjustmentId", replacesAdjustmentId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ReplaceAdjustment = apply { + if (validated) { + return@apply + } + + adjustment().validate() + replacesAdjustmentId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (adjustment.asKnown()?.validity() ?: 0) + + (if (replacesAdjustmentId.asKnown() == null) 0 else 1) + + /** The definition of a new adjustment to create and add to the subscription. */ + @JsonDeserialize(using = Adjustment.Deserializer::class) + @JsonSerialize(using = Adjustment.Serializer::class) + class Adjustment + private constructor( + private val percentageDiscount: NewPercentageDiscount? = null, + private val usageDiscount: NewUsageDiscount? = null, + private val amountDiscount: NewAmountDiscount? = null, + private val minimum: NewMinimum? = null, + private val maximum: NewMaximum? = null, + private val _json: JsonValue? = null, + ) { + + fun percentageDiscount(): NewPercentageDiscount? = percentageDiscount + + fun usageDiscount(): NewUsageDiscount? = usageDiscount + + fun amountDiscount(): NewAmountDiscount? = amountDiscount + + fun minimum(): NewMinimum? = minimum + + fun maximum(): NewMaximum? = maximum + + fun isPercentageDiscount(): Boolean = percentageDiscount != null + + fun isUsageDiscount(): Boolean = usageDiscount != null + + fun isAmountDiscount(): Boolean = amountDiscount != null + + fun isMinimum(): Boolean = minimum != null + + fun isMaximum(): Boolean = maximum != null + + fun asPercentageDiscount(): NewPercentageDiscount = + percentageDiscount.getOrThrow("percentageDiscount") + + fun asUsageDiscount(): NewUsageDiscount = usageDiscount.getOrThrow("usageDiscount") + + fun asAmountDiscount(): NewAmountDiscount = amountDiscount.getOrThrow("amountDiscount") + + fun asMinimum(): NewMinimum = minimum.getOrThrow("minimum") + + fun asMaximum(): NewMaximum = maximum.getOrThrow("maximum") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + percentageDiscount != null -> + visitor.visitPercentageDiscount(percentageDiscount) + usageDiscount != null -> visitor.visitUsageDiscount(usageDiscount) + amountDiscount != null -> visitor.visitAmountDiscount(amountDiscount) + minimum != null -> visitor.visitMinimum(minimum) + maximum != null -> visitor.visitMaximum(maximum) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Adjustment = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitPercentageDiscount( + percentageDiscount: NewPercentageDiscount + ) { + percentageDiscount.validate() + } + + override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) { + usageDiscount.validate() + } + + override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) { + amountDiscount.validate() + } + + override fun visitMinimum(minimum: NewMinimum) { + minimum.validate() + } + + override fun visitMaximum(maximum: NewMaximum) { + maximum.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitPercentageDiscount( + percentageDiscount: NewPercentageDiscount + ) = percentageDiscount.validity() + + override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) = + usageDiscount.validity() + + override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) = + amountDiscount.validity() + + override fun visitMinimum(minimum: NewMinimum) = minimum.validity() + + override fun visitMaximum(maximum: NewMaximum) = maximum.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Adjustment && + percentageDiscount == other.percentageDiscount && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + minimum == other.minimum && + maximum == other.maximum + } + + override fun hashCode(): Int = + Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) + + override fun toString(): String = + when { + percentageDiscount != null -> + "Adjustment{percentageDiscount=$percentageDiscount}" + usageDiscount != null -> "Adjustment{usageDiscount=$usageDiscount}" + amountDiscount != null -> "Adjustment{amountDiscount=$amountDiscount}" + minimum != null -> "Adjustment{minimum=$minimum}" + maximum != null -> "Adjustment{maximum=$maximum}" + _json != null -> "Adjustment{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Adjustment") + } + + companion object { + + fun ofPercentageDiscount(percentageDiscount: NewPercentageDiscount) = + Adjustment(percentageDiscount = percentageDiscount) + + fun ofUsageDiscount(usageDiscount: NewUsageDiscount) = + Adjustment(usageDiscount = usageDiscount) + + fun ofAmountDiscount(amountDiscount: NewAmountDiscount) = + Adjustment(amountDiscount = amountDiscount) + + fun ofMinimum(minimum: NewMinimum) = Adjustment(minimum = minimum) + + fun ofMaximum(maximum: NewMaximum) = Adjustment(maximum = maximum) + } + + /** + * An interface that defines how to map each variant of [Adjustment] to a value of type + * [T]. + */ + interface Visitor { + + fun visitPercentageDiscount(percentageDiscount: NewPercentageDiscount): T + + fun visitUsageDiscount(usageDiscount: NewUsageDiscount): T + + fun visitAmountDiscount(amountDiscount: NewAmountDiscount): T + + fun visitMinimum(minimum: NewMinimum): T + + fun visitMaximum(maximum: NewMaximum): T + + /** + * Maps an unknown variant of [Adjustment] to a value of type [T]. + * + * An instance of [Adjustment] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on an + * older version than the API, then the API may respond with new variants that the + * SDK is unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown Adjustment: $json") + } + } + + internal class Deserializer : BaseDeserializer(Adjustment::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Adjustment { + val json = JsonValue.fromJsonNode(node) + val adjustmentType = json.asObject()?.get("adjustment_type")?.asString() + + when (adjustmentType) { + "percentage_discount" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Adjustment(percentageDiscount = it, _json = json) } + ?: Adjustment(_json = json) + } + "usage_discount" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(usageDiscount = it, _json = json) + } ?: Adjustment(_json = json) + } + "amount_discount" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(amountDiscount = it, _json = json) + } ?: Adjustment(_json = json) + } + "minimum" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(minimum = it, _json = json) + } ?: Adjustment(_json = json) + } + "maximum" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(maximum = it, _json = json) + } ?: Adjustment(_json = json) + } + } + + return Adjustment(_json = json) + } + } + + internal class Serializer : BaseSerializer(Adjustment::class) { + + override fun serialize( + value: Adjustment, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.percentageDiscount != null -> + generator.writeObject(value.percentageDiscount) + value.usageDiscount != null -> generator.writeObject(value.usageDiscount) + value.amountDiscount != null -> generator.writeObject(value.amountDiscount) + value.minimum != null -> generator.writeObject(value.minimum) + value.maximum != null -> generator.writeObject(value.maximum) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Adjustment") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ReplaceAdjustment && + adjustment == other.adjustment && + replacesAdjustmentId == other.replacesAdjustmentId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(adjustment, replacesAdjustmentId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ReplaceAdjustment{adjustment=$adjustment, replacesAdjustmentId=$replacesAdjustmentId, additionalProperties=$additionalProperties}" + } + + class ReplacePrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val replacesPriceId: JsonField, + private val allocationPrice: JsonField, + private val discounts: JsonField>, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val maximumAmount: JsonField, + private val minimumAmount: JsonField, + private val price: JsonField, + private val priceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("replaces_price_id") + @ExcludeMissing + replacesPriceId: JsonField = JsonMissing.of(), + @JsonProperty("allocation_price") + @ExcludeMissing + allocationPrice: JsonField = JsonMissing.of(), + @JsonProperty("discounts") + @ExcludeMissing + discounts: JsonField> = JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("maximum_amount") + @ExcludeMissing + maximumAmount: JsonField = JsonMissing.of(), + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("price") @ExcludeMissing price: JsonField = JsonMissing.of(), + @JsonProperty("price_id") @ExcludeMissing priceId: JsonField = JsonMissing.of(), + ) : this( + replacesPriceId, + allocationPrice, + discounts, + externalPriceId, + fixedPriceQuantity, + maximumAmount, + minimumAmount, + price, + priceId, + mutableMapOf(), + ) + + /** + * The id of the price on the plan to replace in the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun replacesPriceId(): String = replacesPriceId.getRequired("replaces_price_id") + + /** + * The definition of a new allocation price to create and add to the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allocationPrice(): NewAllocationPrice? = allocationPrice.getNullable("allocation_price") + + /** + * [DEPRECATED] Use add_adjustments instead. The subscription's discounts for the + * replacement price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") + fun discounts(): List? = discounts.getNullable("discounts") + + /** + * The external price id of the price to add to the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * The new quantity of the price, if the price is a fixed price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * [DEPRECATED] Use add_adjustments instead. The subscription's maximum amount for the + * replacement price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") + fun maximumAmount(): String? = maximumAmount.getNullable("maximum_amount") + + /** + * [DEPRECATED] Use add_adjustments instead. The subscription's minimum amount for the + * replacement price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") + fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") + + /** + * New subscription price request body params. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun price(): Price? = price.getNullable("price") + + /** + * The id of the price to add to the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun priceId(): String? = priceId.getNullable("price_id") + + /** + * Returns the raw JSON value of [replacesPriceId]. + * + * Unlike [replacesPriceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("replaces_price_id") + @ExcludeMissing + fun _replacesPriceId(): JsonField = replacesPriceId + + /** + * Returns the raw JSON value of [allocationPrice]. + * + * Unlike [allocationPrice], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("allocation_price") + @ExcludeMissing + fun _allocationPrice(): JsonField = allocationPrice + + /** + * Returns the raw JSON value of [discounts]. + * + * Unlike [discounts], this method doesn't throw if the JSON field has an unexpected type. + */ + @Deprecated("deprecated") + @JsonProperty("discounts") + @ExcludeMissing + fun _discounts(): JsonField> = discounts + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [maximumAmount]. + * + * Unlike [maximumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @Deprecated("deprecated") + @JsonProperty("maximum_amount") + @ExcludeMissing + fun _maximumAmount(): JsonField = maximumAmount + + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @Deprecated("deprecated") + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount + + /** + * 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 [priceId]. + * + * Unlike [priceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("price_id") @ExcludeMissing fun _priceId(): JsonField = priceId + + @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 [ReplacePrice]. + * + * The following fields are required: + * ```kotlin + * .replacesPriceId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ReplacePrice]. */ + class Builder internal constructor() { + + private var replacesPriceId: JsonField? = null + private var allocationPrice: JsonField = JsonMissing.of() + private var discounts: JsonField>? = null + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var maximumAmount: JsonField = JsonMissing.of() + private var minimumAmount: JsonField = JsonMissing.of() + private var price: JsonField = JsonMissing.of() + private var priceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(replacePrice: ReplacePrice) = apply { + replacesPriceId = replacePrice.replacesPriceId + allocationPrice = replacePrice.allocationPrice + discounts = replacePrice.discounts.map { it.toMutableList() } + externalPriceId = replacePrice.externalPriceId + fixedPriceQuantity = replacePrice.fixedPriceQuantity + maximumAmount = replacePrice.maximumAmount + minimumAmount = replacePrice.minimumAmount + price = replacePrice.price + priceId = replacePrice.priceId + additionalProperties = replacePrice.additionalProperties.toMutableMap() + } + + /** The id of the price on the plan to replace in the subscription. */ + fun replacesPriceId(replacesPriceId: String) = + replacesPriceId(JsonField.of(replacesPriceId)) + + /** + * Sets [Builder.replacesPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.replacesPriceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun replacesPriceId(replacesPriceId: JsonField) = apply { + this.replacesPriceId = replacesPriceId + } + + /** The definition of a new allocation price to create and add to the subscription. */ + fun allocationPrice(allocationPrice: NewAllocationPrice?) = + allocationPrice(JsonField.ofNullable(allocationPrice)) + + /** + * Sets [Builder.allocationPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.allocationPrice] with a well-typed + * [NewAllocationPrice] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun allocationPrice(allocationPrice: JsonField) = apply { + this.allocationPrice = allocationPrice + } + + /** + * [DEPRECATED] Use add_adjustments instead. The subscription's discounts for the + * replacement price. + */ + @Deprecated("deprecated") + fun discounts(discounts: List?) = + discounts(JsonField.ofNullable(discounts)) + + /** + * Sets [Builder.discounts] to an arbitrary JSON value. + * + * You should usually call [Builder.discounts] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + @Deprecated("deprecated") + fun discounts(discounts: JsonField>) = apply { + this.discounts = discounts.map { it.toMutableList() } + } + + /** + * Adds a single [DiscountOverride] to [discounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + @Deprecated("deprecated") + fun addDiscount(discount: DiscountOverride) = apply { + discounts = + (discounts ?: JsonField.of(mutableListOf())).also { + checkKnown("discounts", it).add(discount) + } + } + + /** The external price id of the price to add to the subscription. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** The new quantity of the price, if the price is a fixed price. */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** + * [DEPRECATED] Use add_adjustments instead. The subscription's maximum amount for the + * replacement price. + */ + @Deprecated("deprecated") + fun maximumAmount(maximumAmount: String?) = + maximumAmount(JsonField.ofNullable(maximumAmount)) + + /** + * Sets [Builder.maximumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun maximumAmount(maximumAmount: JsonField) = apply { + this.maximumAmount = maximumAmount + } + + /** + * [DEPRECATED] Use add_adjustments instead. The subscription's minimum amount for the + * replacement price. + */ + @Deprecated("deprecated") + fun minimumAmount(minimumAmount: String?) = + minimumAmount(JsonField.ofNullable(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } + + /** New subscription price request body params. */ + fun price(price: Price?) = price(JsonField.ofNullable(price)) + + /** + * Sets [Builder.price] to an arbitrary JSON value. + * + * You should usually call [Builder.price] with a well-typed [Price] 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 } + + /** Alias for calling [price] with `Price.ofUnit(unit)`. */ + fun price(unit: NewSubscriptionUnitPrice) = price(Price.ofUnit(unit)) + + /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ + fun price(tiered: NewSubscriptionTieredPrice) = price(Price.ofTiered(tiered)) + + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: NewSubscriptionBulkPrice) = price(Price.ofBulk(bulk)) + + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) + + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: NewSubscriptionPackagePrice) = price(Price.ofPackage(package_)) + + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: NewSubscriptionMatrixPrice) = price(Price.ofMatrix(matrix)) + + /** + * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. + */ + fun price(thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice) = + price(Price.ofThresholdTotalAmount(thresholdTotalAmount)) + + /** Alias for calling [price] with `Price.ofTieredPackage(tieredPackage)`. */ + fun price(tieredPackage: NewSubscriptionTieredPackagePrice) = + price(Price.ofTieredPackage(tieredPackage)) + + /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ + fun price(tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice) = + price(Price.ofTieredWithMinimum(tieredWithMinimum)) + + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: NewSubscriptionGroupedTieredPrice) = + price(Price.ofGroupedTiered(groupedTiered)) + + /** + * Alias for calling [price] with + * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + */ + fun price(tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice) = + price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofPackageWithAllocation(packageWithAllocation)`. + */ + fun price(packageWithAllocation: NewSubscriptionPackageWithAllocationPrice) = + price(Price.ofPackageWithAllocation(packageWithAllocation)) + + /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ + fun price(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = + price(Price.ofUnitWithPercent(unitWithPercent)) + + /** + * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun price(matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice) = + price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + + /** + * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. + */ + fun price(tieredWithProration: Price.TieredWithProration) = + price(Price.ofTieredWithProration(tieredWithProration)) + + /** Alias for calling [price] with `Price.ofUnitWithProration(unitWithProration)`. */ + fun price(unitWithProration: NewSubscriptionUnitWithProrationPrice) = + price(Price.ofUnitWithProration(unitWithProration)) + + /** Alias for calling [price] with `Price.ofGroupedAllocation(groupedAllocation)`. */ + fun price(groupedAllocation: NewSubscriptionGroupedAllocationPrice) = + price(Price.ofGroupedAllocation(groupedAllocation)) + + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = + price(Price.ofBulkWithProration(bulkWithProration)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. + */ + fun price(groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice) = + price(Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. + */ + fun price(groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice) = + price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + + /** + * Alias for calling [price] with + * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. + */ + fun price(matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice) = + price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) + + /** + * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. + */ + fun price(groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice) = + price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + + /** + * Alias for calling [price] with + * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. + */ + fun price(maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice) = + price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + + /** + * Alias for calling [price] with + * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. + */ + fun price( + scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice + ) = price(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) + + /** + * Alias for calling [price] with + * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. + */ + fun price( + scalableMatrixWithTieredPricing: NewSubscriptionScalableMatrixWithTieredPricingPrice + ) = price(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) + + /** + * Alias for calling [price] with + * `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. + */ + fun price(cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice) = + price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + + /** + * Alias for calling [price] with + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. + */ + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: NewSubscriptionMinimumCompositePrice) = + price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) + + /** The id of the price to add to the subscription. */ + fun priceId(priceId: String?) = priceId(JsonField.ofNullable(priceId)) + + /** + * Sets [Builder.priceId] to an arbitrary JSON value. + * + * You should usually call [Builder.priceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun priceId(priceId: JsonField) = apply { this.priceId = priceId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ReplacePrice]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .replacesPriceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ReplacePrice = + ReplacePrice( + checkRequired("replacesPriceId", replacesPriceId), + allocationPrice, + (discounts ?: JsonMissing.of()).map { it.toImmutable() }, + externalPriceId, + fixedPriceQuantity, + maximumAmount, + minimumAmount, + price, + priceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ReplacePrice = apply { + if (validated) { + return@apply + } + + replacesPriceId() + allocationPrice()?.validate() + discounts()?.forEach { it.validate() } + externalPriceId() + fixedPriceQuantity() + maximumAmount() + minimumAmount() + price()?.validate() + priceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (allocationPrice.asKnown()?.validity() ?: 0) + + (discounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (maximumAmount.asKnown() == null) 0 else 1) + + (if (minimumAmount.asKnown() == null) 0 else 1) + + (price.asKnown()?.validity() ?: 0) + + (if (priceId.asKnown() == null) 0 else 1) + + /** New subscription price request body params. */ + @JsonDeserialize(using = Price.Deserializer::class) + @JsonSerialize(using = Price.Serializer::class) + class Price + private constructor( + private val unit: NewSubscriptionUnitPrice? = null, + private val tiered: NewSubscriptionTieredPrice? = null, + private val bulk: NewSubscriptionBulkPrice? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: NewSubscriptionPackagePrice? = null, + private val matrix: NewSubscriptionMatrixPrice? = null, + private val thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice? = null, + private val tieredPackage: NewSubscriptionTieredPackagePrice? = null, + private val tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice? = null, + private val groupedTiered: NewSubscriptionGroupedTieredPrice? = null, + private val tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice? = + null, + private val packageWithAllocation: NewSubscriptionPackageWithAllocationPrice? = null, + private val unitWithPercent: NewSubscriptionUnitWithPercentPrice? = null, + private val matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice? = null, + private val tieredWithProration: TieredWithProration? = null, + private val unitWithProration: NewSubscriptionUnitWithProrationPrice? = null, + private val groupedAllocation: NewSubscriptionGroupedAllocationPrice? = null, + private val bulkWithProration: NewSubscriptionBulkWithProrationPrice? = null, + private val groupedWithProratedMinimum: + NewSubscriptionGroupedWithProratedMinimumPrice? = + null, + private val groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice? = + null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, + private val matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice? = null, + private val groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice? = null, + private val maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice? = null, + private val scalableMatrixWithUnitPricing: + NewSubscriptionScalableMatrixWithUnitPricingPrice? = + null, + private val scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice? = + null, + private val cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: NewSubscriptionMinimumCompositePrice? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, + private val _json: JsonValue? = null, + ) { + + fun unit(): NewSubscriptionUnitPrice? = unit + + fun tiered(): NewSubscriptionTieredPrice? = tiered + + fun bulk(): NewSubscriptionBulkPrice? = bulk + + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters + + fun package_(): NewSubscriptionPackagePrice? = package_ + + fun matrix(): NewSubscriptionMatrixPrice? = matrix + + fun thresholdTotalAmount(): NewSubscriptionThresholdTotalAmountPrice? = + thresholdTotalAmount + + fun tieredPackage(): NewSubscriptionTieredPackagePrice? = tieredPackage + + fun tieredWithMinimum(): NewSubscriptionTieredWithMinimumPrice? = tieredWithMinimum + + fun groupedTiered(): NewSubscriptionGroupedTieredPrice? = groupedTiered + + fun tieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice? = + tieredPackageWithMinimum + + fun packageWithAllocation(): NewSubscriptionPackageWithAllocationPrice? = + packageWithAllocation + + fun unitWithPercent(): NewSubscriptionUnitWithPercentPrice? = unitWithPercent + + fun matrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice? = + matrixWithAllocation + + fun tieredWithProration(): TieredWithProration? = tieredWithProration + + fun unitWithProration(): NewSubscriptionUnitWithProrationPrice? = unitWithProration + + fun groupedAllocation(): NewSubscriptionGroupedAllocationPrice? = groupedAllocation + + fun bulkWithProration(): NewSubscriptionBulkWithProrationPrice? = bulkWithProration + + fun groupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice? = + groupedWithProratedMinimum + + fun groupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice? = + groupedWithMeteredMinimum + + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = + groupedWithMinMaxThresholds + + fun matrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice? = + matrixWithDisplayName + + fun groupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice? = + groupedTieredPackage + + fun maxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice? = + maxGroupTieredPackage + + fun scalableMatrixWithUnitPricing(): + NewSubscriptionScalableMatrixWithUnitPricingPrice? = scalableMatrixWithUnitPricing + + fun scalableMatrixWithTieredPricing(): + NewSubscriptionScalableMatrixWithTieredPricingPrice? = + scalableMatrixWithTieredPricing + + fun cumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice? = + cumulativeGroupedBulk + + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = + cumulativeGroupedAllocation + + fun minimum(): NewSubscriptionMinimumCompositePrice? = minimum + + fun percent(): Percent? = percent + + fun eventOutput(): EventOutput? = eventOutput + + fun isUnit(): Boolean = unit != null + + fun isTiered(): Boolean = tiered != null + + fun isBulk(): Boolean = bulk != null + + fun isBulkWithFilters(): Boolean = bulkWithFilters != null + + fun isPackage(): Boolean = package_ != null + + fun isMatrix(): Boolean = matrix != null + + fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null + + fun isTieredPackage(): Boolean = tieredPackage != null + + fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null + + fun isGroupedTiered(): Boolean = groupedTiered != null + + fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + + fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + + fun isUnitWithPercent(): Boolean = unitWithPercent != null + + fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + + fun isTieredWithProration(): Boolean = tieredWithProration != null + + fun isUnitWithProration(): Boolean = unitWithProration != null + + fun isGroupedAllocation(): Boolean = groupedAllocation != null + + fun isBulkWithProration(): Boolean = bulkWithProration != null + + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null + + fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null + + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null + + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + + fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + + fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null + + fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null + + fun isScalableMatrixWithTieredPricing(): Boolean = + scalableMatrixWithTieredPricing != null + + fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null + + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null + + fun isMinimum(): Boolean = minimum != null + + fun isPercent(): Boolean = percent != null + + fun isEventOutput(): Boolean = eventOutput != null + + fun asUnit(): NewSubscriptionUnitPrice = unit.getOrThrow("unit") + + fun asTiered(): NewSubscriptionTieredPrice = tiered.getOrThrow("tiered") + + fun asBulk(): NewSubscriptionBulkPrice = bulk.getOrThrow("bulk") + + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") + + fun asPackage(): NewSubscriptionPackagePrice = package_.getOrThrow("package_") + + fun asMatrix(): NewSubscriptionMatrixPrice = matrix.getOrThrow("matrix") + + fun asThresholdTotalAmount(): NewSubscriptionThresholdTotalAmountPrice = + thresholdTotalAmount.getOrThrow("thresholdTotalAmount") + + fun asTieredPackage(): NewSubscriptionTieredPackagePrice = + tieredPackage.getOrThrow("tieredPackage") + + fun asTieredWithMinimum(): NewSubscriptionTieredWithMinimumPrice = + tieredWithMinimum.getOrThrow("tieredWithMinimum") + + fun asGroupedTiered(): NewSubscriptionGroupedTieredPrice = + groupedTiered.getOrThrow("groupedTiered") + + fun asTieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice = + tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + + fun asPackageWithAllocation(): NewSubscriptionPackageWithAllocationPrice = + packageWithAllocation.getOrThrow("packageWithAllocation") + + fun asUnitWithPercent(): NewSubscriptionUnitWithPercentPrice = + unitWithPercent.getOrThrow("unitWithPercent") + + fun asMatrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice = + matrixWithAllocation.getOrThrow("matrixWithAllocation") + + fun asTieredWithProration(): TieredWithProration = + tieredWithProration.getOrThrow("tieredWithProration") + + fun asUnitWithProration(): NewSubscriptionUnitWithProrationPrice = + unitWithProration.getOrThrow("unitWithProration") + + fun asGroupedAllocation(): NewSubscriptionGroupedAllocationPrice = + groupedAllocation.getOrThrow("groupedAllocation") + + fun asBulkWithProration(): NewSubscriptionBulkWithProrationPrice = + bulkWithProration.getOrThrow("bulkWithProration") + + fun asGroupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice = + groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") + + fun asGroupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice = + groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") + + fun asMatrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice = + matrixWithDisplayName.getOrThrow("matrixWithDisplayName") + + fun asGroupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice = + groupedTieredPackage.getOrThrow("groupedTieredPackage") + + fun asMaxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice = + maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") + + fun asScalableMatrixWithUnitPricing(): + NewSubscriptionScalableMatrixWithUnitPricingPrice = + scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") + + fun asScalableMatrixWithTieredPricing(): + NewSubscriptionScalableMatrixWithTieredPricingPrice = + scalableMatrixWithTieredPricing.getOrThrow("scalableMatrixWithTieredPricing") + + fun asCumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice = + cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") + + fun asMinimum(): NewSubscriptionMinimumCompositePrice = minimum.getOrThrow("minimum") + + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + unit != null -> visitor.visitUnit(unit) + tiered != null -> visitor.visitTiered(tiered) + bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) + thresholdTotalAmount != null -> + visitor.visitThresholdTotalAmount(thresholdTotalAmount) + tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) + tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + tieredPackageWithMinimum != null -> + visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) + packageWithAllocation != null -> + visitor.visitPackageWithAllocation(packageWithAllocation) + unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + matrixWithAllocation != null -> + visitor.visitMatrixWithAllocation(matrixWithAllocation) + tieredWithProration != null -> + visitor.visitTieredWithProration(tieredWithProration) + unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) + groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) + groupedWithProratedMinimum != null -> + visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) + groupedWithMeteredMinimum != null -> + visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) + matrixWithDisplayName != null -> + visitor.visitMatrixWithDisplayName(matrixWithDisplayName) + groupedTieredPackage != null -> + visitor.visitGroupedTieredPackage(groupedTieredPackage) + maxGroupTieredPackage != null -> + visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) + scalableMatrixWithUnitPricing != null -> + visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) + scalableMatrixWithTieredPricing != null -> + visitor.visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing + ) + cumulativeGroupedBulk != null -> + visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Price = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitUnit(unit: NewSubscriptionUnitPrice) { + unit.validate() + } + + override fun visitTiered(tiered: NewSubscriptionTieredPrice) { + tiered.validate() + } + + override fun visitBulk(bulk: NewSubscriptionBulkPrice) { + bulk.validate() + } + + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() + } + + override fun visitPackage(package_: NewSubscriptionPackagePrice) { + package_.validate() + } + + override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) { + matrix.validate() + } + + override fun visitThresholdTotalAmount( + thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice + ) { + thresholdTotalAmount.validate() + } + + override fun visitTieredPackage( + tieredPackage: NewSubscriptionTieredPackagePrice + ) { + tieredPackage.validate() + } + + override fun visitTieredWithMinimum( + tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice + ) { + tieredWithMinimum.validate() + } + + override fun visitGroupedTiered( + groupedTiered: NewSubscriptionGroupedTieredPrice + ) { + groupedTiered.validate() + } + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ) { + tieredPackageWithMinimum.validate() + } + + override fun visitPackageWithAllocation( + packageWithAllocation: NewSubscriptionPackageWithAllocationPrice + ) { + packageWithAllocation.validate() + } + + override fun visitUnitWithPercent( + unitWithPercent: NewSubscriptionUnitWithPercentPrice + ) { + unitWithPercent.validate() + } + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ) { + matrixWithAllocation.validate() + } + + override fun visitTieredWithProration( + tieredWithProration: TieredWithProration + ) { + tieredWithProration.validate() + } + + override fun visitUnitWithProration( + unitWithProration: NewSubscriptionUnitWithProrationPrice + ) { + unitWithProration.validate() + } + + override fun visitGroupedAllocation( + groupedAllocation: NewSubscriptionGroupedAllocationPrice + ) { + groupedAllocation.validate() + } + + override fun visitBulkWithProration( + bulkWithProration: NewSubscriptionBulkWithProrationPrice + ) { + bulkWithProration.validate() + } + + override fun visitGroupedWithProratedMinimum( + groupedWithProratedMinimum: + NewSubscriptionGroupedWithProratedMinimumPrice + ) { + groupedWithProratedMinimum.validate() + } + + override fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + ) { + groupedWithMeteredMinimum.validate() + } + + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) { + groupedWithMinMaxThresholds.validate() + } + + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + ) { + matrixWithDisplayName.validate() + } + + override fun visitGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + ) { + groupedTieredPackage.validate() + } + + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice + ) { + maxGroupTieredPackage.validate() + } + + override fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: + NewSubscriptionScalableMatrixWithUnitPricingPrice + ) { + scalableMatrixWithUnitPricing.validate() + } + + override fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice + ) { + scalableMatrixWithTieredPricing.validate() + } + + override fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice + ) { + cumulativeGroupedBulk.validate() + } + + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) { + cumulativeGroupedAllocation.validate() + } + + override fun visitMinimum(minimum: NewSubscriptionMinimumCompositePrice) { + minimum.validate() + } + + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitUnit(unit: NewSubscriptionUnitPrice) = unit.validity() + + override fun visitTiered(tiered: NewSubscriptionTieredPrice) = + tiered.validity() + + override fun visitBulk(bulk: NewSubscriptionBulkPrice) = bulk.validity() + + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() + + override fun visitPackage(package_: NewSubscriptionPackagePrice) = + package_.validity() + + override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) = + matrix.validity() + + override fun visitThresholdTotalAmount( + thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice + ) = thresholdTotalAmount.validity() + + override fun visitTieredPackage( + tieredPackage: NewSubscriptionTieredPackagePrice + ) = tieredPackage.validity() + + override fun visitTieredWithMinimum( + tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice + ) = tieredWithMinimum.validity() + + override fun visitGroupedTiered( + groupedTiered: NewSubscriptionGroupedTieredPrice + ) = groupedTiered.validity() + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ) = tieredPackageWithMinimum.validity() + + override fun visitPackageWithAllocation( + packageWithAllocation: NewSubscriptionPackageWithAllocationPrice + ) = packageWithAllocation.validity() + + override fun visitUnitWithPercent( + unitWithPercent: NewSubscriptionUnitWithPercentPrice + ) = unitWithPercent.validity() + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ) = matrixWithAllocation.validity() + + override fun visitTieredWithProration( + tieredWithProration: TieredWithProration + ) = tieredWithProration.validity() + + override fun visitUnitWithProration( + unitWithProration: NewSubscriptionUnitWithProrationPrice + ) = unitWithProration.validity() + + override fun visitGroupedAllocation( + groupedAllocation: NewSubscriptionGroupedAllocationPrice + ) = groupedAllocation.validity() + + override fun visitBulkWithProration( + bulkWithProration: NewSubscriptionBulkWithProrationPrice + ) = bulkWithProration.validity() + + override fun visitGroupedWithProratedMinimum( + groupedWithProratedMinimum: + NewSubscriptionGroupedWithProratedMinimumPrice + ) = groupedWithProratedMinimum.validity() + + override fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + ) = groupedWithMeteredMinimum.validity() + + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + ) = matrixWithDisplayName.validity() + + override fun visitGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + ) = groupedTieredPackage.validity() + + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice + ) = maxGroupTieredPackage.validity() + + override fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: + NewSubscriptionScalableMatrixWithUnitPricingPrice + ) = scalableMatrixWithUnitPricing.validity() + + override fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice + ) = scalableMatrixWithTieredPricing.validity() + + override fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice + ) = cumulativeGroupedBulk.validity() + + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() + + override fun visitMinimum(minimum: NewSubscriptionMinimumCompositePrice) = + minimum.validity() + + override fun visitPercent(percent: Percent) = percent.validity() + + override fun visitEventOutput(eventOutput: EventOutput) = + eventOutput.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Price && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput + } + + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) + + override fun toString(): String = + when { + unit != null -> "Price{unit=$unit}" + tiered != null -> "Price{tiered=$tiered}" + bulk != null -> "Price{bulk=$bulk}" + bulkWithFilters != null -> "Price{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "Price{package_=$package_}" + matrix != null -> "Price{matrix=$matrix}" + thresholdTotalAmount != null -> + "Price{thresholdTotalAmount=$thresholdTotalAmount}" + tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" + tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" + groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" + tieredPackageWithMinimum != null -> + "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" + packageWithAllocation != null -> + "Price{packageWithAllocation=$packageWithAllocation}" + unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + matrixWithAllocation != null -> + "Price{matrixWithAllocation=$matrixWithAllocation}" + tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" + unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" + groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" + groupedWithProratedMinimum != null -> + "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" + groupedWithMeteredMinimum != null -> + "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "Price{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" + matrixWithDisplayName != null -> + "Price{matrixWithDisplayName=$matrixWithDisplayName}" + groupedTieredPackage != null -> + "Price{groupedTieredPackage=$groupedTieredPackage}" + maxGroupTieredPackage != null -> + "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" + scalableMatrixWithUnitPricing != null -> + "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" + scalableMatrixWithTieredPricing != null -> + "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" + cumulativeGroupedBulk != null -> + "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" + cumulativeGroupedAllocation != null -> + "Price{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "Price{minimum=$minimum}" + percent != null -> "Price{percent=$percent}" + eventOutput != null -> "Price{eventOutput=$eventOutput}" + _json != null -> "Price{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Price") + } + + companion object { + + fun ofUnit(unit: NewSubscriptionUnitPrice) = Price(unit = unit) + + fun ofTiered(tiered: NewSubscriptionTieredPrice) = Price(tiered = tiered) + + fun ofBulk(bulk: NewSubscriptionBulkPrice) = Price(bulk = bulk) + + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + Price(bulkWithFilters = bulkWithFilters) + + fun ofPackage(package_: NewSubscriptionPackagePrice) = Price(package_ = package_) + + fun ofMatrix(matrix: NewSubscriptionMatrixPrice) = Price(matrix = matrix) + + fun ofThresholdTotalAmount( + thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice + ) = Price(thresholdTotalAmount = thresholdTotalAmount) + + fun ofTieredPackage(tieredPackage: NewSubscriptionTieredPackagePrice) = + Price(tieredPackage = tieredPackage) + + fun ofTieredWithMinimum(tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice) = + Price(tieredWithMinimum = tieredWithMinimum) + + fun ofGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice) = + Price(groupedTiered = groupedTiered) + + fun ofTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + + fun ofPackageWithAllocation( + packageWithAllocation: NewSubscriptionPackageWithAllocationPrice + ) = Price(packageWithAllocation = packageWithAllocation) + + fun ofUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = + Price(unitWithPercent = unitWithPercent) + + fun ofMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ) = Price(matrixWithAllocation = matrixWithAllocation) + + fun ofTieredWithProration(tieredWithProration: TieredWithProration) = + Price(tieredWithProration = tieredWithProration) + + fun ofUnitWithProration(unitWithProration: NewSubscriptionUnitWithProrationPrice) = + Price(unitWithProration = unitWithProration) + + fun ofGroupedAllocation(groupedAllocation: NewSubscriptionGroupedAllocationPrice) = + Price(groupedAllocation = groupedAllocation) + + fun ofBulkWithProration(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = + Price(bulkWithProration = bulkWithProration) + + fun ofGroupedWithProratedMinimum( + groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice + ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) + + fun ofGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = Price(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + + fun ofMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + ) = Price(matrixWithDisplayName = matrixWithDisplayName) + + fun ofGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + ) = Price(groupedTieredPackage = groupedTieredPackage) + + fun ofMaxGroupTieredPackage( + maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice + ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) + + fun ofScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice + ) = Price(scalableMatrixWithUnitPricing = scalableMatrixWithUnitPricing) + + fun ofScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice + ) = Price(scalableMatrixWithTieredPricing = scalableMatrixWithTieredPricing) + + fun ofCumulativeGroupedBulk( + cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice + ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) + + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = Price(cumulativeGroupedAllocation = cumulativeGroupedAllocation) + + fun ofMinimum(minimum: NewSubscriptionMinimumCompositePrice) = + Price(minimum = minimum) + + fun ofPercent(percent: Percent) = Price(percent = percent) + + fun ofEventOutput(eventOutput: EventOutput) = Price(eventOutput = eventOutput) + } + + /** + * An interface that defines how to map each variant of [Price] to a value of type [T]. + */ + interface Visitor { + + fun visitUnit(unit: NewSubscriptionUnitPrice): T + + fun visitTiered(tiered: NewSubscriptionTieredPrice): T + + fun visitBulk(bulk: NewSubscriptionBulkPrice): T + + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T + + fun visitPackage(package_: NewSubscriptionPackagePrice): T + + fun visitMatrix(matrix: NewSubscriptionMatrixPrice): T + + fun visitThresholdTotalAmount( + thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice + ): T + + fun visitTieredPackage(tieredPackage: NewSubscriptionTieredPackagePrice): T + + fun visitTieredWithMinimum( + tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice + ): T + + fun visitGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice): T + + fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ): T + + fun visitPackageWithAllocation( + packageWithAllocation: NewSubscriptionPackageWithAllocationPrice + ): T + + fun visitUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice): T + + fun visitMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ): T + + fun visitTieredWithProration(tieredWithProration: TieredWithProration): T + + fun visitUnitWithProration( + unitWithProration: NewSubscriptionUnitWithProrationPrice + ): T + + fun visitGroupedAllocation( + groupedAllocation: NewSubscriptionGroupedAllocationPrice + ): T + + fun visitBulkWithProration( + bulkWithProration: NewSubscriptionBulkWithProrationPrice + ): T + + fun visitGroupedWithProratedMinimum( + groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice + ): T + + fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + ): T + + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ): T + + fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + ): T + + fun visitGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + ): T + + fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice + ): T + + fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice + ): T + + fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice + ): T + + fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice + ): T + + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ): T + + fun visitMinimum(minimum: NewSubscriptionMinimumCompositePrice): T + + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T + + /** + * Maps an unknown variant of [Price] to a value of type [T]. + * + * An instance of [Price] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown Price: $json") + } + } + + internal class Deserializer : BaseDeserializer(Price::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Price { + val json = JsonValue.fromJsonNode(node) + val modelType = json.asObject()?.get("model_type")?.asString() + + when (modelType) { + "unit" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(unit = it, _json = json) } ?: Price(_json = json) + } + "tiered" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tiered = it, _json = json) } ?: Price(_json = json) + } + "bulk" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(bulk = it, _json = json) } ?: Price(_json = json) + } + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulkWithFilters = it, _json = json) + } ?: Price(_json = json) + } + "package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) + } + "matrix" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) + } + "threshold_total_amount" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(thresholdTotalAmount = it, _json = json) } + ?: Price(_json = json) + } + "tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "tiered_with_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tieredWithMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_tiered" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedTiered = it, _json = json) } + ?: Price(_json = json) + } + "tiered_package_with_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tieredPackageWithMinimum = it, _json = json) } + ?: Price(_json = json) + } + "package_with_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(packageWithAllocation = it, _json = json) } + ?: Price(_json = json) + } + "unit_with_percent" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(unitWithPercent = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(matrixWithAllocation = it, _json = json) } + ?: Price(_json = json) + } + "tiered_with_proration" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(tieredWithProration = it, _json = json) } + ?: Price(_json = json) + } + "unit_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(unitWithProration = it, _json = json) } + ?: Price(_json = json) + } + "grouped_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedAllocation = it, _json = json) } + ?: Price(_json = json) + } + "bulk_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(bulkWithProration = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_prorated_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithProratedMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_metered_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_min_max_thresholds" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithMinMaxThresholds = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_display_name" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(matrixWithDisplayName = it, _json = json) } + ?: Price(_json = json) + } + "grouped_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedTieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "max_group_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(maxGroupTieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "scalable_matrix_with_unit_pricing" -> { + return tryDeserialize( + node, + jacksonTypeRef< + NewSubscriptionScalableMatrixWithUnitPricingPrice + >(), + ) + ?.let { Price(scalableMatrixWithUnitPricing = it, _json = json) } + ?: Price(_json = json) + } + "scalable_matrix_with_tiered_pricing" -> { + return tryDeserialize( + node, + jacksonTypeRef< + NewSubscriptionScalableMatrixWithTieredPricingPrice + >(), + ) + ?.let { Price(scalableMatrixWithTieredPricing = it, _json = json) } + ?: Price(_json = json) + } + "cumulative_grouped_bulk" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(cumulativeGroupedBulk = it, _json = json) } + ?: Price(_json = json) + } + "cumulative_grouped_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(cumulativeGroupedAllocation = it, _json = json) } + ?: Price(_json = json) + } + "minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(minimum = it, _json = json) } ?: Price(_json = json) + } + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(percent = it, _json = json) + } ?: Price(_json = json) + } + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(eventOutput = it, _json = json) + } ?: Price(_json = json) + } + } + + return Price(_json = json) + } + } + + internal class Serializer : BaseSerializer(Price::class) { + + override fun serialize( + value: Price, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.unit != null -> generator.writeObject(value.unit) + value.tiered != null -> generator.writeObject(value.tiered) + value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> + generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) + value.thresholdTotalAmount != null -> + generator.writeObject(value.thresholdTotalAmount) + value.tieredPackage != null -> generator.writeObject(value.tieredPackage) + value.tieredWithMinimum != null -> + generator.writeObject(value.tieredWithMinimum) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) + value.tieredPackageWithMinimum != null -> + generator.writeObject(value.tieredPackageWithMinimum) + value.packageWithAllocation != null -> + generator.writeObject(value.packageWithAllocation) + value.unitWithPercent != null -> + generator.writeObject(value.unitWithPercent) + value.matrixWithAllocation != null -> + generator.writeObject(value.matrixWithAllocation) + value.tieredWithProration != null -> + generator.writeObject(value.tieredWithProration) + value.unitWithProration != null -> + generator.writeObject(value.unitWithProration) + value.groupedAllocation != null -> + generator.writeObject(value.groupedAllocation) + value.bulkWithProration != null -> + generator.writeObject(value.bulkWithProration) + value.groupedWithProratedMinimum != null -> + generator.writeObject(value.groupedWithProratedMinimum) + value.groupedWithMeteredMinimum != null -> + generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) + value.matrixWithDisplayName != null -> + generator.writeObject(value.matrixWithDisplayName) + value.groupedTieredPackage != null -> + generator.writeObject(value.groupedTieredPackage) + value.maxGroupTieredPackage != null -> + generator.writeObject(value.maxGroupTieredPackage) + value.scalableMatrixWithUnitPricing != null -> + generator.writeObject(value.scalableMatrixWithUnitPricing) + value.scalableMatrixWithTieredPricing != null -> + generator.writeObject(value.scalableMatrixWithTieredPricing) + value.cumulativeGroupedBulk != null -> + generator.writeObject(value.cumulativeGroupedBulk) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Price") + } + } + } + + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bulkWithFiltersConfig: JsonField, + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = + bulkWithFiltersConfig + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [BulkWithFilters]. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFilters]. */ + class Builder internal constructor() { + + private var bulkWithFiltersConfig: JsonField? = null + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + itemId = bulkWithFilters.itemId + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + billableMetricId = bulkWithFilters.billableMetricId + billedInAdvance = bulkWithFilters.billedInAdvance + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + currency = bulkWithFilters.currency + dimensionalPriceConfiguration = + bulkWithFilters.dimensionalPriceConfiguration + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoiceGroupingKey = bulkWithFilters.invoiceGroupingKey + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + metadata = bulkWithFilters.metadata + referenceId = bulkWithFilters.referenceId + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() + } + + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig( + bulkWithFiltersConfig: JsonField + ) = apply { this.bulkWithFiltersConfig = bulkWithFiltersConfig } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BulkWithFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFilters = + BulkWithFilters( + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFilters = apply { + if (validated) { + return@apply + } + + bulkWithFiltersConfig().validate() + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("bulk_with_filters")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) + + /** + * Property filters to apply (all must match) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [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 + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { + + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithFiltersConfig.additionalProperties.toMutableMap() + } + + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + + /** Bulk tiers for rating based on total usage volume */ + 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 [BulkWithFiltersConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } + + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = + propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + propertyKey() + propertyValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = + tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filters, tiers, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFilters && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFilters{bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class TieredWithProration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val tieredWithProrationConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + tieredWithProrationConfig: JsonField = + JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for tiered_with_proration pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tieredWithProrationConfig(): TieredWithProrationConfig = + tieredWithProrationConfig.getRequired("tiered_with_proration_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [tieredWithProrationConfig]. + * + * Unlike [tieredWithProrationConfig], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + fun _tieredWithProrationConfig(): JsonField = + tieredWithProrationConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [TieredWithProration]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProration]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("tiered_with_proration") + private var name: JsonField? = null + private var tieredWithProrationConfig: JsonField? = + null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tieredWithProration: TieredWithProration) = apply { + cadence = tieredWithProration.cadence + itemId = tieredWithProration.itemId + modelType = tieredWithProration.modelType + name = tieredWithProration.name + tieredWithProrationConfig = tieredWithProration.tieredWithProrationConfig + billableMetricId = tieredWithProration.billableMetricId + billedInAdvance = tieredWithProration.billedInAdvance + billingCycleConfiguration = tieredWithProration.billingCycleConfiguration + conversionRate = tieredWithProration.conversionRate + conversionRateConfig = tieredWithProration.conversionRateConfig + currency = tieredWithProration.currency + dimensionalPriceConfiguration = + tieredWithProration.dimensionalPriceConfiguration + externalPriceId = tieredWithProration.externalPriceId + fixedPriceQuantity = tieredWithProration.fixedPriceQuantity + invoiceGroupingKey = tieredWithProration.invoiceGroupingKey + invoicingCycleConfiguration = + tieredWithProration.invoicingCycleConfiguration + metadata = tieredWithProration.metadata + referenceId = tieredWithProration.referenceId + additionalProperties = + tieredWithProration.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for tiered_with_proration pricing */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: TieredWithProrationConfig + ) = tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) + + /** + * Sets [Builder.tieredWithProrationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.tieredWithProrationConfig] with a well-typed + * [TieredWithProrationConfig] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: JsonField + ) = apply { this.tieredWithProrationConfig = tieredWithProrationConfig } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TieredWithProration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProration = + TieredWithProration( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("tieredWithProrationConfig", tieredWithProrationConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProration = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("tiered_with_proration")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + tieredWithProrationConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("tiered_with_proration")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (tieredWithProrationConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for tiered_with_proration pricing */ + class TieredWithProrationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Tiers for rating based on total usage quantities into the specified tier with + * proration + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 + * [TieredWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProrationConfig]. */ + class Builder internal constructor() { + + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = + apply { + tiers = tieredWithProrationConfig.tiers.map { it.toMutableList() } + additionalProperties = + tieredWithProrationConfig.additionalProperties.toMutableMap() + } + + /** + * Tiers for rating based on total usage quantities into the specified tier + * with proration + */ + 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 [TieredWithProrationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProrationConfig = + TieredWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProrationConfig = apply { + if (validated) { + return@apply + } + + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tiered with proration tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Inclusive tier starting value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun tierLowerBound(): String = + tierLowerBound.getRequired("tier_lower_bound") + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Inclusive tier starting value */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProration && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredWithProrationConfig == other.tieredWithProrationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProration{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, tieredWithProrationConfig=$tieredWithProrationConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val groupedWithMinMaxThresholdsConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + groupedWithMinMaxThresholdsConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for grouped_with_min_max_thresholds pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired( + "grouped_with_min_max_thresholds_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. + * + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + fun _groupedWithMinMaxThresholdsConfig(): + JsonField = groupedWithMinMaxThresholdsConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [GroupedWithMinMaxThresholds]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholds]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("grouped_with_min_max_thresholds") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = + apply { + cadence = groupedWithMinMaxThresholds.cadence + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + itemId = groupedWithMinMaxThresholds.itemId + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + billableMetricId = groupedWithMinMaxThresholds.billableMetricId + billedInAdvance = groupedWithMinMaxThresholds.billedInAdvance + billingCycleConfiguration = + groupedWithMinMaxThresholds.billingCycleConfiguration + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + currency = groupedWithMinMaxThresholds.currency + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + invoiceGroupingKey = groupedWithMinMaxThresholds.invoiceGroupingKey + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + metadata = groupedWithMinMaxThresholds.metadata + referenceId = groupedWithMinMaxThresholds.referenceId + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = + groupedWithMinMaxThresholdsConfig( + JsonField.of(groupedWithMinMaxThresholdsConfig) + ) + + /** + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a + * well-typed [GroupedWithMinMaxThresholdsConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: + JsonField + ) = apply { + this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( + checkRequired("cadence", cadence), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholds = apply { + if (validated) { + return@apply + } + + cadence().validate() + groupedWithMinMaxThresholdsConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @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 + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate + additionalProperties = + groupedWithMinMaxThresholdsConfig.additionalProperties + .toMutableMap() + } + + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } + + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } + + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = + perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + if (validated) { + return@apply + } + + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholds && + cadence == other.cadence && + groupedWithMinMaxThresholdsConfig == + other.groupedWithMinMaxThresholdsConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholds{cadence=$cadence, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val cumulativeGroupedAllocationConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for cumulative_grouped_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired( + "cumulative_grouped_allocation_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): + JsonField = cumulativeGroupedAllocationConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [CumulativeGroupedAllocation]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocation]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("cumulative_grouped_allocation") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = + apply { + cadence = cumulativeGroupedAllocation.cadence + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + itemId = cumulativeGroupedAllocation.itemId + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + billableMetricId = cumulativeGroupedAllocation.billableMetricId + billedInAdvance = cumulativeGroupedAllocation.billedInAdvance + billingCycleConfiguration = + cumulativeGroupedAllocation.billingCycleConfiguration + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + currency = cumulativeGroupedAllocation.currency + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoiceGroupingKey = cumulativeGroupedAllocation.invoiceGroupingKey + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + metadata = cumulativeGroupedAllocation.metadata + referenceId = cumulativeGroupedAllocation.referenceId + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = + cumulativeGroupedAllocationConfig( + JsonField.of(cumulativeGroupedAllocationConfig) + ) + + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a + * well-typed [CumulativeGroupedAllocationConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: + JsonField + ) = apply { + this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - /** - * Sets [Builder.maximumAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.maximumAmount] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun maximumAmount(maximumAmount: JsonField) = apply { - this.maximumAmount = maximumAmount - } + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - /** - * [DEPRECATED] Use add_adjustments instead. The subscription's minimum amount for the - * replacement price. - */ - @Deprecated("deprecated") - fun minimumAmount(minimumAmount: String?) = - minimumAmount(JsonField.ofNullable(minimumAmount)) + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - /** - * Sets [Builder.minimumAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.minimumAmount] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun minimumAmount(minimumAmount: JsonField) = apply { - this.minimumAmount = minimumAmount - } + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - /** The definition of a new price to create and add to the subscription. */ - fun price(price: Price?) = price(JsonField.ofNullable(price)) + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - /** - * Sets [Builder.price] to an arbitrary JSON value. - * - * You should usually call [Builder.price] with a well-typed [Price] 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 additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** Alias for calling [price] with `Price.ofUnit(unit)`. */ - fun price(unit: NewSubscriptionUnitPrice) = price(Price.ofUnit(unit)) + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: NewSubscriptionPackagePrice) = price(Price.ofPackage(package_)) + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: NewSubscriptionMatrixPrice) = price(Price.ofMatrix(matrix)) + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ - fun price(tiered: NewSubscriptionTieredPrice) = price(Price.ofTiered(tiered)) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: NewSubscriptionTieredBpsPrice) = - price(Price.ofTieredBps(tieredBps)) + /** + * Returns an immutable instance of [CumulativeGroupedAllocation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( + checkRequired("cadence", cadence), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: NewSubscriptionBpsPrice) = price(Price.ofBps(bps)) + private var validated: Boolean = false - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: NewSubscriptionBulkBpsPrice) = price(Price.ofBulkBps(bulkBps)) + fun validate(): CumulativeGroupedAllocation = apply { + if (validated) { + return@apply + } - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: NewSubscriptionBulkPrice) = price(Price.ofBulk(bulk)) + cadence().validate() + cumulativeGroupedAllocationConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("cumulative_grouped_allocation")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - /** - * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. - */ - fun price(thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice) = - price(Price.ofThresholdTotalAmount(thresholdTotalAmount)) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** Alias for calling [price] with `Price.ofTieredPackage(tieredPackage)`. */ - fun price(tieredPackage: NewSubscriptionTieredPackagePrice) = - price(Price.ofTieredPackage(tieredPackage)) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ - fun price(tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice) = - price(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ - fun price(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = - price(Price.ofUnitWithPercent(unitWithPercent)) + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - /** - * Alias for calling [price] with - * `Price.ofPackageWithAllocation(packageWithAllocation)`. - */ - fun price(packageWithAllocation: NewSubscriptionPackageWithAllocationPrice) = - price(Price.ofPackageWithAllocation(packageWithAllocation)) + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN + } - /** - * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. - */ - fun price(tieredWithProration: NewSubscriptionTierWithProrationPrice) = - price(Price.ofTieredWithProration(tieredWithProration)) + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") + } - /** Alias for calling [price] with `Price.ofUnitWithProration(unitWithProration)`. */ - fun price(unitWithProration: NewSubscriptionUnitWithProrationPrice) = - price(Price.ofUnitWithProration(unitWithProration)) + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } - /** Alias for calling [price] with `Price.ofGroupedAllocation(groupedAllocation)`. */ - fun price(groupedAllocation: NewSubscriptionGroupedAllocationPrice) = - price(Price.ofGroupedAllocation(groupedAllocation)) + known() + validated = true + } - /** - * Alias for calling [price] with - * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. - */ - fun price(groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice) = - price(Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = - price(Price.ofBulkWithProration(bulkWithProration)) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * Alias for calling [price] with - * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. - */ - fun price( - scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice - ) = price(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) + return other is Cadence && value == other.value + } - /** - * Alias for calling [price] with - * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. - */ - fun price( - scalableMatrixWithTieredPricing: NewSubscriptionScalableMatrixWithTieredPricingPrice - ) = price(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) + override fun hashCode() = value.hashCode() - /** - * Alias for calling [price] with - * `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. - */ - fun price(cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice) = - price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + override fun toString() = value.toString() + } - /** - * Alias for calling [price] with - * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. - */ - fun price(maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice) = - price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * Alias for calling [price] with - * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. - */ - fun price(groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice) = - price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + mutableMapOf(), + ) + + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** - * Alias for calling [price] with - * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. - */ - fun price(matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice) = - price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CumulativeGroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - /** - * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. - */ - fun price(groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice) = - price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = + cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties + .toMutableMap() + } - /** - * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. - */ - fun price(matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice) = - price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } - /** - * Alias for calling [price] with - * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. - */ - fun price(tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice) = - price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation + } - /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: NewSubscriptionGroupedTieredPrice) = - price(Price.ofGroupedTiered(groupedTiered)) + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } - /** The id of the price to add to the subscription. */ - fun priceId(priceId: String?) = priceId(JsonField.ofNullable(priceId)) + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } - /** - * Sets [Builder.priceId] to an arbitrary JSON value. - * - * You should usually call [Builder.priceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun priceId(priceId: JsonField) = apply { this.priceId = priceId } + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } - /** - * Returns an immutable instance of [ReplacePrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .replacesPriceId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ReplacePrice = - ReplacePrice( - checkRequired("replacesPriceId", replacesPriceId), - allocationPrice, - (discounts ?: JsonMissing.of()).map { it.toImmutable() }, - externalPriceId, - fixedPriceQuantity, - maximumAmount, - minimumAmount, - price, - priceId, - additionalProperties.toMutableMap(), - ) - } + private var validated: Boolean = false - private var validated: Boolean = false + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply + } - fun validate(): ReplacePrice = apply { - if (validated) { - return@apply - } + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - replacesPriceId() - allocationPrice()?.validate() - discounts()?.forEach { it.validate() } - externalPriceId() - fixedPriceQuantity() - maximumAmount() - minimumAmount() - price()?.validate() - priceId() - validated = true - } + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (replacesPriceId.asKnown() == null) 0 else 1) + - (allocationPrice.asKnown()?.validity() ?: 0) + - (discounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (if (maximumAmount.asKnown() == null) 0 else 1) + - (if (minimumAmount.asKnown() == null) 0 else 1) + - (price.asKnown()?.validity() ?: 0) + - (if (priceId.asKnown() == null) 0 else 1) + override fun hashCode(): Int = hashCode - /** The definition of a new price to create and add to the subscription. */ - @JsonDeserialize(using = Price.Deserializer::class) - @JsonSerialize(using = Price.Serializer::class) - class Price - private constructor( - private val unit: NewSubscriptionUnitPrice? = null, - private val package_: NewSubscriptionPackagePrice? = null, - private val matrix: NewSubscriptionMatrixPrice? = null, - private val tiered: NewSubscriptionTieredPrice? = null, - private val tieredBps: NewSubscriptionTieredBpsPrice? = null, - private val bps: NewSubscriptionBpsPrice? = null, - private val bulkBps: NewSubscriptionBulkBpsPrice? = null, - private val bulk: NewSubscriptionBulkPrice? = null, - private val thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice? = null, - private val tieredPackage: NewSubscriptionTieredPackagePrice? = null, - private val tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice? = null, - private val unitWithPercent: NewSubscriptionUnitWithPercentPrice? = null, - private val packageWithAllocation: NewSubscriptionPackageWithAllocationPrice? = null, - private val tieredWithProration: NewSubscriptionTierWithProrationPrice? = null, - private val unitWithProration: NewSubscriptionUnitWithProrationPrice? = null, - private val groupedAllocation: NewSubscriptionGroupedAllocationPrice? = null, - private val groupedWithProratedMinimum: - NewSubscriptionGroupedWithProratedMinimumPrice? = - null, - private val bulkWithProration: NewSubscriptionBulkWithProrationPrice? = null, - private val scalableMatrixWithUnitPricing: - NewSubscriptionScalableMatrixWithUnitPricingPrice? = - null, - private val scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice? = - null, - private val cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice? = null, - private val maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice? = null, - private val groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice? = - null, - private val matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice? = null, - private val groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice? = null, - private val matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice? = null, - private val tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice? = - null, - private val groupedTiered: NewSubscriptionGroupedTieredPrice? = null, - private val _json: JsonValue? = null, - ) { + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } - fun unit(): NewSubscriptionUnitPrice? = unit + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - fun package_(): NewSubscriptionPackagePrice? = package_ + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - fun matrix(): NewSubscriptionMatrixPrice? = matrix + fun toBuilder() = Builder().from(this) - fun tiered(): NewSubscriptionTieredPrice? = tiered + companion object { - fun tieredBps(): NewSubscriptionTieredBpsPrice? = tieredBps + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + fun builder() = Builder() + } - fun bps(): NewSubscriptionBpsPrice? = bps + /** A builder for [Metadata]. */ + class Builder internal constructor() { - fun bulkBps(): NewSubscriptionBulkBpsPrice? = bulkBps + private var additionalProperties: MutableMap = + mutableMapOf() - fun bulk(): NewSubscriptionBulkPrice? = bulk + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } - fun thresholdTotalAmount(): NewSubscriptionThresholdTotalAmountPrice? = - thresholdTotalAmount + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun tieredPackage(): NewSubscriptionTieredPackagePrice? = tieredPackage + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun tieredWithMinimum(): NewSubscriptionTieredWithMinimumPrice? = tieredWithMinimum + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - fun unitWithPercent(): NewSubscriptionUnitWithPercentPrice? = unitWithPercent + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun packageWithAllocation(): NewSubscriptionPackageWithAllocationPrice? = - packageWithAllocation + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun tieredWithProration(): NewSubscriptionTierWithProrationPrice? = tieredWithProration + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } - fun unitWithProration(): NewSubscriptionUnitWithProrationPrice? = unitWithProration + private var validated: Boolean = false - fun groupedAllocation(): NewSubscriptionGroupedAllocationPrice? = groupedAllocation + fun validate(): Metadata = apply { + if (validated) { + return@apply + } - fun groupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice? = - groupedWithProratedMinimum + validated = true + } - fun bulkWithProration(): NewSubscriptionBulkWithProrationPrice? = bulkWithProration + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun scalableMatrixWithUnitPricing(): - NewSubscriptionScalableMatrixWithUnitPricingPrice? = scalableMatrixWithUnitPricing + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } - fun scalableMatrixWithTieredPricing(): - NewSubscriptionScalableMatrixWithTieredPricingPrice? = - scalableMatrixWithTieredPricing + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun cumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice? = - cumulativeGroupedBulk + return other is Metadata && + additionalProperties == other.additionalProperties + } - fun maxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice? = - maxGroupTieredPackage + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - fun groupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice? = - groupedWithMeteredMinimum + override fun hashCode(): Int = hashCode - fun matrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice? = - matrixWithDisplayName + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } - fun groupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice? = - groupedTieredPackage + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun matrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice? = - matrixWithAllocation + return other is CumulativeGroupedAllocation && + cadence == other.cadence && + cumulativeGroupedAllocationConfig == + other.cumulativeGroupedAllocationConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } - fun tieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice? = - tieredPackageWithMinimum + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } - fun groupedTiered(): NewSubscriptionGroupedTieredPrice? = groupedTiered + override fun hashCode(): Int = hashCode - fun isUnit(): Boolean = unit != null + override fun toString() = + "CumulativeGroupedAllocation{cadence=$cadence, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } - fun isPackage(): Boolean = package_ != null + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val percentConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) - fun isMatrix(): Boolean = matrix != null + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - fun isTiered(): Boolean = tiered != null + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - fun isTieredBps(): Boolean = tieredBps != null + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - fun isBps(): Boolean = bps != null + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - fun isBulkBps(): Boolean = bulkBps != null + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") - fun isBulk(): Boolean = bulk != null + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - fun isTieredPackage(): Boolean = tieredPackage != null + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - fun isUnitWithPercent(): Boolean = unitWithPercent != null + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - fun isTieredWithProration(): Boolean = tieredWithProration != null + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - fun isUnitWithProration(): Boolean = unitWithProration != null + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - fun isGroupedAllocation(): Boolean = groupedAllocation != null + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - fun isBulkWithProration(): Boolean = bulkWithProration != null + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - fun isScalableMatrixWithTieredPricing(): Boolean = - scalableMatrixWithTieredPricing != null + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null + /** + * 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 - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + /** + * Returns the raw JSON value of [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig - fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - fun isGroupedTiered(): Boolean = groupedTiered != null + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - fun asUnit(): NewSubscriptionUnitPrice = unit.getOrThrow("unit") + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - fun asPackage(): NewSubscriptionPackagePrice = package_.getOrThrow("package_") + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - fun asMatrix(): NewSubscriptionMatrixPrice = matrix.getOrThrow("matrix") + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - fun asTiered(): NewSubscriptionTieredPrice = tiered.getOrThrow("tiered") + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - fun asTieredBps(): NewSubscriptionTieredBpsPrice = tieredBps.getOrThrow("tieredBps") + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - fun asBps(): NewSubscriptionBpsPrice = bps.getOrThrow("bps") + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - fun asBulkBps(): NewSubscriptionBulkBpsPrice = bulkBps.getOrThrow("bulkBps") + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - fun asBulk(): NewSubscriptionBulkPrice = bulk.getOrThrow("bulk") + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - fun asThresholdTotalAmount(): NewSubscriptionThresholdTotalAmountPrice = - thresholdTotalAmount.getOrThrow("thresholdTotalAmount") + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - fun asTieredPackage(): NewSubscriptionTieredPackagePrice = - tieredPackage.getOrThrow("tieredPackage") + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun asTieredWithMinimum(): NewSubscriptionTieredWithMinimumPrice = - tieredWithMinimum.getOrThrow("tieredWithMinimum") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Percent]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + */ + fun builder() = Builder() + } - fun asUnitWithPercent(): NewSubscriptionUnitWithPercentPrice = - unitWithPercent.getOrThrow("unitWithPercent") + /** A builder for [Percent]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("percent") + private var name: JsonField? = null + private var percentConfig: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percent: Percent) = apply { + cadence = percent.cadence + itemId = percent.itemId + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + billableMetricId = percent.billableMetricId + billedInAdvance = percent.billedInAdvance + billingCycleConfiguration = percent.billingCycleConfiguration + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + currency = percent.currency + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoiceGroupingKey = percent.invoiceGroupingKey + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + metadata = percent.metadata + referenceId = percent.referenceId + additionalProperties = percent.additionalProperties.toMutableMap() + } - fun asPackageWithAllocation(): NewSubscriptionPackageWithAllocationPrice = - packageWithAllocation.getOrThrow("packageWithAllocation") + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed + * [PercentConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } - fun asTieredWithProration(): NewSubscriptionTierWithProrationPrice = - tieredWithProration.getOrThrow("tieredWithProration") + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - fun asUnitWithProration(): NewSubscriptionUnitWithProrationPrice = - unitWithProration.getOrThrow("unitWithProration") + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - fun asGroupedAllocation(): NewSubscriptionGroupedAllocationPrice = - groupedAllocation.getOrThrow("groupedAllocation") + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - fun asGroupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice = - groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - fun asBulkWithProration(): NewSubscriptionBulkWithProrationPrice = - bulkWithProration.getOrThrow("bulkWithProration") + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - fun asScalableMatrixWithUnitPricing(): - NewSubscriptionScalableMatrixWithUnitPricingPrice = - scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - fun asScalableMatrixWithTieredPricing(): - NewSubscriptionScalableMatrixWithTieredPricingPrice = - scalableMatrixWithTieredPricing.getOrThrow("scalableMatrixWithTieredPricing") + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - fun asCumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice = - cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - fun asMaxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice = - maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - fun asGroupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice = - groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - fun asMatrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice = - matrixWithDisplayName.getOrThrow("matrixWithDisplayName") + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - fun asGroupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice = - groupedTieredPackage.getOrThrow("groupedTieredPackage") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun asMatrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice = - matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun asTieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice = - tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun asGroupedTiered(): NewSubscriptionGroupedTieredPrice = - groupedTiered.getOrThrow("groupedTiered") + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun _json(): JsonValue? = _json + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) - tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) - bulk != null -> visitor.visitBulk(bulk) - thresholdTotalAmount != null -> - visitor.visitThresholdTotalAmount(thresholdTotalAmount) - tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) - tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) - unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) - packageWithAllocation != null -> - visitor.visitPackageWithAllocation(packageWithAllocation) - tieredWithProration != null -> - visitor.visitTieredWithProration(tieredWithProration) - unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) - groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) - groupedWithProratedMinimum != null -> - visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) - scalableMatrixWithUnitPricing != null -> - visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) - scalableMatrixWithTieredPricing != null -> - visitor.visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing + /** + * Returns an immutable instance of [Percent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Percent = + Percent( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("percentConfig", percentConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), ) - cumulativeGroupedBulk != null -> - visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) - maxGroupTieredPackage != null -> - visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) - groupedWithMeteredMinimum != null -> - visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) - matrixWithDisplayName != null -> - visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - groupedTieredPackage != null -> - visitor.visitGroupedTieredPackage(groupedTieredPackage) - matrixWithAllocation != null -> - visitor.visitMatrixWithAllocation(matrixWithAllocation) - tieredPackageWithMinimum != null -> - visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Price = apply { - if (validated) { - return@apply } - accept( - object : Visitor { - override fun visitUnit(unit: NewSubscriptionUnitPrice) { - unit.validate() - } - - override fun visitPackage(package_: NewSubscriptionPackagePrice) { - package_.validate() - } - - override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) { - matrix.validate() - } - - override fun visitTiered(tiered: NewSubscriptionTieredPrice) { - tiered.validate() - } + private var validated: Boolean = false - override fun visitTieredBps(tieredBps: NewSubscriptionTieredBpsPrice) { - tieredBps.validate() - } + fun validate(): Percent = apply { + if (validated) { + return@apply + } - override fun visitBps(bps: NewSubscriptionBpsPrice) { - bps.validate() + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("percent")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") } + } + name() + percentConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - override fun visitBulkBps(bulkBps: NewSubscriptionBulkBpsPrice) { - bulkBps.validate() - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitBulk(bulk: NewSubscriptionBulkPrice) { - bulk.validate() - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - override fun visitThresholdTotalAmount( - thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice - ) { - thresholdTotalAmount.validate() - } + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - override fun visitTieredPackage( - tieredPackage: NewSubscriptionTieredPackagePrice - ) { - tieredPackage.validate() - } + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - override fun visitTieredWithMinimum( - tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice - ) { - tieredWithMinimum.validate() + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN } - override fun visitUnitWithPercent( - unitWithPercent: NewSubscriptionUnitWithPercentPrice - ) { - unitWithPercent.validate() + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") } - override fun visitPackageWithAllocation( - packageWithAllocation: NewSubscriptionPackageWithAllocationPrice - ) { - packageWithAllocation.validate() + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply } - override fun visitTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice - ) { - tieredWithProration.validate() - } + known() + validated = true + } - override fun visitUnitWithProration( - unitWithProration: NewSubscriptionUnitWithProrationPrice - ) { - unitWithProration.validate() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - override fun visitGroupedAllocation( - groupedAllocation: NewSubscriptionGroupedAllocationPrice - ) { - groupedAllocation.validate() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - override fun visitGroupedWithProratedMinimum( - groupedWithProratedMinimum: - NewSubscriptionGroupedWithProratedMinimumPrice - ) { - groupedWithProratedMinimum.validate() - } + return other is Cadence && value == other.value + } - override fun visitBulkWithProration( - bulkWithProration: NewSubscriptionBulkWithProrationPrice - ) { - bulkWithProration.validate() - } + override fun hashCode() = value.hashCode() - override fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: - NewSubscriptionScalableMatrixWithUnitPricingPrice - ) { - scalableMatrixWithUnitPricing.validate() - } + override fun toString() = value.toString() + } - override fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice - ) { - scalableMatrixWithTieredPricing.validate() - } + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val additionalProperties: MutableMap, + ) { - override fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice - ) { - cumulativeGroupedBulk.validate() - } + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent") + @ExcludeMissing + fun _percent(): JsonField = percent + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice - ) { - maxGroupTieredPackage.validate() - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ + fun builder() = Builder() + } - override fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice - ) { - groupedWithMeteredMinimum.validate() - } + /** A builder for [PercentConfig]. */ + class Builder internal constructor() { - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice - ) { - matrixWithDisplayName.validate() - } + private var percent: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() - override fun visitGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice - ) { - groupedTieredPackage.validate() + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() } - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice - ) { - matrixWithAllocation.validate() + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ) { - tieredPackageWithMinimum.validate() + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - override fun visitGroupedTiered( - groupedTiered: NewSubscriptionGroupedTieredPrice - ) { - groupedTiered.validate() + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } + + /** + * Returns an immutable instance of [PercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + private var validated: Boolean = false - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: NewSubscriptionUnitPrice) = unit.validity() + fun validate(): PercentConfig = apply { + if (validated) { + return@apply + } - override fun visitPackage(package_: NewSubscriptionPackagePrice) = - package_.validity() + percent() + validated = true + } - override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) = - matrix.validity() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitTiered(tiered: NewSubscriptionTieredPrice) = - tiered.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun visitTieredBps(tieredBps: NewSubscriptionTieredBpsPrice) = - tieredBps.validity() + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties + } - override fun visitBps(bps: NewSubscriptionBpsPrice) = bps.validity() + private val hashCode: Int by lazy { + Objects.hash(percent, additionalProperties) + } - override fun visitBulkBps(bulkBps: NewSubscriptionBulkBpsPrice) = - bulkBps.validity() + override fun hashCode(): Int = hashCode - override fun visitBulk(bulk: NewSubscriptionBulkPrice) = bulk.validity() + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" + } - override fun visitThresholdTotalAmount( - thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice - ) = thresholdTotalAmount.validity() + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - override fun visitTieredPackage( - tieredPackage: NewSubscriptionTieredPackagePrice - ) = tieredPackage.validity() + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - override fun visitTieredWithMinimum( - tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice - ) = tieredWithMinimum.validity() + fun toBuilder() = Builder().from(this) - override fun visitUnitWithPercent( - unitWithPercent: NewSubscriptionUnitWithPercentPrice - ) = unitWithPercent.validity() + companion object { - override fun visitPackageWithAllocation( - packageWithAllocation: NewSubscriptionPackageWithAllocationPrice - ) = packageWithAllocation.validity() + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + fun builder() = Builder() + } - override fun visitTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice - ) = tieredWithProration.validity() + /** A builder for [Metadata]. */ + class Builder internal constructor() { - override fun visitUnitWithProration( - unitWithProration: NewSubscriptionUnitWithProrationPrice - ) = unitWithProration.validity() + private var additionalProperties: MutableMap = + mutableMapOf() - override fun visitGroupedAllocation( - groupedAllocation: NewSubscriptionGroupedAllocationPrice - ) = groupedAllocation.validity() + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } - override fun visitGroupedWithProratedMinimum( - groupedWithProratedMinimum: - NewSubscriptionGroupedWithProratedMinimumPrice - ) = groupedWithProratedMinimum.validity() + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - override fun visitBulkWithProration( - bulkWithProration: NewSubscriptionBulkWithProrationPrice - ) = bulkWithProration.validity() + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - override fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: - NewSubscriptionScalableMatrixWithUnitPricingPrice - ) = scalableMatrixWithUnitPricing.validity() + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - override fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice - ) = scalableMatrixWithTieredPricing.validity() + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - override fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice - ) = cumulativeGroupedBulk.validity() + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice - ) = maxGroupTieredPackage.validity() + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } - override fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice - ) = groupedWithMeteredMinimum.validity() + private var validated: Boolean = false - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice - ) = matrixWithDisplayName.validity() + fun validate(): Metadata = apply { + if (validated) { + return@apply + } - override fun visitGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice - ) = groupedTieredPackage.validity() + validated = true + } - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice - ) = matrixWithAllocation.validity() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ) = tieredPackageWithMinimum.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } - override fun visitGroupedTiered( - groupedTiered: NewSubscriptionGroupedTieredPrice - ) = groupedTiered.validity() + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun unknown(json: JsonValue?) = 0 + return other is Metadata && + additionalProperties == other.additionalProperties } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } - return /* spotless:off */ other is Price && unit == other.unit && package_ == other.package_ && matrix == other.matrix && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && tieredWithMinimum == other.tieredWithMinimum && unitWithPercent == other.unitWithPercent && packageWithAllocation == other.packageWithAllocation && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && bulkWithProration == other.bulkWithProration && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk && maxGroupTieredPackage == other.maxGroupTieredPackage && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && groupedTieredPackage == other.groupedTieredPackage && matrixWithAllocation == other.matrixWithAllocation && tieredPackageWithMinimum == other.tieredPackageWithMinimum && groupedTiered == other.groupedTiered /* spotless:on */ - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, tieredWithMinimum, unitWithPercent, packageWithAllocation, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, bulkWithProration, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk, maxGroupTieredPackage, groupedWithMeteredMinimum, matrixWithDisplayName, groupedTieredPackage, matrixWithAllocation, tieredPackageWithMinimum, groupedTiered) /* spotless:on */ + return other is Percent && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } - override fun toString(): String = - when { - unit != null -> "Price{unit=$unit}" - package_ != null -> "Price{package_=$package_}" - matrix != null -> "Price{matrix=$matrix}" - tiered != null -> "Price{tiered=$tiered}" - tieredBps != null -> "Price{tieredBps=$tieredBps}" - bps != null -> "Price{bps=$bps}" - bulkBps != null -> "Price{bulkBps=$bulkBps}" - bulk != null -> "Price{bulk=$bulk}" - thresholdTotalAmount != null -> - "Price{thresholdTotalAmount=$thresholdTotalAmount}" - tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" - tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" - unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" - packageWithAllocation != null -> - "Price{packageWithAllocation=$packageWithAllocation}" - tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" - unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" - groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" - groupedWithProratedMinimum != null -> - "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" - bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" - scalableMatrixWithUnitPricing != null -> - "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" - scalableMatrixWithTieredPricing != null -> - "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" - cumulativeGroupedBulk != null -> - "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" - maxGroupTieredPackage != null -> - "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" - groupedWithMeteredMinimum != null -> - "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" - matrixWithDisplayName != null -> - "Price{matrixWithDisplayName=$matrixWithDisplayName}" - groupedTieredPackage != null -> - "Price{groupedTieredPackage=$groupedTieredPackage}" - matrixWithAllocation != null -> - "Price{matrixWithAllocation=$matrixWithAllocation}" - tieredPackageWithMinimum != null -> - "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" - groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" - _json != null -> "Price{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Price") + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) } - companion object { + override fun hashCode(): Int = hashCode - fun ofUnit(unit: NewSubscriptionUnitPrice) = Price(unit = unit) + override fun toString() = + "Percent{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, percentConfig=$percentConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } - fun ofPackage(package_: NewSubscriptionPackagePrice) = Price(package_ = package_) + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val eventOutputConfig: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) - fun ofMatrix(matrix: NewSubscriptionMatrixPrice) = Price(matrix = matrix) + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - fun ofTiered(tiered: NewSubscriptionTieredPrice) = Price(tiered = tiered) + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - fun ofTieredBps(tieredBps: NewSubscriptionTieredBpsPrice) = - Price(tieredBps = tieredBps) + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - fun ofBps(bps: NewSubscriptionBpsPrice) = Price(bps = bps) + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - fun ofBulkBps(bulkBps: NewSubscriptionBulkBpsPrice) = Price(bulkBps = bulkBps) + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - fun ofBulk(bulk: NewSubscriptionBulkPrice) = Price(bulk = bulk) + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - fun ofThresholdTotalAmount( - thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice - ) = Price(thresholdTotalAmount = thresholdTotalAmount) + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - fun ofTieredPackage(tieredPackage: NewSubscriptionTieredPackagePrice) = - Price(tieredPackage = tieredPackage) + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - fun ofTieredWithMinimum(tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice) = - Price(tieredWithMinimum = tieredWithMinimum) + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - fun ofUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = - Price(unitWithPercent = unitWithPercent) + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - fun ofPackageWithAllocation( - packageWithAllocation: NewSubscriptionPackageWithAllocationPrice - ) = Price(packageWithAllocation = packageWithAllocation) + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - fun ofTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice - ) = Price(tieredWithProration = tieredWithProration) + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - fun ofUnitWithProration(unitWithProration: NewSubscriptionUnitWithProrationPrice) = - Price(unitWithProration = unitWithProration) + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - fun ofGroupedAllocation(groupedAllocation: NewSubscriptionGroupedAllocationPrice) = - Price(groupedAllocation = groupedAllocation) + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - fun ofGroupedWithProratedMinimum( - groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice - ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig - fun ofBulkWithProration(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = - Price(bulkWithProration = bulkWithProration) + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - fun ofScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice - ) = Price(scalableMatrixWithUnitPricing = scalableMatrixWithUnitPricing) + /** + * 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 - fun ofScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice - ) = Price(scalableMatrixWithTieredPricing = scalableMatrixWithTieredPricing) + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - fun ofCumulativeGroupedBulk( - cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice - ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - fun ofMaxGroupTieredPackage( - maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice - ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - fun ofGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice - ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - fun ofMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice - ) = Price(matrixWithDisplayName = matrixWithDisplayName) + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - fun ofGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice - ) = Price(groupedTieredPackage = groupedTieredPackage) + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - fun ofMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice - ) = Price(matrixWithAllocation = matrixWithAllocation) + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - fun ofTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - fun ofGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice) = - Price(groupedTiered = groupedTiered) - } + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - /** - * An interface that defines how to map each variant of [Price] to a value of type [T]. - */ - interface Visitor { + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - fun visitUnit(unit: NewSubscriptionUnitPrice): T + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - fun visitPackage(package_: NewSubscriptionPackagePrice): T + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - fun visitMatrix(matrix: NewSubscriptionMatrixPrice): T + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - fun visitTiered(tiered: NewSubscriptionTieredPrice): T + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun visitTieredBps(tieredBps: NewSubscriptionTieredBpsPrice): T + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EventOutput]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } - fun visitBps(bps: NewSubscriptionBpsPrice): T + /** A builder for [EventOutput]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var eventOutputConfig: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("event_output") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutput: EventOutput) = apply { + cadence = eventOutput.cadence + eventOutputConfig = eventOutput.eventOutputConfig + itemId = eventOutput.itemId + modelType = eventOutput.modelType + name = eventOutput.name + billableMetricId = eventOutput.billableMetricId + billedInAdvance = eventOutput.billedInAdvance + billingCycleConfiguration = eventOutput.billingCycleConfiguration + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + currency = eventOutput.currency + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoiceGroupingKey = eventOutput.invoiceGroupingKey + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + metadata = eventOutput.metadata + referenceId = eventOutput.referenceId + additionalProperties = eventOutput.additionalProperties.toMutableMap() + } - fun visitBulkBps(bulkBps: NewSubscriptionBulkBpsPrice): T + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } - fun visitBulk(bulk: NewSubscriptionBulkPrice): T + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - fun visitThresholdTotalAmount( - thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice - ): T + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - fun visitTieredPackage(tieredPackage: NewSubscriptionTieredPackagePrice): T + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - fun visitTieredWithMinimum( - tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice - ): T + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - fun visitUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice): T + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - fun visitPackageWithAllocation( - packageWithAllocation: NewSubscriptionPackageWithAllocationPrice - ): T + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - fun visitTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice - ): T + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - fun visitUnitWithProration( - unitWithProration: NewSubscriptionUnitWithProrationPrice - ): T + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - fun visitGroupedAllocation( - groupedAllocation: NewSubscriptionGroupedAllocationPrice - ): T + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - fun visitGroupedWithProratedMinimum( - groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice - ): T + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - fun visitBulkWithProration( - bulkWithProration: NewSubscriptionBulkWithProrationPrice - ): T + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice - ): T + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice - ): T + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice - ): T + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice - ): T + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice - ): T + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice - ): T + /** + * Returns an immutable instance of [EventOutput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutput = + EventOutput( + checkRequired("cadence", cadence), + checkRequired("eventOutputConfig", eventOutputConfig), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - fun visitGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice - ): T + private var validated: Boolean = false - fun visitMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice - ): T + fun validate(): EventOutput = apply { + if (validated) { + return@apply + } - fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ): T + cadence().validate() + eventOutputConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("event_output")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - fun visitGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [Price] to a value of type [T]. - * - * An instance of [Price] can contain an unknown variant if it was deserialized from - * data that doesn't match any known variant. For example, if the SDK is on an older - * version than the API, then the API may respond with new variants that the SDK is - * unaware of. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown Price: $json") - } - } + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - internal class Deserializer : BaseDeserializer(Price::class) { + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - override fun ObjectCodec.deserialize(node: JsonNode): Price { - val json = JsonValue.fromJsonNode(node) - val modelType = json.asObject()?.get("model_type")?.asString() + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - when (modelType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(unit = it, _json = json) } ?: Price(_json = json) - } - "package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) - } - "matrix" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tiered = it, _json = json) } ?: Price(_json = json) - } - "tiered_bps" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredBps = it, _json = json) } ?: Price(_json = json) - } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bps = it, _json = json) } ?: Price(_json = json) + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN } - "bulk_bps" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(bulkBps = it, _json = json) } ?: Price(_json = json) + + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") } - "bulk" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bulk = it, _json = json) } ?: Price(_json = json) + + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply } - "threshold_total_amount" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(thresholdTotalAmount = it, _json = json) } - ?: Price(_json = json) + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredPackage = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - "tiered_with_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredWithMinimum = it, _json = json) } - ?: Price(_json = json) + + return other is Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a + * unit rate will be ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = + defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events + * will also be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @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 + * [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutputConfig]. */ + class Builder internal constructor() { + + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = + eventOutputConfig.additionalProperties.toMutableMap() } - "unit_with_percent" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(unitWithPercent = it, _json = json) } - ?: Price(_json = json) + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey } - "package_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(packageWithAllocation = it, _json = json) } - ?: Price(_json = json) + + /** + * If provided, this amount will be used as the unit rate when an event does + * not have a value for the `unit_rating_key`. If not provided, events + * missing a unit rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate } - "tiered_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredWithProration = it, _json = json) } - ?: Price(_json = json) + + /** + * An optional key in the event data to group by (e.g., event ID). All + * events will also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey } - "unit_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(unitWithProration = it, _json = json) } - ?: Price(_json = json) + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - "grouped_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedAllocation = it, _json = json) } - ?: Price(_json = json) + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - "grouped_with_prorated_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedWithProratedMinimum = it, _json = json) } - ?: Price(_json = json) + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - "bulk_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(bulkWithProration = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns an immutable instance of [EventOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutputConfig = apply { + if (validated) { + return@apply } - "scalable_matrix_with_unit_pricing" -> { - return tryDeserialize( - node, - jacksonTypeRef< - NewSubscriptionScalableMatrixWithUnitPricingPrice - >(), - ) - ?.let { Price(scalableMatrixWithUnitPricing = it, _json = json) } - ?: Price(_json = json) + + unitRatingKey() + defaultUnitRate() + groupingKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "scalable_matrix_with_tiered_pricing" -> { - return tryDeserialize( - node, - jacksonTypeRef< - NewSubscriptionScalableMatrixWithTieredPricingPrice - >(), - ) - ?.let { Price(scalableMatrixWithTieredPricing = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - "cumulative_grouped_bulk" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(cumulativeGroupedBulk = it, _json = json) } - ?: Price(_json = json) + + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + unitRatingKey, + defaultUnitRate, + groupingKey, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() } - "max_group_tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(maxGroupTieredPackage = it, _json = json) } - ?: Price(_json = json) + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - "grouped_with_metered_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } - ?: Price(_json = json) + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - "matrix_with_display_name" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithDisplayName = it, _json = json) } - ?: Price(_json = json) + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - "grouped_tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedTieredPackage = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply } - "matrix_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithAllocation = it, _json = json) } - ?: Price(_json = json) + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "tiered_package_with_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredPackageWithMinimum = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() } - "grouped_tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedTiered = it, _json = json) } - ?: Price(_json = json) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Metadata && + additionalProperties == other.additionalProperties } - return Price(_json = json) - } - } + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - internal class Serializer : BaseSerializer(Price::class) { + override fun hashCode(): Int = hashCode - override fun serialize( - value: Price, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) - value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) - value.bulk != null -> generator.writeObject(value.bulk) - value.thresholdTotalAmount != null -> - generator.writeObject(value.thresholdTotalAmount) - value.tieredPackage != null -> generator.writeObject(value.tieredPackage) - value.tieredWithMinimum != null -> - generator.writeObject(value.tieredWithMinimum) - value.unitWithPercent != null -> - generator.writeObject(value.unitWithPercent) - value.packageWithAllocation != null -> - generator.writeObject(value.packageWithAllocation) - value.tieredWithProration != null -> - generator.writeObject(value.tieredWithProration) - value.unitWithProration != null -> - generator.writeObject(value.unitWithProration) - value.groupedAllocation != null -> - generator.writeObject(value.groupedAllocation) - value.groupedWithProratedMinimum != null -> - generator.writeObject(value.groupedWithProratedMinimum) - value.bulkWithProration != null -> - generator.writeObject(value.bulkWithProration) - value.scalableMatrixWithUnitPricing != null -> - generator.writeObject(value.scalableMatrixWithUnitPricing) - value.scalableMatrixWithTieredPricing != null -> - generator.writeObject(value.scalableMatrixWithTieredPricing) - value.cumulativeGroupedBulk != null -> - generator.writeObject(value.cumulativeGroupedBulk) - value.maxGroupTieredPackage != null -> - generator.writeObject(value.maxGroupTieredPackage) - value.groupedWithMeteredMinimum != null -> - generator.writeObject(value.groupedWithMeteredMinimum) - value.matrixWithDisplayName != null -> - generator.writeObject(value.matrixWithDisplayName) - value.groupedTieredPackage != null -> - generator.writeObject(value.groupedTieredPackage) - value.matrixWithAllocation != null -> - generator.writeObject(value.matrixWithAllocation) - value.tieredPackageWithMinimum != null -> - generator.writeObject(value.tieredPackageWithMinimum) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Price") + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is EventOutput && + cadence == other.cadence && + eventOutputConfig == other.eventOutputConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutput{cadence=$cadence, eventOutputConfig=$eventOutputConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" } } @@ -8834,12 +30016,33 @@ private constructor( return true } - return /* spotless:off */ other is ReplacePrice && replacesPriceId == other.replacesPriceId && allocationPrice == other.allocationPrice && discounts == other.discounts && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && maximumAmount == other.maximumAmount && minimumAmount == other.minimumAmount && price == other.price && priceId == other.priceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ReplacePrice && + replacesPriceId == other.replacesPriceId && + allocationPrice == other.allocationPrice && + discounts == other.discounts && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + maximumAmount == other.maximumAmount && + minimumAmount == other.minimumAmount && + price == other.price && + priceId == other.priceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(replacesPriceId, allocationPrice, discounts, externalPriceId, fixedPriceQuantity, maximumAmount, minimumAmount, price, priceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + replacesPriceId, + allocationPrice, + discounts, + externalPriceId, + fixedPriceQuantity, + maximumAmount, + minimumAmount, + price, + priceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -8852,10 +30055,13 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "SubscriptionCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchCostsParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchCostsParams.kt index 2ac4a2cb6..9c151623c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchCostsParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchCostsParams.kt @@ -371,7 +371,7 @@ private constructor( return true } - return /* spotless:off */ other is ViewMode && value == other.value /* spotless:on */ + return other is ViewMode && value == other.value } override fun hashCode() = value.hashCode() @@ -384,10 +384,26 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionFetchCostsParams && subscriptionId == other.subscriptionId && currency == other.currency && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && viewMode == other.viewMode && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionFetchCostsParams && + subscriptionId == other.subscriptionId && + currency == other.currency && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + viewMode == other.viewMode && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, currency, timeframeEnd, timeframeStart, viewMode, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + subscriptionId, + currency, + timeframeEnd, + timeframeStart, + viewMode, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "SubscriptionFetchCostsParams{subscriptionId=$subscriptionId, currency=$currency, timeframeEnd=$timeframeEnd, timeframeStart=$timeframeStart, viewMode=$viewMode, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchCostsResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchCostsResponse.kt index 02f45d24e..8fc613442 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchCostsResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchCostsResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class SubscriptionFetchCostsResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val additionalProperties: MutableMap, @@ -175,12 +176,12 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionFetchCostsResponse && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SubscriptionFetchCostsResponse && + data == other.data && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchParams.kt index 0ed84f6e4..dca86f00b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchParams.kt @@ -177,10 +177,14 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionFetchParams && subscriptionId == other.subscriptionId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionFetchParams && + subscriptionId == other.subscriptionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionId, additionalHeaders, additionalQueryParams) override fun toString() = "SubscriptionFetchParams{subscriptionId=$subscriptionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePage.kt index 376368aa8..628bd204e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePage.kt @@ -123,10 +123,13 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionFetchSchedulePage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is SubscriptionFetchSchedulePage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "SubscriptionFetchSchedulePage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageAsync.kt index 655260487..a9bd226c1 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageAsync.kt @@ -125,10 +125,13 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionFetchSchedulePageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is SubscriptionFetchSchedulePageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "SubscriptionFetchSchedulePageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageResponse.kt index 09bd08c90..27a2ca581 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageResponse.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class SubscriptionFetchSchedulePageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -222,12 +223,15 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionFetchSchedulePageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SubscriptionFetchSchedulePageResponse && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchScheduleParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchScheduleParams.kt index 4fd3e45a8..9b07a0b3f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchScheduleParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchScheduleParams.kt @@ -269,10 +269,30 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionFetchScheduleParams && subscriptionId == other.subscriptionId && cursor == other.cursor && limit == other.limit && startDateGt == other.startDateGt && startDateGte == other.startDateGte && startDateLt == other.startDateLt && startDateLte == other.startDateLte && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionFetchScheduleParams && + subscriptionId == other.subscriptionId && + cursor == other.cursor && + limit == other.limit && + startDateGt == other.startDateGt && + startDateGte == other.startDateGte && + startDateLt == other.startDateLt && + startDateLte == other.startDateLte && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, cursor, limit, startDateGt, startDateGte, startDateLt, startDateLte, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + subscriptionId, + cursor, + limit, + startDateGt, + startDateGte, + startDateLt, + startDateLte, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "SubscriptionFetchScheduleParams{subscriptionId=$subscriptionId, cursor=$cursor, limit=$limit, startDateGt=$startDateGt, startDateGte=$startDateGte, startDateLt=$startDateLt, startDateLte=$startDateLte, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchScheduleResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchScheduleResponse.kt index 51d255a21..a7f4bc11b 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchScheduleResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchScheduleResponse.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class SubscriptionFetchScheduleResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val createdAt: JsonField, private val endDate: JsonField, @@ -264,6 +265,7 @@ private constructor( (if (startDate.asKnown() == null) 0 else 1) class Plan + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val externalPlanId: JsonField, @@ -488,12 +490,16 @@ private constructor( return true } - return /* spotless:off */ other is Plan && id == other.id && externalPlanId == other.externalPlanId && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Plan && + id == other.id && + externalPlanId == other.externalPlanId && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, externalPlanId, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, externalPlanId, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -506,12 +512,17 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionFetchScheduleResponse && createdAt == other.createdAt && endDate == other.endDate && plan == other.plan && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SubscriptionFetchScheduleResponse && + createdAt == other.createdAt && + endDate == other.endDate && + plan == other.plan && + startDate == other.startDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(createdAt, endDate, plan, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(createdAt, endDate, plan, startDate, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchUsageParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchUsageParams.kt index 190aa3cef..93cbae60d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchUsageParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchUsageParams.kt @@ -24,7 +24,6 @@ import java.util.Objects * customer's billing period. * * ### Default response shape - * * Orb returns a `data` array with an object corresponding to each billable metric. Nested within * this object is a `usage` array which has a `quantity` value and a corresponding `timeframe_start` * and `timeframe_end`. The `quantity` value represents the calculated usage value for the billable @@ -41,7 +40,6 @@ import java.util.Objects * with each other, e.g. to display grouped usage on a custom timeframe. * * ## Custom timeframe - * * In order to view usage for a custom timeframe rather than the current billing period, specify a * `timeframe_start` and `timeframe_end`. This will calculate quantities for usage incurred between * timeframe_start (inclusive) and timeframe_end (exclusive), i.e. `[timeframe_start, @@ -53,7 +51,6 @@ import java.util.Objects * - Both parameters must be specified if either is specified. * * ## Grouping by custom attributes - * * In order to view a single metric grouped by a specific _attribute_ that each event is tagged with * (e.g. `cluster`), you must additionally specify a `billable_metric_id` and a `group_by` key. The * `group_by` key denotes the event property on which to group. @@ -102,7 +99,6 @@ import java.util.Objects * ``` * * ## Windowed usage - * * The `granularity` parameter can be used to _window_ the usage `quantity` value into periods. When * not specified, usage is returned for the entirety of the time range. * @@ -157,7 +153,6 @@ import java.util.Objects * ``` * * ## Decomposable vs. non-decomposable metrics - * * Billable metrics fall into one of two categories: decomposable and non-decomposable. A * decomposable billable metric, such as a sum or a count, can be displayed and aggregated across * arbitrary timescales. On the other hand, a non-decomposable metric is not meaningful when only a @@ -176,7 +171,6 @@ import java.util.Objects * If no invoice grouping key is present, the metric does not support `group_by`. * * ## Matrix prices - * * When a billable metric is attached to a price that uses matrix pricing, it's important to view * usage grouped by those matrix dimensions. In this case, use the query parameters * `first_dimension_key`, `first_dimension_value` and `second_dimension_key`, @@ -605,7 +599,7 @@ private constructor( return true } - return /* spotless:off */ other is Granularity && value == other.value /* spotless:on */ + return other is Granularity && value == other.value } override fun hashCode() = value.hashCode() @@ -734,7 +728,7 @@ private constructor( return true } - return /* spotless:off */ other is ViewMode && value == other.value /* spotless:on */ + return other is ViewMode && value == other.value } override fun hashCode() = value.hashCode() @@ -747,10 +741,38 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionFetchUsageParams && subscriptionId == other.subscriptionId && billableMetricId == other.billableMetricId && firstDimensionKey == other.firstDimensionKey && firstDimensionValue == other.firstDimensionValue && granularity == other.granularity && groupBy == other.groupBy && secondDimensionKey == other.secondDimensionKey && secondDimensionValue == other.secondDimensionValue && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && viewMode == other.viewMode && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionFetchUsageParams && + subscriptionId == other.subscriptionId && + billableMetricId == other.billableMetricId && + firstDimensionKey == other.firstDimensionKey && + firstDimensionValue == other.firstDimensionValue && + granularity == other.granularity && + groupBy == other.groupBy && + secondDimensionKey == other.secondDimensionKey && + secondDimensionValue == other.secondDimensionValue && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + viewMode == other.viewMode && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, billableMetricId, firstDimensionKey, firstDimensionValue, granularity, groupBy, secondDimensionKey, secondDimensionValue, timeframeEnd, timeframeStart, viewMode, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + subscriptionId, + billableMetricId, + firstDimensionKey, + firstDimensionValue, + granularity, + groupBy, + secondDimensionKey, + secondDimensionValue, + timeframeEnd, + timeframeStart, + viewMode, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "SubscriptionFetchUsageParams{subscriptionId=$subscriptionId, billableMetricId=$billableMetricId, firstDimensionKey=$firstDimensionKey, firstDimensionValue=$firstDimensionValue, granularity=$granularity, groupBy=$groupBy, secondDimensionKey=$secondDimensionKey, secondDimensionValue=$secondDimensionValue, timeframeEnd=$timeframeEnd, timeframeStart=$timeframeStart, viewMode=$viewMode, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPage.kt index 85a804ebc..4fca6dbd5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPage.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is SubscriptionListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "SubscriptionListPage{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPageAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPageAsync.kt index 32008ea0d..7f054402d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPageAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPageAsync.kt @@ -119,10 +119,13 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is SubscriptionListPageAsync && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "SubscriptionListPageAsync{service=$service, params=$params, response=$response}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionListParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionListParams.kt index d37b26257..2548aeaa9 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionListParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionListParams.kt @@ -33,7 +33,9 @@ private constructor( private val cursor: String?, private val customerId: List?, private val externalCustomerId: List?, + private val externalPlanId: String?, private val limit: Long?, + private val planId: String?, private val status: Status?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, @@ -57,9 +59,13 @@ private constructor( fun externalCustomerId(): List? = externalCustomerId + fun externalPlanId(): String? = externalPlanId + /** The number of items to fetch. Defaults to 20. */ fun limit(): Long? = limit + fun planId(): String? = planId + fun status(): Status? = status /** Additional headers to send with the request. */ @@ -88,7 +94,9 @@ private constructor( private var cursor: String? = null private var customerId: MutableList? = null private var externalCustomerId: MutableList? = null + private var externalPlanId: String? = null private var limit: Long? = null + private var planId: String? = null private var status: Status? = null private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @@ -101,7 +109,9 @@ private constructor( cursor = subscriptionListParams.cursor customerId = subscriptionListParams.customerId?.toMutableList() externalCustomerId = subscriptionListParams.externalCustomerId?.toMutableList() + externalPlanId = subscriptionListParams.externalPlanId limit = subscriptionListParams.limit + planId = subscriptionListParams.planId status = subscriptionListParams.status additionalHeaders = subscriptionListParams.additionalHeaders.toBuilder() additionalQueryParams = subscriptionListParams.additionalQueryParams.toBuilder() @@ -148,6 +158,8 @@ private constructor( (this.externalCustomerId ?: mutableListOf()).apply { add(externalCustomerId) } } + fun externalPlanId(externalPlanId: String?) = apply { this.externalPlanId = externalPlanId } + /** The number of items to fetch. Defaults to 20. */ fun limit(limit: Long?) = apply { this.limit = limit } @@ -158,6 +170,8 @@ private constructor( */ fun limit(limit: Long) = limit(limit as Long?) + fun planId(planId: String?) = apply { this.planId = planId } + fun status(status: Status?) = apply { this.status = status } fun additionalHeaders(additionalHeaders: Headers) = apply { @@ -272,7 +286,9 @@ private constructor( cursor, customerId?.toImmutable(), externalCustomerId?.toImmutable(), + externalPlanId, limit, + planId, status, additionalHeaders.build(), additionalQueryParams.build(), @@ -299,7 +315,9 @@ private constructor( cursor?.let { put("cursor", it) } customerId?.forEach { put("customer_id[]", it) } externalCustomerId?.forEach { put("external_customer_id[]", it) } + externalPlanId?.let { put("external_plan_id", it) } limit?.let { put("limit", it.toString()) } + planId?.let { put("plan_id", it) } status?.let { put("status", it.toString()) } putAll(additionalQueryParams) } @@ -427,7 +445,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -440,11 +458,39 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionListParams && createdAtGt == other.createdAtGt && createdAtGte == other.createdAtGte && createdAtLt == other.createdAtLt && createdAtLte == other.createdAtLte && cursor == other.cursor && customerId == other.customerId && externalCustomerId == other.externalCustomerId && limit == other.limit && status == other.status && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionListParams && + createdAtGt == other.createdAtGt && + createdAtGte == other.createdAtGte && + createdAtLt == other.createdAtLt && + createdAtLte == other.createdAtLte && + cursor == other.cursor && + customerId == other.customerId && + externalCustomerId == other.externalCustomerId && + externalPlanId == other.externalPlanId && + limit == other.limit && + planId == other.planId && + status == other.status && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(createdAtGt, createdAtGte, createdAtLt, createdAtLte, cursor, customerId, externalCustomerId, limit, status, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + createdAtGt, + createdAtGte, + createdAtLt, + createdAtLte, + cursor, + customerId, + externalCustomerId, + externalPlanId, + limit, + planId, + status, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = - "SubscriptionListParams{createdAtGt=$createdAtGt, createdAtGte=$createdAtGte, createdAtLt=$createdAtLt, createdAtLte=$createdAtLte, cursor=$cursor, customerId=$customerId, externalCustomerId=$externalCustomerId, limit=$limit, status=$status, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + "SubscriptionListParams{createdAtGt=$createdAtGt, createdAtGte=$createdAtGte, createdAtLt=$createdAtLt, createdAtLte=$createdAtLte, cursor=$cursor, customerId=$customerId, externalCustomerId=$externalCustomerId, externalPlanId=$externalPlanId, limit=$limit, planId=$planId, status=$status, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionMinified.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionMinified.kt index a9a65caa1..e506f9cf1 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionMinified.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionMinified.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class SubscriptionMinified +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val additionalProperties: MutableMap, @@ -151,12 +152,12 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionMinified && id == other.id && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SubscriptionMinified && + id == other.id && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionPriceIntervalsParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionPriceIntervalsParams.kt index b16b1d100..862b3a1ef 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionPriceIntervalsParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionPriceIntervalsParams.kt @@ -15,6 +15,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.withorb.api.core.BaseDeserializer import com.withorb.api.core.BaseSerializer +import com.withorb.api.core.Enum import com.withorb.api.core.ExcludeMissing import com.withorb.api.core.JsonField import com.withorb.api.core.JsonMissing @@ -81,7 +82,6 @@ import java.util.Objects * interval entirely from a subscription, set the `end_date` to be equivalent to the `start_date`. * * ## Fixed fee quantity transitions - * * The fixed fee quantity transitions for a fixed fee price interval can also be specified when * adding or editing by passing an array for `fixed_fee_quantity_transitions`. A fixed fee quantity * transition must have a `quantity` and an `effective_date`, which is the date after which the new @@ -133,6 +133,14 @@ private constructor( */ fun allowInvoiceCreditOrVoid(): Boolean? = body.allowInvoiceCreditOrVoid() + /** + * If set, the default value to use for added/edited price intervals with an end_date set. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun canDeferBilling(): Boolean? = body.canDeferBilling() + /** * A list of price intervals to edit on the subscription. * @@ -171,6 +179,13 @@ private constructor( */ fun _allowInvoiceCreditOrVoid(): JsonField = body._allowInvoiceCreditOrVoid() + /** + * Returns the raw JSON value of [canDeferBilling]. + * + * Unlike [canDeferBilling], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _canDeferBilling(): JsonField = body._canDeferBilling() + /** * Returns the raw JSON value of [edit]. * @@ -233,8 +248,8 @@ private constructor( * - [add] * - [addAdjustments] * - [allowInvoiceCreditOrVoid] + * - [canDeferBilling] * - [edit] - * - [editAdjustments] * - etc. */ fun body(body: Body) = apply { this.body = body.toBuilder() } @@ -310,6 +325,31 @@ private constructor( body.allowInvoiceCreditOrVoid(allowInvoiceCreditOrVoid) } + /** + * If set, the default value to use for added/edited price intervals with an end_date set. + */ + fun canDeferBilling(canDeferBilling: Boolean?) = apply { + body.canDeferBilling(canDeferBilling) + } + + /** + * Alias for [Builder.canDeferBilling]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun canDeferBilling(canDeferBilling: Boolean) = canDeferBilling(canDeferBilling as Boolean?) + + /** + * Sets [Builder.canDeferBilling] to an arbitrary JSON value. + * + * You should usually call [Builder.canDeferBilling] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun canDeferBilling(canDeferBilling: JsonField) = apply { + body.canDeferBilling(canDeferBilling) + } + /** A list of price intervals to edit on the subscription. */ fun edit(edit: List) = apply { body.edit(edit) } @@ -497,10 +537,12 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val add: JsonField>, private val addAdjustments: JsonField>, private val allowInvoiceCreditOrVoid: JsonField, + private val canDeferBilling: JsonField, private val edit: JsonField>, private val editAdjustments: JsonField>, private val additionalProperties: MutableMap, @@ -515,6 +557,9 @@ private constructor( @JsonProperty("allow_invoice_credit_or_void") @ExcludeMissing allowInvoiceCreditOrVoid: JsonField = JsonMissing.of(), + @JsonProperty("can_defer_billing") + @ExcludeMissing + canDeferBilling: JsonField = JsonMissing.of(), @JsonProperty("edit") @ExcludeMissing edit: JsonField> = JsonMissing.of(), @JsonProperty("edit_adjustments") @ExcludeMissing @@ -523,6 +568,7 @@ private constructor( add, addAdjustments, allowInvoiceCreditOrVoid, + canDeferBilling, edit, editAdjustments, mutableMapOf(), @@ -555,6 +601,14 @@ private constructor( fun allowInvoiceCreditOrVoid(): Boolean? = allowInvoiceCreditOrVoid.getNullable("allow_invoice_credit_or_void") + /** + * If set, the default value to use for added/edited price intervals with an end_date set. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun canDeferBilling(): Boolean? = canDeferBilling.getNullable("can_defer_billing") + /** * A list of price intervals to edit on the subscription. * @@ -599,6 +653,16 @@ private constructor( @ExcludeMissing fun _allowInvoiceCreditOrVoid(): JsonField = allowInvoiceCreditOrVoid + /** + * Returns the raw JSON value of [canDeferBilling]. + * + * Unlike [canDeferBilling], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("can_defer_billing") + @ExcludeMissing + fun _canDeferBilling(): JsonField = canDeferBilling + /** * Returns the raw JSON value of [edit]. * @@ -640,6 +704,7 @@ private constructor( private var add: JsonField>? = null private var addAdjustments: JsonField>? = null private var allowInvoiceCreditOrVoid: JsonField = JsonMissing.of() + private var canDeferBilling: JsonField = JsonMissing.of() private var edit: JsonField>? = null private var editAdjustments: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -648,6 +713,7 @@ private constructor( add = body.add.map { it.toMutableList() } addAdjustments = body.addAdjustments.map { it.toMutableList() } allowInvoiceCreditOrVoid = body.allowInvoiceCreditOrVoid + canDeferBilling = body.canDeferBilling edit = body.edit.map { it.toMutableList() } editAdjustments = body.editAdjustments.map { it.toMutableList() } additionalProperties = body.additionalProperties.toMutableMap() @@ -731,6 +797,32 @@ private constructor( this.allowInvoiceCreditOrVoid = allowInvoiceCreditOrVoid } + /** + * If set, the default value to use for added/edited price intervals with an end_date + * set. + */ + fun canDeferBilling(canDeferBilling: Boolean?) = + canDeferBilling(JsonField.ofNullable(canDeferBilling)) + + /** + * Alias for [Builder.canDeferBilling]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun canDeferBilling(canDeferBilling: Boolean) = + canDeferBilling(canDeferBilling as Boolean?) + + /** + * Sets [Builder.canDeferBilling] to an arbitrary JSON value. + * + * You should usually call [Builder.canDeferBilling] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun canDeferBilling(canDeferBilling: JsonField) = apply { + this.canDeferBilling = canDeferBilling + } + /** A list of price intervals to edit on the subscription. */ fun edit(edit: List) = edit(JsonField.of(edit)) @@ -813,6 +905,7 @@ private constructor( (add ?: JsonMissing.of()).map { it.toImmutable() }, (addAdjustments ?: JsonMissing.of()).map { it.toImmutable() }, allowInvoiceCreditOrVoid, + canDeferBilling, (edit ?: JsonMissing.of()).map { it.toImmutable() }, (editAdjustments ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toMutableMap(), @@ -829,6 +922,7 @@ private constructor( add()?.forEach { it.validate() } addAdjustments()?.forEach { it.validate() } allowInvoiceCreditOrVoid() + canDeferBilling() edit()?.forEach { it.validate() } editAdjustments()?.forEach { it.validate() } validated = true @@ -852,6 +946,7 @@ private constructor( (add.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (addAdjustments.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (if (allowInvoiceCreditOrVoid.asKnown() == null) 0 else 1) + + (if (canDeferBilling.asKnown() == null) 0 else 1) + (edit.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (editAdjustments.asKnown()?.sumOf { it.validity().toInt() } ?: 0) @@ -860,23 +955,40 @@ private constructor( return true } - return /* spotless:off */ other is Body && add == other.add && addAdjustments == other.addAdjustments && allowInvoiceCreditOrVoid == other.allowInvoiceCreditOrVoid && edit == other.edit && editAdjustments == other.editAdjustments && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + add == other.add && + addAdjustments == other.addAdjustments && + allowInvoiceCreditOrVoid == other.allowInvoiceCreditOrVoid && + canDeferBilling == other.canDeferBilling && + edit == other.edit && + editAdjustments == other.editAdjustments && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(add, addAdjustments, allowInvoiceCreditOrVoid, edit, editAdjustments, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + add, + addAdjustments, + allowInvoiceCreditOrVoid, + canDeferBilling, + edit, + editAdjustments, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Body{add=$add, addAdjustments=$addAdjustments, allowInvoiceCreditOrVoid=$allowInvoiceCreditOrVoid, edit=$edit, editAdjustments=$editAdjustments, additionalProperties=$additionalProperties}" + "Body{add=$add, addAdjustments=$addAdjustments, allowInvoiceCreditOrVoid=$allowInvoiceCreditOrVoid, canDeferBilling=$canDeferBilling, edit=$edit, editAdjustments=$editAdjustments, additionalProperties=$additionalProperties}" } class Add + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val startDate: JsonField, private val allocationPrice: JsonField, + private val canDeferBilling: JsonField, private val discounts: JsonField>, private val endDate: JsonField, private val externalPriceId: JsonField, @@ -898,6 +1010,9 @@ private constructor( @JsonProperty("allocation_price") @ExcludeMissing allocationPrice: JsonField = JsonMissing.of(), + @JsonProperty("can_defer_billing") + @ExcludeMissing + canDeferBilling: JsonField = JsonMissing.of(), @JsonProperty("discounts") @ExcludeMissing discounts: JsonField> = JsonMissing.of(), @@ -926,6 +1041,7 @@ private constructor( ) : this( startDate, allocationPrice, + canDeferBilling, discounts, endDate, externalPriceId, @@ -956,6 +1072,15 @@ private constructor( */ fun allocationPrice(): NewAllocationPrice? = allocationPrice.getNullable("allocation_price") + /** + * If true, an in-arrears price interval ending mid-cycle will defer billing the final line + * item until the next scheduled invoice. If false, it will be billed on its end date. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun canDeferBilling(): Boolean? = canDeferBilling.getNullable("can_defer_billing") + /** * A list of discounts to initialize on the price interval. * @@ -1019,7 +1144,7 @@ private constructor( fun minimumAmount(): Double? = minimumAmount.getNullable("minimum_amount") /** - * The definition of a new price to create and add to the subscription. + * New floating price request body params. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1065,6 +1190,16 @@ private constructor( @ExcludeMissing fun _allocationPrice(): JsonField = allocationPrice + /** + * Returns the raw JSON value of [canDeferBilling]. + * + * Unlike [canDeferBilling], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("can_defer_billing") + @ExcludeMissing + fun _canDeferBilling(): JsonField = canDeferBilling + /** * Returns the raw JSON value of [discounts]. * @@ -1183,6 +1318,7 @@ private constructor( private var startDate: JsonField? = null private var allocationPrice: JsonField = JsonMissing.of() + private var canDeferBilling: JsonField = JsonMissing.of() private var discounts: JsonField>? = null private var endDate: JsonField = JsonMissing.of() private var externalPriceId: JsonField = JsonMissing.of() @@ -1200,6 +1336,7 @@ private constructor( internal fun from(add: Add) = apply { startDate = add.startDate allocationPrice = add.allocationPrice + canDeferBilling = add.canDeferBilling discounts = add.discounts.map { it.toMutableList() } endDate = add.endDate externalPriceId = add.externalPriceId @@ -1254,6 +1391,33 @@ private constructor( this.allocationPrice = allocationPrice } + /** + * If true, an in-arrears price interval ending mid-cycle will defer billing the final + * line item until the next scheduled invoice. If false, it will be billed on its end + * date. + */ + fun canDeferBilling(canDeferBilling: Boolean?) = + canDeferBilling(JsonField.ofNullable(canDeferBilling)) + + /** + * Alias for [Builder.canDeferBilling]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun canDeferBilling(canDeferBilling: Boolean) = + canDeferBilling(canDeferBilling as Boolean?) + + /** + * Sets [Builder.canDeferBilling] to an arbitrary JSON value. + * + * You should usually call [Builder.canDeferBilling] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun canDeferBilling(canDeferBilling: JsonField) = apply { + this.canDeferBilling = canDeferBilling + } + /** A list of discounts to initialize on the price interval. */ fun discounts(discounts: List?) = discounts(JsonField.ofNullable(discounts)) @@ -1465,7 +1629,7 @@ private constructor( this.minimumAmount = minimumAmount } - /** The definition of a new price to create and add to the subscription. */ + /** New floating price request body params. */ fun price(price: Price?) = price(JsonField.ofNullable(price)) /** @@ -1480,32 +1644,21 @@ private constructor( /** Alias for calling [price] with `Price.ofUnit(unit)`. */ fun price(unit: NewFloatingUnitPrice) = price(Price.ofUnit(unit)) - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: NewFloatingPackagePrice) = price(Price.ofPackage(package_)) - - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: NewFloatingMatrixPrice) = price(Price.ofMatrix(matrix)) - - /** - * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. - */ - fun price(matrixWithAllocation: NewFloatingMatrixWithAllocationPrice) = - price(Price.ofMatrixWithAllocation(matrixWithAllocation)) - /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ fun price(tiered: NewFloatingTieredPrice) = price(Price.ofTiered(tiered)) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: NewFloatingTieredBpsPrice) = price(Price.ofTieredBps(tieredBps)) + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: NewFloatingBulkPrice) = price(Price.ofBulk(bulk)) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: NewFloatingBpsPrice) = price(Price.ofBps(bps)) + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: NewFloatingBulkBpsPrice) = price(Price.ofBulkBps(bulkBps)) + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: NewFloatingPackagePrice) = price(Price.ofPackage(package_)) - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: NewFloatingBulkPrice) = price(Price.ofBulk(bulk)) + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: NewFloatingMatrixPrice) = price(Price.ofMatrix(matrix)) /** * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. @@ -1517,20 +1670,20 @@ private constructor( fun price(tieredPackage: NewFloatingTieredPackagePrice) = price(Price.ofTieredPackage(tieredPackage)) + /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ + fun price(tieredWithMinimum: NewFloatingTieredWithMinimumPrice) = + price(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ fun price(groupedTiered: NewFloatingGroupedTieredPrice) = price(Price.ofGroupedTiered(groupedTiered)) /** * Alias for calling [price] with - * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. + * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. */ - fun price(maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice) = - price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) - - /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ - fun price(tieredWithMinimum: NewFloatingTieredWithMinimumPrice) = - price(Price.ofTieredWithMinimum(tieredWithMinimum)) + fun price(tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice) = + price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) /** * Alias for calling [price] with @@ -1539,17 +1692,16 @@ private constructor( fun price(packageWithAllocation: NewFloatingPackageWithAllocationPrice) = price(Price.ofPackageWithAllocation(packageWithAllocation)) - /** - * Alias for calling [price] with - * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. - */ - fun price(tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice) = - price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) - /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ fun price(unitWithPercent: NewFloatingUnitWithPercentPrice) = price(Price.ofUnitWithPercent(unitWithPercent)) + /** + * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun price(matrixWithAllocation: NewFloatingMatrixWithAllocationPrice) = + price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + /** * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. */ @@ -1564,6 +1716,10 @@ private constructor( fun price(groupedAllocation: NewFloatingGroupedAllocationPrice) = price(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: NewFloatingBulkWithProrationPrice) = + price(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [price] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -1578,6 +1734,13 @@ private constructor( fun price(groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice) = price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + /** * Alias for calling [price] with * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. @@ -1585,16 +1748,19 @@ private constructor( fun price(matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice) = price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: NewFloatingBulkWithProrationPrice) = - price(Price.ofBulkWithProration(bulkWithProration)) - /** * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. */ fun price(groupedTieredPackage: NewFloatingGroupedTieredPackagePrice) = price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + /** + * Alias for calling [price] with + * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. + */ + fun price(maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice) = + price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + /** * Alias for calling [price] with * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. @@ -1618,6 +1784,22 @@ private constructor( fun price(cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice) = price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + /** + * Alias for calling [price] with + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. + */ + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: NewFloatingMinimumCompositePrice) = price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) + /** The id of the price to add to the subscription. */ fun priceId(priceId: String?) = priceId(JsonField.ofNullable(priceId)) @@ -1699,6 +1881,7 @@ private constructor( Add( checkRequired("startDate", startDate), allocationPrice, + canDeferBilling, (discounts ?: JsonMissing.of()).map { it.toImmutable() }, endDate, externalPriceId, @@ -1722,6 +1905,7 @@ private constructor( startDate().validate() allocationPrice()?.validate() + canDeferBilling() discounts()?.forEach { it.validate() } endDate()?.validate() externalPriceId() @@ -1752,6 +1936,7 @@ private constructor( internal fun validity(): Int = (startDate.asKnown()?.validity() ?: 0) + (allocationPrice.asKnown()?.validity() ?: 0) + + (if (canDeferBilling.asKnown() == null) 0 else 1) + (discounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + (endDate.asKnown()?.validity() ?: 0) + (if (externalPriceId.asKnown() == null) 0 else 1) + @@ -1852,10 +2037,12 @@ private constructor( return true } - return /* spotless:off */ other is StartDate && dateTime == other.dateTime && billingCycleRelative == other.billingCycleRelative /* spotless:on */ + return other is StartDate && + dateTime == other.dateTime && + billingCycleRelative == other.billingCycleRelative } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(dateTime, billingCycleRelative) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(dateTime, billingCycleRelative) override fun toString(): String = when { @@ -2041,10 +2228,13 @@ private constructor( return true } - return /* spotless:off */ other is Discount && amount == other.amount && percentage == other.percentage && usage == other.usage /* spotless:on */ + return other is Discount && + amount == other.amount && + percentage == other.percentage && + usage == other.usage } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(amount, percentage, usage) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(amount, percentage, usage) override fun toString(): String = when { @@ -2137,6 +2327,7 @@ private constructor( } class Amount + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amountDiscount: JsonField, private val discountType: JsonValue, @@ -2335,12 +2526,15 @@ private constructor( return true } - return /* spotless:off */ other is Amount && amountDiscount == other.amountDiscount && discountType == other.discountType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Amount && + amountDiscount == other.amountDiscount && + discountType == other.discountType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amountDiscount, discountType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(amountDiscount, discountType, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2349,6 +2543,7 @@ private constructor( } class Percentage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val discountType: JsonValue, private val percentageDiscount: JsonField, @@ -2552,12 +2747,15 @@ private constructor( return true } - return /* spotless:off */ other is Percentage && discountType == other.discountType && percentageDiscount == other.percentageDiscount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Percentage && + discountType == other.discountType && + percentageDiscount == other.percentageDiscount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(discountType, percentageDiscount, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(discountType, percentageDiscount, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2566,6 +2764,7 @@ private constructor( } class Usage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val discountType: JsonValue, private val usageDiscount: JsonField, @@ -2768,12 +2967,15 @@ private constructor( return true } - return /* spotless:off */ other is Usage && discountType == other.discountType && usageDiscount == other.usageDiscount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Usage && + discountType == other.discountType && + usageDiscount == other.usageDiscount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(discountType, usageDiscount, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(discountType, usageDiscount, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2871,10 +3073,12 @@ private constructor( return true } - return /* spotless:off */ other is EndDate && dateTime == other.dateTime && billingCycleRelative == other.billingCycleRelative /* spotless:on */ + return other is EndDate && + dateTime == other.dateTime && + billingCycleRelative == other.billingCycleRelative } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(dateTime, billingCycleRelative) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(dateTime, billingCycleRelative) override fun toString(): String = when { @@ -2966,6 +3170,7 @@ private constructor( } class FixedFeeQuantityTransition + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val effectiveDate: JsonField, private val quantity: JsonField, @@ -3164,12 +3369,15 @@ private constructor( return true } - return /* spotless:off */ other is FixedFeeQuantityTransition && effectiveDate == other.effectiveDate && quantity == other.quantity && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FixedFeeQuantityTransition && + effectiveDate == other.effectiveDate && + quantity == other.quantity && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(effectiveDate, quantity, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(effectiveDate, quantity, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3177,38 +3385,37 @@ private constructor( "FixedFeeQuantityTransition{effectiveDate=$effectiveDate, quantity=$quantity, additionalProperties=$additionalProperties}" } - /** The definition of a new price to create and add to the subscription. */ + /** New floating price request body params. */ @JsonDeserialize(using = Price.Deserializer::class) @JsonSerialize(using = Price.Serializer::class) class Price private constructor( private val unit: NewFloatingUnitPrice? = null, - private val package_: NewFloatingPackagePrice? = null, - private val matrix: NewFloatingMatrixPrice? = null, - private val matrixWithAllocation: NewFloatingMatrixWithAllocationPrice? = null, private val tiered: NewFloatingTieredPrice? = null, - private val tieredBps: NewFloatingTieredBpsPrice? = null, - private val bps: NewFloatingBpsPrice? = null, - private val bulkBps: NewFloatingBulkBpsPrice? = null, private val bulk: NewFloatingBulkPrice? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: NewFloatingPackagePrice? = null, + private val matrix: NewFloatingMatrixPrice? = null, private val thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice? = null, private val tieredPackage: NewFloatingTieredPackagePrice? = null, - private val groupedTiered: NewFloatingGroupedTieredPrice? = null, - private val maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice? = null, private val tieredWithMinimum: NewFloatingTieredWithMinimumPrice? = null, - private val packageWithAllocation: NewFloatingPackageWithAllocationPrice? = null, + private val groupedTiered: NewFloatingGroupedTieredPrice? = null, private val tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice? = null, + private val packageWithAllocation: NewFloatingPackageWithAllocationPrice? = null, private val unitWithPercent: NewFloatingUnitWithPercentPrice? = null, + private val matrixWithAllocation: NewFloatingMatrixWithAllocationPrice? = null, private val tieredWithProration: NewFloatingTieredWithProrationPrice? = null, private val unitWithProration: NewFloatingUnitWithProrationPrice? = null, private val groupedAllocation: NewFloatingGroupedAllocationPrice? = null, + private val bulkWithProration: NewFloatingBulkWithProrationPrice? = null, private val groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice? = null, private val groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice? = null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, private val matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice? = null, - private val bulkWithProration: NewFloatingBulkWithProrationPrice? = null, private val groupedTieredPackage: NewFloatingGroupedTieredPackagePrice? = null, + private val maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice? = null, private val scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice? = null, @@ -3216,65 +3423,68 @@ private constructor( NewFloatingScalableMatrixWithTieredPricingPrice? = null, private val cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: NewFloatingMinimumCompositePrice? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, private val _json: JsonValue? = null, ) { fun unit(): NewFloatingUnitPrice? = unit - fun package_(): NewFloatingPackagePrice? = package_ - - fun matrix(): NewFloatingMatrixPrice? = matrix - - fun matrixWithAllocation(): NewFloatingMatrixWithAllocationPrice? = matrixWithAllocation - fun tiered(): NewFloatingTieredPrice? = tiered - fun tieredBps(): NewFloatingTieredBpsPrice? = tieredBps + fun bulk(): NewFloatingBulkPrice? = bulk - fun bps(): NewFloatingBpsPrice? = bps + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters - fun bulkBps(): NewFloatingBulkBpsPrice? = bulkBps + fun package_(): NewFloatingPackagePrice? = package_ - fun bulk(): NewFloatingBulkPrice? = bulk + fun matrix(): NewFloatingMatrixPrice? = matrix fun thresholdTotalAmount(): NewFloatingThresholdTotalAmountPrice? = thresholdTotalAmount fun tieredPackage(): NewFloatingTieredPackagePrice? = tieredPackage - fun groupedTiered(): NewFloatingGroupedTieredPrice? = groupedTiered - - fun maxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice? = - maxGroupTieredPackage - fun tieredWithMinimum(): NewFloatingTieredWithMinimumPrice? = tieredWithMinimum - fun packageWithAllocation(): NewFloatingPackageWithAllocationPrice? = - packageWithAllocation + fun groupedTiered(): NewFloatingGroupedTieredPrice? = groupedTiered fun tieredPackageWithMinimum(): NewFloatingTieredPackageWithMinimumPrice? = tieredPackageWithMinimum + fun packageWithAllocation(): NewFloatingPackageWithAllocationPrice? = + packageWithAllocation + fun unitWithPercent(): NewFloatingUnitWithPercentPrice? = unitWithPercent + fun matrixWithAllocation(): NewFloatingMatrixWithAllocationPrice? = matrixWithAllocation + fun tieredWithProration(): NewFloatingTieredWithProrationPrice? = tieredWithProration fun unitWithProration(): NewFloatingUnitWithProrationPrice? = unitWithProration fun groupedAllocation(): NewFloatingGroupedAllocationPrice? = groupedAllocation + fun bulkWithProration(): NewFloatingBulkWithProrationPrice? = bulkWithProration + fun groupedWithProratedMinimum(): NewFloatingGroupedWithProratedMinimumPrice? = groupedWithProratedMinimum fun groupedWithMeteredMinimum(): NewFloatingGroupedWithMeteredMinimumPrice? = groupedWithMeteredMinimum + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = + groupedWithMinMaxThresholds + fun matrixWithDisplayName(): NewFloatingMatrixWithDisplayNamePrice? = matrixWithDisplayName - fun bulkWithProration(): NewFloatingBulkWithProrationPrice? = bulkWithProration - fun groupedTieredPackage(): NewFloatingGroupedTieredPackagePrice? = groupedTieredPackage + fun maxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice? = + maxGroupTieredPackage + fun scalableMatrixWithUnitPricing(): NewFloatingScalableMatrixWithUnitPricingPrice? = scalableMatrixWithUnitPricing @@ -3284,56 +3494,63 @@ private constructor( fun cumulativeGroupedBulk(): NewFloatingCumulativeGroupedBulkPrice? = cumulativeGroupedBulk - fun isUnit(): Boolean = unit != null + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = + cumulativeGroupedAllocation - fun isPackage(): Boolean = package_ != null + fun minimum(): NewFloatingMinimumCompositePrice? = minimum - fun isMatrix(): Boolean = matrix != null + fun percent(): Percent? = percent - fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun eventOutput(): EventOutput? = eventOutput + + fun isUnit(): Boolean = unit != null fun isTiered(): Boolean = tiered != null - fun isTieredBps(): Boolean = tieredBps != null + fun isBulk(): Boolean = bulk != null - fun isBps(): Boolean = bps != null + fun isBulkWithFilters(): Boolean = bulkWithFilters != null - fun isBulkBps(): Boolean = bulkBps != null + fun isPackage(): Boolean = package_ != null - fun isBulk(): Boolean = bulk != null + fun isMatrix(): Boolean = matrix != null fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null fun isTieredPackage(): Boolean = tieredPackage != null - fun isGroupedTiered(): Boolean = groupedTiered != null - - fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null - fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null - fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + fun isGroupedTiered(): Boolean = groupedTiered != null fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + fun isUnitWithPercent(): Boolean = unitWithPercent != null + fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isTieredWithProration(): Boolean = tieredWithProration != null fun isUnitWithProration(): Boolean = unitWithProration != null fun isGroupedAllocation(): Boolean = groupedAllocation != null + fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null - fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null + fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null fun isScalableMatrixWithTieredPricing(): Boolean = @@ -3341,24 +3558,25 @@ private constructor( fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null - fun asUnit(): NewFloatingUnitPrice = unit.getOrThrow("unit") + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null - fun asPackage(): NewFloatingPackagePrice = package_.getOrThrow("package_") + fun isMinimum(): Boolean = minimum != null - fun asMatrix(): NewFloatingMatrixPrice = matrix.getOrThrow("matrix") + fun isPercent(): Boolean = percent != null - fun asMatrixWithAllocation(): NewFloatingMatrixWithAllocationPrice = - matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun isEventOutput(): Boolean = eventOutput != null + + fun asUnit(): NewFloatingUnitPrice = unit.getOrThrow("unit") fun asTiered(): NewFloatingTieredPrice = tiered.getOrThrow("tiered") - fun asTieredBps(): NewFloatingTieredBpsPrice = tieredBps.getOrThrow("tieredBps") + fun asBulk(): NewFloatingBulkPrice = bulk.getOrThrow("bulk") - fun asBps(): NewFloatingBpsPrice = bps.getOrThrow("bps") + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") - fun asBulkBps(): NewFloatingBulkBpsPrice = bulkBps.getOrThrow("bulkBps") + fun asPackage(): NewFloatingPackagePrice = package_.getOrThrow("package_") - fun asBulk(): NewFloatingBulkPrice = bulk.getOrThrow("bulk") + fun asMatrix(): NewFloatingMatrixPrice = matrix.getOrThrow("matrix") fun asThresholdTotalAmount(): NewFloatingThresholdTotalAmountPrice = thresholdTotalAmount.getOrThrow("thresholdTotalAmount") @@ -3366,23 +3584,23 @@ private constructor( fun asTieredPackage(): NewFloatingTieredPackagePrice = tieredPackage.getOrThrow("tieredPackage") - fun asGroupedTiered(): NewFloatingGroupedTieredPrice = - groupedTiered.getOrThrow("groupedTiered") - - fun asMaxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice = - maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") - fun asTieredWithMinimum(): NewFloatingTieredWithMinimumPrice = tieredWithMinimum.getOrThrow("tieredWithMinimum") - fun asPackageWithAllocation(): NewFloatingPackageWithAllocationPrice = - packageWithAllocation.getOrThrow("packageWithAllocation") + fun asGroupedTiered(): NewFloatingGroupedTieredPrice = + groupedTiered.getOrThrow("groupedTiered") fun asTieredPackageWithMinimum(): NewFloatingTieredPackageWithMinimumPrice = tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") - fun asUnitWithPercent(): NewFloatingUnitWithPercentPrice = - unitWithPercent.getOrThrow("unitWithPercent") + fun asPackageWithAllocation(): NewFloatingPackageWithAllocationPrice = + packageWithAllocation.getOrThrow("packageWithAllocation") + + fun asUnitWithPercent(): NewFloatingUnitWithPercentPrice = + unitWithPercent.getOrThrow("unitWithPercent") + + fun asMatrixWithAllocation(): NewFloatingMatrixWithAllocationPrice = + matrixWithAllocation.getOrThrow("matrixWithAllocation") fun asTieredWithProration(): NewFloatingTieredWithProrationPrice = tieredWithProration.getOrThrow("tieredWithProration") @@ -3393,21 +3611,27 @@ private constructor( fun asGroupedAllocation(): NewFloatingGroupedAllocationPrice = groupedAllocation.getOrThrow("groupedAllocation") + fun asBulkWithProration(): NewFloatingBulkWithProrationPrice = + bulkWithProration.getOrThrow("bulkWithProration") + fun asGroupedWithProratedMinimum(): NewFloatingGroupedWithProratedMinimumPrice = groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") fun asGroupedWithMeteredMinimum(): NewFloatingGroupedWithMeteredMinimumPrice = groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") + fun asMatrixWithDisplayName(): NewFloatingMatrixWithDisplayNamePrice = matrixWithDisplayName.getOrThrow("matrixWithDisplayName") - fun asBulkWithProration(): NewFloatingBulkWithProrationPrice = - bulkWithProration.getOrThrow("bulkWithProration") - fun asGroupedTieredPackage(): NewFloatingGroupedTieredPackagePrice = groupedTieredPackage.getOrThrow("groupedTieredPackage") + fun asMaxGroupTieredPackage(): NewFloatingMaxGroupTieredPackagePrice = + maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") + fun asScalableMatrixWithUnitPricing(): NewFloatingScalableMatrixWithUnitPricingPrice = scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") @@ -3418,45 +3642,54 @@ private constructor( fun asCumulativeGroupedBulk(): NewFloatingCumulativeGroupedBulkPrice = cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") + + fun asMinimum(): NewFloatingMinimumCompositePrice = minimum.getOrThrow("minimum") + + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") + fun _json(): JsonValue? = _json fun accept(visitor: Visitor): T = when { unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) - matrixWithAllocation != null -> - visitor.visitMatrixWithAllocation(matrixWithAllocation) tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) thresholdTotalAmount != null -> visitor.visitThresholdTotalAmount(thresholdTotalAmount) tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) - maxGroupTieredPackage != null -> - visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) - packageWithAllocation != null -> - visitor.visitPackageWithAllocation(packageWithAllocation) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) tieredPackageWithMinimum != null -> visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) + packageWithAllocation != null -> + visitor.visitPackageWithAllocation(packageWithAllocation) unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + matrixWithAllocation != null -> + visitor.visitMatrixWithAllocation(matrixWithAllocation) tieredWithProration != null -> visitor.visitTieredWithProration(tieredWithProration) unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedWithProratedMinimum != null -> visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) groupedWithMeteredMinimum != null -> visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) matrixWithDisplayName != null -> visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedTieredPackage != null -> visitor.visitGroupedTieredPackage(groupedTieredPackage) + maxGroupTieredPackage != null -> + visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) scalableMatrixWithUnitPricing != null -> visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) scalableMatrixWithTieredPricing != null -> @@ -3465,6 +3698,11 @@ private constructor( ) cumulativeGroupedBulk != null -> visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) else -> visitor.unknown(_json) } @@ -3481,38 +3719,24 @@ private constructor( unit.validate() } - override fun visitPackage(package_: NewFloatingPackagePrice) { - package_.validate() - } - - override fun visitMatrix(matrix: NewFloatingMatrixPrice) { - matrix.validate() - } - - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ) { - matrixWithAllocation.validate() - } - override fun visitTiered(tiered: NewFloatingTieredPrice) { tiered.validate() } - override fun visitTieredBps(tieredBps: NewFloatingTieredBpsPrice) { - tieredBps.validate() + override fun visitBulk(bulk: NewFloatingBulkPrice) { + bulk.validate() } - override fun visitBps(bps: NewFloatingBpsPrice) { - bps.validate() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() } - override fun visitBulkBps(bulkBps: NewFloatingBulkBpsPrice) { - bulkBps.validate() + override fun visitPackage(package_: NewFloatingPackagePrice) { + package_.validate() } - override fun visitBulk(bulk: NewFloatingBulkPrice) { - bulk.validate() + override fun visitMatrix(matrix: NewFloatingMatrixPrice) { + matrix.validate() } override fun visitThresholdTotalAmount( @@ -3527,28 +3751,16 @@ private constructor( tieredPackage.validate() } - override fun visitGroupedTiered( - groupedTiered: NewFloatingGroupedTieredPrice - ) { - groupedTiered.validate() - } - - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice - ) { - maxGroupTieredPackage.validate() - } - override fun visitTieredWithMinimum( tieredWithMinimum: NewFloatingTieredWithMinimumPrice ) { tieredWithMinimum.validate() } - override fun visitPackageWithAllocation( - packageWithAllocation: NewFloatingPackageWithAllocationPrice + override fun visitGroupedTiered( + groupedTiered: NewFloatingGroupedTieredPrice ) { - packageWithAllocation.validate() + groupedTiered.validate() } override fun visitTieredPackageWithMinimum( @@ -3557,12 +3769,24 @@ private constructor( tieredPackageWithMinimum.validate() } + override fun visitPackageWithAllocation( + packageWithAllocation: NewFloatingPackageWithAllocationPrice + ) { + packageWithAllocation.validate() + } + override fun visitUnitWithPercent( unitWithPercent: NewFloatingUnitWithPercentPrice ) { unitWithPercent.validate() } + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ) { + matrixWithAllocation.validate() + } + override fun visitTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ) { @@ -3581,6 +3805,12 @@ private constructor( groupedAllocation.validate() } + override fun visitBulkWithProration( + bulkWithProration: NewFloatingBulkWithProrationPrice + ) { + bulkWithProration.validate() + } + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ) { @@ -3593,16 +3823,16 @@ private constructor( groupedWithMeteredMinimum.validate() } - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds ) { - matrixWithDisplayName.validate() + groupedWithMinMaxThresholds.validate() } - override fun visitBulkWithProration( - bulkWithProration: NewFloatingBulkWithProrationPrice + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ) { - bulkWithProration.validate() + matrixWithDisplayName.validate() } override fun visitGroupedTieredPackage( @@ -3611,6 +3841,12 @@ private constructor( groupedTieredPackage.validate() } + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ) { + maxGroupTieredPackage.validate() + } + override fun visitScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice @@ -3630,6 +3866,24 @@ private constructor( ) { cumulativeGroupedBulk.validate() } + + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) { + cumulativeGroupedAllocation.validate() + } + + override fun visitMinimum(minimum: NewFloatingMinimumCompositePrice) { + minimum.validate() + } + + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() + } } ) validated = true @@ -3654,26 +3908,17 @@ private constructor( object : Visitor { override fun visitUnit(unit: NewFloatingUnitPrice) = unit.validity() - override fun visitPackage(package_: NewFloatingPackagePrice) = - package_.validity() - - override fun visitMatrix(matrix: NewFloatingMatrixPrice) = matrix.validity() - - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ) = matrixWithAllocation.validity() - override fun visitTiered(tiered: NewFloatingTieredPrice) = tiered.validity() - override fun visitTieredBps(tieredBps: NewFloatingTieredBpsPrice) = - tieredBps.validity() + override fun visitBulk(bulk: NewFloatingBulkPrice) = bulk.validity() - override fun visitBps(bps: NewFloatingBpsPrice) = bps.validity() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() - override fun visitBulkBps(bulkBps: NewFloatingBulkBpsPrice) = - bulkBps.validity() + override fun visitPackage(package_: NewFloatingPackagePrice) = + package_.validity() - override fun visitBulk(bulk: NewFloatingBulkPrice) = bulk.validity() + override fun visitMatrix(matrix: NewFloatingMatrixPrice) = matrix.validity() override fun visitThresholdTotalAmount( thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice @@ -3683,30 +3928,30 @@ private constructor( tieredPackage: NewFloatingTieredPackagePrice ) = tieredPackage.validity() - override fun visitGroupedTiered( - groupedTiered: NewFloatingGroupedTieredPrice - ) = groupedTiered.validity() - - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice - ) = maxGroupTieredPackage.validity() - override fun visitTieredWithMinimum( tieredWithMinimum: NewFloatingTieredWithMinimumPrice ) = tieredWithMinimum.validity() - override fun visitPackageWithAllocation( - packageWithAllocation: NewFloatingPackageWithAllocationPrice - ) = packageWithAllocation.validity() + override fun visitGroupedTiered( + groupedTiered: NewFloatingGroupedTieredPrice + ) = groupedTiered.validity() override fun visitTieredPackageWithMinimum( tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice ) = tieredPackageWithMinimum.validity() + override fun visitPackageWithAllocation( + packageWithAllocation: NewFloatingPackageWithAllocationPrice + ) = packageWithAllocation.validity() + override fun visitUnitWithPercent( unitWithPercent: NewFloatingUnitWithPercentPrice ) = unitWithPercent.validity() + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ) = matrixWithAllocation.validity() + override fun visitTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ) = tieredWithProration.validity() @@ -3719,6 +3964,10 @@ private constructor( groupedAllocation: NewFloatingGroupedAllocationPrice ) = groupedAllocation.validity() + override fun visitBulkWithProration( + bulkWithProration: NewFloatingBulkWithProrationPrice + ) = bulkWithProration.validity() + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ) = groupedWithProratedMinimum.validity() @@ -3727,18 +3976,22 @@ private constructor( groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice ) = groupedWithMeteredMinimum.validity() + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + override fun visitMatrixWithDisplayName( matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ) = matrixWithDisplayName.validity() - override fun visitBulkWithProration( - bulkWithProration: NewFloatingBulkWithProrationPrice - ) = bulkWithProration.validity() - override fun visitGroupedTieredPackage( groupedTieredPackage: NewFloatingGroupedTieredPackagePrice ) = groupedTieredPackage.validity() + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ) = maxGroupTieredPackage.validity() + override fun visitScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice @@ -3753,6 +4006,18 @@ private constructor( cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice ) = cumulativeGroupedBulk.validity() + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() + + override fun visitMinimum(minimum: NewFloatingMinimumCompositePrice) = + minimum.validity() + + override fun visitPercent(percent: Percent) = percent.validity() + + override fun visitEventOutput(eventOutput: EventOutput) = + eventOutput.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -3762,53 +4027,122 @@ private constructor( return true } - return /* spotless:off */ other is Price && unit == other.unit && package_ == other.package_ && matrix == other.matrix && matrixWithAllocation == other.matrixWithAllocation && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && groupedTiered == other.groupedTiered && maxGroupTieredPackage == other.maxGroupTieredPackage && tieredWithMinimum == other.tieredWithMinimum && packageWithAllocation == other.packageWithAllocation && tieredPackageWithMinimum == other.tieredPackageWithMinimum && unitWithPercent == other.unitWithPercent && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && bulkWithProration == other.bulkWithProration && groupedTieredPackage == other.groupedTieredPackage && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, matrixWithAllocation, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, groupedTiered, maxGroupTieredPackage, tieredWithMinimum, packageWithAllocation, tieredPackageWithMinimum, unitWithPercent, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, groupedWithMeteredMinimum, matrixWithDisplayName, bulkWithProration, groupedTieredPackage, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk) /* spotless:on */ + return other is Price && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput + } + + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) override fun toString(): String = when { unit != null -> "Price{unit=$unit}" - package_ != null -> "Price{package_=$package_}" - matrix != null -> "Price{matrix=$matrix}" - matrixWithAllocation != null -> - "Price{matrixWithAllocation=$matrixWithAllocation}" tiered != null -> "Price{tiered=$tiered}" - tieredBps != null -> "Price{tieredBps=$tieredBps}" - bps != null -> "Price{bps=$bps}" - bulkBps != null -> "Price{bulkBps=$bulkBps}" bulk != null -> "Price{bulk=$bulk}" + bulkWithFilters != null -> "Price{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "Price{package_=$package_}" + matrix != null -> "Price{matrix=$matrix}" thresholdTotalAmount != null -> "Price{thresholdTotalAmount=$thresholdTotalAmount}" tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" - groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" - maxGroupTieredPackage != null -> - "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" - packageWithAllocation != null -> - "Price{packageWithAllocation=$packageWithAllocation}" + groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" tieredPackageWithMinimum != null -> "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" + packageWithAllocation != null -> + "Price{packageWithAllocation=$packageWithAllocation}" unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + matrixWithAllocation != null -> + "Price{matrixWithAllocation=$matrixWithAllocation}" tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedWithProratedMinimum != null -> "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" groupedWithMeteredMinimum != null -> "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "Price{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" matrixWithDisplayName != null -> "Price{matrixWithDisplayName=$matrixWithDisplayName}" - bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedTieredPackage != null -> "Price{groupedTieredPackage=$groupedTieredPackage}" + maxGroupTieredPackage != null -> + "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" scalableMatrixWithUnitPricing != null -> "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" scalableMatrixWithTieredPricing != null -> "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" cumulativeGroupedBulk != null -> "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" + cumulativeGroupedAllocation != null -> + "Price{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "Price{minimum=$minimum}" + percent != null -> "Price{percent=$percent}" + eventOutput != null -> "Price{eventOutput=$eventOutput}" _json != null -> "Price{_unknown=$_json}" else -> throw IllegalStateException("Invalid Price") } @@ -3817,23 +4151,16 @@ private constructor( fun ofUnit(unit: NewFloatingUnitPrice) = Price(unit = unit) - fun ofPackage(package_: NewFloatingPackagePrice) = Price(package_ = package_) - - fun ofMatrix(matrix: NewFloatingMatrixPrice) = Price(matrix = matrix) - - fun ofMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ) = Price(matrixWithAllocation = matrixWithAllocation) - fun ofTiered(tiered: NewFloatingTieredPrice) = Price(tiered = tiered) - fun ofTieredBps(tieredBps: NewFloatingTieredBpsPrice) = Price(tieredBps = tieredBps) + fun ofBulk(bulk: NewFloatingBulkPrice) = Price(bulk = bulk) - fun ofBps(bps: NewFloatingBpsPrice) = Price(bps = bps) + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + Price(bulkWithFilters = bulkWithFilters) - fun ofBulkBps(bulkBps: NewFloatingBulkBpsPrice) = Price(bulkBps = bulkBps) + fun ofPackage(package_: NewFloatingPackagePrice) = Price(package_ = package_) - fun ofBulk(bulk: NewFloatingBulkPrice) = Price(bulk = bulk) + fun ofMatrix(matrix: NewFloatingMatrixPrice) = Price(matrix = matrix) fun ofThresholdTotalAmount( thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice @@ -3842,27 +4169,27 @@ private constructor( fun ofTieredPackage(tieredPackage: NewFloatingTieredPackagePrice) = Price(tieredPackage = tieredPackage) - fun ofGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice) = - Price(groupedTiered = groupedTiered) - - fun ofMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice - ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) - fun ofTieredWithMinimum(tieredWithMinimum: NewFloatingTieredWithMinimumPrice) = Price(tieredWithMinimum = tieredWithMinimum) - fun ofPackageWithAllocation( - packageWithAllocation: NewFloatingPackageWithAllocationPrice - ) = Price(packageWithAllocation = packageWithAllocation) + fun ofGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice) = + Price(groupedTiered = groupedTiered) fun ofTieredPackageWithMinimum( tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + fun ofPackageWithAllocation( + packageWithAllocation: NewFloatingPackageWithAllocationPrice + ) = Price(packageWithAllocation = packageWithAllocation) + fun ofUnitWithPercent(unitWithPercent: NewFloatingUnitWithPercentPrice) = Price(unitWithPercent = unitWithPercent) + fun ofMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ) = Price(matrixWithAllocation = matrixWithAllocation) + fun ofTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ) = Price(tieredWithProration = tieredWithProration) @@ -3873,6 +4200,9 @@ private constructor( fun ofGroupedAllocation(groupedAllocation: NewFloatingGroupedAllocationPrice) = Price(groupedAllocation = groupedAllocation) + fun ofBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice) = + Price(bulkWithProration = bulkWithProration) + fun ofGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) @@ -3881,17 +4211,22 @@ private constructor( groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = Price(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + fun ofMatrixWithDisplayName( matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ) = Price(matrixWithDisplayName = matrixWithDisplayName) - fun ofBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice) = - Price(bulkWithProration = bulkWithProration) - fun ofGroupedTieredPackage( groupedTieredPackage: NewFloatingGroupedTieredPackagePrice ) = Price(groupedTieredPackage = groupedTieredPackage) + fun ofMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) + fun ofScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice ) = Price(scalableMatrixWithUnitPricing = scalableMatrixWithUnitPricing) @@ -3903,6 +4238,16 @@ private constructor( fun ofCumulativeGroupedBulk( cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) + + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = Price(cumulativeGroupedAllocation = cumulativeGroupedAllocation) + + fun ofMinimum(minimum: NewFloatingMinimumCompositePrice) = Price(minimum = minimum) + + fun ofPercent(percent: Percent) = Price(percent = percent) + + fun ofEventOutput(eventOutput: EventOutput) = Price(eventOutput = eventOutput) } /** @@ -3912,48 +4257,40 @@ private constructor( fun visitUnit(unit: NewFloatingUnitPrice): T + fun visitTiered(tiered: NewFloatingTieredPrice): T + + fun visitBulk(bulk: NewFloatingBulkPrice): T + + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T + fun visitPackage(package_: NewFloatingPackagePrice): T fun visitMatrix(matrix: NewFloatingMatrixPrice): T - fun visitMatrixWithAllocation( - matrixWithAllocation: NewFloatingMatrixWithAllocationPrice - ): T - - fun visitTiered(tiered: NewFloatingTieredPrice): T - - fun visitTieredBps(tieredBps: NewFloatingTieredBpsPrice): T - - fun visitBps(bps: NewFloatingBpsPrice): T - - fun visitBulkBps(bulkBps: NewFloatingBulkBpsPrice): T - - fun visitBulk(bulk: NewFloatingBulkPrice): T - fun visitThresholdTotalAmount( thresholdTotalAmount: NewFloatingThresholdTotalAmountPrice ): T fun visitTieredPackage(tieredPackage: NewFloatingTieredPackagePrice): T + fun visitTieredWithMinimum(tieredWithMinimum: NewFloatingTieredWithMinimumPrice): T + fun visitGroupedTiered(groupedTiered: NewFloatingGroupedTieredPrice): T - fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice ): T - fun visitTieredWithMinimum(tieredWithMinimum: NewFloatingTieredWithMinimumPrice): T - fun visitPackageWithAllocation( packageWithAllocation: NewFloatingPackageWithAllocationPrice ): T - fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewFloatingTieredPackageWithMinimumPrice - ): T - fun visitUnitWithPercent(unitWithPercent: NewFloatingUnitWithPercentPrice): T + fun visitMatrixWithAllocation( + matrixWithAllocation: NewFloatingMatrixWithAllocationPrice + ): T + fun visitTieredWithProration( tieredWithProration: NewFloatingTieredWithProrationPrice ): T @@ -3962,6 +4299,8 @@ private constructor( fun visitGroupedAllocation(groupedAllocation: NewFloatingGroupedAllocationPrice): T + fun visitBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice): T + fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewFloatingGroupedWithProratedMinimumPrice ): T @@ -3970,16 +4309,22 @@ private constructor( groupedWithMeteredMinimum: NewFloatingGroupedWithMeteredMinimumPrice ): T + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ): T + fun visitMatrixWithDisplayName( matrixWithDisplayName: NewFloatingMatrixWithDisplayNamePrice ): T - fun visitBulkWithProration(bulkWithProration: NewFloatingBulkWithProrationPrice): T - fun visitGroupedTieredPackage( groupedTieredPackage: NewFloatingGroupedTieredPackagePrice ): T + fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewFloatingMaxGroupTieredPackagePrice + ): T + fun visitScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewFloatingScalableMatrixWithUnitPricingPrice ): T @@ -3992,6 +4337,16 @@ private constructor( cumulativeGroupedBulk: NewFloatingCumulativeGroupedBulkPrice ): T + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ): T + + fun visitMinimum(minimum: NewFloatingMinimumCompositePrice): T + + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T + /** * Maps an unknown variant of [Price] to a value of type [T]. * @@ -4018,42 +4373,27 @@ private constructor( return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(unit = it, _json = json) } ?: Price(_json = json) } - "package" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) - } - "matrix" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) - } - "matrix_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithAllocation = it, _json = json) } - ?: Price(_json = json) - } "tiered" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(tiered = it, _json = json) } ?: Price(_json = json) } - "tiered_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(tieredBps = it, _json = json) } ?: Price(_json = json) - } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bps = it, _json = json) } ?: Price(_json = json) - } - "bulk_bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bulkBps = it, _json = json) } ?: Price(_json = json) - } "bulk" -> { return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(bulk = it, _json = json) } ?: Price(_json = json) } + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulkWithFilters = it, _json = json) + } ?: Price(_json = json) + } + "package" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) + } + "matrix" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) + } "threshold_total_amount" -> { return tryDeserialize( node, @@ -4070,28 +4410,28 @@ private constructor( ?.let { Price(tieredPackage = it, _json = json) } ?: Price(_json = json) } - "grouped_tiered" -> { + "tiered_with_minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(groupedTiered = it, _json = json) } + ?.let { Price(tieredWithMinimum = it, _json = json) } ?: Price(_json = json) } - "max_group_tiered_package" -> { + "grouped_tiered" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(maxGroupTieredPackage = it, _json = json) } + ?.let { Price(groupedTiered = it, _json = json) } ?: Price(_json = json) } - "tiered_with_minimum" -> { + "tiered_package_with_minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(tieredWithMinimum = it, _json = json) } + ?.let { Price(tieredPackageWithMinimum = it, _json = json) } ?: Price(_json = json) } "package_with_allocation" -> { @@ -4102,20 +4442,20 @@ private constructor( ?.let { Price(packageWithAllocation = it, _json = json) } ?: Price(_json = json) } - "tiered_package_with_minimum" -> { + "unit_with_percent" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(tieredPackageWithMinimum = it, _json = json) } + ?.let { Price(unitWithPercent = it, _json = json) } ?: Price(_json = json) } - "unit_with_percent" -> { + "matrix_with_allocation" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(unitWithPercent = it, _json = json) } + ?.let { Price(matrixWithAllocation = it, _json = json) } ?: Price(_json = json) } "tiered_with_proration" -> { @@ -4142,6 +4482,14 @@ private constructor( ?.let { Price(groupedAllocation = it, _json = json) } ?: Price(_json = json) } + "bulk_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(bulkWithProration = it, _json = json) } + ?: Price(_json = json) + } "grouped_with_prorated_minimum" -> { return tryDeserialize( node, @@ -4158,20 +4506,20 @@ private constructor( ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } ?: Price(_json = json) } - "matrix_with_display_name" -> { + "grouped_with_min_max_thresholds" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(matrixWithDisplayName = it, _json = json) } + ?.let { Price(groupedWithMinMaxThresholds = it, _json = json) } ?: Price(_json = json) } - "bulk_with_proration" -> { + "matrix_with_display_name" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(bulkWithProration = it, _json = json) } + ?.let { Price(matrixWithDisplayName = it, _json = json) } ?: Price(_json = json) } "grouped_tiered_package" -> { @@ -4182,6 +4530,14 @@ private constructor( ?.let { Price(groupedTieredPackage = it, _json = json) } ?: Price(_json = json) } + "max_group_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(maxGroupTieredPackage = it, _json = json) } + ?: Price(_json = json) + } "scalable_matrix_with_unit_pricing" -> { return tryDeserialize( node, @@ -4208,6 +4564,31 @@ private constructor( ?.let { Price(cumulativeGroupedBulk = it, _json = json) } ?: Price(_json = json) } + "cumulative_grouped_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(cumulativeGroupedAllocation = it, _json = json) } + ?: Price(_json = json) + } + "minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(minimum = it, _json = json) } ?: Price(_json = json) + } + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(percent = it, _json = json) + } ?: Price(_json = json) + } + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(eventOutput = it, _json = json) + } ?: Price(_json = json) + } } return Price(_json = json) @@ -4223,113 +4604,8489 @@ private constructor( ) { when { value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) - value.matrixWithAllocation != null -> - generator.writeObject(value.matrixWithAllocation) value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> + generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) value.thresholdTotalAmount != null -> generator.writeObject(value.thresholdTotalAmount) value.tieredPackage != null -> generator.writeObject(value.tieredPackage) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) - value.maxGroupTieredPackage != null -> - generator.writeObject(value.maxGroupTieredPackage) value.tieredWithMinimum != null -> generator.writeObject(value.tieredWithMinimum) - value.packageWithAllocation != null -> - generator.writeObject(value.packageWithAllocation) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) value.tieredPackageWithMinimum != null -> generator.writeObject(value.tieredPackageWithMinimum) + value.packageWithAllocation != null -> + generator.writeObject(value.packageWithAllocation) value.unitWithPercent != null -> generator.writeObject(value.unitWithPercent) + value.matrixWithAllocation != null -> + generator.writeObject(value.matrixWithAllocation) value.tieredWithProration != null -> generator.writeObject(value.tieredWithProration) value.unitWithProration != null -> generator.writeObject(value.unitWithProration) value.groupedAllocation != null -> generator.writeObject(value.groupedAllocation) + value.bulkWithProration != null -> + generator.writeObject(value.bulkWithProration) value.groupedWithProratedMinimum != null -> generator.writeObject(value.groupedWithProratedMinimum) value.groupedWithMeteredMinimum != null -> generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) value.matrixWithDisplayName != null -> generator.writeObject(value.matrixWithDisplayName) - value.bulkWithProration != null -> - generator.writeObject(value.bulkWithProration) value.groupedTieredPackage != null -> generator.writeObject(value.groupedTieredPackage) + value.maxGroupTieredPackage != null -> + generator.writeObject(value.maxGroupTieredPackage) value.scalableMatrixWithUnitPricing != null -> generator.writeObject(value.scalableMatrixWithUnitPricing) value.scalableMatrixWithTieredPricing != null -> generator.writeObject(value.scalableMatrixWithTieredPricing) value.cumulativeGroupedBulk != null -> generator.writeObject(value.cumulativeGroupedBulk) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Price") } } } - } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bulkWithFiltersConfig: JsonField, + private val cadence: JsonField, + private val currency: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { - return /* spotless:off */ other is Add && startDate == other.startDate && allocationPrice == other.allocationPrice && discounts == other.discounts && endDate == other.endDate && externalPriceId == other.externalPriceId && filter == other.filter && fixedFeeQuantityTransitions == other.fixedFeeQuantityTransitions && maximumAmount == other.maximumAmount && minimumAmount == other.minimumAmount && price == other.price && priceId == other.priceId && usageCustomerIds == other.usageCustomerIds && additionalProperties == other.additionalProperties /* spotless:on */ - } + @JsonCreator + private constructor( + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + bulkWithFiltersConfig, + cadence, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(startDate, allocationPrice, discounts, endDate, externalPriceId, filter, fixedFeeQuantityTransitions, maximumAmount, minimumAmount, price, priceId, usageCustomerIds, additionalProperties) } - /* spotless:on */ + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") - override fun hashCode(): Int = hashCode + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - override fun toString() = - "Add{startDate=$startDate, allocationPrice=$allocationPrice, discounts=$discounts, endDate=$endDate, externalPriceId=$externalPriceId, filter=$filter, fixedFeeQuantityTransitions=$fixedFeeQuantityTransitions, maximumAmount=$maximumAmount, minimumAmount=$minimumAmount, price=$price, priceId=$priceId, usageCustomerIds=$usageCustomerIds, additionalProperties=$additionalProperties}" - } + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") - class AddAdjustment - private constructor( - private val adjustment: JsonField, - private val startDate: JsonField, - private val endDate: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - @JsonCreator - private constructor( - @JsonProperty("adjustment") - @ExcludeMissing - adjustment: JsonField = JsonMissing.of(), - @JsonProperty("start_date") - @ExcludeMissing - startDate: JsonField = JsonMissing.of(), - @JsonProperty("end_date") @ExcludeMissing endDate: JsonField = JsonMissing.of(), - ) : this(adjustment, startDate, endDate, mutableMapOf()) + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - /** - * The definition of a new adjustment to create and add to the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun adjustment(): Adjustment = adjustment.getRequired("adjustment") + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - /** - * The start date of the adjustment interval. This is the date that the adjustment will - * start affecting prices on the subscription. The adjustment will apply to invoice dates - * that overlap with this `start_date`. This `start_date` is treated as inclusive for + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = + bulkWithFiltersConfig + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [BulkWithFilters]. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .currency() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFilters]. */ + class Builder internal constructor() { + + private var bulkWithFiltersConfig: JsonField? = null + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + currency = bulkWithFilters.currency + itemId = bulkWithFilters.itemId + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + billableMetricId = bulkWithFilters.billableMetricId + billedInAdvance = bulkWithFilters.billedInAdvance + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + dimensionalPriceConfiguration = + bulkWithFilters.dimensionalPriceConfiguration + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoiceGroupingKey = bulkWithFilters.invoiceGroupingKey + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + metadata = bulkWithFilters.metadata + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() + } + + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig( + bulkWithFiltersConfig: JsonField + ) = apply { this.bulkWithFiltersConfig = bulkWithFiltersConfig } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BulkWithFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .currency() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFilters = + BulkWithFilters( + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFilters = apply { + if (validated) { + return@apply + } + + bulkWithFiltersConfig().validate() + cadence().validate() + currency() + itemId() + _modelType().let { + if (it != JsonValue.from("bulk_with_filters")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) + + /** + * Property filters to apply (all must match) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [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 + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { + + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithFiltersConfig.additionalProperties.toMutableMap() + } + + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + + /** Bulk tiers for rating based on total usage volume */ + 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 [BulkWithFiltersConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } + + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = + propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + propertyKey() + propertyValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = + tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filters, tiers, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFilters && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bulkWithFiltersConfig, + cadence, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFilters{bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val currency: JsonField, + private val groupedWithMinMaxThresholdsConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + groupedWithMinMaxThresholdsConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + currency, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * Configuration for grouped_with_min_max_thresholds pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired( + "grouped_with_min_max_thresholds_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. + * + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + fun _groupedWithMinMaxThresholdsConfig(): + JsonField = groupedWithMinMaxThresholdsConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 + * [GroupedWithMinMaxThresholds]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholds]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("grouped_with_min_max_thresholds") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = + apply { + cadence = groupedWithMinMaxThresholds.cadence + currency = groupedWithMinMaxThresholds.currency + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + itemId = groupedWithMinMaxThresholds.itemId + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + billableMetricId = groupedWithMinMaxThresholds.billableMetricId + billedInAdvance = groupedWithMinMaxThresholds.billedInAdvance + billingCycleConfiguration = + groupedWithMinMaxThresholds.billingCycleConfiguration + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + invoiceGroupingKey = groupedWithMinMaxThresholds.invoiceGroupingKey + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + metadata = groupedWithMinMaxThresholds.metadata + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = + groupedWithMinMaxThresholdsConfig( + JsonField.of(groupedWithMinMaxThresholdsConfig) + ) + + /** + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a + * well-typed [GroupedWithMinMaxThresholdsConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: + JsonField + ) = apply { + this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholds = apply { + if (validated) { + return@apply + } + + cadence().validate() + currency() + groupedWithMinMaxThresholdsConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @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 + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate + additionalProperties = + groupedWithMinMaxThresholdsConfig.additionalProperties + .toMutableMap() + } + + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } + + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } + + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = + perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + if (validated) { + return@apply + } + + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholds && + cadence == other.cadence && + currency == other.currency && + groupedWithMinMaxThresholdsConfig == + other.groupedWithMinMaxThresholdsConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholds{cadence=$cadence, currency=$currency, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val cumulativeGroupedAllocationConfig: + JsonField, + private val currency: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + cumulativeGroupedAllocationConfig, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for cumulative_grouped_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired( + "cumulative_grouped_allocation_config" + ) + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): + JsonField = cumulativeGroupedAllocationConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 + * [CumulativeGroupedAllocation]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .currency() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocation]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null + private var currency: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("cumulative_grouped_allocation") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = + apply { + cadence = cumulativeGroupedAllocation.cadence + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + currency = cumulativeGroupedAllocation.currency + itemId = cumulativeGroupedAllocation.itemId + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + billableMetricId = cumulativeGroupedAllocation.billableMetricId + billedInAdvance = cumulativeGroupedAllocation.billedInAdvance + billingCycleConfiguration = + cumulativeGroupedAllocation.billingCycleConfiguration + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoiceGroupingKey = cumulativeGroupedAllocation.invoiceGroupingKey + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + metadata = cumulativeGroupedAllocation.metadata + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = + cumulativeGroupedAllocationConfig( + JsonField.of(cumulativeGroupedAllocationConfig) + ) + + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a + * well-typed [CumulativeGroupedAllocationConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: + JsonField + ) = apply { + this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig + } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .currency() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( + checkRequired("cadence", cadence), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), + checkRequired("currency", currency), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocation = apply { + if (validated) { + return@apply + } + + cadence().validate() + cumulativeGroupedAllocationConfig().validate() + currency() + itemId() + _modelType().let { + if (it != JsonValue.from("cumulative_grouped_allocation")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + mutableMapOf(), + ) + + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 + * [CumulativeGroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = + cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties + .toMutableMap() + } + + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } + + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation + } + + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply + } + + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocation && + cadence == other.cadence && + cumulativeGroupedAllocationConfig == + other.cumulativeGroupedAllocationConfig && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedAllocationConfig, + currency, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocation{cadence=$cadence, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val currency: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val percentConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + currency, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [Percent]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .itemId() + * .name() + * .percentConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Percent]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("percent") + private var name: JsonField? = null + private var percentConfig: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percent: Percent) = apply { + cadence = percent.cadence + currency = percent.currency + itemId = percent.itemId + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + billableMetricId = percent.billableMetricId + billedInAdvance = percent.billedInAdvance + billingCycleConfiguration = percent.billingCycleConfiguration + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoiceGroupingKey = percent.invoiceGroupingKey + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + metadata = percent.metadata + additionalProperties = percent.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed + * [PercentConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Percent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .itemId() + * .name() + * .percentConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Percent = + Percent( + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("percentConfig", percentConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Percent = apply { + if (validated) { + return@apply + } + + cadence().validate() + currency() + itemId() + _modelType().let { + if (it != JsonValue.from("percent")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + percentConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent") + @ExcludeMissing + fun _percent(): JsonField = percent + + @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 + * [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PercentConfig]. */ + class Builder internal constructor() { + + private var percent: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() + } + + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PercentConfig = apply { + if (validated) { + return@apply + } + + percent() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(percent, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Percent && + cadence == other.cadence && + currency == other.currency && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Percent{cadence=$cadence, currency=$currency, itemId=$itemId, modelType=$modelType, name=$name, percentConfig=$percentConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val currency: JsonField, + private val eventOutputConfig: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this( + cadence, + currency, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * An ISO 4217 currency string for which this price is billed in. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currency(): String = currency.getRequired("currency") + + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [EventOutput]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutput]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var currency: JsonField? = null + private var eventOutputConfig: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("event_output") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutput: EventOutput) = apply { + cadence = eventOutput.cadence + currency = eventOutput.currency + eventOutputConfig = eventOutput.eventOutputConfig + itemId = eventOutput.itemId + modelType = eventOutput.modelType + name = eventOutput.name + billableMetricId = eventOutput.billableMetricId + billedInAdvance = eventOutput.billedInAdvance + billingCycleConfiguration = eventOutput.billingCycleConfiguration + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoiceGroupingKey = eventOutput.invoiceGroupingKey + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + metadata = eventOutput.metadata + additionalProperties = eventOutput.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** An ISO 4217 currency string for which this price is billed in. */ + fun currency(currency: String) = currency(JsonField.of(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .currency() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutput = + EventOutput( + checkRequired("cadence", cadence), + checkRequired("currency", currency), + checkRequired("eventOutputConfig", eventOutputConfig), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutput = apply { + if (validated) { + return@apply + } + + cadence().validate() + currency() + eventOutputConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("event_output")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a + * unit rate will be ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = + defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events + * will also be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @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 + * [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutputConfig]. */ + class Builder internal constructor() { + + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = + eventOutputConfig.additionalProperties.toMutableMap() + } + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey + } + + /** + * If provided, this amount will be used as the unit rate when an event does + * not have a value for the `unit_rating_key`. If not provided, events + * missing a unit rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate + } + + /** + * An optional key in the event data to group by (e.g., event ID). All + * events will also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutputConfig = apply { + if (validated) { + return@apply + } + + unitRatingKey() + defaultUnitRate() + groupingKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + unitRatingKey, + defaultUnitRate, + groupingKey, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutput && + cadence == other.cadence && + currency == other.currency && + eventOutputConfig == other.eventOutputConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + currency, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutput{cadence=$cadence, currency=$currency, eventOutputConfig=$eventOutputConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Add && + startDate == other.startDate && + allocationPrice == other.allocationPrice && + canDeferBilling == other.canDeferBilling && + discounts == other.discounts && + endDate == other.endDate && + externalPriceId == other.externalPriceId && + filter == other.filter && + fixedFeeQuantityTransitions == other.fixedFeeQuantityTransitions && + maximumAmount == other.maximumAmount && + minimumAmount == other.minimumAmount && + price == other.price && + priceId == other.priceId && + usageCustomerIds == other.usageCustomerIds && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + startDate, + allocationPrice, + canDeferBilling, + discounts, + endDate, + externalPriceId, + filter, + fixedFeeQuantityTransitions, + maximumAmount, + minimumAmount, + price, + priceId, + usageCustomerIds, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Add{startDate=$startDate, allocationPrice=$allocationPrice, canDeferBilling=$canDeferBilling, discounts=$discounts, endDate=$endDate, externalPriceId=$externalPriceId, filter=$filter, fixedFeeQuantityTransitions=$fixedFeeQuantityTransitions, maximumAmount=$maximumAmount, minimumAmount=$minimumAmount, price=$price, priceId=$priceId, usageCustomerIds=$usageCustomerIds, additionalProperties=$additionalProperties}" + } + + class AddAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val startDate: JsonField, + private val adjustment: JsonField, + private val adjustmentId: JsonField, + private val endDate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("start_date") + @ExcludeMissing + startDate: JsonField = JsonMissing.of(), + @JsonProperty("adjustment") + @ExcludeMissing + adjustment: JsonField = JsonMissing.of(), + @JsonProperty("adjustment_id") + @ExcludeMissing + adjustmentId: JsonField = JsonMissing.of(), + @JsonProperty("end_date") @ExcludeMissing endDate: JsonField = JsonMissing.of(), + ) : this(startDate, adjustment, adjustmentId, endDate, mutableMapOf()) + + /** + * The start date of the adjustment interval. This is the date that the adjustment will + * start affecting prices on the subscription. The adjustment will apply to invoice dates + * that overlap with this `start_date`. This `start_date` is treated as inclusive for * in-advance prices, and exclusive for in-arrears prices. * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun startDate(): StartDate = startDate.getRequired("start_date") + + /** + * The definition of a new adjustment to create and add to the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun startDate(): StartDate = startDate.getRequired("start_date") + fun adjustment(): Adjustment? = adjustment.getNullable("adjustment") + + /** + * The ID of the adjustment to add to the subscription. Adjustment IDs can be re-used from + * existing subscriptions or plans, but adjustments associated with coupon redemptions + * cannot be re-used. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun adjustmentId(): String? = adjustmentId.getNullable("adjustment_id") /** * The end date of the adjustment interval. This is the date that the adjustment will stop @@ -4342,6 +13099,15 @@ private constructor( */ fun endDate(): EndDate? = endDate.getNullable("end_date") + /** + * Returns the raw JSON value of [startDate]. + * + * Unlike [startDate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("start_date") + @ExcludeMissing + fun _startDate(): JsonField = startDate + /** * Returns the raw JSON value of [adjustment]. * @@ -4352,13 +13118,14 @@ private constructor( fun _adjustment(): JsonField = adjustment /** - * Returns the raw JSON value of [startDate]. + * Returns the raw JSON value of [adjustmentId]. * - * Unlike [startDate], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [adjustmentId], this method doesn't throw if the JSON field has an unexpected + * type. */ - @JsonProperty("start_date") + @JsonProperty("adjustment_id") @ExcludeMissing - fun _startDate(): JsonField = startDate + fun _adjustmentId(): JsonField = adjustmentId /** * Returns the raw JSON value of [endDate]. @@ -4386,7 +13153,6 @@ private constructor( * * The following fields are required: * ```kotlin - * .adjustment() * .startDate() * ``` */ @@ -4396,20 +13162,49 @@ private constructor( /** A builder for [AddAdjustment]. */ class Builder internal constructor() { - private var adjustment: JsonField? = null private var startDate: JsonField? = null + private var adjustment: JsonField = JsonMissing.of() + private var adjustmentId: JsonField = JsonMissing.of() private var endDate: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(addAdjustment: AddAdjustment) = apply { - adjustment = addAdjustment.adjustment startDate = addAdjustment.startDate + adjustment = addAdjustment.adjustment + adjustmentId = addAdjustment.adjustmentId endDate = addAdjustment.endDate additionalProperties = addAdjustment.additionalProperties.toMutableMap() } + /** + * The start date of the adjustment interval. This is the date that the adjustment will + * start affecting prices on the subscription. The adjustment will apply to invoice + * dates that overlap with this `start_date`. This `start_date` is treated as inclusive + * for in-advance prices, and exclusive for in-arrears prices. + */ + fun startDate(startDate: StartDate) = startDate(JsonField.of(startDate)) + + /** + * Sets [Builder.startDate] to an arbitrary JSON value. + * + * You should usually call [Builder.startDate] with a well-typed [StartDate] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun startDate(startDate: JsonField) = apply { this.startDate = startDate } + + /** Alias for calling [startDate] with `StartDate.ofDateTime(dateTime)`. */ + fun startDate(dateTime: OffsetDateTime) = startDate(StartDate.ofDateTime(dateTime)) + + /** + * Alias for calling [startDate] with + * `StartDate.ofBillingCycleRelative(billingCycleRelative)`. + */ + fun startDate(billingCycleRelative: BillingCycleRelativeDate) = + startDate(StartDate.ofBillingCycleRelative(billingCycleRelative)) + /** The definition of a new adjustment to create and add to the subscription. */ - fun adjustment(adjustment: Adjustment) = adjustment(JsonField.of(adjustment)) + fun adjustment(adjustment: Adjustment?) = adjustment(JsonField.ofNullable(adjustment)) /** * Sets [Builder.adjustment] to an arbitrary JSON value. @@ -4514,31 +13309,23 @@ private constructor( ) /** - * The start date of the adjustment interval. This is the date that the adjustment will - * start affecting prices on the subscription. The adjustment will apply to invoice - * dates that overlap with this `start_date`. This `start_date` is treated as inclusive - * for in-advance prices, and exclusive for in-arrears prices. + * The ID of the adjustment to add to the subscription. Adjustment IDs can be re-used + * from existing subscriptions or plans, but adjustments associated with coupon + * redemptions cannot be re-used. */ - fun startDate(startDate: StartDate) = startDate(JsonField.of(startDate)) + fun adjustmentId(adjustmentId: String?) = + adjustmentId(JsonField.ofNullable(adjustmentId)) /** - * Sets [Builder.startDate] to an arbitrary JSON value. + * Sets [Builder.adjustmentId] to an arbitrary JSON value. * - * You should usually call [Builder.startDate] with a well-typed [StartDate] value + * You should usually call [Builder.adjustmentId] with a well-typed [String] value * instead. This method is primarily for setting the field to an undocumented or not yet * supported value. */ - fun startDate(startDate: JsonField) = apply { this.startDate = startDate } - - /** Alias for calling [startDate] with `StartDate.ofDateTime(dateTime)`. */ - fun startDate(dateTime: OffsetDateTime) = startDate(StartDate.ofDateTime(dateTime)) - - /** - * Alias for calling [startDate] with - * `StartDate.ofBillingCycleRelative(billingCycleRelative)`. - */ - fun startDate(billingCycleRelative: BillingCycleRelativeDate) = - startDate(StartDate.ofBillingCycleRelative(billingCycleRelative)) + fun adjustmentId(adjustmentId: JsonField) = apply { + this.adjustmentId = adjustmentId + } /** * The end date of the adjustment interval. This is the date that the adjustment will @@ -4593,7 +13380,6 @@ private constructor( * * The following fields are required: * ```kotlin - * .adjustment() * .startDate() * ``` * @@ -4601,8 +13387,9 @@ private constructor( */ fun build(): AddAdjustment = AddAdjustment( - checkRequired("adjustment", adjustment), checkRequired("startDate", startDate), + adjustment, + adjustmentId, endDate, additionalProperties.toMutableMap(), ) @@ -4615,30 +13402,219 @@ private constructor( return@apply } - adjustment().validate() - startDate().validate() - endDate()?.validate() - validated = true - } + startDate().validate() + adjustment()?.validate() + adjustmentId() + endDate()?.validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (startDate.asKnown()?.validity() ?: 0) + + (adjustment.asKnown()?.validity() ?: 0) + + (if (adjustmentId.asKnown() == null) 0 else 1) + + (endDate.asKnown()?.validity() ?: 0) + + /** + * The start date of the adjustment interval. This is the date that the adjustment will + * start affecting prices on the subscription. The adjustment will apply to invoice dates + * that overlap with this `start_date`. This `start_date` is treated as inclusive for + * in-advance prices, and exclusive for in-arrears prices. + */ + @JsonDeserialize(using = StartDate.Deserializer::class) + @JsonSerialize(using = StartDate.Serializer::class) + class StartDate + private constructor( + private val dateTime: OffsetDateTime? = null, + private val billingCycleRelative: BillingCycleRelativeDate? = null, + private val _json: JsonValue? = null, + ) { + + fun dateTime(): OffsetDateTime? = dateTime + + fun billingCycleRelative(): BillingCycleRelativeDate? = billingCycleRelative + + fun isDateTime(): Boolean = dateTime != null + + fun isBillingCycleRelative(): Boolean = billingCycleRelative != null + + fun asDateTime(): OffsetDateTime = dateTime.getOrThrow("dateTime") + + fun asBillingCycleRelative(): BillingCycleRelativeDate = + billingCycleRelative.getOrThrow("billingCycleRelative") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + dateTime != null -> visitor.visitDateTime(dateTime) + billingCycleRelative != null -> + visitor.visitBillingCycleRelative(billingCycleRelative) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): StartDate = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitDateTime(dateTime: OffsetDateTime) {} + + override fun visitBillingCycleRelative( + billingCycleRelative: BillingCycleRelativeDate + ) { + billingCycleRelative.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitDateTime(dateTime: OffsetDateTime) = 1 + + override fun visitBillingCycleRelative( + billingCycleRelative: BillingCycleRelativeDate + ) = billingCycleRelative.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StartDate && + dateTime == other.dateTime && + billingCycleRelative == other.billingCycleRelative + } + + override fun hashCode(): Int = Objects.hash(dateTime, billingCycleRelative) + + override fun toString(): String = + when { + dateTime != null -> "StartDate{dateTime=$dateTime}" + billingCycleRelative != null -> + "StartDate{billingCycleRelative=$billingCycleRelative}" + _json != null -> "StartDate{_unknown=$_json}" + else -> throw IllegalStateException("Invalid StartDate") + } + + companion object { + + fun ofDateTime(dateTime: OffsetDateTime) = StartDate(dateTime = dateTime) + + fun ofBillingCycleRelative(billingCycleRelative: BillingCycleRelativeDate) = + StartDate(billingCycleRelative = billingCycleRelative) + } + + /** + * An interface that defines how to map each variant of [StartDate] to a value of type + * [T]. + */ + interface Visitor { + + fun visitDateTime(dateTime: OffsetDateTime): T + + fun visitBillingCycleRelative(billingCycleRelative: BillingCycleRelativeDate): T + + /** + * Maps an unknown variant of [StartDate] to a value of type [T]. + * + * An instance of [StartDate] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on an + * older version than the API, then the API may respond with new variants that the + * SDK is unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown StartDate: $json") + } + } + + internal class Deserializer : BaseDeserializer(StartDate::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): StartDate { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef()) + ?.let { StartDate(billingCycleRelative = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef())?.let { + StartDate(dateTime = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible + // with all the possible variants (e.g. deserializing from object). + 0 -> StartDate(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the + // first completely valid match, or simply the first match if none are + // completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(StartDate::class) { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + override fun serialize( + value: StartDate, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.dateTime != null -> generator.writeObject(value.dateTime) + value.billingCycleRelative != null -> + generator.writeObject(value.billingCycleRelative) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid StartDate") + } + } } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (adjustment.asKnown()?.validity() ?: 0) + - (startDate.asKnown()?.validity() ?: 0) + - (endDate.asKnown()?.validity() ?: 0) + } /** The definition of a new adjustment to create and add to the subscription. */ @JsonDeserialize(using = Adjustment.Deserializer::class) @@ -4772,10 +13748,16 @@ private constructor( return true } - return /* spotless:off */ other is Adjustment && percentageDiscount == other.percentageDiscount && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ + return other is Adjustment && + percentageDiscount == other.percentageDiscount && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + minimum == other.minimum && + maximum == other.maximum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) override fun toString(): String = when { @@ -4895,191 +13877,6 @@ private constructor( } } - /** - * The start date of the adjustment interval. This is the date that the adjustment will - * start affecting prices on the subscription. The adjustment will apply to invoice dates - * that overlap with this `start_date`. This `start_date` is treated as inclusive for - * in-advance prices, and exclusive for in-arrears prices. - */ - @JsonDeserialize(using = StartDate.Deserializer::class) - @JsonSerialize(using = StartDate.Serializer::class) - class StartDate - private constructor( - private val dateTime: OffsetDateTime? = null, - private val billingCycleRelative: BillingCycleRelativeDate? = null, - private val _json: JsonValue? = null, - ) { - - fun dateTime(): OffsetDateTime? = dateTime - - fun billingCycleRelative(): BillingCycleRelativeDate? = billingCycleRelative - - fun isDateTime(): Boolean = dateTime != null - - fun isBillingCycleRelative(): Boolean = billingCycleRelative != null - - fun asDateTime(): OffsetDateTime = dateTime.getOrThrow("dateTime") - - fun asBillingCycleRelative(): BillingCycleRelativeDate = - billingCycleRelative.getOrThrow("billingCycleRelative") - - fun _json(): JsonValue? = _json - - fun accept(visitor: Visitor): T = - when { - dateTime != null -> visitor.visitDateTime(dateTime) - billingCycleRelative != null -> - visitor.visitBillingCycleRelative(billingCycleRelative) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): StartDate = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitDateTime(dateTime: OffsetDateTime) {} - - override fun visitBillingCycleRelative( - billingCycleRelative: BillingCycleRelativeDate - ) { - billingCycleRelative.validate() - } - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitDateTime(dateTime: OffsetDateTime) = 1 - - override fun visitBillingCycleRelative( - billingCycleRelative: BillingCycleRelativeDate - ) = billingCycleRelative.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is StartDate && dateTime == other.dateTime && billingCycleRelative == other.billingCycleRelative /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(dateTime, billingCycleRelative) /* spotless:on */ - - override fun toString(): String = - when { - dateTime != null -> "StartDate{dateTime=$dateTime}" - billingCycleRelative != null -> - "StartDate{billingCycleRelative=$billingCycleRelative}" - _json != null -> "StartDate{_unknown=$_json}" - else -> throw IllegalStateException("Invalid StartDate") - } - - companion object { - - fun ofDateTime(dateTime: OffsetDateTime) = StartDate(dateTime = dateTime) - - fun ofBillingCycleRelative(billingCycleRelative: BillingCycleRelativeDate) = - StartDate(billingCycleRelative = billingCycleRelative) - } - - /** - * An interface that defines how to map each variant of [StartDate] to a value of type - * [T]. - */ - interface Visitor { - - fun visitDateTime(dateTime: OffsetDateTime): T - - fun visitBillingCycleRelative(billingCycleRelative: BillingCycleRelativeDate): T - - /** - * Maps an unknown variant of [StartDate] to a value of type [T]. - * - * An instance of [StartDate] can contain an unknown variant if it was deserialized - * from data that doesn't match any known variant. For example, if the SDK is on an - * older version than the API, then the API may respond with new variants that the - * SDK is unaware of. - * - * @throws OrbInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown StartDate: $json") - } - } - - internal class Deserializer : BaseDeserializer(StartDate::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): StartDate { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef()) - ?.let { StartDate(billingCycleRelative = it, _json = json) }, - tryDeserialize(node, jacksonTypeRef())?.let { - StartDate(dateTime = it, _json = json) - }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely incompatible - // with all the possible variants (e.g. deserializing from object). - 0 -> StartDate(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, then use the - // first completely valid match, or simply the first match if none are - // completely valid. - else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(StartDate::class) { - - override fun serialize( - value: StartDate, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.dateTime != null -> generator.writeObject(value.dateTime) - value.billingCycleRelative != null -> - generator.writeObject(value.billingCycleRelative) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid StartDate") - } - } - } - } - /** * The end date of the adjustment interval. This is the date that the adjustment will stop * affecting prices on the subscription. The adjustment will apply to invoice dates that @@ -5171,10 +13968,12 @@ private constructor( return true } - return /* spotless:off */ other is EndDate && dateTime == other.dateTime && billingCycleRelative == other.billingCycleRelative /* spotless:on */ + return other is EndDate && + dateTime == other.dateTime && + billingCycleRelative == other.billingCycleRelative } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(dateTime, billingCycleRelative) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(dateTime, billingCycleRelative) override fun toString(): String = when { @@ -5270,23 +14069,30 @@ private constructor( return true } - return /* spotless:off */ other is AddAdjustment && adjustment == other.adjustment && startDate == other.startDate && endDate == other.endDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AddAdjustment && + startDate == other.startDate && + adjustment == other.adjustment && + adjustmentId == other.adjustmentId && + endDate == other.endDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustment, startDate, endDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(startDate, adjustment, adjustmentId, endDate, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "AddAdjustment{adjustment=$adjustment, startDate=$startDate, endDate=$endDate, additionalProperties=$additionalProperties}" + "AddAdjustment{startDate=$startDate, adjustment=$adjustment, adjustmentId=$adjustmentId, endDate=$endDate, additionalProperties=$additionalProperties}" } class Edit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val priceIntervalId: JsonField, private val billingCycleDay: JsonField, + private val canDeferBilling: JsonField, private val endDate: JsonField, private val filter: JsonField, private val fixedFeeQuantityTransitions: JsonField>, @@ -5303,6 +14109,9 @@ private constructor( @JsonProperty("billing_cycle_day") @ExcludeMissing billingCycleDay: JsonField = JsonMissing.of(), + @JsonProperty("can_defer_billing") + @ExcludeMissing + canDeferBilling: JsonField = JsonMissing.of(), @JsonProperty("end_date") @ExcludeMissing endDate: JsonField = JsonMissing.of(), @@ -5320,6 +14129,7 @@ private constructor( ) : this( priceIntervalId, billingCycleDay, + canDeferBilling, endDate, filter, fixedFeeQuantityTransitions, @@ -5346,6 +14156,15 @@ private constructor( */ fun billingCycleDay(): Long? = billingCycleDay.getNullable("billing_cycle_day") + /** + * If true, an in-arrears price interval ending mid-cycle will defer billing the final line + * item until the next scheduled invoice. If false, it will be billed on its end date. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun canDeferBilling(): Boolean? = canDeferBilling.getNullable("can_defer_billing") + /** * The updated end date of this price interval. If not specified, the end date will not be * updated. @@ -5416,6 +14235,16 @@ private constructor( @ExcludeMissing fun _billingCycleDay(): JsonField = billingCycleDay + /** + * Returns the raw JSON value of [canDeferBilling]. + * + * Unlike [canDeferBilling], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("can_defer_billing") + @ExcludeMissing + fun _canDeferBilling(): JsonField = canDeferBilling + /** * Returns the raw JSON value of [endDate]. * @@ -5490,6 +14319,7 @@ private constructor( private var priceIntervalId: JsonField? = null private var billingCycleDay: JsonField = JsonMissing.of() + private var canDeferBilling: JsonField = JsonMissing.of() private var endDate: JsonField = JsonMissing.of() private var filter: JsonField = JsonMissing.of() private var fixedFeeQuantityTransitions: @@ -5502,6 +14332,7 @@ private constructor( internal fun from(edit: Edit) = apply { priceIntervalId = edit.priceIntervalId billingCycleDay = edit.billingCycleDay + canDeferBilling = edit.canDeferBilling endDate = edit.endDate filter = edit.filter fixedFeeQuantityTransitions = @@ -5552,6 +14383,33 @@ private constructor( this.billingCycleDay = billingCycleDay } + /** + * If true, an in-arrears price interval ending mid-cycle will defer billing the final + * line item until the next scheduled invoice. If false, it will be billed on its end + * date. + */ + fun canDeferBilling(canDeferBilling: Boolean?) = + canDeferBilling(JsonField.ofNullable(canDeferBilling)) + + /** + * Alias for [Builder.canDeferBilling]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun canDeferBilling(canDeferBilling: Boolean) = + canDeferBilling(canDeferBilling as Boolean?) + + /** + * Sets [Builder.canDeferBilling] to an arbitrary JSON value. + * + * You should usually call [Builder.canDeferBilling] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun canDeferBilling(canDeferBilling: JsonField) = apply { + this.canDeferBilling = canDeferBilling + } + /** * The updated end date of this price interval. If not specified, the end date will not * be updated. @@ -5725,6 +14583,7 @@ private constructor( Edit( checkRequired("priceIntervalId", priceIntervalId), billingCycleDay, + canDeferBilling, endDate, filter, (fixedFeeQuantityTransitions ?: JsonMissing.of()).map { it.toImmutable() }, @@ -5743,6 +14602,7 @@ private constructor( priceIntervalId() billingCycleDay() + canDeferBilling() endDate()?.validate() filter() fixedFeeQuantityTransitions()?.forEach { it.validate() } @@ -5768,6 +14628,7 @@ private constructor( internal fun validity(): Int = (if (priceIntervalId.asKnown() == null) 0 else 1) + (if (billingCycleDay.asKnown() == null) 0 else 1) + + (if (canDeferBilling.asKnown() == null) 0 else 1) + (endDate.asKnown()?.validity() ?: 0) + (if (filter.asKnown() == null) 0 else 1) + (fixedFeeQuantityTransitions.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + @@ -5863,10 +14724,12 @@ private constructor( return true } - return /* spotless:off */ other is EndDate && dateTime == other.dateTime && billingCycleRelative == other.billingCycleRelative /* spotless:on */ + return other is EndDate && + dateTime == other.dateTime && + billingCycleRelative == other.billingCycleRelative } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(dateTime, billingCycleRelative) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(dateTime, billingCycleRelative) override fun toString(): String = when { @@ -5958,6 +14821,7 @@ private constructor( } class FixedFeeQuantityTransition + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val effectiveDate: JsonField, private val quantity: JsonField, @@ -6156,12 +15020,15 @@ private constructor( return true } - return /* spotless:off */ other is FixedFeeQuantityTransition && effectiveDate == other.effectiveDate && quantity == other.quantity && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FixedFeeQuantityTransition && + effectiveDate == other.effectiveDate && + quantity == other.quantity && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(effectiveDate, quantity, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(effectiveDate, quantity, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -6258,10 +15125,12 @@ private constructor( return true } - return /* spotless:off */ other is StartDate && dateTime == other.dateTime && billingCycleRelative == other.billingCycleRelative /* spotless:on */ + return other is StartDate && + dateTime == other.dateTime && + billingCycleRelative == other.billingCycleRelative } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(dateTime, billingCycleRelative) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(dateTime, billingCycleRelative) override fun toString(): String = when { @@ -6357,20 +15226,40 @@ private constructor( return true } - return /* spotless:off */ other is Edit && priceIntervalId == other.priceIntervalId && billingCycleDay == other.billingCycleDay && endDate == other.endDate && filter == other.filter && fixedFeeQuantityTransitions == other.fixedFeeQuantityTransitions && startDate == other.startDate && usageCustomerIds == other.usageCustomerIds && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Edit && + priceIntervalId == other.priceIntervalId && + billingCycleDay == other.billingCycleDay && + canDeferBilling == other.canDeferBilling && + endDate == other.endDate && + filter == other.filter && + fixedFeeQuantityTransitions == other.fixedFeeQuantityTransitions && + startDate == other.startDate && + usageCustomerIds == other.usageCustomerIds && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(priceIntervalId, billingCycleDay, endDate, filter, fixedFeeQuantityTransitions, startDate, usageCustomerIds, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + priceIntervalId, + billingCycleDay, + canDeferBilling, + endDate, + filter, + fixedFeeQuantityTransitions, + startDate, + usageCustomerIds, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode override fun toString() = - "Edit{priceIntervalId=$priceIntervalId, billingCycleDay=$billingCycleDay, endDate=$endDate, filter=$filter, fixedFeeQuantityTransitions=$fixedFeeQuantityTransitions, startDate=$startDate, usageCustomerIds=$usageCustomerIds, additionalProperties=$additionalProperties}" + "Edit{priceIntervalId=$priceIntervalId, billingCycleDay=$billingCycleDay, canDeferBilling=$canDeferBilling, endDate=$endDate, filter=$filter, fixedFeeQuantityTransitions=$fixedFeeQuantityTransitions, startDate=$startDate, usageCustomerIds=$usageCustomerIds, additionalProperties=$additionalProperties}" } class EditAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val adjustmentIntervalId: JsonField, private val endDate: JsonField, @@ -6710,10 +15599,12 @@ private constructor( return true } - return /* spotless:off */ other is EndDate && dateTime == other.dateTime && billingCycleRelative == other.billingCycleRelative /* spotless:on */ + return other is EndDate && + dateTime == other.dateTime && + billingCycleRelative == other.billingCycleRelative } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(dateTime, billingCycleRelative) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(dateTime, billingCycleRelative) override fun toString(): String = when { @@ -6893,10 +15784,12 @@ private constructor( return true } - return /* spotless:off */ other is StartDate && dateTime == other.dateTime && billingCycleRelative == other.billingCycleRelative /* spotless:on */ + return other is StartDate && + dateTime == other.dateTime && + billingCycleRelative == other.billingCycleRelative } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(dateTime, billingCycleRelative) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(dateTime, billingCycleRelative) override fun toString(): String = when { @@ -6992,12 +15885,16 @@ private constructor( return true } - return /* spotless:off */ other is EditAdjustment && adjustmentIntervalId == other.adjustmentIntervalId && endDate == other.endDate && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EditAdjustment && + adjustmentIntervalId == other.adjustmentIntervalId && + endDate == other.endDate && + startDate == other.startDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustmentIntervalId, endDate, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(adjustmentIntervalId, endDate, startDate, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -7010,10 +15907,15 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionPriceIntervalsParams && subscriptionId == other.subscriptionId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionPriceIntervalsParams && + subscriptionId == other.subscriptionId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) override fun toString() = "SubscriptionPriceIntervalsParams{subscriptionId=$subscriptionId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionRedeemCouponParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionRedeemCouponParams.kt index 28eebd84e..a384196b1 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionRedeemCouponParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionRedeemCouponParams.kt @@ -400,6 +400,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val changeOption: JsonField, private val allowInvoiceCreditOrVoid: JsonField, @@ -736,13 +737,26 @@ private constructor( return true } - return /* spotless:off */ other is Body && changeOption == other.changeOption && allowInvoiceCreditOrVoid == other.allowInvoiceCreditOrVoid && changeDate == other.changeDate && couponId == other.couponId && couponRedemptionCode == other.couponRedemptionCode && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + changeOption == other.changeOption && + allowInvoiceCreditOrVoid == other.allowInvoiceCreditOrVoid && + changeDate == other.changeDate && + couponId == other.couponId && + couponRedemptionCode == other.couponRedemptionCode && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + changeOption, + allowInvoiceCreditOrVoid, + changeDate, + couponId, + couponRedemptionCode, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(changeOption, allowInvoiceCreditOrVoid, changeDate, couponId, couponRedemptionCode, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = @@ -874,7 +888,7 @@ private constructor( return true } - return /* spotless:off */ other is ChangeOption && value == other.value /* spotless:on */ + return other is ChangeOption && value == other.value } override fun hashCode() = value.hashCode() @@ -887,10 +901,15 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionRedeemCouponParams && subscriptionId == other.subscriptionId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionRedeemCouponParams && + subscriptionId == other.subscriptionId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) override fun toString() = "SubscriptionRedeemCouponParams{subscriptionId=$subscriptionId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionSchedulePlanChangeParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionSchedulePlanChangeParams.kt index dc69f8776..7a6b91c32 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionSchedulePlanChangeParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionSchedulePlanChangeParams.kt @@ -36,7 +36,7 @@ import java.util.Objects * This endpoint can be used to change an existing subscription's plan. It returns the serialized * updated subscription object. * - * The body parameter `change_option` determines when the plan change occurrs. Orb supports three + * The body parameter `change_option` determines when the plan change occurs. Orb supports three * options: * - `end_of_subscription_term`: changes the plan at the end of the existing plan's term. * - Issuing this plan change request for a monthly subscription will keep the existing plan @@ -175,19 +175,16 @@ import java.util.Objects * the billable metric, cadence, type, and name of a price can not be overridden. * * ### Maximums, and minimums - * * Price overrides are used to update some or all prices in the target plan. Minimums and maximums, * much like price overrides, can be useful when a new customer has negotiated a new or different * minimum or maximum spend cap than the default for the plan. The request format for maximums and * minimums is the same as those in [subscription creation](create-subscription). * * ## Scheduling multiple plan changes - * * When scheduling multiple plan changes with the same date, the latest plan change on that day * takes effect. * * ## Prorations for in-advance fees - * * By default, Orb calculates the prorated difference in any fixed fees when making a plan change, * adjusting the customer balance as needed. For details on this behavior, see * [Modifying subscriptions](/product-catalog/modifying-subscriptions#prorations-for-in-advance-fees). @@ -1436,6 +1433,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val changeOption: JsonField, private val addAdjustments: JsonField>, @@ -2917,12 +2915,67 @@ private constructor( return true } - return /* spotless:off */ other is Body && changeOption == other.changeOption && addAdjustments == other.addAdjustments && addPrices == other.addPrices && alignBillingWithPlanChangeDate == other.alignBillingWithPlanChangeDate && autoCollection == other.autoCollection && billingCycleAlignment == other.billingCycleAlignment && billingCycleAnchorConfiguration == other.billingCycleAnchorConfiguration && changeDate == other.changeDate && couponRedemptionCode == other.couponRedemptionCode && creditsOverageRate == other.creditsOverageRate && defaultInvoiceMemo == other.defaultInvoiceMemo && externalPlanId == other.externalPlanId && filter == other.filter && initialPhaseOrder == other.initialPhaseOrder && invoicingThreshold == other.invoicingThreshold && netTerms == other.netTerms && perCreditOverageAmount == other.perCreditOverageAmount && planId == other.planId && planVersionNumber == other.planVersionNumber && priceOverrides == other.priceOverrides && removeAdjustments == other.removeAdjustments && removePrices == other.removePrices && replaceAdjustments == other.replaceAdjustments && replacePrices == other.replacePrices && trialDurationDays == other.trialDurationDays && usageCustomerIds == other.usageCustomerIds && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + changeOption == other.changeOption && + addAdjustments == other.addAdjustments && + addPrices == other.addPrices && + alignBillingWithPlanChangeDate == other.alignBillingWithPlanChangeDate && + autoCollection == other.autoCollection && + billingCycleAlignment == other.billingCycleAlignment && + billingCycleAnchorConfiguration == other.billingCycleAnchorConfiguration && + changeDate == other.changeDate && + couponRedemptionCode == other.couponRedemptionCode && + creditsOverageRate == other.creditsOverageRate && + defaultInvoiceMemo == other.defaultInvoiceMemo && + externalPlanId == other.externalPlanId && + filter == other.filter && + initialPhaseOrder == other.initialPhaseOrder && + invoicingThreshold == other.invoicingThreshold && + netTerms == other.netTerms && + perCreditOverageAmount == other.perCreditOverageAmount && + planId == other.planId && + planVersionNumber == other.planVersionNumber && + priceOverrides == other.priceOverrides && + removeAdjustments == other.removeAdjustments && + removePrices == other.removePrices && + replaceAdjustments == other.replaceAdjustments && + replacePrices == other.replacePrices && + trialDurationDays == other.trialDurationDays && + usageCustomerIds == other.usageCustomerIds && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(changeOption, addAdjustments, addPrices, alignBillingWithPlanChangeDate, autoCollection, billingCycleAlignment, billingCycleAnchorConfiguration, changeDate, couponRedemptionCode, creditsOverageRate, defaultInvoiceMemo, externalPlanId, filter, initialPhaseOrder, invoicingThreshold, netTerms, perCreditOverageAmount, planId, planVersionNumber, priceOverrides, removeAdjustments, removePrices, replaceAdjustments, replacePrices, trialDurationDays, usageCustomerIds, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + changeOption, + addAdjustments, + addPrices, + alignBillingWithPlanChangeDate, + autoCollection, + billingCycleAlignment, + billingCycleAnchorConfiguration, + changeDate, + couponRedemptionCode, + creditsOverageRate, + defaultInvoiceMemo, + externalPlanId, + filter, + initialPhaseOrder, + invoicingThreshold, + netTerms, + perCreditOverageAmount, + planId, + planVersionNumber, + priceOverrides, + removeAdjustments, + removePrices, + replaceAdjustments, + replacePrices, + trialDurationDays, + usageCustomerIds, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -3055,7 +3108,7 @@ private constructor( return true } - return /* spotless:off */ other is ChangeOption && value == other.value /* spotless:on */ + return other is ChangeOption && value == other.value } override fun hashCode() = value.hashCode() @@ -3064,6 +3117,7 @@ private constructor( } class AddAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val adjustment: JsonField, private val endDate: JsonField, @@ -3569,10 +3623,16 @@ private constructor( return true } - return /* spotless:off */ other is Adjustment && percentageDiscount == other.percentageDiscount && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ + return other is Adjustment && + percentageDiscount == other.percentageDiscount && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + minimum == other.minimum && + maximum == other.maximum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) override fun toString(): String = when { @@ -3697,12 +3757,17 @@ private constructor( return true } - return /* spotless:off */ other is AddAdjustment && adjustment == other.adjustment && endDate == other.endDate && planPhaseOrder == other.planPhaseOrder && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AddAdjustment && + adjustment == other.adjustment && + endDate == other.endDate && + planPhaseOrder == other.planPhaseOrder && + startDate == other.startDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustment, endDate, planPhaseOrder, startDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(adjustment, endDate, planPhaseOrder, startDate, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3711,6 +3776,7 @@ private constructor( } class AddPrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val allocationPrice: JsonField, private val discounts: JsonField>, @@ -3830,7 +3896,7 @@ private constructor( fun planPhaseOrder(): Long? = planPhaseOrder.getNullable("plan_phase_order") /** - * The definition of a new price to create and add to the subscription. + * New subscription price request body params. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -4135,7 +4201,7 @@ private constructor( this.planPhaseOrder = planPhaseOrder } - /** The definition of a new price to create and add to the subscription. */ + /** New subscription price request body params. */ fun price(price: Price?) = price(JsonField.ofNullable(price)) /** @@ -4150,27 +4216,21 @@ private constructor( /** Alias for calling [price] with `Price.ofUnit(unit)`. */ fun price(unit: NewSubscriptionUnitPrice) = price(Price.ofUnit(unit)) - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: NewSubscriptionPackagePrice) = price(Price.ofPackage(package_)) - - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: NewSubscriptionMatrixPrice) = price(Price.ofMatrix(matrix)) - /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ fun price(tiered: NewSubscriptionTieredPrice) = price(Price.ofTiered(tiered)) - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: NewSubscriptionTieredBpsPrice) = - price(Price.ofTieredBps(tieredBps)) + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: NewSubscriptionBulkPrice) = price(Price.ofBulk(bulk)) - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: NewSubscriptionBpsPrice) = price(Price.ofBps(bps)) + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: NewSubscriptionBulkBpsPrice) = price(Price.ofBulkBps(bulkBps)) + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: NewSubscriptionPackagePrice) = price(Price.ofPackage(package_)) - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: NewSubscriptionBulkPrice) = price(Price.ofBulk(bulk)) + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: NewSubscriptionMatrixPrice) = price(Price.ofMatrix(matrix)) /** * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. @@ -4186,9 +4246,16 @@ private constructor( fun price(tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice) = price(Price.ofTieredWithMinimum(tieredWithMinimum)) - /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ - fun price(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = - price(Price.ofUnitWithPercent(unitWithPercent)) + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: NewSubscriptionGroupedTieredPrice) = + price(Price.ofGroupedTiered(groupedTiered)) + + /** + * Alias for calling [price] with + * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + */ + fun price(tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice) = + price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) /** * Alias for calling [price] with @@ -4197,10 +4264,20 @@ private constructor( fun price(packageWithAllocation: NewSubscriptionPackageWithAllocationPrice) = price(Price.ofPackageWithAllocation(packageWithAllocation)) + /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ + fun price(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = + price(Price.ofUnitWithPercent(unitWithPercent)) + + /** + * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun price(matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice) = + price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + /** * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. */ - fun price(tieredWithProration: NewSubscriptionTierWithProrationPrice) = + fun price(tieredWithProration: Price.TieredWithProration) = price(Price.ofTieredWithProration(tieredWithProration)) /** Alias for calling [price] with `Price.ofUnitWithProration(unitWithProration)`. */ @@ -4211,6 +4288,10 @@ private constructor( fun price(groupedAllocation: NewSubscriptionGroupedAllocationPrice) = price(Price.ofGroupedAllocation(groupedAllocation)) + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = + price(Price.ofBulkWithProration(bulkWithProration)) + /** * Alias for calling [price] with * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. @@ -4218,32 +4299,32 @@ private constructor( fun price(groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice) = price(Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)) - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = - price(Price.ofBulkWithProration(bulkWithProration)) - /** * Alias for calling [price] with - * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. + * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. */ - fun price( - scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice - ) = price(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) + fun price(groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice) = + price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) /** * Alias for calling [price] with - * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. */ - fun price( - scalableMatrixWithTieredPricing: NewSubscriptionScalableMatrixWithTieredPricingPrice - ) = price(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) /** * Alias for calling [price] with - * `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. + * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. */ - fun price(cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice) = - price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + fun price(matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice) = + price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) + + /** + * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. + */ + fun price(groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice) = + price(Price.ofGroupedTieredPackage(groupedTieredPackage)) /** * Alias for calling [price] with @@ -4254,40 +4335,43 @@ private constructor( /** * Alias for calling [price] with - * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. + * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. */ - fun price(groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice) = - price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + fun price( + scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice + ) = price(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) /** * Alias for calling [price] with - * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. - */ - fun price(matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice) = - price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) - - /** - * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. + * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. */ - fun price(groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice) = - price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + fun price( + scalableMatrixWithTieredPricing: NewSubscriptionScalableMatrixWithTieredPricingPrice + ) = price(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) /** - * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + * Alias for calling [price] with + * `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. */ - fun price(matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice) = - price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + fun price(cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice) = + price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) /** * Alias for calling [price] with - * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. */ - fun price(tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice) = - price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) - /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: NewSubscriptionGroupedTieredPrice) = - price(Price.ofGroupedTiered(groupedTiered)) + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: NewSubscriptionMinimumCompositePrice) = + price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) /** The id of the price to add to the subscription. */ fun priceId(priceId: String?) = priceId(JsonField.ofNullable(priceId)) @@ -4405,31 +4489,39 @@ private constructor( (if (priceId.asKnown() == null) 0 else 1) + (if (startDate.asKnown() == null) 0 else 1) - /** The definition of a new price to create and add to the subscription. */ + /** New subscription price request body params. */ @JsonDeserialize(using = Price.Deserializer::class) @JsonSerialize(using = Price.Serializer::class) class Price private constructor( private val unit: NewSubscriptionUnitPrice? = null, - private val package_: NewSubscriptionPackagePrice? = null, - private val matrix: NewSubscriptionMatrixPrice? = null, private val tiered: NewSubscriptionTieredPrice? = null, - private val tieredBps: NewSubscriptionTieredBpsPrice? = null, - private val bps: NewSubscriptionBpsPrice? = null, - private val bulkBps: NewSubscriptionBulkBpsPrice? = null, private val bulk: NewSubscriptionBulkPrice? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: NewSubscriptionPackagePrice? = null, + private val matrix: NewSubscriptionMatrixPrice? = null, private val thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice? = null, private val tieredPackage: NewSubscriptionTieredPackagePrice? = null, private val tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice? = null, - private val unitWithPercent: NewSubscriptionUnitWithPercentPrice? = null, + private val groupedTiered: NewSubscriptionGroupedTieredPrice? = null, + private val tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice? = + null, private val packageWithAllocation: NewSubscriptionPackageWithAllocationPrice? = null, - private val tieredWithProration: NewSubscriptionTierWithProrationPrice? = null, + private val unitWithPercent: NewSubscriptionUnitWithPercentPrice? = null, + private val matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice? = null, + private val tieredWithProration: TieredWithProration? = null, private val unitWithProration: NewSubscriptionUnitWithProrationPrice? = null, private val groupedAllocation: NewSubscriptionGroupedAllocationPrice? = null, + private val bulkWithProration: NewSubscriptionBulkWithProrationPrice? = null, private val groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice? = null, - private val bulkWithProration: NewSubscriptionBulkWithProrationPrice? = null, + private val groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice? = + null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, + private val matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice? = null, + private val groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice? = null, + private val maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice? = null, private val scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice? = null, @@ -4437,33 +4529,24 @@ private constructor( NewSubscriptionScalableMatrixWithTieredPricingPrice? = null, private val cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice? = null, - private val maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice? = null, - private val groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice? = - null, - private val matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice? = null, - private val groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice? = null, - private val matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice? = null, - private val tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice? = - null, - private val groupedTiered: NewSubscriptionGroupedTieredPrice? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: NewSubscriptionMinimumCompositePrice? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, private val _json: JsonValue? = null, ) { fun unit(): NewSubscriptionUnitPrice? = unit - fun package_(): NewSubscriptionPackagePrice? = package_ - - fun matrix(): NewSubscriptionMatrixPrice? = matrix - fun tiered(): NewSubscriptionTieredPrice? = tiered - fun tieredBps(): NewSubscriptionTieredBpsPrice? = tieredBps + fun bulk(): NewSubscriptionBulkPrice? = bulk - fun bps(): NewSubscriptionBpsPrice? = bps + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters - fun bulkBps(): NewSubscriptionBulkBpsPrice? = bulkBps + fun package_(): NewSubscriptionPackagePrice? = package_ - fun bulk(): NewSubscriptionBulkPrice? = bulk + fun matrix(): NewSubscriptionMatrixPrice? = matrix fun thresholdTotalAmount(): NewSubscriptionThresholdTotalAmountPrice? = thresholdTotalAmount @@ -4472,21 +4555,44 @@ private constructor( fun tieredWithMinimum(): NewSubscriptionTieredWithMinimumPrice? = tieredWithMinimum - fun unitWithPercent(): NewSubscriptionUnitWithPercentPrice? = unitWithPercent + fun groupedTiered(): NewSubscriptionGroupedTieredPrice? = groupedTiered + + fun tieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice? = + tieredPackageWithMinimum fun packageWithAllocation(): NewSubscriptionPackageWithAllocationPrice? = packageWithAllocation - fun tieredWithProration(): NewSubscriptionTierWithProrationPrice? = tieredWithProration + fun unitWithPercent(): NewSubscriptionUnitWithPercentPrice? = unitWithPercent + + fun matrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice? = + matrixWithAllocation + + fun tieredWithProration(): TieredWithProration? = tieredWithProration fun unitWithProration(): NewSubscriptionUnitWithProrationPrice? = unitWithProration fun groupedAllocation(): NewSubscriptionGroupedAllocationPrice? = groupedAllocation + fun bulkWithProration(): NewSubscriptionBulkWithProrationPrice? = bulkWithProration + fun groupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice? = groupedWithProratedMinimum - fun bulkWithProration(): NewSubscriptionBulkWithProrationPrice? = bulkWithProration + fun groupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice? = + groupedWithMeteredMinimum + + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = + groupedWithMinMaxThresholds + + fun matrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice? = + matrixWithDisplayName + + fun groupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice? = + groupedTieredPackage + + fun maxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice? = + maxGroupTieredPackage fun scalableMatrixWithUnitPricing(): NewSubscriptionScalableMatrixWithUnitPricingPrice? = scalableMatrixWithUnitPricing @@ -4498,41 +4604,26 @@ private constructor( fun cumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice? = cumulativeGroupedBulk - fun maxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice? = - maxGroupTieredPackage - - fun groupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice? = - groupedWithMeteredMinimum - - fun matrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice? = - matrixWithDisplayName - - fun groupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice? = - groupedTieredPackage + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = + cumulativeGroupedAllocation - fun matrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice? = - matrixWithAllocation + fun minimum(): NewSubscriptionMinimumCompositePrice? = minimum - fun tieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice? = - tieredPackageWithMinimum + fun percent(): Percent? = percent - fun groupedTiered(): NewSubscriptionGroupedTieredPrice? = groupedTiered + fun eventOutput(): EventOutput? = eventOutput fun isUnit(): Boolean = unit != null - fun isPackage(): Boolean = package_ != null - - fun isMatrix(): Boolean = matrix != null - fun isTiered(): Boolean = tiered != null - fun isTieredBps(): Boolean = tieredBps != null + fun isBulk(): Boolean = bulk != null - fun isBps(): Boolean = bps != null + fun isBulkWithFilters(): Boolean = bulkWithFilters != null - fun isBulkBps(): Boolean = bulkBps != null + fun isPackage(): Boolean = package_ != null - fun isBulk(): Boolean = bulk != null + fun isMatrix(): Boolean = matrix != null fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null @@ -4540,56 +4631,62 @@ private constructor( fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null - fun isUnitWithPercent(): Boolean = unitWithPercent != null + fun isGroupedTiered(): Boolean = groupedTiered != null + + fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + fun isUnitWithPercent(): Boolean = unitWithPercent != null + + fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isTieredWithProration(): Boolean = tieredWithProration != null fun isUnitWithProration(): Boolean = unitWithProration != null fun isGroupedAllocation(): Boolean = groupedAllocation != null + fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null - fun isBulkWithProration(): Boolean = bulkWithProration != null + fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null - fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null - fun isScalableMatrixWithTieredPricing(): Boolean = - scalableMatrixWithTieredPricing != null + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null - fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null + fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null - fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null - - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null - fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + fun isScalableMatrixWithTieredPricing(): Boolean = + scalableMatrixWithTieredPricing != null - fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null - fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null - fun isGroupedTiered(): Boolean = groupedTiered != null + fun isMinimum(): Boolean = minimum != null - fun asUnit(): NewSubscriptionUnitPrice = unit.getOrThrow("unit") + fun isPercent(): Boolean = percent != null - fun asPackage(): NewSubscriptionPackagePrice = package_.getOrThrow("package_") + fun isEventOutput(): Boolean = eventOutput != null - fun asMatrix(): NewSubscriptionMatrixPrice = matrix.getOrThrow("matrix") + fun asUnit(): NewSubscriptionUnitPrice = unit.getOrThrow("unit") fun asTiered(): NewSubscriptionTieredPrice = tiered.getOrThrow("tiered") - fun asTieredBps(): NewSubscriptionTieredBpsPrice = tieredBps.getOrThrow("tieredBps") + fun asBulk(): NewSubscriptionBulkPrice = bulk.getOrThrow("bulk") - fun asBps(): NewSubscriptionBpsPrice = bps.getOrThrow("bps") + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") - fun asBulkBps(): NewSubscriptionBulkBpsPrice = bulkBps.getOrThrow("bulkBps") + fun asPackage(): NewSubscriptionPackagePrice = package_.getOrThrow("package_") - fun asBulk(): NewSubscriptionBulkPrice = bulk.getOrThrow("bulk") + fun asMatrix(): NewSubscriptionMatrixPrice = matrix.getOrThrow("matrix") fun asThresholdTotalAmount(): NewSubscriptionThresholdTotalAmountPrice = thresholdTotalAmount.getOrThrow("thresholdTotalAmount") @@ -4600,13 +4697,22 @@ private constructor( fun asTieredWithMinimum(): NewSubscriptionTieredWithMinimumPrice = tieredWithMinimum.getOrThrow("tieredWithMinimum") - fun asUnitWithPercent(): NewSubscriptionUnitWithPercentPrice = - unitWithPercent.getOrThrow("unitWithPercent") + fun asGroupedTiered(): NewSubscriptionGroupedTieredPrice = + groupedTiered.getOrThrow("groupedTiered") + + fun asTieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice = + tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") fun asPackageWithAllocation(): NewSubscriptionPackageWithAllocationPrice = packageWithAllocation.getOrThrow("packageWithAllocation") - fun asTieredWithProration(): NewSubscriptionTierWithProrationPrice = + fun asUnitWithPercent(): NewSubscriptionUnitWithPercentPrice = + unitWithPercent.getOrThrow("unitWithPercent") + + fun asMatrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice = + matrixWithAllocation.getOrThrow("matrixWithAllocation") + + fun asTieredWithProration(): TieredWithProration = tieredWithProration.getOrThrow("tieredWithProration") fun asUnitWithProration(): NewSubscriptionUnitWithProrationPrice = @@ -4615,28 +4721,17 @@ private constructor( fun asGroupedAllocation(): NewSubscriptionGroupedAllocationPrice = groupedAllocation.getOrThrow("groupedAllocation") - fun asGroupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice = - groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") - fun asBulkWithProration(): NewSubscriptionBulkWithProrationPrice = bulkWithProration.getOrThrow("bulkWithProration") - fun asScalableMatrixWithUnitPricing(): - NewSubscriptionScalableMatrixWithUnitPricingPrice = - scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") + fun asGroupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice = + groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") - fun asScalableMatrixWithTieredPricing(): - NewSubscriptionScalableMatrixWithTieredPricingPrice = - scalableMatrixWithTieredPricing.getOrThrow("scalableMatrixWithTieredPricing") + fun asGroupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice = + groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") - fun asCumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice = - cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") - - fun asMaxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice = - maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") - - fun asGroupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice = - groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") fun asMatrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice = matrixWithDisplayName.getOrThrow("matrixWithDisplayName") @@ -4644,41 +4739,68 @@ private constructor( fun asGroupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice = groupedTieredPackage.getOrThrow("groupedTieredPackage") - fun asMatrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice = - matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun asMaxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice = + maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") - fun asTieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice = - tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + fun asScalableMatrixWithUnitPricing(): + NewSubscriptionScalableMatrixWithUnitPricingPrice = + scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") - fun asGroupedTiered(): NewSubscriptionGroupedTieredPrice = - groupedTiered.getOrThrow("groupedTiered") + fun asScalableMatrixWithTieredPricing(): + NewSubscriptionScalableMatrixWithTieredPricingPrice = + scalableMatrixWithTieredPricing.getOrThrow("scalableMatrixWithTieredPricing") + + fun asCumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice = + cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") + + fun asMinimum(): NewSubscriptionMinimumCompositePrice = minimum.getOrThrow("minimum") + + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") fun _json(): JsonValue? = _json fun accept(visitor: Visitor): T = when { unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) thresholdTotalAmount != null -> visitor.visitThresholdTotalAmount(thresholdTotalAmount) tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) - unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + tieredPackageWithMinimum != null -> + visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) packageWithAllocation != null -> visitor.visitPackageWithAllocation(packageWithAllocation) + unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + matrixWithAllocation != null -> + visitor.visitMatrixWithAllocation(matrixWithAllocation) tieredWithProration != null -> visitor.visitTieredWithProration(tieredWithProration) unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) groupedWithProratedMinimum != null -> visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) + groupedWithMeteredMinimum != null -> + visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) + matrixWithDisplayName != null -> + visitor.visitMatrixWithDisplayName(matrixWithDisplayName) + groupedTieredPackage != null -> + visitor.visitGroupedTieredPackage(groupedTieredPackage) + maxGroupTieredPackage != null -> + visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) scalableMatrixWithUnitPricing != null -> visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) scalableMatrixWithTieredPricing != null -> @@ -4687,19 +4809,11 @@ private constructor( ) cumulativeGroupedBulk != null -> visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) - maxGroupTieredPackage != null -> - visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) - groupedWithMeteredMinimum != null -> - visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) - matrixWithDisplayName != null -> - visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - groupedTieredPackage != null -> - visitor.visitGroupedTieredPackage(groupedTieredPackage) - matrixWithAllocation != null -> - visitor.visitMatrixWithAllocation(matrixWithAllocation) - tieredPackageWithMinimum != null -> - visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) else -> visitor.unknown(_json) } @@ -4716,32 +4830,24 @@ private constructor( unit.validate() } - override fun visitPackage(package_: NewSubscriptionPackagePrice) { - package_.validate() - } - - override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) { - matrix.validate() - } - override fun visitTiered(tiered: NewSubscriptionTieredPrice) { tiered.validate() } - override fun visitTieredBps(tieredBps: NewSubscriptionTieredBpsPrice) { - tieredBps.validate() + override fun visitBulk(bulk: NewSubscriptionBulkPrice) { + bulk.validate() } - override fun visitBps(bps: NewSubscriptionBpsPrice) { - bps.validate() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() } - override fun visitBulkBps(bulkBps: NewSubscriptionBulkBpsPrice) { - bulkBps.validate() + override fun visitPackage(package_: NewSubscriptionPackagePrice) { + package_.validate() } - override fun visitBulk(bulk: NewSubscriptionBulkPrice) { - bulk.validate() + override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) { + matrix.validate() } override fun visitThresholdTotalAmount( @@ -4762,10 +4868,16 @@ private constructor( tieredWithMinimum.validate() } - override fun visitUnitWithPercent( - unitWithPercent: NewSubscriptionUnitWithPercentPrice + override fun visitGroupedTiered( + groupedTiered: NewSubscriptionGroupedTieredPrice ) { - unitWithPercent.validate() + groupedTiered.validate() + } + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ) { + tieredPackageWithMinimum.validate() } override fun visitPackageWithAllocation( @@ -4774,8 +4886,20 @@ private constructor( packageWithAllocation.validate() } + override fun visitUnitWithPercent( + unitWithPercent: NewSubscriptionUnitWithPercentPrice + ) { + unitWithPercent.validate() + } + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ) { + matrixWithAllocation.validate() + } + override fun visitTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice + tieredWithProration: TieredWithProration ) { tieredWithProration.validate() } @@ -4792,6 +4916,12 @@ private constructor( groupedAllocation.validate() } + override fun visitBulkWithProration( + bulkWithProration: NewSubscriptionBulkWithProrationPrice + ) { + bulkWithProration.validate() + } + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice @@ -4799,30 +4929,28 @@ private constructor( groupedWithProratedMinimum.validate() } - override fun visitBulkWithProration( - bulkWithProration: NewSubscriptionBulkWithProrationPrice + override fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice ) { - bulkWithProration.validate() + groupedWithMeteredMinimum.validate() } - override fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: - NewSubscriptionScalableMatrixWithUnitPricingPrice + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds ) { - scalableMatrixWithUnitPricing.validate() + groupedWithMinMaxThresholds.validate() } - override fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice ) { - scalableMatrixWithTieredPricing.validate() + matrixWithDisplayName.validate() } - override fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice + override fun visitGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice ) { - cumulativeGroupedBulk.validate() + groupedTieredPackage.validate() } override fun visitMaxGroupTieredPackage( @@ -4831,40 +4959,42 @@ private constructor( maxGroupTieredPackage.validate() } - override fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + override fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: + NewSubscriptionScalableMatrixWithUnitPricingPrice ) { - groupedWithMeteredMinimum.validate() + scalableMatrixWithUnitPricing.validate() } - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + override fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice ) { - matrixWithDisplayName.validate() + scalableMatrixWithTieredPricing.validate() } - override fun visitGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + override fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice ) { - groupedTieredPackage.validate() + cumulativeGroupedBulk.validate() } - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation ) { - matrixWithAllocation.validate() + cumulativeGroupedAllocation.validate() } - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ) { - tieredPackageWithMinimum.validate() + override fun visitMinimum(minimum: NewSubscriptionMinimumCompositePrice) { + minimum.validate() } - override fun visitGroupedTiered( - groupedTiered: NewSubscriptionGroupedTieredPrice - ) { - groupedTiered.validate() + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() } } ) @@ -4890,24 +5020,19 @@ private constructor( object : Visitor { override fun visitUnit(unit: NewSubscriptionUnitPrice) = unit.validity() - override fun visitPackage(package_: NewSubscriptionPackagePrice) = - package_.validity() - - override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) = - matrix.validity() - override fun visitTiered(tiered: NewSubscriptionTieredPrice) = tiered.validity() - override fun visitTieredBps(tieredBps: NewSubscriptionTieredBpsPrice) = - tieredBps.validity() + override fun visitBulk(bulk: NewSubscriptionBulkPrice) = bulk.validity() - override fun visitBps(bps: NewSubscriptionBpsPrice) = bps.validity() + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() - override fun visitBulkBps(bulkBps: NewSubscriptionBulkBpsPrice) = - bulkBps.validity() + override fun visitPackage(package_: NewSubscriptionPackagePrice) = + package_.validity() - override fun visitBulk(bulk: NewSubscriptionBulkPrice) = bulk.validity() + override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) = + matrix.validity() override fun visitThresholdTotalAmount( thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice @@ -4921,16 +5046,28 @@ private constructor( tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice ) = tieredWithMinimum.validity() - override fun visitUnitWithPercent( - unitWithPercent: NewSubscriptionUnitWithPercentPrice - ) = unitWithPercent.validity() + override fun visitGroupedTiered( + groupedTiered: NewSubscriptionGroupedTieredPrice + ) = groupedTiered.validity() + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ) = tieredPackageWithMinimum.validity() override fun visitPackageWithAllocation( packageWithAllocation: NewSubscriptionPackageWithAllocationPrice ) = packageWithAllocation.validity() + override fun visitUnitWithPercent( + unitWithPercent: NewSubscriptionUnitWithPercentPrice + ) = unitWithPercent.validity() + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ) = matrixWithAllocation.validity() + override fun visitTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice + tieredWithProration: TieredWithProration ) = tieredWithProration.validity() override fun visitUnitWithProration( @@ -4941,14 +5078,34 @@ private constructor( groupedAllocation: NewSubscriptionGroupedAllocationPrice ) = groupedAllocation.validity() + override fun visitBulkWithProration( + bulkWithProration: NewSubscriptionBulkWithProrationPrice + ) = bulkWithProration.validity() + override fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice ) = groupedWithProratedMinimum.validity() - override fun visitBulkWithProration( - bulkWithProration: NewSubscriptionBulkWithProrationPrice - ) = bulkWithProration.validity() + override fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + ) = groupedWithMeteredMinimum.validity() + + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + ) = matrixWithDisplayName.validity() + + override fun visitGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + ) = groupedTieredPackage.validity() + + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice + ) = maxGroupTieredPackage.validity() override fun visitScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: @@ -4964,33 +5121,17 @@ private constructor( cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice ) = cumulativeGroupedBulk.validity() - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice - ) = maxGroupTieredPackage.validity() - - override fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice - ) = groupedWithMeteredMinimum.validity() - - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice - ) = matrixWithDisplayName.validity() - - override fun visitGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice - ) = groupedTieredPackage.validity() + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice - ) = matrixWithAllocation.validity() + override fun visitMinimum(minimum: NewSubscriptionMinimumCompositePrice) = + minimum.validity() - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ) = tieredPackageWithMinimum.validity() + override fun visitPercent(percent: Percent) = percent.validity() - override fun visitGroupedTiered( - groupedTiered: NewSubscriptionGroupedTieredPrice - ) = groupedTiered.validity() + override fun visitEventOutput(eventOutput: EventOutput) = + eventOutput.validity() override fun unknown(json: JsonValue?) = 0 } @@ -5001,53 +5142,122 @@ private constructor( return true } - return /* spotless:off */ other is Price && unit == other.unit && package_ == other.package_ && matrix == other.matrix && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && tieredWithMinimum == other.tieredWithMinimum && unitWithPercent == other.unitWithPercent && packageWithAllocation == other.packageWithAllocation && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && bulkWithProration == other.bulkWithProration && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk && maxGroupTieredPackage == other.maxGroupTieredPackage && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && groupedTieredPackage == other.groupedTieredPackage && matrixWithAllocation == other.matrixWithAllocation && tieredPackageWithMinimum == other.tieredPackageWithMinimum && groupedTiered == other.groupedTiered /* spotless:on */ + return other is Price && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, tieredWithMinimum, unitWithPercent, packageWithAllocation, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, bulkWithProration, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk, maxGroupTieredPackage, groupedWithMeteredMinimum, matrixWithDisplayName, groupedTieredPackage, matrixWithAllocation, tieredPackageWithMinimum, groupedTiered) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) override fun toString(): String = when { unit != null -> "Price{unit=$unit}" - package_ != null -> "Price{package_=$package_}" - matrix != null -> "Price{matrix=$matrix}" tiered != null -> "Price{tiered=$tiered}" - tieredBps != null -> "Price{tieredBps=$tieredBps}" - bps != null -> "Price{bps=$bps}" - bulkBps != null -> "Price{bulkBps=$bulkBps}" bulk != null -> "Price{bulk=$bulk}" + bulkWithFilters != null -> "Price{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "Price{package_=$package_}" + matrix != null -> "Price{matrix=$matrix}" thresholdTotalAmount != null -> "Price{thresholdTotalAmount=$thresholdTotalAmount}" tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" - unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" + tieredPackageWithMinimum != null -> + "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" packageWithAllocation != null -> "Price{packageWithAllocation=$packageWithAllocation}" + unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + matrixWithAllocation != null -> + "Price{matrixWithAllocation=$matrixWithAllocation}" tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" groupedWithProratedMinimum != null -> "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" - bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" - scalableMatrixWithUnitPricing != null -> - "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" - scalableMatrixWithTieredPricing != null -> - "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" - cumulativeGroupedBulk != null -> - "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" - maxGroupTieredPackage != null -> - "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" groupedWithMeteredMinimum != null -> "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "Price{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" matrixWithDisplayName != null -> "Price{matrixWithDisplayName=$matrixWithDisplayName}" groupedTieredPackage != null -> "Price{groupedTieredPackage=$groupedTieredPackage}" - matrixWithAllocation != null -> - "Price{matrixWithAllocation=$matrixWithAllocation}" - tieredPackageWithMinimum != null -> - "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" - groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" + maxGroupTieredPackage != null -> + "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" + scalableMatrixWithUnitPricing != null -> + "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" + scalableMatrixWithTieredPricing != null -> + "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" + cumulativeGroupedBulk != null -> + "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" + cumulativeGroupedAllocation != null -> + "Price{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "Price{minimum=$minimum}" + percent != null -> "Price{percent=$percent}" + eventOutput != null -> "Price{eventOutput=$eventOutput}" _json != null -> "Price{_unknown=$_json}" else -> throw IllegalStateException("Invalid Price") } @@ -5056,20 +5266,16 @@ private constructor( fun ofUnit(unit: NewSubscriptionUnitPrice) = Price(unit = unit) - fun ofPackage(package_: NewSubscriptionPackagePrice) = Price(package_ = package_) - - fun ofMatrix(matrix: NewSubscriptionMatrixPrice) = Price(matrix = matrix) - fun ofTiered(tiered: NewSubscriptionTieredPrice) = Price(tiered = tiered) - fun ofTieredBps(tieredBps: NewSubscriptionTieredBpsPrice) = - Price(tieredBps = tieredBps) + fun ofBulk(bulk: NewSubscriptionBulkPrice) = Price(bulk = bulk) - fun ofBps(bps: NewSubscriptionBpsPrice) = Price(bps = bps) + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + Price(bulkWithFilters = bulkWithFilters) - fun ofBulkBps(bulkBps: NewSubscriptionBulkBpsPrice) = Price(bulkBps = bulkBps) + fun ofPackage(package_: NewSubscriptionPackagePrice) = Price(package_ = package_) - fun ofBulk(bulk: NewSubscriptionBulkPrice) = Price(bulk = bulk) + fun ofMatrix(matrix: NewSubscriptionMatrixPrice) = Price(matrix = matrix) fun ofThresholdTotalAmount( thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice @@ -5081,16 +5287,26 @@ private constructor( fun ofTieredWithMinimum(tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice) = Price(tieredWithMinimum = tieredWithMinimum) - fun ofUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = - Price(unitWithPercent = unitWithPercent) + fun ofGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice) = + Price(groupedTiered = groupedTiered) + + fun ofTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) fun ofPackageWithAllocation( packageWithAllocation: NewSubscriptionPackageWithAllocationPrice ) = Price(packageWithAllocation = packageWithAllocation) - fun ofTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice - ) = Price(tieredWithProration = tieredWithProration) + fun ofUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = + Price(unitWithPercent = unitWithPercent) + + fun ofMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ) = Price(matrixWithAllocation = matrixWithAllocation) + + fun ofTieredWithProration(tieredWithProration: TieredWithProration) = + Price(tieredWithProration = tieredWithProration) fun ofUnitWithProration(unitWithProration: NewSubscriptionUnitWithProrationPrice) = Price(unitWithProration = unitWithProration) @@ -5098,12 +5314,32 @@ private constructor( fun ofGroupedAllocation(groupedAllocation: NewSubscriptionGroupedAllocationPrice) = Price(groupedAllocation = groupedAllocation) + fun ofBulkWithProration(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = + Price(bulkWithProration = bulkWithProration) + fun ofGroupedWithProratedMinimum( groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) - fun ofBulkWithProration(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = - Price(bulkWithProration = bulkWithProration) + fun ofGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = Price(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + + fun ofMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + ) = Price(matrixWithDisplayName = matrixWithDisplayName) + + fun ofGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + ) = Price(groupedTieredPackage = groupedTieredPackage) + + fun ofMaxGroupTieredPackage( + maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice + ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) fun ofScalableMatrixWithUnitPricing( scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice @@ -5118,32 +5354,16 @@ private constructor( cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) - fun ofMaxGroupTieredPackage( - maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice - ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) - - fun ofGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice - ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) - - fun ofMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice - ) = Price(matrixWithDisplayName = matrixWithDisplayName) - - fun ofGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice - ) = Price(groupedTieredPackage = groupedTieredPackage) + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = Price(cumulativeGroupedAllocation = cumulativeGroupedAllocation) - fun ofMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice - ) = Price(matrixWithAllocation = matrixWithAllocation) + fun ofMinimum(minimum: NewSubscriptionMinimumCompositePrice) = + Price(minimum = minimum) - fun ofTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + fun ofPercent(percent: Percent) = Price(percent = percent) - fun ofGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice) = - Price(groupedTiered = groupedTiered) + fun ofEventOutput(eventOutput: EventOutput) = Price(eventOutput = eventOutput) } /** @@ -5153,19 +5373,15 @@ private constructor( fun visitUnit(unit: NewSubscriptionUnitPrice): T - fun visitPackage(package_: NewSubscriptionPackagePrice): T - - fun visitMatrix(matrix: NewSubscriptionMatrixPrice): T - fun visitTiered(tiered: NewSubscriptionTieredPrice): T - fun visitTieredBps(tieredBps: NewSubscriptionTieredBpsPrice): T + fun visitBulk(bulk: NewSubscriptionBulkPrice): T - fun visitBps(bps: NewSubscriptionBpsPrice): T + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T - fun visitBulkBps(bulkBps: NewSubscriptionBulkBpsPrice): T + fun visitPackage(package_: NewSubscriptionPackagePrice): T - fun visitBulk(bulk: NewSubscriptionBulkPrice): T + fun visitMatrix(matrix: NewSubscriptionMatrixPrice): T fun visitThresholdTotalAmount( thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice @@ -5177,16 +5393,24 @@ private constructor( tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice ): T - fun visitUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice): T + fun visitGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice): T + + fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ): T fun visitPackageWithAllocation( packageWithAllocation: NewSubscriptionPackageWithAllocationPrice ): T - fun visitTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice + fun visitUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice): T + + fun visitMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice ): T + fun visitTieredWithProration(tieredWithProration: TieredWithProration): T + fun visitUnitWithProration( unitWithProration: NewSubscriptionUnitWithProrationPrice ): T @@ -5195,52 +5419,56 @@ private constructor( groupedAllocation: NewSubscriptionGroupedAllocationPrice ): T + fun visitBulkWithProration( + bulkWithProration: NewSubscriptionBulkWithProrationPrice + ): T + fun visitGroupedWithProratedMinimum( groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice ): T - fun visitBulkWithProration( - bulkWithProration: NewSubscriptionBulkWithProrationPrice + fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice ): T - fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds ): T - fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice + fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice ): T - fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice + fun visitGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice ): T fun visitMaxGroupTieredPackage( maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice ): T - fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice ): T - fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice ): T - fun visitGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice ): T - fun visitMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation ): T - fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ): T + fun visitMinimum(minimum: NewSubscriptionMinimumCompositePrice): T - fun visitGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice): T + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T /** * Maps an unknown variant of [Price] to a value of type [T]. @@ -5268,20 +5496,6 @@ private constructor( return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(unit = it, _json = json) } ?: Price(_json = json) } - "package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) - } - "matrix" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) - } "tiered" -> { return tryDeserialize( node, @@ -5289,27 +5503,28 @@ private constructor( ) ?.let { Price(tiered = it, _json = json) } ?: Price(_json = json) } - "tiered_bps" -> { + "bulk" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(bulk = it, _json = json) } ?: Price(_json = json) + } + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulkWithFilters = it, _json = json) + } ?: Price(_json = json) + } + "package" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(tieredBps = it, _json = json) } ?: Price(_json = json) - } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bps = it, _json = json) } ?: Price(_json = json) + ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) } - "bulk_bps" -> { + "matrix" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(bulkBps = it, _json = json) } ?: Price(_json = json) - } - "bulk" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bulk = it, _json = json) } ?: Price(_json = json) + ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) } "threshold_total_amount" -> { return tryDeserialize( @@ -5335,12 +5550,20 @@ private constructor( ?.let { Price(tieredWithMinimum = it, _json = json) } ?: Price(_json = json) } - "unit_with_percent" -> { + "grouped_tiered" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(unitWithPercent = it, _json = json) } + ?.let { Price(groupedTiered = it, _json = json) } + ?: Price(_json = json) + } + "tiered_package_with_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tieredPackageWithMinimum = it, _json = json) } ?: Price(_json = json) } "package_with_allocation" -> { @@ -5351,11 +5574,24 @@ private constructor( ?.let { Price(packageWithAllocation = it, _json = json) } ?: Price(_json = json) } - "tiered_with_proration" -> { + "unit_with_percent" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(unitWithPercent = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_allocation" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) + ?.let { Price(matrixWithAllocation = it, _json = json) } + ?: Price(_json = json) + } + "tiered_with_proration" -> { + return tryDeserialize(node, jacksonTypeRef()) ?.let { Price(tieredWithProration = it, _json = json) } ?: Price(_json = json) } @@ -5375,6 +5611,14 @@ private constructor( ?.let { Price(groupedAllocation = it, _json = json) } ?: Price(_json = json) } + "bulk_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(bulkWithProration = it, _json = json) } + ?: Price(_json = json) + } "grouped_with_prorated_minimum" -> { return tryDeserialize( node, @@ -5383,12 +5627,44 @@ private constructor( ?.let { Price(groupedWithProratedMinimum = it, _json = json) } ?: Price(_json = json) } - "bulk_with_proration" -> { + "grouped_with_metered_minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(bulkWithProration = it, _json = json) } + ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_min_max_thresholds" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithMinMaxThresholds = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_display_name" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(matrixWithDisplayName = it, _json = json) } + ?: Price(_json = json) + } + "grouped_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedTieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "max_group_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(maxGroupTieredPackage = it, _json = json) } ?: Price(_json = json) } "scalable_matrix_with_unit_pricing" -> { @@ -5419,61 +5695,30 @@ private constructor( ?.let { Price(cumulativeGroupedBulk = it, _json = json) } ?: Price(_json = json) } - "max_group_tiered_package" -> { + "cumulative_grouped_allocation" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(maxGroupTieredPackage = it, _json = json) } + ?.let { Price(cumulativeGroupedAllocation = it, _json = json) } ?: Price(_json = json) } - "grouped_with_metered_minimum" -> { + "minimum" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } - ?: Price(_json = json) - } - "matrix_with_display_name" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithDisplayName = it, _json = json) } - ?: Price(_json = json) - } - "grouped_tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedTieredPackage = it, _json = json) } - ?: Price(_json = json) - } - "matrix_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithAllocation = it, _json = json) } - ?: Price(_json = json) + ?.let { Price(minimum = it, _json = json) } ?: Price(_json = json) } - "tiered_package_with_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredPackageWithMinimum = it, _json = json) } - ?: Price(_json = json) + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(percent = it, _json = json) + } ?: Price(_json = json) } - "grouped_tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedTiered = it, _json = json) } - ?: Price(_json = json) + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(eventOutput = it, _json = json) + } ?: Price(_json = json) } } @@ -5490,2916 +5735,23836 @@ private constructor( ) { when { value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> + generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) value.thresholdTotalAmount != null -> generator.writeObject(value.thresholdTotalAmount) value.tieredPackage != null -> generator.writeObject(value.tieredPackage) value.tieredWithMinimum != null -> generator.writeObject(value.tieredWithMinimum) - value.unitWithPercent != null -> - generator.writeObject(value.unitWithPercent) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) + value.tieredPackageWithMinimum != null -> + generator.writeObject(value.tieredPackageWithMinimum) value.packageWithAllocation != null -> generator.writeObject(value.packageWithAllocation) + value.unitWithPercent != null -> + generator.writeObject(value.unitWithPercent) + value.matrixWithAllocation != null -> + generator.writeObject(value.matrixWithAllocation) value.tieredWithProration != null -> generator.writeObject(value.tieredWithProration) value.unitWithProration != null -> generator.writeObject(value.unitWithProration) value.groupedAllocation != null -> generator.writeObject(value.groupedAllocation) - value.groupedWithProratedMinimum != null -> - generator.writeObject(value.groupedWithProratedMinimum) value.bulkWithProration != null -> generator.writeObject(value.bulkWithProration) - value.scalableMatrixWithUnitPricing != null -> - generator.writeObject(value.scalableMatrixWithUnitPricing) - value.scalableMatrixWithTieredPricing != null -> - generator.writeObject(value.scalableMatrixWithTieredPricing) - value.cumulativeGroupedBulk != null -> - generator.writeObject(value.cumulativeGroupedBulk) - value.maxGroupTieredPackage != null -> - generator.writeObject(value.maxGroupTieredPackage) + value.groupedWithProratedMinimum != null -> + generator.writeObject(value.groupedWithProratedMinimum) value.groupedWithMeteredMinimum != null -> generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) value.matrixWithDisplayName != null -> generator.writeObject(value.matrixWithDisplayName) value.groupedTieredPackage != null -> generator.writeObject(value.groupedTieredPackage) - value.matrixWithAllocation != null -> - generator.writeObject(value.matrixWithAllocation) - value.tieredPackageWithMinimum != null -> - generator.writeObject(value.tieredPackageWithMinimum) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) + value.maxGroupTieredPackage != null -> + generator.writeObject(value.maxGroupTieredPackage) + value.scalableMatrixWithUnitPricing != null -> + generator.writeObject(value.scalableMatrixWithUnitPricing) + value.scalableMatrixWithTieredPricing != null -> + generator.writeObject(value.scalableMatrixWithTieredPricing) + value.cumulativeGroupedBulk != null -> + generator.writeObject(value.cumulativeGroupedBulk) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Price") } } } - } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bulkWithFiltersConfig: JsonField, + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) - return /* spotless:off */ other is AddPrice && allocationPrice == other.allocationPrice && discounts == other.discounts && endDate == other.endDate && externalPriceId == other.externalPriceId && maximumAmount == other.maximumAmount && minimumAmount == other.minimumAmount && planPhaseOrder == other.planPhaseOrder && price == other.price && priceId == other.priceId && startDate == other.startDate && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(allocationPrice, discounts, endDate, externalPriceId, maximumAmount, minimumAmount, planPhaseOrder, price, priceId, startDate, additionalProperties) } - /* spotless:on */ + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - override fun hashCode(): Int = hashCode + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - override fun toString() = - "AddPrice{allocationPrice=$allocationPrice, discounts=$discounts, endDate=$endDate, externalPriceId=$externalPriceId, maximumAmount=$maximumAmount, minimumAmount=$minimumAmount, planPhaseOrder=$planPhaseOrder, price=$price, priceId=$priceId, startDate=$startDate, additionalProperties=$additionalProperties}" - } + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - /** - * Reset billing periods to be aligned with the plan change's effective date or start of the - * month. Defaults to `unchanged` which keeps subscription's existing billing cycle alignment. - */ - class BillingCycleAlignment - @JsonCreator - private constructor(private val value: JsonField) : Enum { + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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 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 + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - companion object { + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - val UNCHANGED = of("unchanged") + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - val PLAN_CHANGE_DATE = of("plan_change_date") + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - val START_OF_MONTH = of("start_of_month") + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - fun of(value: String) = BillingCycleAlignment(JsonField.of(value)) - } + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - /** An enum containing [BillingCycleAlignment]'s known values. */ - enum class Known { - UNCHANGED, - PLAN_CHANGE_DATE, - START_OF_MONTH, - } + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - /** - * An enum containing [BillingCycleAlignment]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [BillingCycleAlignment] 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 { - UNCHANGED, - PLAN_CHANGE_DATE, - START_OF_MONTH, - /** - * An enum member indicating that [BillingCycleAlignment] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - /** - * 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) { - UNCHANGED -> Value.UNCHANGED - PLAN_CHANGE_DATE -> Value.PLAN_CHANGE_DATE - START_OF_MONTH -> Value.START_OF_MONTH - else -> Value._UNKNOWN - } + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - /** - * 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - UNCHANGED -> Known.UNCHANGED - PLAN_CHANGE_DATE -> Known.PLAN_CHANGE_DATE - START_OF_MONTH -> Known.START_OF_MONTH - else -> throw OrbInvalidDataException("Unknown BillingCycleAlignment: $value") - } + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - /** - * 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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - private var validated: Boolean = false + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - fun validate(): BillingCycleAlignment = apply { - if (validated) { - return@apply - } + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - known() - validated = true - } + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = + bulkWithFiltersConfig - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - return /* spotless:off */ other is BillingCycleAlignment && value == other.value /* spotless:on */ - } + /** + * 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 - override fun hashCode() = value.hashCode() + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - override fun toString() = value.toString() - } + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - class RemoveAdjustment - private constructor( - private val adjustmentId: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - @JsonCreator - private constructor( - @JsonProperty("adjustment_id") - @ExcludeMissing - adjustmentId: JsonField = JsonMissing.of() - ) : this(adjustmentId, mutableMapOf()) + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - /** - * The id of the adjustment to remove on the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun adjustmentId(): String = adjustmentId.getRequired("adjustment_id") + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - /** - * Returns the raw JSON value of [adjustmentId]. - * - * Unlike [adjustmentId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("adjustment_id") - @ExcludeMissing - fun _adjustmentId(): JsonField = adjustmentId + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - fun toBuilder() = Builder().from(this) + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - companion object { + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - /** - * Returns a mutable builder for constructing an instance of [RemoveAdjustment]. - * - * The following fields are required: - * ```kotlin - * .adjustmentId() - * ``` - */ - fun builder() = Builder() - } + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - /** A builder for [RemoveAdjustment]. */ - class Builder internal constructor() { + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - private var adjustmentId: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - internal fun from(removeAdjustment: RemoveAdjustment) = apply { - adjustmentId = removeAdjustment.adjustmentId - additionalProperties = removeAdjustment.additionalProperties.toMutableMap() - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** The id of the adjustment to remove on the subscription. */ - fun adjustmentId(adjustmentId: String) = adjustmentId(JsonField.of(adjustmentId)) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [BulkWithFilters]. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } - /** - * Sets [Builder.adjustmentId] to an arbitrary JSON value. - * - * You should usually call [Builder.adjustmentId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun adjustmentId(adjustmentId: JsonField) = apply { - this.adjustmentId = adjustmentId - } + /** A builder for [BulkWithFilters]. */ + class Builder internal constructor() { + + private var bulkWithFiltersConfig: JsonField? = null + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + itemId = bulkWithFilters.itemId + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + billableMetricId = bulkWithFilters.billableMetricId + billedInAdvance = bulkWithFilters.billedInAdvance + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + currency = bulkWithFilters.currency + dimensionalPriceConfiguration = + bulkWithFilters.dimensionalPriceConfiguration + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoiceGroupingKey = bulkWithFilters.invoiceGroupingKey + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + metadata = bulkWithFilters.metadata + referenceId = bulkWithFilters.referenceId + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig( + bulkWithFiltersConfig: JsonField + ) = apply { this.bulkWithFiltersConfig = bulkWithFiltersConfig } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - /** - * Returns an immutable instance of [RemoveAdjustment]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .adjustmentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): RemoveAdjustment = - RemoveAdjustment( - checkRequired("adjustmentId", adjustmentId), - additionalProperties.toMutableMap(), - ) - } + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - private var validated: Boolean = false + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - fun validate(): RemoveAdjustment = apply { - if (validated) { - return@apply - } + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - adjustmentId() - validated = true - } + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = (if (adjustmentId.asKnown() == null) 0 else 1) + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - return /* spotless:off */ other is RemoveAdjustment && adjustmentId == other.adjustmentId && additionalProperties == other.additionalProperties /* spotless:on */ - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustmentId, additionalProperties) } - /* spotless:on */ + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - override fun hashCode(): Int = hashCode + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - override fun toString() = - "RemoveAdjustment{adjustmentId=$adjustmentId, additionalProperties=$additionalProperties}" - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - class RemovePrice - private constructor( - private val externalPriceId: JsonField, - private val priceId: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * Returns an immutable instance of [BulkWithFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFilters = + BulkWithFilters( + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - @JsonCreator - private constructor( - @JsonProperty("external_price_id") - @ExcludeMissing - externalPriceId: JsonField = JsonMissing.of(), - @JsonProperty("price_id") @ExcludeMissing priceId: JsonField = JsonMissing.of(), - ) : this(externalPriceId, priceId, mutableMapOf()) + private var validated: Boolean = false - /** - * The external price id of the price to remove on the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + fun validate(): BulkWithFilters = apply { + if (validated) { + return@apply + } - /** - * The id of the price to remove on the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun priceId(): String? = priceId.getNullable("price_id") + bulkWithFiltersConfig().validate() + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("bulk_with_filters")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - /** - * Returns the raw JSON value of [externalPriceId]. - * - * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("external_price_id") - @ExcludeMissing - fun _externalPriceId(): JsonField = externalPriceId + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** - * Returns the raw JSON value of [priceId]. - * - * Unlike [priceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("price_id") @ExcludeMissing fun _priceId(): JsonField = priceId + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) + + /** + * Property filters to apply (all must match) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [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) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() + } - fun toBuilder() = Builder().from(this) + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { - companion object { + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() - /** Returns a mutable builder for constructing an instance of [RemovePrice]. */ - fun builder() = Builder() - } + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithFiltersConfig.additionalProperties.toMutableMap() + } - /** A builder for [RemovePrice]. */ - class Builder internal constructor() { + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } - private var externalPriceId: JsonField = JsonMissing.of() - private var priceId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } - internal fun from(removePrice: RemovePrice) = apply { - externalPriceId = removePrice.externalPriceId - priceId = removePrice.priceId - additionalProperties = removePrice.additionalProperties.toMutableMap() - } + /** Bulk tiers for rating based on total usage volume */ + 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() } + } - /** The external price id of the price to remove on the subscription. */ - fun externalPriceId(externalPriceId: String?) = - externalPriceId(JsonField.ofNullable(externalPriceId)) + /** + * 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) + } + } - /** - * Sets [Builder.externalPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.externalPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun externalPriceId(externalPriceId: JsonField) = apply { - this.externalPriceId = externalPriceId - } + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** The id of the price to remove on the subscription. */ - fun priceId(priceId: String?) = priceId(JsonField.ofNullable(priceId)) + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** - * Sets [Builder.priceId] to an arbitrary JSON value. - * - * You should usually call [Builder.priceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun priceId(priceId: JsonField) = apply { this.priceId = priceId } + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + /** + * Returns an immutable instance of [BulkWithFiltersConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + private var validated: Boolean = false - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } - /** - * Returns an immutable instance of [RemovePrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): RemovePrice = - RemovePrice(externalPriceId, priceId, additionalProperties.toMutableMap()) - } + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } - private var validated: Boolean = false + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun validate(): RemovePrice = apply { - if (validated) { - return@apply - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - externalPriceId() - priceId() - validated = true - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = + propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (priceId.asKnown() == null) 0 else 1) + private var validated: Boolean = false - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun validate(): Filter = apply { + if (validated) { + return@apply + } - return /* spotless:off */ other is RemovePrice && externalPriceId == other.externalPriceId && priceId == other.priceId && additionalProperties == other.additionalProperties /* spotless:on */ - } + propertyKey() + propertyValue() + validated = true + } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(externalPriceId, priceId, additionalProperties) } - /* spotless:on */ + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } - override fun hashCode(): Int = hashCode + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } - override fun toString() = - "RemovePrice{externalPriceId=$externalPriceId, priceId=$priceId, additionalProperties=$additionalProperties}" - } + override fun hashCode(): Int = hashCode - class ReplaceAdjustment - private constructor( - private val adjustment: JsonField, - private val replacesAdjustmentId: JsonField, - private val additionalProperties: MutableMap, - ) { + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } - @JsonCreator - private constructor( - @JsonProperty("adjustment") - @ExcludeMissing - adjustment: JsonField = JsonMissing.of(), - @JsonProperty("replaces_adjustment_id") - @ExcludeMissing - replacesAdjustmentId: JsonField = JsonMissing.of(), - ) : this(adjustment, replacesAdjustmentId, mutableMapOf()) + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = + tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** - * The definition of a new adjustment to create and add to the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun adjustment(): Adjustment = adjustment.getRequired("adjustment") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - /** - * The id of the adjustment on the plan to replace in the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun replacesAdjustmentId(): String = - replacesAdjustmentId.getRequired("replaces_adjustment_id") + fun toBuilder() = Builder().from(this) - /** - * Returns the raw JSON value of [adjustment]. - * - * Unlike [adjustment], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("adjustment") - @ExcludeMissing - fun _adjustment(): JsonField = adjustment + companion object { - /** - * Returns the raw JSON value of [replacesAdjustmentId]. - * - * Unlike [replacesAdjustmentId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("replaces_adjustment_id") - @ExcludeMissing - fun _replacesAdjustmentId(): JsonField = replacesAdjustmentId + /** + * Returns a mutable builder for constructing an instance of [Tier]. + * + * The following fields are required: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + private var validated: Boolean = false - fun toBuilder() = Builder().from(this) + fun validate(): Tier = apply { + if (validated) { + return@apply + } - companion object { + unitAmount() + tierLowerBound() + validated = true + } - /** - * Returns a mutable builder for constructing an instance of [ReplaceAdjustment]. - * - * The following fields are required: - * ```kotlin - * .adjustment() - * .replacesAdjustmentId() - * ``` - */ - fun builder() = Builder() - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } - /** A builder for [ReplaceAdjustment]. */ - class Builder internal constructor() { + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } - private var adjustment: JsonField? = null - private var replacesAdjustmentId: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() + override fun hashCode(): Int = hashCode - internal fun from(replaceAdjustment: ReplaceAdjustment) = apply { - adjustment = replaceAdjustment.adjustment - replacesAdjustmentId = replaceAdjustment.replacesAdjustmentId - additionalProperties = replaceAdjustment.additionalProperties.toMutableMap() - } + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } - /** The definition of a new adjustment to create and add to the subscription. */ - fun adjustment(adjustment: Adjustment) = adjustment(JsonField.of(adjustment)) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * Sets [Builder.adjustment] to an arbitrary JSON value. - * - * You should usually call [Builder.adjustment] with a well-typed [Adjustment] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun adjustment(adjustment: JsonField) = apply { - this.adjustment = adjustment - } + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } - /** - * Alias for calling [adjustment] with - * `Adjustment.ofPercentageDiscount(percentageDiscount)`. - */ - fun adjustment(percentageDiscount: NewPercentageDiscount) = - adjustment(Adjustment.ofPercentageDiscount(percentageDiscount)) + private val hashCode: Int by lazy { + Objects.hash(filters, tiers, additionalProperties) + } - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewPercentageDiscount.builder() - * .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) - * .percentageDiscount(percentageDiscount) - * .build() - * ``` - */ - fun percentageDiscountAdjustment(percentageDiscount: Double) = - adjustment( - NewPercentageDiscount.builder() - .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) - .percentageDiscount(percentageDiscount) - .build() - ) - - /** Alias for calling [adjustment] with `Adjustment.ofUsageDiscount(usageDiscount)`. */ - fun adjustment(usageDiscount: NewUsageDiscount) = - adjustment(Adjustment.ofUsageDiscount(usageDiscount)) - - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewUsageDiscount.builder() - * .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) - * .usageDiscount(usageDiscount) - * .build() - * ``` - */ - fun usageDiscountAdjustment(usageDiscount: Double) = - adjustment( - NewUsageDiscount.builder() - .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) - .usageDiscount(usageDiscount) - .build() - ) - - /** - * Alias for calling [adjustment] with `Adjustment.ofAmountDiscount(amountDiscount)`. - */ - fun adjustment(amountDiscount: NewAmountDiscount) = - adjustment(Adjustment.ofAmountDiscount(amountDiscount)) + override fun hashCode(): Int = hashCode - /** - * Alias for calling [adjustment] with the following: - * ```kotlin - * NewAmountDiscount.builder() - * .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) - * .amountDiscount(amountDiscount) - * .build() - * ``` - */ - fun amountDiscountAdjustment(amountDiscount: String) = - adjustment( - NewAmountDiscount.builder() - .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) - .amountDiscount(amountDiscount) - .build() - ) + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } - /** Alias for calling [adjustment] with `Adjustment.ofMinimum(minimum)`. */ - fun adjustment(minimum: NewMinimum) = adjustment(Adjustment.ofMinimum(minimum)) + /** The cadence to bill for this price on. */ + class Cadence + @JsonCreator + private constructor(private val value: JsonField) : Enum { - /** Alias for calling [adjustment] with `Adjustment.ofMaximum(maximum)`. */ - fun adjustment(maximum: NewMaximum) = adjustment(Adjustment.ofMaximum(maximum)) + /** + * 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 [adjustment] with the following: - * ```kotlin - * NewMaximum.builder() - * .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) - * .maximumAmount(maximumAmount) - * .build() - * ``` - */ - fun maximumAdjustment(maximumAmount: String) = - adjustment( - NewMaximum.builder() - .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) - .maximumAmount(maximumAmount) - .build() - ) + companion object { - /** The id of the adjustment on the plan to replace in the subscription. */ - fun replacesAdjustmentId(replacesAdjustmentId: String) = - replacesAdjustmentId(JsonField.of(replacesAdjustmentId)) + val ANNUAL = of("annual") - /** - * Sets [Builder.replacesAdjustmentId] to an arbitrary JSON value. - * - * You should usually call [Builder.replacesAdjustmentId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun replacesAdjustmentId(replacesAdjustmentId: JsonField) = apply { - this.replacesAdjustmentId = replacesAdjustmentId - } + val SEMI_ANNUAL = of("semi_annual") - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + val MONTHLY = of("monthly") - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + val QUARTERLY = of("quarterly") - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + val ONE_TIME = of("one_time") - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + val CUSTOM = of("custom") - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun of(value: String) = Cadence(JsonField.of(value)) + } - /** - * Returns an immutable instance of [ReplaceAdjustment]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .adjustment() - * .replacesAdjustmentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ReplaceAdjustment = - ReplaceAdjustment( - checkRequired("adjustment", adjustment), - checkRequired("replacesAdjustmentId", replacesAdjustmentId), - additionalProperties.toMutableMap(), - ) - } + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - private var validated: Boolean = false + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - fun validate(): ReplaceAdjustment = apply { - if (validated) { - return@apply - } + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN + } - adjustment().validate() - replacesAdjustmentId() - validated = true - } + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (adjustment.asKnown()?.validity() ?: 0) + - (if (replacesAdjustmentId.asKnown() == null) 0 else 1) + known() + validated = true + } - /** The definition of a new adjustment to create and add to the subscription. */ - @JsonDeserialize(using = Adjustment.Deserializer::class) - @JsonSerialize(using = Adjustment.Serializer::class) - class Adjustment - private constructor( - private val percentageDiscount: NewPercentageDiscount? = null, - private val usageDiscount: NewUsageDiscount? = null, - private val amountDiscount: NewAmountDiscount? = null, - private val minimum: NewMinimum? = null, - private val maximum: NewMaximum? = null, - private val _json: JsonValue? = null, - ) { + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun percentageDiscount(): NewPercentageDiscount? = percentageDiscount + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun usageDiscount(): NewUsageDiscount? = usageDiscount + return other is Cadence && value == other.value + } - fun amountDiscount(): NewAmountDiscount? = amountDiscount + override fun hashCode() = value.hashCode() - fun minimum(): NewMinimum? = minimum + override fun toString() = value.toString() + } - fun maximum(): NewMaximum? = maximum + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - fun isPercentageDiscount(): Boolean = percentageDiscount != null + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - fun isUsageDiscount(): Boolean = usageDiscount != null + fun toBuilder() = Builder().from(this) - fun isAmountDiscount(): Boolean = amountDiscount != null + companion object { - fun isMinimum(): Boolean = minimum != null + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + fun builder() = Builder() + } - fun isMaximum(): Boolean = maximum != null + /** A builder for [Metadata]. */ + class Builder internal constructor() { - fun asPercentageDiscount(): NewPercentageDiscount = - percentageDiscount.getOrThrow("percentageDiscount") + private var additionalProperties: MutableMap = + mutableMapOf() - fun asUsageDiscount(): NewUsageDiscount = usageDiscount.getOrThrow("usageDiscount") + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } - fun asAmountDiscount(): NewAmountDiscount = amountDiscount.getOrThrow("amountDiscount") + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun asMinimum(): NewMinimum = minimum.getOrThrow("minimum") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun asMaximum(): NewMaximum = maximum.getOrThrow("maximum") + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - fun _json(): JsonValue? = _json + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun accept(visitor: Visitor): T = - when { - percentageDiscount != null -> - visitor.visitPercentageDiscount(percentageDiscount) - usageDiscount != null -> visitor.visitUsageDiscount(usageDiscount) - amountDiscount != null -> visitor.visitAmountDiscount(amountDiscount) - minimum != null -> visitor.visitMinimum(minimum) - maximum != null -> visitor.visitMaximum(maximum) - else -> visitor.unknown(_json) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - private var validated: Boolean = false + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } - fun validate(): Adjustment = apply { - if (validated) { - return@apply - } + private var validated: Boolean = false - accept( - object : Visitor { - override fun visitPercentageDiscount( - percentageDiscount: NewPercentageDiscount - ) { - percentageDiscount.validate() + fun validate(): Metadata = apply { + if (validated) { + return@apply } - override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) { - usageDiscount.validate() - } + validated = true + } - override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) { - amountDiscount.validate() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - override fun visitMinimum(minimum: NewMinimum) { - minimum.validate() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() } - override fun visitMaximum(maximum: NewMaximum) { - maximum.validate() + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Metadata && + additionalProperties == other.additionalProperties } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitPercentageDiscount( - percentageDiscount: NewPercentageDiscount - ) = percentageDiscount.validity() + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) = - usageDiscount.validity() + return other is BulkWithFilters && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } - override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) = - amountDiscount.validity() + private val hashCode: Int by lazy { + Objects.hash( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } - override fun visitMinimum(minimum: NewMinimum) = minimum.validity() + override fun hashCode(): Int = hashCode - override fun visitMaximum(maximum: NewMaximum) = maximum.validity() + override fun toString() = + "BulkWithFilters{bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } - override fun unknown(json: JsonValue?) = 0 - } + class TieredWithProration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val tieredWithProrationConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + tieredWithProrationConfig: JsonField = + JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - return /* spotless:off */ other is Adjustment && percentageDiscount == other.percentageDiscount && usageDiscount == other.usageDiscount && amountDiscount == other.amountDiscount && minimum == other.minimum && maximum == other.maximum /* spotless:on */ - } + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) /* spotless:on */ + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - override fun toString(): String = - when { - percentageDiscount != null -> - "Adjustment{percentageDiscount=$percentageDiscount}" - usageDiscount != null -> "Adjustment{usageDiscount=$usageDiscount}" - amountDiscount != null -> "Adjustment{amountDiscount=$amountDiscount}" - minimum != null -> "Adjustment{minimum=$minimum}" - maximum != null -> "Adjustment{maximum=$maximum}" - _json != null -> "Adjustment{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Adjustment") - } + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - companion object { + /** + * Configuration for tiered_with_proration pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tieredWithProrationConfig(): TieredWithProrationConfig = + tieredWithProrationConfig.getRequired("tiered_with_proration_config") - fun ofPercentageDiscount(percentageDiscount: NewPercentageDiscount) = - Adjustment(percentageDiscount = percentageDiscount) + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - fun ofUsageDiscount(usageDiscount: NewUsageDiscount) = - Adjustment(usageDiscount = usageDiscount) + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - fun ofAmountDiscount(amountDiscount: NewAmountDiscount) = - Adjustment(amountDiscount = amountDiscount) + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - fun ofMinimum(minimum: NewMinimum) = Adjustment(minimum = minimum) + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - fun ofMaximum(maximum: NewMaximum) = Adjustment(maximum = maximum) - } + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - /** - * An interface that defines how to map each variant of [Adjustment] to a value of type - * [T]. - */ - interface Visitor { + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - fun visitPercentageDiscount(percentageDiscount: NewPercentageDiscount): T + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - fun visitUsageDiscount(usageDiscount: NewUsageDiscount): T + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - fun visitAmountDiscount(amountDiscount: NewAmountDiscount): T + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - fun visitMinimum(minimum: NewMinimum): T + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - fun visitMaximum(maximum: NewMaximum): T + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") /** - * Maps an unknown variant of [Adjustment] to a value of type [T]. + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. * - * An instance of [Adjustment] can contain an unknown variant if it was deserialized - * from data that doesn't match any known variant. For example, if the SDK is on an - * older version than the API, then the API may respond with new variants that the - * SDK is unaware of. + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. * - * @throws OrbInvalidDataException in the default implementation. + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown Adjustment: $json") + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [tieredWithProrationConfig]. + * + * Unlike [tieredWithProrationConfig], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + fun _tieredWithProrationConfig(): JsonField = + tieredWithProrationConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - } - internal class Deserializer : BaseDeserializer(Adjustment::class) { + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [TieredWithProration]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + */ + fun builder() = Builder() + } - override fun ObjectCodec.deserialize(node: JsonNode): Adjustment { - val json = JsonValue.fromJsonNode(node) - val adjustmentType = json.asObject()?.get("adjustment_type")?.asString() + /** A builder for [TieredWithProration]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("tiered_with_proration") + private var name: JsonField? = null + private var tieredWithProrationConfig: JsonField? = + null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tieredWithProration: TieredWithProration) = apply { + cadence = tieredWithProration.cadence + itemId = tieredWithProration.itemId + modelType = tieredWithProration.modelType + name = tieredWithProration.name + tieredWithProrationConfig = tieredWithProration.tieredWithProrationConfig + billableMetricId = tieredWithProration.billableMetricId + billedInAdvance = tieredWithProration.billedInAdvance + billingCycleConfiguration = tieredWithProration.billingCycleConfiguration + conversionRate = tieredWithProration.conversionRate + conversionRateConfig = tieredWithProration.conversionRateConfig + currency = tieredWithProration.currency + dimensionalPriceConfiguration = + tieredWithProration.dimensionalPriceConfiguration + externalPriceId = tieredWithProration.externalPriceId + fixedPriceQuantity = tieredWithProration.fixedPriceQuantity + invoiceGroupingKey = tieredWithProration.invoiceGroupingKey + invoicingCycleConfiguration = + tieredWithProration.invoicingCycleConfiguration + metadata = tieredWithProration.metadata + referenceId = tieredWithProration.referenceId + additionalProperties = + tieredWithProration.additionalProperties.toMutableMap() + } - when (adjustmentType) { - "percentage_discount" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Adjustment(percentageDiscount = it, _json = json) } - ?: Adjustment(_json = json) - } - "usage_discount" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(usageDiscount = it, _json = json) - } ?: Adjustment(_json = json) - } - "amount_discount" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(amountDiscount = it, _json = json) - } ?: Adjustment(_json = json) - } - "minimum" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(minimum = it, _json = json) - } ?: Adjustment(_json = json) - } - "maximum" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Adjustment(maximum = it, _json = json) - } ?: Adjustment(_json = json) - } + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for tiered_with_proration pricing */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: TieredWithProrationConfig + ) = tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) + + /** + * Sets [Builder.tieredWithProrationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.tieredWithProrationConfig] with a well-typed + * [TieredWithProrationConfig] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: JsonField + ) = apply { this.tieredWithProrationConfig = tieredWithProrationConfig } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId } - return Adjustment(_json = json) - } - } + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - internal class Serializer : BaseSerializer(Adjustment::class) { + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - override fun serialize( - value: Adjustment, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.percentageDiscount != null -> - generator.writeObject(value.percentageDiscount) - value.usageDiscount != null -> generator.writeObject(value.usageDiscount) - value.amountDiscount != null -> generator.writeObject(value.amountDiscount) - value.minimum != null -> generator.writeObject(value.minimum) - value.maximum != null -> generator.writeObject(value.maximum) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Adjustment") + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId } - } - } - } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - return /* spotless:off */ other is ReplaceAdjustment && adjustment == other.adjustment && replacesAdjustmentId == other.replacesAdjustmentId && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(adjustment, replacesAdjustmentId, additionalProperties) } - /* spotless:on */ + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - override fun hashCode(): Int = hashCode + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - override fun toString() = - "ReplaceAdjustment{adjustment=$adjustment, replacesAdjustmentId=$replacesAdjustmentId, additionalProperties=$additionalProperties}" - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - class ReplacePrice - private constructor( - private val replacesPriceId: JsonField, - private val allocationPrice: JsonField, - private val discounts: JsonField>, - private val externalPriceId: JsonField, - private val fixedPriceQuantity: JsonField, - private val maximumAmount: JsonField, - private val minimumAmount: JsonField, - private val price: JsonField, - private val priceId: JsonField, - private val additionalProperties: MutableMap, - ) { + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TieredWithProration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProration = + TieredWithProration( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("tieredWithProrationConfig", tieredWithProrationConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProration = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("tiered_with_proration")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + tieredWithProrationConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("tiered_with_proration")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (tieredWithProrationConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for tiered_with_proration pricing */ + class TieredWithProrationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Tiers for rating based on total usage quantities into the specified tier with + * proration + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 + * [TieredWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProrationConfig]. */ + class Builder internal constructor() { + + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = + apply { + tiers = tieredWithProrationConfig.tiers.map { it.toMutableList() } + additionalProperties = + tieredWithProrationConfig.additionalProperties.toMutableMap() + } + + /** + * Tiers for rating based on total usage quantities into the specified tier + * with proration + */ + 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 [TieredWithProrationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProrationConfig = + TieredWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProrationConfig = apply { + if (validated) { + return@apply + } + + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tiered with proration tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Inclusive tier starting value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun tierLowerBound(): String = + tierLowerBound.getRequired("tier_lower_bound") + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Inclusive tier starting value */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProration && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredWithProrationConfig == other.tieredWithProrationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProration{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, tieredWithProrationConfig=$tieredWithProrationConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val groupedWithMinMaxThresholdsConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + groupedWithMinMaxThresholdsConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for grouped_with_min_max_thresholds pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired( + "grouped_with_min_max_thresholds_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. + * + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + fun _groupedWithMinMaxThresholdsConfig(): + JsonField = groupedWithMinMaxThresholdsConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [GroupedWithMinMaxThresholds]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholds]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("grouped_with_min_max_thresholds") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = + apply { + cadence = groupedWithMinMaxThresholds.cadence + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + itemId = groupedWithMinMaxThresholds.itemId + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + billableMetricId = groupedWithMinMaxThresholds.billableMetricId + billedInAdvance = groupedWithMinMaxThresholds.billedInAdvance + billingCycleConfiguration = + groupedWithMinMaxThresholds.billingCycleConfiguration + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + currency = groupedWithMinMaxThresholds.currency + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + invoiceGroupingKey = groupedWithMinMaxThresholds.invoiceGroupingKey + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + metadata = groupedWithMinMaxThresholds.metadata + referenceId = groupedWithMinMaxThresholds.referenceId + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = + groupedWithMinMaxThresholdsConfig( + JsonField.of(groupedWithMinMaxThresholdsConfig) + ) + + /** + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a + * well-typed [GroupedWithMinMaxThresholdsConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: + JsonField + ) = apply { + this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( + checkRequired("cadence", cadence), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholds = apply { + if (validated) { + return@apply + } + + cadence().validate() + groupedWithMinMaxThresholdsConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @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 + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate + additionalProperties = + groupedWithMinMaxThresholdsConfig.additionalProperties + .toMutableMap() + } + + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } + + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } + + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = + perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + if (validated) { + return@apply + } + + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholds && + cadence == other.cadence && + groupedWithMinMaxThresholdsConfig == + other.groupedWithMinMaxThresholdsConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholds{cadence=$cadence, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val cumulativeGroupedAllocationConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for cumulative_grouped_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired( + "cumulative_grouped_allocation_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): + JsonField = cumulativeGroupedAllocationConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [CumulativeGroupedAllocation]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocation]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("cumulative_grouped_allocation") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = + apply { + cadence = cumulativeGroupedAllocation.cadence + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + itemId = cumulativeGroupedAllocation.itemId + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + billableMetricId = cumulativeGroupedAllocation.billableMetricId + billedInAdvance = cumulativeGroupedAllocation.billedInAdvance + billingCycleConfiguration = + cumulativeGroupedAllocation.billingCycleConfiguration + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + currency = cumulativeGroupedAllocation.currency + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoiceGroupingKey = cumulativeGroupedAllocation.invoiceGroupingKey + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + metadata = cumulativeGroupedAllocation.metadata + referenceId = cumulativeGroupedAllocation.referenceId + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = + cumulativeGroupedAllocationConfig( + JsonField.of(cumulativeGroupedAllocationConfig) + ) + + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a + * well-typed [CumulativeGroupedAllocationConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: + JsonField + ) = apply { + this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( + checkRequired("cadence", cadence), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocation = apply { + if (validated) { + return@apply + } + + cadence().validate() + cumulativeGroupedAllocationConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("cumulative_grouped_allocation")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + mutableMapOf(), + ) + + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 + * [CumulativeGroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = + cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties + .toMutableMap() + } + + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } + + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation + } + + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply + } + + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CumulativeGroupedAllocation && + cadence == other.cadence && + cumulativeGroupedAllocationConfig == + other.cumulativeGroupedAllocationConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CumulativeGroupedAllocation{cadence=$cadence, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val percentConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [Percent]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Percent]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("percent") + private var name: JsonField? = null + private var percentConfig: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percent: Percent) = apply { + cadence = percent.cadence + itemId = percent.itemId + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + billableMetricId = percent.billableMetricId + billedInAdvance = percent.billedInAdvance + billingCycleConfiguration = percent.billingCycleConfiguration + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + currency = percent.currency + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoiceGroupingKey = percent.invoiceGroupingKey + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + metadata = percent.metadata + referenceId = percent.referenceId + additionalProperties = percent.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed + * [PercentConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Percent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Percent = + Percent( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("percentConfig", percentConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Percent = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("percent")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + percentConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent") + @ExcludeMissing + fun _percent(): JsonField = percent + + @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 + * [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [PercentConfig]. */ + class Builder internal constructor() { + + private var percent: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() + } + + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [PercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PercentConfig = apply { + if (validated) { + return@apply + } + + percent() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(percent, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Percent && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Percent{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, percentConfig=$percentConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val eventOutputConfig: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [EventOutput]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutput]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var eventOutputConfig: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("event_output") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutput: EventOutput) = apply { + cadence = eventOutput.cadence + eventOutputConfig = eventOutput.eventOutputConfig + itemId = eventOutput.itemId + modelType = eventOutput.modelType + name = eventOutput.name + billableMetricId = eventOutput.billableMetricId + billedInAdvance = eventOutput.billedInAdvance + billingCycleConfiguration = eventOutput.billingCycleConfiguration + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + currency = eventOutput.currency + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoiceGroupingKey = eventOutput.invoiceGroupingKey + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + metadata = eventOutput.metadata + referenceId = eventOutput.referenceId + additionalProperties = eventOutput.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutput = + EventOutput( + checkRequired("cadence", cadence), + checkRequired("eventOutputConfig", eventOutputConfig), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutput = apply { + if (validated) { + return@apply + } + + cadence().validate() + eventOutputConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("event_output")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a + * unit rate will be ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = + defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events + * will also be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @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 + * [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutputConfig]. */ + class Builder internal constructor() { + + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = + eventOutputConfig.additionalProperties.toMutableMap() + } + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey + } + + /** + * If provided, this amount will be used as the unit rate when an event does + * not have a value for the `unit_rating_key`. If not provided, events + * missing a unit rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate + } + + /** + * An optional key in the event data to group by (e.g., event ID). All + * events will also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EventOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutputConfig = apply { + if (validated) { + return@apply + } + + unitRatingKey() + defaultUnitRate() + groupingKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + unitRatingKey, + defaultUnitRate, + groupingKey, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventOutput && + cadence == other.cadence && + eventOutputConfig == other.eventOutputConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutput{cadence=$cadence, eventOutputConfig=$eventOutputConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddPrice && + allocationPrice == other.allocationPrice && + discounts == other.discounts && + endDate == other.endDate && + externalPriceId == other.externalPriceId && + maximumAmount == other.maximumAmount && + minimumAmount == other.minimumAmount && + planPhaseOrder == other.planPhaseOrder && + price == other.price && + priceId == other.priceId && + startDate == other.startDate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + allocationPrice, + discounts, + endDate, + externalPriceId, + maximumAmount, + minimumAmount, + planPhaseOrder, + price, + priceId, + startDate, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddPrice{allocationPrice=$allocationPrice, discounts=$discounts, endDate=$endDate, externalPriceId=$externalPriceId, maximumAmount=$maximumAmount, minimumAmount=$minimumAmount, planPhaseOrder=$planPhaseOrder, price=$price, priceId=$priceId, startDate=$startDate, additionalProperties=$additionalProperties}" + } + + /** + * Reset billing periods to be aligned with the plan change's effective date or start of the + * month. Defaults to `unchanged` which keeps subscription's existing billing cycle alignment. + */ + class BillingCycleAlignment + @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 { + + val UNCHANGED = of("unchanged") + + val PLAN_CHANGE_DATE = of("plan_change_date") + + val START_OF_MONTH = of("start_of_month") + + fun of(value: String) = BillingCycleAlignment(JsonField.of(value)) + } + + /** An enum containing [BillingCycleAlignment]'s known values. */ + enum class Known { + UNCHANGED, + PLAN_CHANGE_DATE, + START_OF_MONTH, + } + + /** + * An enum containing [BillingCycleAlignment]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [BillingCycleAlignment] 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 { + UNCHANGED, + PLAN_CHANGE_DATE, + START_OF_MONTH, + /** + * An enum member indicating that [BillingCycleAlignment] 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) { + UNCHANGED -> Value.UNCHANGED + PLAN_CHANGE_DATE -> Value.PLAN_CHANGE_DATE + START_OF_MONTH -> Value.START_OF_MONTH + 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 OrbInvalidDataException if this class instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + UNCHANGED -> Known.UNCHANGED + PLAN_CHANGE_DATE -> Known.PLAN_CHANGE_DATE + START_OF_MONTH -> Known.START_OF_MONTH + else -> throw OrbInvalidDataException("Unknown BillingCycleAlignment: $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 OrbInvalidDataException if this class instance's value does not have the expected + * primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): BillingCycleAlignment = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 BillingCycleAlignment && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class RemoveAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val adjustmentId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("adjustment_id") + @ExcludeMissing + adjustmentId: JsonField = JsonMissing.of() + ) : this(adjustmentId, mutableMapOf()) + + /** + * The id of the adjustment to remove on the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun adjustmentId(): String = adjustmentId.getRequired("adjustment_id") + + /** + * Returns the raw JSON value of [adjustmentId]. + * + * Unlike [adjustmentId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("adjustment_id") + @ExcludeMissing + fun _adjustmentId(): JsonField = adjustmentId + + @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 [RemoveAdjustment]. + * + * The following fields are required: + * ```kotlin + * .adjustmentId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [RemoveAdjustment]. */ + class Builder internal constructor() { + + private var adjustmentId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(removeAdjustment: RemoveAdjustment) = apply { + adjustmentId = removeAdjustment.adjustmentId + additionalProperties = removeAdjustment.additionalProperties.toMutableMap() + } + + /** The id of the adjustment to remove on the subscription. */ + fun adjustmentId(adjustmentId: String) = adjustmentId(JsonField.of(adjustmentId)) + + /** + * Sets [Builder.adjustmentId] to an arbitrary JSON value. + * + * You should usually call [Builder.adjustmentId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun adjustmentId(adjustmentId: JsonField) = apply { + this.adjustmentId = adjustmentId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [RemoveAdjustment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .adjustmentId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RemoveAdjustment = + RemoveAdjustment( + checkRequired("adjustmentId", adjustmentId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RemoveAdjustment = apply { + if (validated) { + return@apply + } + + adjustmentId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (adjustmentId.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RemoveAdjustment && + adjustmentId == other.adjustmentId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(adjustmentId, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemoveAdjustment{adjustmentId=$adjustmentId, additionalProperties=$additionalProperties}" + } + + class RemovePrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val externalPriceId: JsonField, + private val priceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("price_id") @ExcludeMissing priceId: JsonField = JsonMissing.of(), + ) : this(externalPriceId, priceId, mutableMapOf()) + + /** + * The external price id of the price to remove on the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * The id of the price to remove on the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun priceId(): String? = priceId.getNullable("price_id") + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [priceId]. + * + * Unlike [priceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("price_id") @ExcludeMissing fun _priceId(): JsonField = priceId + + @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 [RemovePrice]. */ + fun builder() = Builder() + } + + /** A builder for [RemovePrice]. */ + class Builder internal constructor() { + + private var externalPriceId: JsonField = JsonMissing.of() + private var priceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(removePrice: RemovePrice) = apply { + externalPriceId = removePrice.externalPriceId + priceId = removePrice.priceId + additionalProperties = removePrice.additionalProperties.toMutableMap() + } + + /** The external price id of the price to remove on the subscription. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** The id of the price to remove on the subscription. */ + fun priceId(priceId: String?) = priceId(JsonField.ofNullable(priceId)) + + /** + * Sets [Builder.priceId] to an arbitrary JSON value. + * + * You should usually call [Builder.priceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun priceId(priceId: JsonField) = apply { this.priceId = priceId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [RemovePrice]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RemovePrice = + RemovePrice(externalPriceId, priceId, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): RemovePrice = apply { + if (validated) { + return@apply + } + + externalPriceId() + priceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (priceId.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RemovePrice && + externalPriceId == other.externalPriceId && + priceId == other.priceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(externalPriceId, priceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RemovePrice{externalPriceId=$externalPriceId, priceId=$priceId, additionalProperties=$additionalProperties}" + } + + class ReplaceAdjustment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val adjustment: JsonField, + private val replacesAdjustmentId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("adjustment") + @ExcludeMissing + adjustment: JsonField = JsonMissing.of(), + @JsonProperty("replaces_adjustment_id") + @ExcludeMissing + replacesAdjustmentId: JsonField = JsonMissing.of(), + ) : this(adjustment, replacesAdjustmentId, mutableMapOf()) + + /** + * The definition of a new adjustment to create and add to the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun adjustment(): Adjustment = adjustment.getRequired("adjustment") + + /** + * The id of the adjustment on the plan to replace in the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun replacesAdjustmentId(): String = + replacesAdjustmentId.getRequired("replaces_adjustment_id") + + /** + * Returns the raw JSON value of [adjustment]. + * + * Unlike [adjustment], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("adjustment") + @ExcludeMissing + fun _adjustment(): JsonField = adjustment + + /** + * Returns the raw JSON value of [replacesAdjustmentId]. + * + * Unlike [replacesAdjustmentId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("replaces_adjustment_id") + @ExcludeMissing + fun _replacesAdjustmentId(): JsonField = replacesAdjustmentId + + @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 [ReplaceAdjustment]. + * + * The following fields are required: + * ```kotlin + * .adjustment() + * .replacesAdjustmentId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ReplaceAdjustment]. */ + class Builder internal constructor() { + + private var adjustment: JsonField? = null + private var replacesAdjustmentId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(replaceAdjustment: ReplaceAdjustment) = apply { + adjustment = replaceAdjustment.adjustment + replacesAdjustmentId = replaceAdjustment.replacesAdjustmentId + additionalProperties = replaceAdjustment.additionalProperties.toMutableMap() + } + + /** The definition of a new adjustment to create and add to the subscription. */ + fun adjustment(adjustment: Adjustment) = adjustment(JsonField.of(adjustment)) + + /** + * Sets [Builder.adjustment] to an arbitrary JSON value. + * + * You should usually call [Builder.adjustment] with a well-typed [Adjustment] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun adjustment(adjustment: JsonField) = apply { + this.adjustment = adjustment + } + + /** + * Alias for calling [adjustment] with + * `Adjustment.ofPercentageDiscount(percentageDiscount)`. + */ + fun adjustment(percentageDiscount: NewPercentageDiscount) = + adjustment(Adjustment.ofPercentageDiscount(percentageDiscount)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewPercentageDiscount.builder() + * .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) + * .percentageDiscount(percentageDiscount) + * .build() + * ``` + */ + fun percentageDiscountAdjustment(percentageDiscount: Double) = + adjustment( + NewPercentageDiscount.builder() + .adjustmentType(NewPercentageDiscount.AdjustmentType.PERCENTAGE_DISCOUNT) + .percentageDiscount(percentageDiscount) + .build() + ) + + /** Alias for calling [adjustment] with `Adjustment.ofUsageDiscount(usageDiscount)`. */ + fun adjustment(usageDiscount: NewUsageDiscount) = + adjustment(Adjustment.ofUsageDiscount(usageDiscount)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewUsageDiscount.builder() + * .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) + * .usageDiscount(usageDiscount) + * .build() + * ``` + */ + fun usageDiscountAdjustment(usageDiscount: Double) = + adjustment( + NewUsageDiscount.builder() + .adjustmentType(NewUsageDiscount.AdjustmentType.USAGE_DISCOUNT) + .usageDiscount(usageDiscount) + .build() + ) + + /** + * Alias for calling [adjustment] with `Adjustment.ofAmountDiscount(amountDiscount)`. + */ + fun adjustment(amountDiscount: NewAmountDiscount) = + adjustment(Adjustment.ofAmountDiscount(amountDiscount)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewAmountDiscount.builder() + * .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) + * .amountDiscount(amountDiscount) + * .build() + * ``` + */ + fun amountDiscountAdjustment(amountDiscount: String) = + adjustment( + NewAmountDiscount.builder() + .adjustmentType(NewAmountDiscount.AdjustmentType.AMOUNT_DISCOUNT) + .amountDiscount(amountDiscount) + .build() + ) + + /** Alias for calling [adjustment] with `Adjustment.ofMinimum(minimum)`. */ + fun adjustment(minimum: NewMinimum) = adjustment(Adjustment.ofMinimum(minimum)) + + /** Alias for calling [adjustment] with `Adjustment.ofMaximum(maximum)`. */ + fun adjustment(maximum: NewMaximum) = adjustment(Adjustment.ofMaximum(maximum)) + + /** + * Alias for calling [adjustment] with the following: + * ```kotlin + * NewMaximum.builder() + * .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) + * .maximumAmount(maximumAmount) + * .build() + * ``` + */ + fun maximumAdjustment(maximumAmount: String) = + adjustment( + NewMaximum.builder() + .adjustmentType(NewMaximum.AdjustmentType.MAXIMUM) + .maximumAmount(maximumAmount) + .build() + ) + + /** The id of the adjustment on the plan to replace in the subscription. */ + fun replacesAdjustmentId(replacesAdjustmentId: String) = + replacesAdjustmentId(JsonField.of(replacesAdjustmentId)) + + /** + * Sets [Builder.replacesAdjustmentId] to an arbitrary JSON value. + * + * You should usually call [Builder.replacesAdjustmentId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun replacesAdjustmentId(replacesAdjustmentId: JsonField) = apply { + this.replacesAdjustmentId = replacesAdjustmentId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ReplaceAdjustment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .adjustment() + * .replacesAdjustmentId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ReplaceAdjustment = + ReplaceAdjustment( + checkRequired("adjustment", adjustment), + checkRequired("replacesAdjustmentId", replacesAdjustmentId), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ReplaceAdjustment = apply { + if (validated) { + return@apply + } + + adjustment().validate() + replacesAdjustmentId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (adjustment.asKnown()?.validity() ?: 0) + + (if (replacesAdjustmentId.asKnown() == null) 0 else 1) + + /** The definition of a new adjustment to create and add to the subscription. */ + @JsonDeserialize(using = Adjustment.Deserializer::class) + @JsonSerialize(using = Adjustment.Serializer::class) + class Adjustment + private constructor( + private val percentageDiscount: NewPercentageDiscount? = null, + private val usageDiscount: NewUsageDiscount? = null, + private val amountDiscount: NewAmountDiscount? = null, + private val minimum: NewMinimum? = null, + private val maximum: NewMaximum? = null, + private val _json: JsonValue? = null, + ) { + + fun percentageDiscount(): NewPercentageDiscount? = percentageDiscount + + fun usageDiscount(): NewUsageDiscount? = usageDiscount + + fun amountDiscount(): NewAmountDiscount? = amountDiscount + + fun minimum(): NewMinimum? = minimum + + fun maximum(): NewMaximum? = maximum + + fun isPercentageDiscount(): Boolean = percentageDiscount != null + + fun isUsageDiscount(): Boolean = usageDiscount != null + + fun isAmountDiscount(): Boolean = amountDiscount != null + + fun isMinimum(): Boolean = minimum != null + + fun isMaximum(): Boolean = maximum != null + + fun asPercentageDiscount(): NewPercentageDiscount = + percentageDiscount.getOrThrow("percentageDiscount") + + fun asUsageDiscount(): NewUsageDiscount = usageDiscount.getOrThrow("usageDiscount") + + fun asAmountDiscount(): NewAmountDiscount = amountDiscount.getOrThrow("amountDiscount") + + fun asMinimum(): NewMinimum = minimum.getOrThrow("minimum") + + fun asMaximum(): NewMaximum = maximum.getOrThrow("maximum") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + percentageDiscount != null -> + visitor.visitPercentageDiscount(percentageDiscount) + usageDiscount != null -> visitor.visitUsageDiscount(usageDiscount) + amountDiscount != null -> visitor.visitAmountDiscount(amountDiscount) + minimum != null -> visitor.visitMinimum(minimum) + maximum != null -> visitor.visitMaximum(maximum) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Adjustment = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitPercentageDiscount( + percentageDiscount: NewPercentageDiscount + ) { + percentageDiscount.validate() + } + + override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) { + usageDiscount.validate() + } + + override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) { + amountDiscount.validate() + } + + override fun visitMinimum(minimum: NewMinimum) { + minimum.validate() + } + + override fun visitMaximum(maximum: NewMaximum) { + maximum.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitPercentageDiscount( + percentageDiscount: NewPercentageDiscount + ) = percentageDiscount.validity() + + override fun visitUsageDiscount(usageDiscount: NewUsageDiscount) = + usageDiscount.validity() + + override fun visitAmountDiscount(amountDiscount: NewAmountDiscount) = + amountDiscount.validity() + + override fun visitMinimum(minimum: NewMinimum) = minimum.validity() + + override fun visitMaximum(maximum: NewMaximum) = maximum.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Adjustment && + percentageDiscount == other.percentageDiscount && + usageDiscount == other.usageDiscount && + amountDiscount == other.amountDiscount && + minimum == other.minimum && + maximum == other.maximum + } + + override fun hashCode(): Int = + Objects.hash(percentageDiscount, usageDiscount, amountDiscount, minimum, maximum) + + override fun toString(): String = + when { + percentageDiscount != null -> + "Adjustment{percentageDiscount=$percentageDiscount}" + usageDiscount != null -> "Adjustment{usageDiscount=$usageDiscount}" + amountDiscount != null -> "Adjustment{amountDiscount=$amountDiscount}" + minimum != null -> "Adjustment{minimum=$minimum}" + maximum != null -> "Adjustment{maximum=$maximum}" + _json != null -> "Adjustment{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Adjustment") + } + + companion object { + + fun ofPercentageDiscount(percentageDiscount: NewPercentageDiscount) = + Adjustment(percentageDiscount = percentageDiscount) + + fun ofUsageDiscount(usageDiscount: NewUsageDiscount) = + Adjustment(usageDiscount = usageDiscount) + + fun ofAmountDiscount(amountDiscount: NewAmountDiscount) = + Adjustment(amountDiscount = amountDiscount) + + fun ofMinimum(minimum: NewMinimum) = Adjustment(minimum = minimum) + + fun ofMaximum(maximum: NewMaximum) = Adjustment(maximum = maximum) + } + + /** + * An interface that defines how to map each variant of [Adjustment] to a value of type + * [T]. + */ + interface Visitor { + + fun visitPercentageDiscount(percentageDiscount: NewPercentageDiscount): T + + fun visitUsageDiscount(usageDiscount: NewUsageDiscount): T + + fun visitAmountDiscount(amountDiscount: NewAmountDiscount): T + + fun visitMinimum(minimum: NewMinimum): T + + fun visitMaximum(maximum: NewMaximum): T + + /** + * Maps an unknown variant of [Adjustment] to a value of type [T]. + * + * An instance of [Adjustment] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on an + * older version than the API, then the API may respond with new variants that the + * SDK is unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown Adjustment: $json") + } + } + + internal class Deserializer : BaseDeserializer(Adjustment::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Adjustment { + val json = JsonValue.fromJsonNode(node) + val adjustmentType = json.asObject()?.get("adjustment_type")?.asString() + + when (adjustmentType) { + "percentage_discount" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Adjustment(percentageDiscount = it, _json = json) } + ?: Adjustment(_json = json) + } + "usage_discount" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(usageDiscount = it, _json = json) + } ?: Adjustment(_json = json) + } + "amount_discount" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(amountDiscount = it, _json = json) + } ?: Adjustment(_json = json) + } + "minimum" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(minimum = it, _json = json) + } ?: Adjustment(_json = json) + } + "maximum" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Adjustment(maximum = it, _json = json) + } ?: Adjustment(_json = json) + } + } + + return Adjustment(_json = json) + } + } + + internal class Serializer : BaseSerializer(Adjustment::class) { + + override fun serialize( + value: Adjustment, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.percentageDiscount != null -> + generator.writeObject(value.percentageDiscount) + value.usageDiscount != null -> generator.writeObject(value.usageDiscount) + value.amountDiscount != null -> generator.writeObject(value.amountDiscount) + value.minimum != null -> generator.writeObject(value.minimum) + value.maximum != null -> generator.writeObject(value.maximum) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Adjustment") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ReplaceAdjustment && + adjustment == other.adjustment && + replacesAdjustmentId == other.replacesAdjustmentId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(adjustment, replacesAdjustmentId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ReplaceAdjustment{adjustment=$adjustment, replacesAdjustmentId=$replacesAdjustmentId, additionalProperties=$additionalProperties}" + } + + class ReplacePrice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val replacesPriceId: JsonField, + private val allocationPrice: JsonField, + private val discounts: JsonField>, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val maximumAmount: JsonField, + private val minimumAmount: JsonField, + private val price: JsonField, + private val priceId: JsonField, + private val additionalProperties: MutableMap, + ) { @JsonCreator private constructor( - @JsonProperty("replaces_price_id") - @ExcludeMissing - replacesPriceId: JsonField = JsonMissing.of(), - @JsonProperty("allocation_price") - @ExcludeMissing - allocationPrice: JsonField = JsonMissing.of(), - @JsonProperty("discounts") - @ExcludeMissing - discounts: JsonField> = JsonMissing.of(), - @JsonProperty("external_price_id") - @ExcludeMissing - externalPriceId: JsonField = JsonMissing.of(), - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fixedPriceQuantity: JsonField = JsonMissing.of(), - @JsonProperty("maximum_amount") - @ExcludeMissing - maximumAmount: JsonField = JsonMissing.of(), - @JsonProperty("minimum_amount") - @ExcludeMissing - minimumAmount: JsonField = JsonMissing.of(), - @JsonProperty("price") @ExcludeMissing price: JsonField = JsonMissing.of(), - @JsonProperty("price_id") @ExcludeMissing priceId: JsonField = JsonMissing.of(), - ) : this( - replacesPriceId, - allocationPrice, - discounts, - externalPriceId, - fixedPriceQuantity, - maximumAmount, - minimumAmount, - price, - priceId, - mutableMapOf(), - ) + @JsonProperty("replaces_price_id") + @ExcludeMissing + replacesPriceId: JsonField = JsonMissing.of(), + @JsonProperty("allocation_price") + @ExcludeMissing + allocationPrice: JsonField = JsonMissing.of(), + @JsonProperty("discounts") + @ExcludeMissing + discounts: JsonField> = JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("maximum_amount") + @ExcludeMissing + maximumAmount: JsonField = JsonMissing.of(), + @JsonProperty("minimum_amount") + @ExcludeMissing + minimumAmount: JsonField = JsonMissing.of(), + @JsonProperty("price") @ExcludeMissing price: JsonField = JsonMissing.of(), + @JsonProperty("price_id") @ExcludeMissing priceId: JsonField = JsonMissing.of(), + ) : this( + replacesPriceId, + allocationPrice, + discounts, + externalPriceId, + fixedPriceQuantity, + maximumAmount, + minimumAmount, + price, + priceId, + mutableMapOf(), + ) + + /** + * The id of the price on the plan to replace in the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun replacesPriceId(): String = replacesPriceId.getRequired("replaces_price_id") + + /** + * The definition of a new allocation price to create and add to the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allocationPrice(): NewAllocationPrice? = allocationPrice.getNullable("allocation_price") + + /** + * [DEPRECATED] Use add_adjustments instead. The subscription's discounts for the + * replacement price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") + fun discounts(): List? = discounts.getNullable("discounts") + + /** + * The external price id of the price to add to the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * The new quantity of the price, if the price is a fixed price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * [DEPRECATED] Use add_adjustments instead. The subscription's maximum amount for the + * replacement price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") + fun maximumAmount(): String? = maximumAmount.getNullable("maximum_amount") + + /** + * [DEPRECATED] Use add_adjustments instead. The subscription's minimum amount for the + * replacement price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") + fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") + + /** + * New subscription price request body params. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun price(): Price? = price.getNullable("price") + + /** + * The id of the price to add to the subscription. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun priceId(): String? = priceId.getNullable("price_id") + + /** + * Returns the raw JSON value of [replacesPriceId]. + * + * Unlike [replacesPriceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("replaces_price_id") + @ExcludeMissing + fun _replacesPriceId(): JsonField = replacesPriceId + + /** + * Returns the raw JSON value of [allocationPrice]. + * + * Unlike [allocationPrice], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("allocation_price") + @ExcludeMissing + fun _allocationPrice(): JsonField = allocationPrice + + /** + * Returns the raw JSON value of [discounts]. + * + * Unlike [discounts], this method doesn't throw if the JSON field has an unexpected type. + */ + @Deprecated("deprecated") + @JsonProperty("discounts") + @ExcludeMissing + fun _discounts(): JsonField> = discounts + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [maximumAmount]. + * + * Unlike [maximumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @Deprecated("deprecated") + @JsonProperty("maximum_amount") + @ExcludeMissing + fun _maximumAmount(): JsonField = maximumAmount + + /** + * Returns the raw JSON value of [minimumAmount]. + * + * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @Deprecated("deprecated") + @JsonProperty("minimum_amount") + @ExcludeMissing + fun _minimumAmount(): JsonField = minimumAmount + + /** + * 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 [priceId]. + * + * Unlike [priceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("price_id") @ExcludeMissing fun _priceId(): JsonField = priceId + + @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 [ReplacePrice]. + * + * The following fields are required: + * ```kotlin + * .replacesPriceId() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [ReplacePrice]. */ + class Builder internal constructor() { + + private var replacesPriceId: JsonField? = null + private var allocationPrice: JsonField = JsonMissing.of() + private var discounts: JsonField>? = null + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var maximumAmount: JsonField = JsonMissing.of() + private var minimumAmount: JsonField = JsonMissing.of() + private var price: JsonField = JsonMissing.of() + private var priceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(replacePrice: ReplacePrice) = apply { + replacesPriceId = replacePrice.replacesPriceId + allocationPrice = replacePrice.allocationPrice + discounts = replacePrice.discounts.map { it.toMutableList() } + externalPriceId = replacePrice.externalPriceId + fixedPriceQuantity = replacePrice.fixedPriceQuantity + maximumAmount = replacePrice.maximumAmount + minimumAmount = replacePrice.minimumAmount + price = replacePrice.price + priceId = replacePrice.priceId + additionalProperties = replacePrice.additionalProperties.toMutableMap() + } + + /** The id of the price on the plan to replace in the subscription. */ + fun replacesPriceId(replacesPriceId: String) = + replacesPriceId(JsonField.of(replacesPriceId)) + + /** + * Sets [Builder.replacesPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.replacesPriceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun replacesPriceId(replacesPriceId: JsonField) = apply { + this.replacesPriceId = replacesPriceId + } + + /** The definition of a new allocation price to create and add to the subscription. */ + fun allocationPrice(allocationPrice: NewAllocationPrice?) = + allocationPrice(JsonField.ofNullable(allocationPrice)) + + /** + * Sets [Builder.allocationPrice] to an arbitrary JSON value. + * + * You should usually call [Builder.allocationPrice] with a well-typed + * [NewAllocationPrice] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun allocationPrice(allocationPrice: JsonField) = apply { + this.allocationPrice = allocationPrice + } + + /** + * [DEPRECATED] Use add_adjustments instead. The subscription's discounts for the + * replacement price. + */ + @Deprecated("deprecated") + fun discounts(discounts: List?) = + discounts(JsonField.ofNullable(discounts)) + + /** + * Sets [Builder.discounts] to an arbitrary JSON value. + * + * You should usually call [Builder.discounts] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + @Deprecated("deprecated") + fun discounts(discounts: JsonField>) = apply { + this.discounts = discounts.map { it.toMutableList() } + } + + /** + * Adds a single [DiscountOverride] to [discounts]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + @Deprecated("deprecated") + fun addDiscount(discount: DiscountOverride) = apply { + discounts = + (discounts ?: JsonField.of(mutableListOf())).also { + checkKnown("discounts", it).add(discount) + } + } + + /** The external price id of the price to add to the subscription. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** The new quantity of the price, if the price is a fixed price. */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** + * [DEPRECATED] Use add_adjustments instead. The subscription's maximum amount for the + * replacement price. + */ + @Deprecated("deprecated") + fun maximumAmount(maximumAmount: String?) = + maximumAmount(JsonField.ofNullable(maximumAmount)) + + /** + * Sets [Builder.maximumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun maximumAmount(maximumAmount: JsonField) = apply { + this.maximumAmount = maximumAmount + } + + /** + * [DEPRECATED] Use add_adjustments instead. The subscription's minimum amount for the + * replacement price. + */ + @Deprecated("deprecated") + fun minimumAmount(minimumAmount: String?) = + minimumAmount(JsonField.ofNullable(minimumAmount)) + + /** + * Sets [Builder.minimumAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun minimumAmount(minimumAmount: JsonField) = apply { + this.minimumAmount = minimumAmount + } + + /** New subscription price request body params. */ + fun price(price: Price?) = price(JsonField.ofNullable(price)) + + /** + * Sets [Builder.price] to an arbitrary JSON value. + * + * You should usually call [Builder.price] with a well-typed [Price] 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 } + + /** Alias for calling [price] with `Price.ofUnit(unit)`. */ + fun price(unit: NewSubscriptionUnitPrice) = price(Price.ofUnit(unit)) + + /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ + fun price(tiered: NewSubscriptionTieredPrice) = price(Price.ofTiered(tiered)) + + /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ + fun price(bulk: NewSubscriptionBulkPrice) = price(Price.ofBulk(bulk)) + + /** Alias for calling [price] with `Price.ofBulkWithFilters(bulkWithFilters)`. */ + fun price(bulkWithFilters: Price.BulkWithFilters) = + price(Price.ofBulkWithFilters(bulkWithFilters)) + + /** Alias for calling [price] with `Price.ofPackage(package_)`. */ + fun price(package_: NewSubscriptionPackagePrice) = price(Price.ofPackage(package_)) + + /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ + fun price(matrix: NewSubscriptionMatrixPrice) = price(Price.ofMatrix(matrix)) + + /** + * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. + */ + fun price(thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice) = + price(Price.ofThresholdTotalAmount(thresholdTotalAmount)) + + /** Alias for calling [price] with `Price.ofTieredPackage(tieredPackage)`. */ + fun price(tieredPackage: NewSubscriptionTieredPackagePrice) = + price(Price.ofTieredPackage(tieredPackage)) + + /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ + fun price(tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice) = + price(Price.ofTieredWithMinimum(tieredWithMinimum)) + + /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun price(groupedTiered: NewSubscriptionGroupedTieredPrice) = + price(Price.ofGroupedTiered(groupedTiered)) + + /** + * Alias for calling [price] with + * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + */ + fun price(tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice) = + price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofPackageWithAllocation(packageWithAllocation)`. + */ + fun price(packageWithAllocation: NewSubscriptionPackageWithAllocationPrice) = + price(Price.ofPackageWithAllocation(packageWithAllocation)) + + /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ + fun price(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = + price(Price.ofUnitWithPercent(unitWithPercent)) + + /** + * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun price(matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice) = + price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + + /** + * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. + */ + fun price(tieredWithProration: Price.TieredWithProration) = + price(Price.ofTieredWithProration(tieredWithProration)) + + /** Alias for calling [price] with `Price.ofUnitWithProration(unitWithProration)`. */ + fun price(unitWithProration: NewSubscriptionUnitWithProrationPrice) = + price(Price.ofUnitWithProration(unitWithProration)) + + /** Alias for calling [price] with `Price.ofGroupedAllocation(groupedAllocation)`. */ + fun price(groupedAllocation: NewSubscriptionGroupedAllocationPrice) = + price(Price.ofGroupedAllocation(groupedAllocation)) + + /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun price(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = + price(Price.ofBulkWithProration(bulkWithProration)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. + */ + fun price(groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice) = + price(Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. + */ + fun price(groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice) = + price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + + /** + * Alias for calling [price] with + * `Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)`. + */ + fun price(groupedWithMinMaxThresholds: Price.GroupedWithMinMaxThresholds) = + price(Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds)) + + /** + * Alias for calling [price] with + * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. + */ + fun price(matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice) = + price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) + + /** + * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. + */ + fun price(groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice) = + price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + + /** + * Alias for calling [price] with + * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. + */ + fun price(maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice) = + price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + + /** + * Alias for calling [price] with + * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. + */ + fun price( + scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice + ) = price(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) + + /** + * Alias for calling [price] with + * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. + */ + fun price( + scalableMatrixWithTieredPricing: NewSubscriptionScalableMatrixWithTieredPricingPrice + ) = price(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) + + /** + * Alias for calling [price] with + * `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. + */ + fun price(cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice) = + price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + + /** + * Alias for calling [price] with + * `Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)`. + */ + fun price(cumulativeGroupedAllocation: Price.CumulativeGroupedAllocation) = + price(Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation)) + + /** Alias for calling [price] with `Price.ofMinimum(minimum)`. */ + fun price(minimum: NewSubscriptionMinimumCompositePrice) = + price(Price.ofMinimum(minimum)) + + /** Alias for calling [price] with `Price.ofPercent(percent)`. */ + fun price(percent: Price.Percent) = price(Price.ofPercent(percent)) + + /** Alias for calling [price] with `Price.ofEventOutput(eventOutput)`. */ + fun price(eventOutput: Price.EventOutput) = price(Price.ofEventOutput(eventOutput)) + + /** The id of the price to add to the subscription. */ + fun priceId(priceId: String?) = priceId(JsonField.ofNullable(priceId)) + + /** + * Sets [Builder.priceId] to an arbitrary JSON value. + * + * You should usually call [Builder.priceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun priceId(priceId: JsonField) = apply { this.priceId = priceId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ReplacePrice]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .replacesPriceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ReplacePrice = + ReplacePrice( + checkRequired("replacesPriceId", replacesPriceId), + allocationPrice, + (discounts ?: JsonMissing.of()).map { it.toImmutable() }, + externalPriceId, + fixedPriceQuantity, + maximumAmount, + minimumAmount, + price, + priceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ReplacePrice = apply { + if (validated) { + return@apply + } + + replacesPriceId() + allocationPrice()?.validate() + discounts()?.forEach { it.validate() } + externalPriceId() + fixedPriceQuantity() + maximumAmount() + minimumAmount() + price()?.validate() + priceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (replacesPriceId.asKnown() == null) 0 else 1) + + (allocationPrice.asKnown()?.validity() ?: 0) + + (discounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (maximumAmount.asKnown() == null) 0 else 1) + + (if (minimumAmount.asKnown() == null) 0 else 1) + + (price.asKnown()?.validity() ?: 0) + + (if (priceId.asKnown() == null) 0 else 1) + + /** New subscription price request body params. */ + @JsonDeserialize(using = Price.Deserializer::class) + @JsonSerialize(using = Price.Serializer::class) + class Price + private constructor( + private val unit: NewSubscriptionUnitPrice? = null, + private val tiered: NewSubscriptionTieredPrice? = null, + private val bulk: NewSubscriptionBulkPrice? = null, + private val bulkWithFilters: BulkWithFilters? = null, + private val package_: NewSubscriptionPackagePrice? = null, + private val matrix: NewSubscriptionMatrixPrice? = null, + private val thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice? = null, + private val tieredPackage: NewSubscriptionTieredPackagePrice? = null, + private val tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice? = null, + private val groupedTiered: NewSubscriptionGroupedTieredPrice? = null, + private val tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice? = + null, + private val packageWithAllocation: NewSubscriptionPackageWithAllocationPrice? = null, + private val unitWithPercent: NewSubscriptionUnitWithPercentPrice? = null, + private val matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice? = null, + private val tieredWithProration: TieredWithProration? = null, + private val unitWithProration: NewSubscriptionUnitWithProrationPrice? = null, + private val groupedAllocation: NewSubscriptionGroupedAllocationPrice? = null, + private val bulkWithProration: NewSubscriptionBulkWithProrationPrice? = null, + private val groupedWithProratedMinimum: + NewSubscriptionGroupedWithProratedMinimumPrice? = + null, + private val groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice? = + null, + private val groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds? = null, + private val matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice? = null, + private val groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice? = null, + private val maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice? = null, + private val scalableMatrixWithUnitPricing: + NewSubscriptionScalableMatrixWithUnitPricingPrice? = + null, + private val scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice? = + null, + private val cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice? = null, + private val cumulativeGroupedAllocation: CumulativeGroupedAllocation? = null, + private val minimum: NewSubscriptionMinimumCompositePrice? = null, + private val percent: Percent? = null, + private val eventOutput: EventOutput? = null, + private val _json: JsonValue? = null, + ) { + + fun unit(): NewSubscriptionUnitPrice? = unit + + fun tiered(): NewSubscriptionTieredPrice? = tiered + + fun bulk(): NewSubscriptionBulkPrice? = bulk + + fun bulkWithFilters(): BulkWithFilters? = bulkWithFilters + + fun package_(): NewSubscriptionPackagePrice? = package_ + + fun matrix(): NewSubscriptionMatrixPrice? = matrix + + fun thresholdTotalAmount(): NewSubscriptionThresholdTotalAmountPrice? = + thresholdTotalAmount + + fun tieredPackage(): NewSubscriptionTieredPackagePrice? = tieredPackage + + fun tieredWithMinimum(): NewSubscriptionTieredWithMinimumPrice? = tieredWithMinimum + + fun groupedTiered(): NewSubscriptionGroupedTieredPrice? = groupedTiered + + fun tieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice? = + tieredPackageWithMinimum + + fun packageWithAllocation(): NewSubscriptionPackageWithAllocationPrice? = + packageWithAllocation + + fun unitWithPercent(): NewSubscriptionUnitWithPercentPrice? = unitWithPercent + + fun matrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice? = + matrixWithAllocation + + fun tieredWithProration(): TieredWithProration? = tieredWithProration + + fun unitWithProration(): NewSubscriptionUnitWithProrationPrice? = unitWithProration + + fun groupedAllocation(): NewSubscriptionGroupedAllocationPrice? = groupedAllocation + + fun bulkWithProration(): NewSubscriptionBulkWithProrationPrice? = bulkWithProration + + fun groupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice? = + groupedWithProratedMinimum + + fun groupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice? = + groupedWithMeteredMinimum + + fun groupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds? = + groupedWithMinMaxThresholds + + fun matrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice? = + matrixWithDisplayName + + fun groupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice? = + groupedTieredPackage + + fun maxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice? = + maxGroupTieredPackage + + fun scalableMatrixWithUnitPricing(): + NewSubscriptionScalableMatrixWithUnitPricingPrice? = scalableMatrixWithUnitPricing + + fun scalableMatrixWithTieredPricing(): + NewSubscriptionScalableMatrixWithTieredPricingPrice? = + scalableMatrixWithTieredPricing + + fun cumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice? = + cumulativeGroupedBulk + + fun cumulativeGroupedAllocation(): CumulativeGroupedAllocation? = + cumulativeGroupedAllocation + + fun minimum(): NewSubscriptionMinimumCompositePrice? = minimum + + fun percent(): Percent? = percent + + fun eventOutput(): EventOutput? = eventOutput + + fun isUnit(): Boolean = unit != null + + fun isTiered(): Boolean = tiered != null + + fun isBulk(): Boolean = bulk != null + + fun isBulkWithFilters(): Boolean = bulkWithFilters != null + + fun isPackage(): Boolean = package_ != null + + fun isMatrix(): Boolean = matrix != null + + fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null + + fun isTieredPackage(): Boolean = tieredPackage != null + + fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null + + fun isGroupedTiered(): Boolean = groupedTiered != null + + fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + + fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + + fun isUnitWithPercent(): Boolean = unitWithPercent != null + + fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + + fun isTieredWithProration(): Boolean = tieredWithProration != null + + fun isUnitWithProration(): Boolean = unitWithProration != null + + fun isGroupedAllocation(): Boolean = groupedAllocation != null + + fun isBulkWithProration(): Boolean = bulkWithProration != null + + fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null + + fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null + + fun isGroupedWithMinMaxThresholds(): Boolean = groupedWithMinMaxThresholds != null + + fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + + fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + + fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null + + fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null + + fun isScalableMatrixWithTieredPricing(): Boolean = + scalableMatrixWithTieredPricing != null + + fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null + + fun isCumulativeGroupedAllocation(): Boolean = cumulativeGroupedAllocation != null + + fun isMinimum(): Boolean = minimum != null + + fun isPercent(): Boolean = percent != null + + fun isEventOutput(): Boolean = eventOutput != null + + fun asUnit(): NewSubscriptionUnitPrice = unit.getOrThrow("unit") + + fun asTiered(): NewSubscriptionTieredPrice = tiered.getOrThrow("tiered") + + fun asBulk(): NewSubscriptionBulkPrice = bulk.getOrThrow("bulk") + + fun asBulkWithFilters(): BulkWithFilters = bulkWithFilters.getOrThrow("bulkWithFilters") + + fun asPackage(): NewSubscriptionPackagePrice = package_.getOrThrow("package_") + + fun asMatrix(): NewSubscriptionMatrixPrice = matrix.getOrThrow("matrix") + + fun asThresholdTotalAmount(): NewSubscriptionThresholdTotalAmountPrice = + thresholdTotalAmount.getOrThrow("thresholdTotalAmount") + + fun asTieredPackage(): NewSubscriptionTieredPackagePrice = + tieredPackage.getOrThrow("tieredPackage") + + fun asTieredWithMinimum(): NewSubscriptionTieredWithMinimumPrice = + tieredWithMinimum.getOrThrow("tieredWithMinimum") + + fun asGroupedTiered(): NewSubscriptionGroupedTieredPrice = + groupedTiered.getOrThrow("groupedTiered") + + fun asTieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice = + tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + + fun asPackageWithAllocation(): NewSubscriptionPackageWithAllocationPrice = + packageWithAllocation.getOrThrow("packageWithAllocation") + + fun asUnitWithPercent(): NewSubscriptionUnitWithPercentPrice = + unitWithPercent.getOrThrow("unitWithPercent") + + fun asMatrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice = + matrixWithAllocation.getOrThrow("matrixWithAllocation") + + fun asTieredWithProration(): TieredWithProration = + tieredWithProration.getOrThrow("tieredWithProration") + + fun asUnitWithProration(): NewSubscriptionUnitWithProrationPrice = + unitWithProration.getOrThrow("unitWithProration") + + fun asGroupedAllocation(): NewSubscriptionGroupedAllocationPrice = + groupedAllocation.getOrThrow("groupedAllocation") + + fun asBulkWithProration(): NewSubscriptionBulkWithProrationPrice = + bulkWithProration.getOrThrow("bulkWithProration") + + fun asGroupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice = + groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") + + fun asGroupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice = + groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + + fun asGroupedWithMinMaxThresholds(): GroupedWithMinMaxThresholds = + groupedWithMinMaxThresholds.getOrThrow("groupedWithMinMaxThresholds") + + fun asMatrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice = + matrixWithDisplayName.getOrThrow("matrixWithDisplayName") + + fun asGroupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice = + groupedTieredPackage.getOrThrow("groupedTieredPackage") + + fun asMaxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice = + maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") + + fun asScalableMatrixWithUnitPricing(): + NewSubscriptionScalableMatrixWithUnitPricingPrice = + scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") + + fun asScalableMatrixWithTieredPricing(): + NewSubscriptionScalableMatrixWithTieredPricingPrice = + scalableMatrixWithTieredPricing.getOrThrow("scalableMatrixWithTieredPricing") + + fun asCumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice = + cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + + fun asCumulativeGroupedAllocation(): CumulativeGroupedAllocation = + cumulativeGroupedAllocation.getOrThrow("cumulativeGroupedAllocation") + + fun asMinimum(): NewSubscriptionMinimumCompositePrice = minimum.getOrThrow("minimum") + + fun asPercent(): Percent = percent.getOrThrow("percent") + + fun asEventOutput(): EventOutput = eventOutput.getOrThrow("eventOutput") + + fun _json(): JsonValue? = _json + + fun accept(visitor: Visitor): T = + when { + unit != null -> visitor.visitUnit(unit) + tiered != null -> visitor.visitTiered(tiered) + bulk != null -> visitor.visitBulk(bulk) + bulkWithFilters != null -> visitor.visitBulkWithFilters(bulkWithFilters) + package_ != null -> visitor.visitPackage(package_) + matrix != null -> visitor.visitMatrix(matrix) + thresholdTotalAmount != null -> + visitor.visitThresholdTotalAmount(thresholdTotalAmount) + tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) + tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) + groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) + tieredPackageWithMinimum != null -> + visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) + packageWithAllocation != null -> + visitor.visitPackageWithAllocation(packageWithAllocation) + unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) + matrixWithAllocation != null -> + visitor.visitMatrixWithAllocation(matrixWithAllocation) + tieredWithProration != null -> + visitor.visitTieredWithProration(tieredWithProration) + unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) + groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) + bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) + groupedWithProratedMinimum != null -> + visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) + groupedWithMeteredMinimum != null -> + visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + groupedWithMinMaxThresholds != null -> + visitor.visitGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) + matrixWithDisplayName != null -> + visitor.visitMatrixWithDisplayName(matrixWithDisplayName) + groupedTieredPackage != null -> + visitor.visitGroupedTieredPackage(groupedTieredPackage) + maxGroupTieredPackage != null -> + visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) + scalableMatrixWithUnitPricing != null -> + visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) + scalableMatrixWithTieredPricing != null -> + visitor.visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing + ) + cumulativeGroupedBulk != null -> + visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) + cumulativeGroupedAllocation != null -> + visitor.visitCumulativeGroupedAllocation(cumulativeGroupedAllocation) + minimum != null -> visitor.visitMinimum(minimum) + percent != null -> visitor.visitPercent(percent) + eventOutput != null -> visitor.visitEventOutput(eventOutput) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Price = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitUnit(unit: NewSubscriptionUnitPrice) { + unit.validate() + } + + override fun visitTiered(tiered: NewSubscriptionTieredPrice) { + tiered.validate() + } + + override fun visitBulk(bulk: NewSubscriptionBulkPrice) { + bulk.validate() + } + + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) { + bulkWithFilters.validate() + } + + override fun visitPackage(package_: NewSubscriptionPackagePrice) { + package_.validate() + } + + override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) { + matrix.validate() + } + + override fun visitThresholdTotalAmount( + thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice + ) { + thresholdTotalAmount.validate() + } + + override fun visitTieredPackage( + tieredPackage: NewSubscriptionTieredPackagePrice + ) { + tieredPackage.validate() + } + + override fun visitTieredWithMinimum( + tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice + ) { + tieredWithMinimum.validate() + } + + override fun visitGroupedTiered( + groupedTiered: NewSubscriptionGroupedTieredPrice + ) { + groupedTiered.validate() + } + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ) { + tieredPackageWithMinimum.validate() + } + + override fun visitPackageWithAllocation( + packageWithAllocation: NewSubscriptionPackageWithAllocationPrice + ) { + packageWithAllocation.validate() + } + + override fun visitUnitWithPercent( + unitWithPercent: NewSubscriptionUnitWithPercentPrice + ) { + unitWithPercent.validate() + } + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ) { + matrixWithAllocation.validate() + } + + override fun visitTieredWithProration( + tieredWithProration: TieredWithProration + ) { + tieredWithProration.validate() + } + + override fun visitUnitWithProration( + unitWithProration: NewSubscriptionUnitWithProrationPrice + ) { + unitWithProration.validate() + } + + override fun visitGroupedAllocation( + groupedAllocation: NewSubscriptionGroupedAllocationPrice + ) { + groupedAllocation.validate() + } + + override fun visitBulkWithProration( + bulkWithProration: NewSubscriptionBulkWithProrationPrice + ) { + bulkWithProration.validate() + } + + override fun visitGroupedWithProratedMinimum( + groupedWithProratedMinimum: + NewSubscriptionGroupedWithProratedMinimumPrice + ) { + groupedWithProratedMinimum.validate() + } + + override fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + ) { + groupedWithMeteredMinimum.validate() + } + + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) { + groupedWithMinMaxThresholds.validate() + } + + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + ) { + matrixWithDisplayName.validate() + } + + override fun visitGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + ) { + groupedTieredPackage.validate() + } + + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice + ) { + maxGroupTieredPackage.validate() + } + + override fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: + NewSubscriptionScalableMatrixWithUnitPricingPrice + ) { + scalableMatrixWithUnitPricing.validate() + } + + override fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice + ) { + scalableMatrixWithTieredPricing.validate() + } + + override fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice + ) { + cumulativeGroupedBulk.validate() + } + + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) { + cumulativeGroupedAllocation.validate() + } + + override fun visitMinimum(minimum: NewSubscriptionMinimumCompositePrice) { + minimum.validate() + } + + override fun visitPercent(percent: Percent) { + percent.validate() + } + + override fun visitEventOutput(eventOutput: EventOutput) { + eventOutput.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitUnit(unit: NewSubscriptionUnitPrice) = unit.validity() + + override fun visitTiered(tiered: NewSubscriptionTieredPrice) = + tiered.validity() + + override fun visitBulk(bulk: NewSubscriptionBulkPrice) = bulk.validity() + + override fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters) = + bulkWithFilters.validity() + + override fun visitPackage(package_: NewSubscriptionPackagePrice) = + package_.validity() + + override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) = + matrix.validity() + + override fun visitThresholdTotalAmount( + thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice + ) = thresholdTotalAmount.validity() + + override fun visitTieredPackage( + tieredPackage: NewSubscriptionTieredPackagePrice + ) = tieredPackage.validity() + + override fun visitTieredWithMinimum( + tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice + ) = tieredWithMinimum.validity() + + override fun visitGroupedTiered( + groupedTiered: NewSubscriptionGroupedTieredPrice + ) = groupedTiered.validity() + + override fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ) = tieredPackageWithMinimum.validity() + + override fun visitPackageWithAllocation( + packageWithAllocation: NewSubscriptionPackageWithAllocationPrice + ) = packageWithAllocation.validity() + + override fun visitUnitWithPercent( + unitWithPercent: NewSubscriptionUnitWithPercentPrice + ) = unitWithPercent.validity() + + override fun visitMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ) = matrixWithAllocation.validity() + + override fun visitTieredWithProration( + tieredWithProration: TieredWithProration + ) = tieredWithProration.validity() + + override fun visitUnitWithProration( + unitWithProration: NewSubscriptionUnitWithProrationPrice + ) = unitWithProration.validity() + + override fun visitGroupedAllocation( + groupedAllocation: NewSubscriptionGroupedAllocationPrice + ) = groupedAllocation.validity() + + override fun visitBulkWithProration( + bulkWithProration: NewSubscriptionBulkWithProrationPrice + ) = bulkWithProration.validity() + + override fun visitGroupedWithProratedMinimum( + groupedWithProratedMinimum: + NewSubscriptionGroupedWithProratedMinimumPrice + ) = groupedWithProratedMinimum.validity() + + override fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + ) = groupedWithMeteredMinimum.validity() + + override fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = groupedWithMinMaxThresholds.validity() + + override fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + ) = matrixWithDisplayName.validity() + + override fun visitGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + ) = groupedTieredPackage.validity() + + override fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice + ) = maxGroupTieredPackage.validity() + + override fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: + NewSubscriptionScalableMatrixWithUnitPricingPrice + ) = scalableMatrixWithUnitPricing.validity() + + override fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice + ) = scalableMatrixWithTieredPricing.validity() + + override fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice + ) = cumulativeGroupedBulk.validity() + + override fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = cumulativeGroupedAllocation.validity() + + override fun visitMinimum(minimum: NewSubscriptionMinimumCompositePrice) = + minimum.validity() + + override fun visitPercent(percent: Percent) = percent.validity() + + override fun visitEventOutput(eventOutput: EventOutput) = + eventOutput.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Price && + unit == other.unit && + tiered == other.tiered && + bulk == other.bulk && + bulkWithFilters == other.bulkWithFilters && + package_ == other.package_ && + matrix == other.matrix && + thresholdTotalAmount == other.thresholdTotalAmount && + tieredPackage == other.tieredPackage && + tieredWithMinimum == other.tieredWithMinimum && + groupedTiered == other.groupedTiered && + tieredPackageWithMinimum == other.tieredPackageWithMinimum && + packageWithAllocation == other.packageWithAllocation && + unitWithPercent == other.unitWithPercent && + matrixWithAllocation == other.matrixWithAllocation && + tieredWithProration == other.tieredWithProration && + unitWithProration == other.unitWithProration && + groupedAllocation == other.groupedAllocation && + bulkWithProration == other.bulkWithProration && + groupedWithProratedMinimum == other.groupedWithProratedMinimum && + groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && + groupedWithMinMaxThresholds == other.groupedWithMinMaxThresholds && + matrixWithDisplayName == other.matrixWithDisplayName && + groupedTieredPackage == other.groupedTieredPackage && + maxGroupTieredPackage == other.maxGroupTieredPackage && + scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && + scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && + cumulativeGroupedBulk == other.cumulativeGroupedBulk && + cumulativeGroupedAllocation == other.cumulativeGroupedAllocation && + minimum == other.minimum && + percent == other.percent && + eventOutput == other.eventOutput + } + + override fun hashCode(): Int = + Objects.hash( + unit, + tiered, + bulk, + bulkWithFilters, + package_, + matrix, + thresholdTotalAmount, + tieredPackage, + tieredWithMinimum, + groupedTiered, + tieredPackageWithMinimum, + packageWithAllocation, + unitWithPercent, + matrixWithAllocation, + tieredWithProration, + unitWithProration, + groupedAllocation, + bulkWithProration, + groupedWithProratedMinimum, + groupedWithMeteredMinimum, + groupedWithMinMaxThresholds, + matrixWithDisplayName, + groupedTieredPackage, + maxGroupTieredPackage, + scalableMatrixWithUnitPricing, + scalableMatrixWithTieredPricing, + cumulativeGroupedBulk, + cumulativeGroupedAllocation, + minimum, + percent, + eventOutput, + ) + + override fun toString(): String = + when { + unit != null -> "Price{unit=$unit}" + tiered != null -> "Price{tiered=$tiered}" + bulk != null -> "Price{bulk=$bulk}" + bulkWithFilters != null -> "Price{bulkWithFilters=$bulkWithFilters}" + package_ != null -> "Price{package_=$package_}" + matrix != null -> "Price{matrix=$matrix}" + thresholdTotalAmount != null -> + "Price{thresholdTotalAmount=$thresholdTotalAmount}" + tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" + tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" + groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" + tieredPackageWithMinimum != null -> + "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" + packageWithAllocation != null -> + "Price{packageWithAllocation=$packageWithAllocation}" + unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" + matrixWithAllocation != null -> + "Price{matrixWithAllocation=$matrixWithAllocation}" + tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" + unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" + groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" + bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" + groupedWithProratedMinimum != null -> + "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" + groupedWithMeteredMinimum != null -> + "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" + groupedWithMinMaxThresholds != null -> + "Price{groupedWithMinMaxThresholds=$groupedWithMinMaxThresholds}" + matrixWithDisplayName != null -> + "Price{matrixWithDisplayName=$matrixWithDisplayName}" + groupedTieredPackage != null -> + "Price{groupedTieredPackage=$groupedTieredPackage}" + maxGroupTieredPackage != null -> + "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" + scalableMatrixWithUnitPricing != null -> + "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" + scalableMatrixWithTieredPricing != null -> + "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" + cumulativeGroupedBulk != null -> + "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" + cumulativeGroupedAllocation != null -> + "Price{cumulativeGroupedAllocation=$cumulativeGroupedAllocation}" + minimum != null -> "Price{minimum=$minimum}" + percent != null -> "Price{percent=$percent}" + eventOutput != null -> "Price{eventOutput=$eventOutput}" + _json != null -> "Price{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Price") + } + + companion object { + + fun ofUnit(unit: NewSubscriptionUnitPrice) = Price(unit = unit) + + fun ofTiered(tiered: NewSubscriptionTieredPrice) = Price(tiered = tiered) + + fun ofBulk(bulk: NewSubscriptionBulkPrice) = Price(bulk = bulk) + + fun ofBulkWithFilters(bulkWithFilters: BulkWithFilters) = + Price(bulkWithFilters = bulkWithFilters) + + fun ofPackage(package_: NewSubscriptionPackagePrice) = Price(package_ = package_) + + fun ofMatrix(matrix: NewSubscriptionMatrixPrice) = Price(matrix = matrix) + + fun ofThresholdTotalAmount( + thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice + ) = Price(thresholdTotalAmount = thresholdTotalAmount) + + fun ofTieredPackage(tieredPackage: NewSubscriptionTieredPackagePrice) = + Price(tieredPackage = tieredPackage) + + fun ofTieredWithMinimum(tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice) = + Price(tieredWithMinimum = tieredWithMinimum) + + fun ofGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice) = + Price(groupedTiered = groupedTiered) + + fun ofTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + + fun ofPackageWithAllocation( + packageWithAllocation: NewSubscriptionPackageWithAllocationPrice + ) = Price(packageWithAllocation = packageWithAllocation) + + fun ofUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = + Price(unitWithPercent = unitWithPercent) + + fun ofMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ) = Price(matrixWithAllocation = matrixWithAllocation) + + fun ofTieredWithProration(tieredWithProration: TieredWithProration) = + Price(tieredWithProration = tieredWithProration) + + fun ofUnitWithProration(unitWithProration: NewSubscriptionUnitWithProrationPrice) = + Price(unitWithProration = unitWithProration) + + fun ofGroupedAllocation(groupedAllocation: NewSubscriptionGroupedAllocationPrice) = + Price(groupedAllocation = groupedAllocation) + + fun ofBulkWithProration(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = + Price(bulkWithProration = bulkWithProration) + + fun ofGroupedWithProratedMinimum( + groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice + ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) + + fun ofGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + + fun ofGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ) = Price(groupedWithMinMaxThresholds = groupedWithMinMaxThresholds) + + fun ofMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + ) = Price(matrixWithDisplayName = matrixWithDisplayName) + + fun ofGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + ) = Price(groupedTieredPackage = groupedTieredPackage) + + fun ofMaxGroupTieredPackage( + maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice + ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) + + fun ofScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice + ) = Price(scalableMatrixWithUnitPricing = scalableMatrixWithUnitPricing) + + fun ofScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice + ) = Price(scalableMatrixWithTieredPricing = scalableMatrixWithTieredPricing) + + fun ofCumulativeGroupedBulk( + cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice + ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) + + fun ofCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ) = Price(cumulativeGroupedAllocation = cumulativeGroupedAllocation) + + fun ofMinimum(minimum: NewSubscriptionMinimumCompositePrice) = + Price(minimum = minimum) + + fun ofPercent(percent: Percent) = Price(percent = percent) + + fun ofEventOutput(eventOutput: EventOutput) = Price(eventOutput = eventOutput) + } + + /** + * An interface that defines how to map each variant of [Price] to a value of type [T]. + */ + interface Visitor { + + fun visitUnit(unit: NewSubscriptionUnitPrice): T + + fun visitTiered(tiered: NewSubscriptionTieredPrice): T + + fun visitBulk(bulk: NewSubscriptionBulkPrice): T + + fun visitBulkWithFilters(bulkWithFilters: BulkWithFilters): T + + fun visitPackage(package_: NewSubscriptionPackagePrice): T + + fun visitMatrix(matrix: NewSubscriptionMatrixPrice): T + + fun visitThresholdTotalAmount( + thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice + ): T + + fun visitTieredPackage(tieredPackage: NewSubscriptionTieredPackagePrice): T + + fun visitTieredWithMinimum( + tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice + ): T + + fun visitGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice): T + + fun visitTieredPackageWithMinimum( + tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice + ): T + + fun visitPackageWithAllocation( + packageWithAllocation: NewSubscriptionPackageWithAllocationPrice + ): T + + fun visitUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice): T + + fun visitMatrixWithAllocation( + matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice + ): T + + fun visitTieredWithProration(tieredWithProration: TieredWithProration): T + + fun visitUnitWithProration( + unitWithProration: NewSubscriptionUnitWithProrationPrice + ): T + + fun visitGroupedAllocation( + groupedAllocation: NewSubscriptionGroupedAllocationPrice + ): T + + fun visitBulkWithProration( + bulkWithProration: NewSubscriptionBulkWithProrationPrice + ): T + + fun visitGroupedWithProratedMinimum( + groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice + ): T + + fun visitGroupedWithMeteredMinimum( + groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice + ): T + + fun visitGroupedWithMinMaxThresholds( + groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds + ): T + + fun visitMatrixWithDisplayName( + matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice + ): T + + fun visitGroupedTieredPackage( + groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice + ): T + + fun visitMaxGroupTieredPackage( + maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice + ): T + + fun visitScalableMatrixWithUnitPricing( + scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice + ): T + + fun visitScalableMatrixWithTieredPricing( + scalableMatrixWithTieredPricing: + NewSubscriptionScalableMatrixWithTieredPricingPrice + ): T + + fun visitCumulativeGroupedBulk( + cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice + ): T + + fun visitCumulativeGroupedAllocation( + cumulativeGroupedAllocation: CumulativeGroupedAllocation + ): T + + fun visitMinimum(minimum: NewSubscriptionMinimumCompositePrice): T + + fun visitPercent(percent: Percent): T + + fun visitEventOutput(eventOutput: EventOutput): T + + /** + * Maps an unknown variant of [Price] to a value of type [T]. + * + * An instance of [Price] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws OrbInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OrbInvalidDataException("Unknown Price: $json") + } + } + + internal class Deserializer : BaseDeserializer(Price::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Price { + val json = JsonValue.fromJsonNode(node) + val modelType = json.asObject()?.get("model_type")?.asString() + + when (modelType) { + "unit" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(unit = it, _json = json) } ?: Price(_json = json) + } + "tiered" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tiered = it, _json = json) } ?: Price(_json = json) + } + "bulk" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(bulk = it, _json = json) } ?: Price(_json = json) + } + "bulk_with_filters" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(bulkWithFilters = it, _json = json) + } ?: Price(_json = json) + } + "package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) + } + "matrix" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) + } + "threshold_total_amount" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(thresholdTotalAmount = it, _json = json) } + ?: Price(_json = json) + } + "tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "tiered_with_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tieredWithMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_tiered" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedTiered = it, _json = json) } + ?: Price(_json = json) + } + "tiered_package_with_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(tieredPackageWithMinimum = it, _json = json) } + ?: Price(_json = json) + } + "package_with_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(packageWithAllocation = it, _json = json) } + ?: Price(_json = json) + } + "unit_with_percent" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(unitWithPercent = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(matrixWithAllocation = it, _json = json) } + ?: Price(_json = json) + } + "tiered_with_proration" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Price(tieredWithProration = it, _json = json) } + ?: Price(_json = json) + } + "unit_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(unitWithProration = it, _json = json) } + ?: Price(_json = json) + } + "grouped_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedAllocation = it, _json = json) } + ?: Price(_json = json) + } + "bulk_with_proration" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(bulkWithProration = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_prorated_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithProratedMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_metered_minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } + ?: Price(_json = json) + } + "grouped_with_min_max_thresholds" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedWithMinMaxThresholds = it, _json = json) } + ?: Price(_json = json) + } + "matrix_with_display_name" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(matrixWithDisplayName = it, _json = json) } + ?: Price(_json = json) + } + "grouped_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(groupedTieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "max_group_tiered_package" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(maxGroupTieredPackage = it, _json = json) } + ?: Price(_json = json) + } + "scalable_matrix_with_unit_pricing" -> { + return tryDeserialize( + node, + jacksonTypeRef< + NewSubscriptionScalableMatrixWithUnitPricingPrice + >(), + ) + ?.let { Price(scalableMatrixWithUnitPricing = it, _json = json) } + ?: Price(_json = json) + } + "scalable_matrix_with_tiered_pricing" -> { + return tryDeserialize( + node, + jacksonTypeRef< + NewSubscriptionScalableMatrixWithTieredPricingPrice + >(), + ) + ?.let { Price(scalableMatrixWithTieredPricing = it, _json = json) } + ?: Price(_json = json) + } + "cumulative_grouped_bulk" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(cumulativeGroupedBulk = it, _json = json) } + ?: Price(_json = json) + } + "cumulative_grouped_allocation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(cumulativeGroupedAllocation = it, _json = json) } + ?: Price(_json = json) + } + "minimum" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Price(minimum = it, _json = json) } ?: Price(_json = json) + } + "percent" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(percent = it, _json = json) + } ?: Price(_json = json) + } + "event_output" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Price(eventOutput = it, _json = json) + } ?: Price(_json = json) + } + } + + return Price(_json = json) + } + } + + internal class Serializer : BaseSerializer(Price::class) { + + override fun serialize( + value: Price, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.unit != null -> generator.writeObject(value.unit) + value.tiered != null -> generator.writeObject(value.tiered) + value.bulk != null -> generator.writeObject(value.bulk) + value.bulkWithFilters != null -> + generator.writeObject(value.bulkWithFilters) + value.package_ != null -> generator.writeObject(value.package_) + value.matrix != null -> generator.writeObject(value.matrix) + value.thresholdTotalAmount != null -> + generator.writeObject(value.thresholdTotalAmount) + value.tieredPackage != null -> generator.writeObject(value.tieredPackage) + value.tieredWithMinimum != null -> + generator.writeObject(value.tieredWithMinimum) + value.groupedTiered != null -> generator.writeObject(value.groupedTiered) + value.tieredPackageWithMinimum != null -> + generator.writeObject(value.tieredPackageWithMinimum) + value.packageWithAllocation != null -> + generator.writeObject(value.packageWithAllocation) + value.unitWithPercent != null -> + generator.writeObject(value.unitWithPercent) + value.matrixWithAllocation != null -> + generator.writeObject(value.matrixWithAllocation) + value.tieredWithProration != null -> + generator.writeObject(value.tieredWithProration) + value.unitWithProration != null -> + generator.writeObject(value.unitWithProration) + value.groupedAllocation != null -> + generator.writeObject(value.groupedAllocation) + value.bulkWithProration != null -> + generator.writeObject(value.bulkWithProration) + value.groupedWithProratedMinimum != null -> + generator.writeObject(value.groupedWithProratedMinimum) + value.groupedWithMeteredMinimum != null -> + generator.writeObject(value.groupedWithMeteredMinimum) + value.groupedWithMinMaxThresholds != null -> + generator.writeObject(value.groupedWithMinMaxThresholds) + value.matrixWithDisplayName != null -> + generator.writeObject(value.matrixWithDisplayName) + value.groupedTieredPackage != null -> + generator.writeObject(value.groupedTieredPackage) + value.maxGroupTieredPackage != null -> + generator.writeObject(value.maxGroupTieredPackage) + value.scalableMatrixWithUnitPricing != null -> + generator.writeObject(value.scalableMatrixWithUnitPricing) + value.scalableMatrixWithTieredPricing != null -> + generator.writeObject(value.scalableMatrixWithTieredPricing) + value.cumulativeGroupedBulk != null -> + generator.writeObject(value.cumulativeGroupedBulk) + value.cumulativeGroupedAllocation != null -> + generator.writeObject(value.cumulativeGroupedAllocation) + value.minimum != null -> generator.writeObject(value.minimum) + value.percent != null -> generator.writeObject(value.percent) + value.eventOutput != null -> generator.writeObject(value.eventOutput) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Price") + } + } + } + + class BulkWithFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bulkWithFiltersConfig: JsonField, + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + bulkWithFiltersConfig: JsonField = JsonMissing.of(), + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * Configuration for bulk_with_filters pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun bulkWithFiltersConfig(): BulkWithFiltersConfig = + bulkWithFiltersConfig.getRequired("bulk_with_filters_config") + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [bulkWithFiltersConfig]. + * + * Unlike [bulkWithFiltersConfig], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("bulk_with_filters_config") + @ExcludeMissing + fun _bulkWithFiltersConfig(): JsonField = + bulkWithFiltersConfig + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 [BulkWithFilters]. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFilters]. */ + class Builder internal constructor() { + + private var bulkWithFiltersConfig: JsonField? = null + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("bulk_with_filters") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(bulkWithFilters: BulkWithFilters) = apply { + bulkWithFiltersConfig = bulkWithFilters.bulkWithFiltersConfig + cadence = bulkWithFilters.cadence + itemId = bulkWithFilters.itemId + modelType = bulkWithFilters.modelType + name = bulkWithFilters.name + billableMetricId = bulkWithFilters.billableMetricId + billedInAdvance = bulkWithFilters.billedInAdvance + billingCycleConfiguration = bulkWithFilters.billingCycleConfiguration + conversionRate = bulkWithFilters.conversionRate + conversionRateConfig = bulkWithFilters.conversionRateConfig + currency = bulkWithFilters.currency + dimensionalPriceConfiguration = + bulkWithFilters.dimensionalPriceConfiguration + externalPriceId = bulkWithFilters.externalPriceId + fixedPriceQuantity = bulkWithFilters.fixedPriceQuantity + invoiceGroupingKey = bulkWithFilters.invoiceGroupingKey + invoicingCycleConfiguration = bulkWithFilters.invoicingCycleConfiguration + metadata = bulkWithFilters.metadata + referenceId = bulkWithFilters.referenceId + additionalProperties = bulkWithFilters.additionalProperties.toMutableMap() + } + + /** Configuration for bulk_with_filters pricing */ + fun bulkWithFiltersConfig(bulkWithFiltersConfig: BulkWithFiltersConfig) = + bulkWithFiltersConfig(JsonField.of(bulkWithFiltersConfig)) + + /** + * Sets [Builder.bulkWithFiltersConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.bulkWithFiltersConfig] with a well-typed + * [BulkWithFiltersConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun bulkWithFiltersConfig( + bulkWithFiltersConfig: JsonField + ) = apply { this.bulkWithFiltersConfig = bulkWithFiltersConfig } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("bulk_with_filters") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BulkWithFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .bulkWithFiltersConfig() + * .cadence() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFilters = + BulkWithFilters( + checkRequired("bulkWithFiltersConfig", bulkWithFiltersConfig), + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFilters = apply { + if (validated) { + return@apply + } + + bulkWithFiltersConfig().validate() + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("bulk_with_filters")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (bulkWithFiltersConfig.asKnown()?.validity() ?: 0) + + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("bulk_with_filters")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** Configuration for bulk_with_filters pricing */ + class BulkWithFiltersConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filters: JsonField>, + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("filters") + @ExcludeMissing + filters: JsonField> = JsonMissing.of(), + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of(), + ) : this(filters, tiers, mutableMapOf()) + + /** + * Property filters to apply (all must match) + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun filters(): List = filters.getRequired("filters") + + /** + * Bulk tiers for rating based on total usage volume + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * Returns the raw JSON value of [filters]. + * + * Unlike [filters], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("filters") + @ExcludeMissing + fun _filters(): JsonField> = filters + + /** + * Returns the raw JSON value of [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 + * [BulkWithFiltersConfig]. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [BulkWithFiltersConfig]. */ + class Builder internal constructor() { + + private var filters: JsonField>? = null + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(bulkWithFiltersConfig: BulkWithFiltersConfig) = apply { + filters = bulkWithFiltersConfig.filters.map { it.toMutableList() } + tiers = bulkWithFiltersConfig.tiers.map { it.toMutableList() } + additionalProperties = + bulkWithFiltersConfig.additionalProperties.toMutableMap() + } + + /** Property filters to apply (all must match) */ + fun filters(filters: List) = filters(JsonField.of(filters)) + + /** + * Sets [Builder.filters] to an arbitrary JSON value. + * + * You should usually call [Builder.filters] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun filters(filters: JsonField>) = apply { + this.filters = filters.map { it.toMutableList() } + } + + /** + * Adds a single [Filter] to [filters]. + * + * @throws IllegalStateException if the field was previously set to a + * non-list. + */ + fun addFilter(filter: Filter) = apply { + filters = + (filters ?: JsonField.of(mutableListOf())).also { + checkKnown("filters", it).add(filter) + } + } + + /** Bulk tiers for rating based on total usage volume */ + 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 [BulkWithFiltersConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .filters() + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BulkWithFiltersConfig = + BulkWithFiltersConfig( + checkRequired("filters", filters).map { it.toImmutable() }, + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BulkWithFiltersConfig = apply { + if (validated) { + return@apply + } + + filters().forEach { it.validate() } + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (filters.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single property filter */ + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val propertyKey: JsonField, + private val propertyValue: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("property_key") + @ExcludeMissing + propertyKey: JsonField = JsonMissing.of(), + @JsonProperty("property_value") + @ExcludeMissing + propertyValue: JsonField = JsonMissing.of(), + ) : this(propertyKey, propertyValue, mutableMapOf()) + + /** + * Event property key to filter on + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyKey(): String = propertyKey.getRequired("property_key") + + /** + * Event property value to match + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun propertyValue(): String = propertyValue.getRequired("property_value") + + /** + * Returns the raw JSON value of [propertyKey]. + * + * Unlike [propertyKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("property_key") + @ExcludeMissing + fun _propertyKey(): JsonField = propertyKey + + /** + * Returns the raw JSON value of [propertyValue]. + * + * Unlike [propertyValue], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("property_value") + @ExcludeMissing + fun _propertyValue(): JsonField = propertyValue + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var propertyKey: JsonField? = null + private var propertyValue: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(filter: Filter) = apply { + propertyKey = filter.propertyKey + propertyValue = filter.propertyValue + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** Event property key to filter on */ + fun propertyKey(propertyKey: String) = + propertyKey(JsonField.of(propertyKey)) + + /** + * Sets [Builder.propertyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyKey(propertyKey: JsonField) = apply { + this.propertyKey = propertyKey + } + + /** Event property value to match */ + fun propertyValue(propertyValue: String) = + propertyValue(JsonField.of(propertyValue)) + + /** + * Sets [Builder.propertyValue] to an arbitrary JSON value. + * + * You should usually call [Builder.propertyValue] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun propertyValue(propertyValue: JsonField) = apply { + this.propertyValue = propertyValue + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Filter]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```kotlin + * .propertyKey() + * .propertyValue() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("propertyKey", propertyKey), + checkRequired("propertyValue", propertyValue), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + propertyKey() + propertyValue() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (propertyKey.asKnown() == null) 0 else 1) + + (if (propertyValue.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{propertyKey=$propertyKey, propertyValue=$propertyValue, additionalProperties=$additionalProperties}" + } + + /** Configuration for a single bulk pricing tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitAmount: JsonField, + private val tierLowerBound: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + ) : this(unitAmount, tierLowerBound, mutableMapOf()) + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * The lower bound for this tier + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun tierLowerBound(): String? = + tierLowerBound.getNullable("tier_lower_bound") + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + @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: + * ```kotlin + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var unitAmount: JsonField? = null + private var tierLowerBound: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + unitAmount = tier.unitAmount + tierLowerBound = tier.tierLowerBound + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + /** The lower bound for this tier */ + fun tierLowerBound(tierLowerBound: String?) = + tierLowerBound(JsonField.ofNullable(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("unitAmount", unitAmount), + tierLowerBound, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + unitAmount() + tierLowerBound() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + + (if (tierLowerBound.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + unitAmount == other.unitAmount && + tierLowerBound == other.tierLowerBound && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(unitAmount, tierLowerBound, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{unitAmount=$unitAmount, tierLowerBound=$tierLowerBound, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFiltersConfig && + filters == other.filters && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filters, tiers, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFiltersConfig{filters=$filters, tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BulkWithFilters && + bulkWithFiltersConfig == other.bulkWithFiltersConfig && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bulkWithFiltersConfig, + cadence, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BulkWithFilters{bulkWithFiltersConfig=$bulkWithFiltersConfig, cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class TieredWithProration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val tieredWithProrationConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + tieredWithProrationConfig: JsonField = + JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * Configuration for tiered_with_proration pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun tieredWithProrationConfig(): TieredWithProrationConfig = + tieredWithProrationConfig.getRequired("tiered_with_proration_config") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [tieredWithProrationConfig]. + * + * Unlike [tieredWithProrationConfig], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("tiered_with_proration_config") + @ExcludeMissing + fun _tieredWithProrationConfig(): JsonField = + tieredWithProrationConfig + + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [TieredWithProration]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProration]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("tiered_with_proration") + private var name: JsonField? = null + private var tieredWithProrationConfig: JsonField? = + null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tieredWithProration: TieredWithProration) = apply { + cadence = tieredWithProration.cadence + itemId = tieredWithProration.itemId + modelType = tieredWithProration.modelType + name = tieredWithProration.name + tieredWithProrationConfig = tieredWithProration.tieredWithProrationConfig + billableMetricId = tieredWithProration.billableMetricId + billedInAdvance = tieredWithProration.billedInAdvance + billingCycleConfiguration = tieredWithProration.billingCycleConfiguration + conversionRate = tieredWithProration.conversionRate + conversionRateConfig = tieredWithProration.conversionRateConfig + currency = tieredWithProration.currency + dimensionalPriceConfiguration = + tieredWithProration.dimensionalPriceConfiguration + externalPriceId = tieredWithProration.externalPriceId + fixedPriceQuantity = tieredWithProration.fixedPriceQuantity + invoiceGroupingKey = tieredWithProration.invoiceGroupingKey + invoicingCycleConfiguration = + tieredWithProration.invoicingCycleConfiguration + metadata = tieredWithProration.metadata + referenceId = tieredWithProration.referenceId + additionalProperties = + tieredWithProration.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("tiered_with_proration") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for tiered_with_proration pricing */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: TieredWithProrationConfig + ) = tieredWithProrationConfig(JsonField.of(tieredWithProrationConfig)) + + /** + * Sets [Builder.tieredWithProrationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.tieredWithProrationConfig] with a well-typed + * [TieredWithProrationConfig] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun tieredWithProrationConfig( + tieredWithProrationConfig: JsonField + ) = apply { this.tieredWithProrationConfig = tieredWithProrationConfig } + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TieredWithProration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .tieredWithProrationConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProration = + TieredWithProration( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("tieredWithProrationConfig", tieredWithProrationConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProration = apply { + if (validated) { + return@apply + } + + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("tiered_with_proration")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + tieredWithProrationConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("tiered_with_proration")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (tieredWithProrationConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } + + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } + + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for tiered_with_proration pricing */ + class TieredWithProrationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tiers: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tiers") + @ExcludeMissing + tiers: JsonField> = JsonMissing.of() + ) : this(tiers, mutableMapOf()) + + /** + * Tiers for rating based on total usage quantities into the specified tier with + * proration + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun tiers(): List = tiers.getRequired("tiers") + + /** + * 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 + * [TieredWithProrationConfig]. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TieredWithProrationConfig]. */ + class Builder internal constructor() { + + private var tiers: JsonField>? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tieredWithProrationConfig: TieredWithProrationConfig) = + apply { + tiers = tieredWithProrationConfig.tiers.map { it.toMutableList() } + additionalProperties = + tieredWithProrationConfig.additionalProperties.toMutableMap() + } + + /** + * Tiers for rating based on total usage quantities into the specified tier + * with proration + */ + 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 [TieredWithProrationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .tiers() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TieredWithProrationConfig = + TieredWithProrationConfig( + checkRequired("tiers", tiers).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TieredWithProrationConfig = apply { + if (validated) { + return@apply + } + + tiers().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration for a single tiered with proration tier */ + class Tier + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tierLowerBound: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tier_lower_bound") + @ExcludeMissing + tierLowerBound: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(tierLowerBound, unitAmount, mutableMapOf()) + + /** + * Inclusive tier starting value + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun tierLowerBound(): String = + tierLowerBound.getRequired("tier_lower_bound") + + /** + * Amount per unit + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [tierLowerBound]. + * + * Unlike [tierLowerBound], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("tier_lower_bound") + @ExcludeMissing + fun _tierLowerBound(): JsonField = tierLowerBound + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var tierLowerBound: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(tier: Tier) = apply { + tierLowerBound = tier.tierLowerBound + unitAmount = tier.unitAmount + additionalProperties = tier.additionalProperties.toMutableMap() + } + + /** Inclusive tier starting value */ + fun tierLowerBound(tierLowerBound: String) = + tierLowerBound(JsonField.of(tierLowerBound)) + + /** + * Sets [Builder.tierLowerBound] to an arbitrary JSON value. + * + * You should usually call [Builder.tierLowerBound] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tierLowerBound(tierLowerBound: JsonField) = apply { + this.tierLowerBound = tierLowerBound + } + + /** Amount per unit */ + fun unitAmount(unitAmount: String) = + unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.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: + * ```kotlin + * .tierLowerBound() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tier = + Tier( + checkRequired("tierLowerBound", tierLowerBound), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + tierLowerBound() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (tierLowerBound.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tier && + tierLowerBound == other.tierLowerBound && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(tierLowerBound, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{tierLowerBound=$tierLowerBound, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProrationConfig && + tiers == other.tiers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProrationConfig{tiers=$tiers, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TieredWithProration && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + tieredWithProrationConfig == other.tieredWithProrationConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + tieredWithProrationConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TieredWithProration{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, tieredWithProrationConfig=$tieredWithProrationConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class GroupedWithMinMaxThresholds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val groupedWithMinMaxThresholdsConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + groupedWithMinMaxThresholdsConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for grouped_with_min_max_thresholds pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun groupedWithMinMaxThresholdsConfig(): GroupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholdsConfig.getRequired( + "grouped_with_min_max_thresholds_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") + + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence + + /** + * Returns the raw JSON value of [groupedWithMinMaxThresholdsConfig]. + * + * Unlike [groupedWithMinMaxThresholdsConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("grouped_with_min_max_thresholds_config") + @ExcludeMissing + fun _groupedWithMinMaxThresholdsConfig(): + JsonField = groupedWithMinMaxThresholdsConfig + + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId + + /** + * 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 [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId + + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance + + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration + + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate + + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig + + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency + + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration + + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId + + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey + + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId + + @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 + * [GroupedWithMinMaxThresholds]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholds]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var groupedWithMinMaxThresholdsConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("grouped_with_min_max_thresholds") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(groupedWithMinMaxThresholds: GroupedWithMinMaxThresholds) = + apply { + cadence = groupedWithMinMaxThresholds.cadence + groupedWithMinMaxThresholdsConfig = + groupedWithMinMaxThresholds.groupedWithMinMaxThresholdsConfig + itemId = groupedWithMinMaxThresholds.itemId + modelType = groupedWithMinMaxThresholds.modelType + name = groupedWithMinMaxThresholds.name + billableMetricId = groupedWithMinMaxThresholds.billableMetricId + billedInAdvance = groupedWithMinMaxThresholds.billedInAdvance + billingCycleConfiguration = + groupedWithMinMaxThresholds.billingCycleConfiguration + conversionRate = groupedWithMinMaxThresholds.conversionRate + conversionRateConfig = groupedWithMinMaxThresholds.conversionRateConfig + currency = groupedWithMinMaxThresholds.currency + dimensionalPriceConfiguration = + groupedWithMinMaxThresholds.dimensionalPriceConfiguration + externalPriceId = groupedWithMinMaxThresholds.externalPriceId + fixedPriceQuantity = groupedWithMinMaxThresholds.fixedPriceQuantity + invoiceGroupingKey = groupedWithMinMaxThresholds.invoiceGroupingKey + invoicingCycleConfiguration = + groupedWithMinMaxThresholds.invoicingCycleConfiguration + metadata = groupedWithMinMaxThresholds.metadata + referenceId = groupedWithMinMaxThresholds.referenceId + additionalProperties = + groupedWithMinMaxThresholds.additionalProperties.toMutableMap() + } + + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = + groupedWithMinMaxThresholdsConfig( + JsonField.of(groupedWithMinMaxThresholdsConfig) + ) + + /** + * Sets [Builder.groupedWithMinMaxThresholdsConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.groupedWithMinMaxThresholdsConfig] with a + * well-typed [GroupedWithMinMaxThresholdsConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun groupedWithMinMaxThresholdsConfig( + groupedWithMinMaxThresholdsConfig: + JsonField + ) = apply { + this.groupedWithMinMaxThresholdsConfig = groupedWithMinMaxThresholdsConfig + } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("grouped_with_min_max_thresholds") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } + + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) + + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } + + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } + + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) + + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholds]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .groupedWithMinMaxThresholdsConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholds = + GroupedWithMinMaxThresholds( + checkRequired("cadence", cadence), + checkRequired( + "groupedWithMinMaxThresholdsConfig", + groupedWithMinMaxThresholdsConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholds = apply { + if (validated) { + return@apply + } + + cadence().validate() + groupedWithMinMaxThresholdsConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("grouped_with_min_max_thresholds")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (groupedWithMinMaxThresholdsConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("grouped_with_min_max_thresholds")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - /** - * The id of the price on the plan to replace in the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - fun replacesPriceId(): String = replacesPriceId.getRequired("replaces_price_id") + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - /** - * The definition of a new allocation price to create and add to the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun allocationPrice(): NewAllocationPrice? = allocationPrice.getNullable("allocation_price") + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - /** - * [DEPRECATED] Use add_adjustments instead. The subscription's discounts for the - * replacement price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") - fun discounts(): List? = discounts.getNullable("discounts") + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN + } - /** - * The external price id of the price to add to the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") + } - /** - * The new quantity of the price, if the price is a fixed price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun fixedPriceQuantity(): Double? = fixedPriceQuantity.getNullable("fixed_price_quantity") + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } - /** - * [DEPRECATED] Use add_adjustments instead. The subscription's maximum amount for the - * replacement price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") - fun maximumAmount(): String? = maximumAmount.getNullable("maximum_amount") + known() + validated = true + } - /** - * [DEPRECATED] Use add_adjustments instead. The subscription's minimum amount for the - * replacement price. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") - fun minimumAmount(): String? = minimumAmount.getNullable("minimum_amount") + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** - * The definition of a new price to create and add to the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun price(): Price? = price.getNullable("price") + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * The id of the price to add to the subscription. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun priceId(): String? = priceId.getNullable("price_id") + return other is Cadence && value == other.value + } - /** - * Returns the raw JSON value of [replacesPriceId]. - * - * Unlike [replacesPriceId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("replaces_price_id") - @ExcludeMissing - fun _replacesPriceId(): JsonField = replacesPriceId + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for grouped_with_min_max_thresholds pricing */ + class GroupedWithMinMaxThresholdsConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupingKey: JsonField, + private val maximumCharge: JsonField, + private val minimumCharge: JsonField, + private val perUnitRate: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("maximum_charge") + @ExcludeMissing + maximumCharge: JsonField = JsonMissing.of(), + @JsonProperty("minimum_charge") + @ExcludeMissing + minimumCharge: JsonField = JsonMissing.of(), + @JsonProperty("per_unit_rate") + @ExcludeMissing + perUnitRate: JsonField = JsonMissing.of(), + ) : this(groupingKey, maximumCharge, minimumCharge, perUnitRate, mutableMapOf()) + + /** + * The event property used to group before applying thresholds + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The maximum amount to charge each group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun maximumCharge(): String = maximumCharge.getRequired("maximum_charge") + + /** + * The minimum amount to charge each group, regardless of usage + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun minimumCharge(): String = minimumCharge.getRequired("minimum_charge") + + /** + * The base price charged per group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun perUnitRate(): String = perUnitRate.getRequired("per_unit_rate") + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [maximumCharge]. + * + * Unlike [maximumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("maximum_charge") + @ExcludeMissing + fun _maximumCharge(): JsonField = maximumCharge + + /** + * Returns the raw JSON value of [minimumCharge]. + * + * Unlike [minimumCharge], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("minimum_charge") + @ExcludeMissing + fun _minimumCharge(): JsonField = minimumCharge + + /** + * Returns the raw JSON value of [perUnitRate]. + * + * Unlike [perUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("per_unit_rate") + @ExcludeMissing + fun _perUnitRate(): JsonField = perUnitRate + + @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 + * [GroupedWithMinMaxThresholdsConfig]. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [GroupedWithMinMaxThresholdsConfig]. */ + class Builder internal constructor() { + + private var groupingKey: JsonField? = null + private var maximumCharge: JsonField? = null + private var minimumCharge: JsonField? = null + private var perUnitRate: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + groupedWithMinMaxThresholdsConfig: GroupedWithMinMaxThresholdsConfig + ) = apply { + groupingKey = groupedWithMinMaxThresholdsConfig.groupingKey + maximumCharge = groupedWithMinMaxThresholdsConfig.maximumCharge + minimumCharge = groupedWithMinMaxThresholdsConfig.minimumCharge + perUnitRate = groupedWithMinMaxThresholdsConfig.perUnitRate + additionalProperties = + groupedWithMinMaxThresholdsConfig.additionalProperties + .toMutableMap() + } + + /** The event property used to group before applying thresholds */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } + + /** The maximum amount to charge each group */ + fun maximumCharge(maximumCharge: String) = + maximumCharge(JsonField.of(maximumCharge)) + + /** + * Sets [Builder.maximumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.maximumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun maximumCharge(maximumCharge: JsonField) = apply { + this.maximumCharge = maximumCharge + } + + /** The minimum amount to charge each group, regardless of usage */ + fun minimumCharge(minimumCharge: String) = + minimumCharge(JsonField.of(minimumCharge)) + + /** + * Sets [Builder.minimumCharge] to an arbitrary JSON value. + * + * You should usually call [Builder.minimumCharge] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun minimumCharge(minimumCharge: JsonField) = apply { + this.minimumCharge = minimumCharge + } + + /** The base price charged per group */ + fun perUnitRate(perUnitRate: String) = + perUnitRate(JsonField.of(perUnitRate)) + + /** + * Sets [Builder.perUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.perUnitRate] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun perUnitRate(perUnitRate: JsonField) = apply { + this.perUnitRate = perUnitRate + } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [GroupedWithMinMaxThresholdsConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .groupingKey() + * .maximumCharge() + * .minimumCharge() + * .perUnitRate() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GroupedWithMinMaxThresholdsConfig = + GroupedWithMinMaxThresholdsConfig( + checkRequired("groupingKey", groupingKey), + checkRequired("maximumCharge", maximumCharge), + checkRequired("minimumCharge", minimumCharge), + checkRequired("perUnitRate", perUnitRate), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): GroupedWithMinMaxThresholdsConfig = apply { + if (validated) { + return@apply + } + + groupingKey() + maximumCharge() + minimumCharge() + perUnitRate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (maximumCharge.asKnown() == null) 0 else 1) + + (if (minimumCharge.asKnown() == null) 0 else 1) + + (if (perUnitRate.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholdsConfig && + groupingKey == other.groupingKey && + maximumCharge == other.maximumCharge && + minimumCharge == other.minimumCharge && + perUnitRate == other.perUnitRate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + groupingKey, + maximumCharge, + minimumCharge, + perUnitRate, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholdsConfig{groupingKey=$groupingKey, maximumCharge=$maximumCharge, minimumCharge=$minimumCharge, perUnitRate=$perUnitRate, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is GroupedWithMinMaxThresholds && + cadence == other.cadence && + groupedWithMinMaxThresholdsConfig == + other.groupedWithMinMaxThresholdsConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + groupedWithMinMaxThresholdsConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GroupedWithMinMaxThresholds{cadence=$cadence, groupedWithMinMaxThresholdsConfig=$groupedWithMinMaxThresholdsConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } + + class CumulativeGroupedAllocation + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val cumulativeGroupedAllocationConfig: + JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + cumulativeGroupedAllocationConfig: + JsonField = + JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) + + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") + + /** + * Configuration for cumulative_grouped_allocation pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cumulativeGroupedAllocationConfig(): CumulativeGroupedAllocationConfig = + cumulativeGroupedAllocationConfig.getRequired( + "cumulative_grouped_allocation_config" + ) + + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") + + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType + + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") + + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") + + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") + + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") + + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") + + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") + + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") + + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") + + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") + + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - /** - * Returns the raw JSON value of [allocationPrice]. - * - * Unlike [allocationPrice], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("allocation_price") - @ExcludeMissing - fun _allocationPrice(): JsonField = allocationPrice + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - /** - * Returns the raw JSON value of [discounts]. - * - * Unlike [discounts], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("discounts") - @ExcludeMissing - fun _discounts(): JsonField> = discounts + /** + * Returns the raw JSON value of [cumulativeGroupedAllocationConfig]. + * + * Unlike [cumulativeGroupedAllocationConfig], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("cumulative_grouped_allocation_config") + @ExcludeMissing + fun _cumulativeGroupedAllocationConfig(): + JsonField = cumulativeGroupedAllocationConfig - /** - * Returns the raw JSON value of [externalPriceId]. - * - * Unlike [externalPriceId], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("external_price_id") - @ExcludeMissing - fun _externalPriceId(): JsonField = externalPriceId + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - /** - * Returns the raw JSON value of [fixedPriceQuantity]. - * - * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("fixed_price_quantity") - @ExcludeMissing - fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity + /** + * 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 [maximumAmount]. - * - * Unlike [maximumAmount], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @Deprecated("deprecated") - @JsonProperty("maximum_amount") - @ExcludeMissing - fun _maximumAmount(): JsonField = maximumAmount + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - /** - * Returns the raw JSON value of [minimumAmount]. - * - * Unlike [minimumAmount], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @Deprecated("deprecated") - @JsonProperty("minimum_amount") - @ExcludeMissing - fun _minimumAmount(): JsonField = minimumAmount + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - /** - * 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 [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - /** - * Returns the raw JSON value of [priceId]. - * - * Unlike [priceId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("price_id") @ExcludeMissing fun _priceId(): JsonField = priceId + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - fun toBuilder() = Builder().from(this) + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - companion object { + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - /** - * Returns a mutable builder for constructing an instance of [ReplacePrice]. - * - * The following fields are required: - * ```kotlin - * .replacesPriceId() - * ``` - */ - fun builder() = Builder() - } + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - /** A builder for [ReplacePrice]. */ - class Builder internal constructor() { + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - private var replacesPriceId: JsonField? = null - private var allocationPrice: JsonField = JsonMissing.of() - private var discounts: JsonField>? = null - private var externalPriceId: JsonField = JsonMissing.of() - private var fixedPriceQuantity: JsonField = JsonMissing.of() - private var maximumAmount: JsonField = JsonMissing.of() - private var minimumAmount: JsonField = JsonMissing.of() - private var price: JsonField = JsonMissing.of() - private var priceId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - internal fun from(replacePrice: ReplacePrice) = apply { - replacesPriceId = replacePrice.replacesPriceId - allocationPrice = replacePrice.allocationPrice - discounts = replacePrice.discounts.map { it.toMutableList() } - externalPriceId = replacePrice.externalPriceId - fixedPriceQuantity = replacePrice.fixedPriceQuantity - maximumAmount = replacePrice.maximumAmount - minimumAmount = replacePrice.minimumAmount - price = replacePrice.price - priceId = replacePrice.priceId - additionalProperties = replacePrice.additionalProperties.toMutableMap() - } + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - /** The id of the price on the plan to replace in the subscription. */ - fun replacesPriceId(replacesPriceId: String) = - replacesPriceId(JsonField.of(replacesPriceId)) + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - /** - * Sets [Builder.replacesPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.replacesPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun replacesPriceId(replacesPriceId: JsonField) = apply { - this.replacesPriceId = replacesPriceId - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** The definition of a new allocation price to create and add to the subscription. */ - fun allocationPrice(allocationPrice: NewAllocationPrice?) = - allocationPrice(JsonField.ofNullable(allocationPrice)) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CumulativeGroupedAllocation]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } - /** - * Sets [Builder.allocationPrice] to an arbitrary JSON value. - * - * You should usually call [Builder.allocationPrice] with a well-typed - * [NewAllocationPrice] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun allocationPrice(allocationPrice: JsonField) = apply { - this.allocationPrice = allocationPrice - } + /** A builder for [CumulativeGroupedAllocation]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var cumulativeGroupedAllocationConfig: + JsonField? = + null + private var itemId: JsonField? = null + private var modelType: JsonValue = + JsonValue.from("cumulative_grouped_allocation") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(cumulativeGroupedAllocation: CumulativeGroupedAllocation) = + apply { + cadence = cumulativeGroupedAllocation.cadence + cumulativeGroupedAllocationConfig = + cumulativeGroupedAllocation.cumulativeGroupedAllocationConfig + itemId = cumulativeGroupedAllocation.itemId + modelType = cumulativeGroupedAllocation.modelType + name = cumulativeGroupedAllocation.name + billableMetricId = cumulativeGroupedAllocation.billableMetricId + billedInAdvance = cumulativeGroupedAllocation.billedInAdvance + billingCycleConfiguration = + cumulativeGroupedAllocation.billingCycleConfiguration + conversionRate = cumulativeGroupedAllocation.conversionRate + conversionRateConfig = cumulativeGroupedAllocation.conversionRateConfig + currency = cumulativeGroupedAllocation.currency + dimensionalPriceConfiguration = + cumulativeGroupedAllocation.dimensionalPriceConfiguration + externalPriceId = cumulativeGroupedAllocation.externalPriceId + fixedPriceQuantity = cumulativeGroupedAllocation.fixedPriceQuantity + invoiceGroupingKey = cumulativeGroupedAllocation.invoiceGroupingKey + invoicingCycleConfiguration = + cumulativeGroupedAllocation.invoicingCycleConfiguration + metadata = cumulativeGroupedAllocation.metadata + referenceId = cumulativeGroupedAllocation.referenceId + additionalProperties = + cumulativeGroupedAllocation.additionalProperties.toMutableMap() + } - /** - * [DEPRECATED] Use add_adjustments instead. The subscription's discounts for the - * replacement price. - */ - @Deprecated("deprecated") - fun discounts(discounts: List?) = - discounts(JsonField.ofNullable(discounts)) + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for cumulative_grouped_allocation pricing */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = + cumulativeGroupedAllocationConfig( + JsonField.of(cumulativeGroupedAllocationConfig) + ) - /** - * Sets [Builder.discounts] to an arbitrary JSON value. - * - * You should usually call [Builder.discounts] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - @Deprecated("deprecated") - fun discounts(discounts: JsonField>) = apply { - this.discounts = discounts.map { it.toMutableList() } - } + /** + * Sets [Builder.cumulativeGroupedAllocationConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeGroupedAllocationConfig] with a + * well-typed [CumulativeGroupedAllocationConfig] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun cumulativeGroupedAllocationConfig( + cumulativeGroupedAllocationConfig: + JsonField + ) = apply { + this.cumulativeGroupedAllocationConfig = cumulativeGroupedAllocationConfig + } - /** - * Adds a single [DiscountOverride] to [discounts]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - @Deprecated("deprecated") - fun addDiscount(discount: DiscountOverride) = apply { - discounts = - (discounts ?: JsonField.of(mutableListOf())).also { - checkKnown("discounts", it).add(discount) + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("cumulative_grouped_allocation") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId } - } - /** The external price id of the price to add to the subscription. */ - fun externalPriceId(externalPriceId: String?) = - externalPriceId(JsonField.ofNullable(externalPriceId)) + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - /** - * Sets [Builder.externalPriceId] to an arbitrary JSON value. - * - * You should usually call [Builder.externalPriceId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun externalPriceId(externalPriceId: JsonField) = apply { - this.externalPriceId = externalPriceId - } + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - /** The new quantity of the price, if the price is a fixed price. */ - fun fixedPriceQuantity(fixedPriceQuantity: Double?) = - fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - /** - * Alias for [Builder.fixedPriceQuantity]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun fixedPriceQuantity(fixedPriceQuantity: Double) = - fixedPriceQuantity(fixedPriceQuantity as Double?) + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) + + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - /** - * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. - * - * You should usually call [Builder.fixedPriceQuantity] with a well-typed [Double] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { - this.fixedPriceQuantity = fixedPriceQuantity - } + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - /** - * [DEPRECATED] Use add_adjustments instead. The subscription's maximum amount for the - * replacement price. - */ - @Deprecated("deprecated") - fun maximumAmount(maximumAmount: String?) = - maximumAmount(JsonField.ofNullable(maximumAmount)) + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - /** - * Sets [Builder.maximumAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.maximumAmount] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun maximumAmount(maximumAmount: JsonField) = apply { - this.maximumAmount = maximumAmount - } + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - /** - * [DEPRECATED] Use add_adjustments instead. The subscription's minimum amount for the - * replacement price. - */ - @Deprecated("deprecated") - fun minimumAmount(minimumAmount: String?) = - minimumAmount(JsonField.ofNullable(minimumAmount)) + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - /** - * Sets [Builder.minimumAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.minimumAmount] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun minimumAmount(minimumAmount: JsonField) = apply { - this.minimumAmount = minimumAmount - } + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - /** The definition of a new price to create and add to the subscription. */ - fun price(price: Price?) = price(JsonField.ofNullable(price)) + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** - * Sets [Builder.price] to an arbitrary JSON value. - * - * You should usually call [Builder.price] with a well-typed [Price] 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 putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** Alias for calling [price] with `Price.ofUnit(unit)`. */ - fun price(unit: NewSubscriptionUnitPrice) = price(Price.ofUnit(unit)) + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** Alias for calling [price] with `Price.ofPackage(package_)`. */ - fun price(package_: NewSubscriptionPackagePrice) = price(Price.ofPackage(package_)) + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - /** Alias for calling [price] with `Price.ofMatrix(matrix)`. */ - fun price(matrix: NewSubscriptionMatrixPrice) = price(Price.ofMatrix(matrix)) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** Alias for calling [price] with `Price.ofTiered(tiered)`. */ - fun price(tiered: NewSubscriptionTieredPrice) = price(Price.ofTiered(tiered)) + /** + * Returns an immutable instance of [CumulativeGroupedAllocation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .cumulativeGroupedAllocationConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocation = + CumulativeGroupedAllocation( + checkRequired("cadence", cadence), + checkRequired( + "cumulativeGroupedAllocationConfig", + cumulativeGroupedAllocationConfig, + ), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - /** Alias for calling [price] with `Price.ofTieredBps(tieredBps)`. */ - fun price(tieredBps: NewSubscriptionTieredBpsPrice) = - price(Price.ofTieredBps(tieredBps)) + private var validated: Boolean = false - /** Alias for calling [price] with `Price.ofBps(bps)`. */ - fun price(bps: NewSubscriptionBpsPrice) = price(Price.ofBps(bps)) + fun validate(): CumulativeGroupedAllocation = apply { + if (validated) { + return@apply + } - /** Alias for calling [price] with `Price.ofBulkBps(bulkBps)`. */ - fun price(bulkBps: NewSubscriptionBulkBpsPrice) = price(Price.ofBulkBps(bulkBps)) + cadence().validate() + cumulativeGroupedAllocationConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("cumulative_grouped_allocation")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - /** Alias for calling [price] with `Price.ofBulk(bulk)`. */ - fun price(bulk: NewSubscriptionBulkPrice) = price(Price.ofBulk(bulk)) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** - * Alias for calling [price] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. - */ - fun price(thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice) = - price(Price.ofThresholdTotalAmount(thresholdTotalAmount)) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (cumulativeGroupedAllocationConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { + if (it == JsonValue.from("cumulative_grouped_allocation")) 1 else 0 + } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - /** Alias for calling [price] with `Price.ofTieredPackage(tieredPackage)`. */ - fun price(tieredPackage: NewSubscriptionTieredPackagePrice) = - price(Price.ofTieredPackage(tieredPackage)) + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - /** Alias for calling [price] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ - fun price(tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice) = - price(Price.ofTieredWithMinimum(tieredWithMinimum)) + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - /** Alias for calling [price] with `Price.ofUnitWithPercent(unitWithPercent)`. */ - fun price(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = - price(Price.ofUnitWithPercent(unitWithPercent)) + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN + } - /** - * Alias for calling [price] with - * `Price.ofPackageWithAllocation(packageWithAllocation)`. - */ - fun price(packageWithAllocation: NewSubscriptionPackageWithAllocationPrice) = - price(Price.ofPackageWithAllocation(packageWithAllocation)) + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") + } - /** - * Alias for calling [price] with `Price.ofTieredWithProration(tieredWithProration)`. - */ - fun price(tieredWithProration: NewSubscriptionTierWithProrationPrice) = - price(Price.ofTieredWithProration(tieredWithProration)) + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply + } - /** Alias for calling [price] with `Price.ofUnitWithProration(unitWithProration)`. */ - fun price(unitWithProration: NewSubscriptionUnitWithProrationPrice) = - price(Price.ofUnitWithProration(unitWithProration)) + known() + validated = true + } - /** Alias for calling [price] with `Price.ofGroupedAllocation(groupedAllocation)`. */ - fun price(groupedAllocation: NewSubscriptionGroupedAllocationPrice) = - price(Price.ofGroupedAllocation(groupedAllocation)) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** - * Alias for calling [price] with - * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. - */ - fun price(groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice) = - price(Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)) + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** Alias for calling [price] with `Price.ofBulkWithProration(bulkWithProration)`. */ - fun price(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = - price(Price.ofBulkWithProration(bulkWithProration)) + return other is Cadence && value == other.value + } - /** - * Alias for calling [price] with - * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. - */ - fun price( - scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice - ) = price(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) + override fun hashCode() = value.hashCode() - /** - * Alias for calling [price] with - * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. - */ - fun price( - scalableMatrixWithTieredPricing: NewSubscriptionScalableMatrixWithTieredPricingPrice - ) = price(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) + override fun toString() = value.toString() + } - /** - * Alias for calling [price] with - * `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. - */ - fun price(cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice) = - price(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + /** Configuration for cumulative_grouped_allocation pricing */ + class CumulativeGroupedAllocationConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cumulativeAllocation: JsonField, + private val groupAllocation: JsonField, + private val groupingKey: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * Alias for calling [price] with - * `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. - */ - fun price(maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice) = - price(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + @JsonCreator + private constructor( + @JsonProperty("cumulative_allocation") + @ExcludeMissing + cumulativeAllocation: JsonField = JsonMissing.of(), + @JsonProperty("group_allocation") + @ExcludeMissing + groupAllocation: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + mutableMapOf(), + ) + + /** + * The overall allocation across all groups + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun cumulativeAllocation(): String = + cumulativeAllocation.getRequired("cumulative_allocation") + + /** + * The allocation per individual group + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupAllocation(): String = groupAllocation.getRequired("group_allocation") + + /** + * The event property used to group usage before applying allocations + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun groupingKey(): String = groupingKey.getRequired("grouping_key") + + /** + * The amount to charge for each unit outside of the allocation + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [cumulativeAllocation]. + * + * Unlike [cumulativeAllocation], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("cumulative_allocation") + @ExcludeMissing + fun _cumulativeAllocation(): JsonField = cumulativeAllocation + + /** + * Returns the raw JSON value of [groupAllocation]. + * + * Unlike [groupAllocation], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("group_allocation") + @ExcludeMissing + fun _groupAllocation(): JsonField = groupAllocation + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** - * Alias for calling [price] with - * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. - */ - fun price(groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice) = - price(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CumulativeGroupedAllocationConfig]. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } - /** - * Alias for calling [price] with - * `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. - */ - fun price(matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice) = - price(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) + /** A builder for [CumulativeGroupedAllocationConfig]. */ + class Builder internal constructor() { + + private var cumulativeAllocation: JsonField? = null + private var groupAllocation: JsonField? = null + private var groupingKey: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from( + cumulativeGroupedAllocationConfig: CumulativeGroupedAllocationConfig + ) = apply { + cumulativeAllocation = + cumulativeGroupedAllocationConfig.cumulativeAllocation + groupAllocation = cumulativeGroupedAllocationConfig.groupAllocation + groupingKey = cumulativeGroupedAllocationConfig.groupingKey + unitAmount = cumulativeGroupedAllocationConfig.unitAmount + additionalProperties = + cumulativeGroupedAllocationConfig.additionalProperties + .toMutableMap() + } - /** - * Alias for calling [price] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. - */ - fun price(groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice) = - price(Price.ofGroupedTieredPackage(groupedTieredPackage)) + /** The overall allocation across all groups */ + fun cumulativeAllocation(cumulativeAllocation: String) = + cumulativeAllocation(JsonField.of(cumulativeAllocation)) + + /** + * Sets [Builder.cumulativeAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.cumulativeAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun cumulativeAllocation(cumulativeAllocation: JsonField) = apply { + this.cumulativeAllocation = cumulativeAllocation + } - /** - * Alias for calling [price] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. - */ - fun price(matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice) = - price(Price.ofMatrixWithAllocation(matrixWithAllocation)) + /** The allocation per individual group */ + fun groupAllocation(groupAllocation: String) = + groupAllocation(JsonField.of(groupAllocation)) + + /** + * Sets [Builder.groupAllocation] to an arbitrary JSON value. + * + * You should usually call [Builder.groupAllocation] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun groupAllocation(groupAllocation: JsonField) = apply { + this.groupAllocation = groupAllocation + } - /** - * Alias for calling [price] with - * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. - */ - fun price(tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice) = - price(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + /** The event property used to group usage before applying allocations */ + fun groupingKey(groupingKey: String) = + groupingKey(JsonField.of(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey + } - /** Alias for calling [price] with `Price.ofGroupedTiered(groupedTiered)`. */ - fun price(groupedTiered: NewSubscriptionGroupedTieredPrice) = - price(Price.ofGroupedTiered(groupedTiered)) + /** The amount to charge for each unit outside of the allocation */ + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { + this.unitAmount = unitAmount + } - /** The id of the price to add to the subscription. */ - fun priceId(priceId: String?) = priceId(JsonField.ofNullable(priceId)) + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** - * Sets [Builder.priceId] to an arbitrary JSON value. - * - * You should usually call [Builder.priceId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun priceId(priceId: JsonField) = apply { this.priceId = priceId } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + /** + * Returns an immutable instance of [CumulativeGroupedAllocationConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cumulativeAllocation() + * .groupAllocation() + * .groupingKey() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CumulativeGroupedAllocationConfig = + CumulativeGroupedAllocationConfig( + checkRequired("cumulativeAllocation", cumulativeAllocation), + checkRequired("groupAllocation", groupAllocation), + checkRequired("groupingKey", groupingKey), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + private var validated: Boolean = false - /** - * Returns an immutable instance of [ReplacePrice]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .replacesPriceId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ReplacePrice = - ReplacePrice( - checkRequired("replacesPriceId", replacesPriceId), - allocationPrice, - (discounts ?: JsonMissing.of()).map { it.toImmutable() }, - externalPriceId, - fixedPriceQuantity, - maximumAmount, - minimumAmount, - price, - priceId, - additionalProperties.toMutableMap(), - ) - } + fun validate(): CumulativeGroupedAllocationConfig = apply { + if (validated) { + return@apply + } + + cumulativeAllocation() + groupAllocation() + groupingKey() + unitAmount() + validated = true + } - private var validated: Boolean = false + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun validate(): ReplacePrice = apply { - if (validated) { - return@apply - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (cumulativeAllocation.asKnown() == null) 0 else 1) + + (if (groupAllocation.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - replacesPriceId() - allocationPrice()?.validate() - discounts()?.forEach { it.validate() } - externalPriceId() - fixedPriceQuantity() - maximumAmount() - minimumAmount() - price()?.validate() - priceId() - validated = true - } + return other is CumulativeGroupedAllocationConfig && + cumulativeAllocation == other.cumulativeAllocation && + groupAllocation == other.groupAllocation && + groupingKey == other.groupingKey && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + private val hashCode: Int by lazy { + Objects.hash( + cumulativeAllocation, + groupAllocation, + groupingKey, + unitAmount, + additionalProperties, + ) + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (replacesPriceId.asKnown() == null) 0 else 1) + - (allocationPrice.asKnown()?.validity() ?: 0) + - (discounts.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + - (if (externalPriceId.asKnown() == null) 0 else 1) + - (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + - (if (maximumAmount.asKnown() == null) 0 else 1) + - (if (minimumAmount.asKnown() == null) 0 else 1) + - (price.asKnown()?.validity() ?: 0) + - (if (priceId.asKnown() == null) 0 else 1) + override fun hashCode(): Int = hashCode - /** The definition of a new price to create and add to the subscription. */ - @JsonDeserialize(using = Price.Deserializer::class) - @JsonSerialize(using = Price.Serializer::class) - class Price - private constructor( - private val unit: NewSubscriptionUnitPrice? = null, - private val package_: NewSubscriptionPackagePrice? = null, - private val matrix: NewSubscriptionMatrixPrice? = null, - private val tiered: NewSubscriptionTieredPrice? = null, - private val tieredBps: NewSubscriptionTieredBpsPrice? = null, - private val bps: NewSubscriptionBpsPrice? = null, - private val bulkBps: NewSubscriptionBulkBpsPrice? = null, - private val bulk: NewSubscriptionBulkPrice? = null, - private val thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice? = null, - private val tieredPackage: NewSubscriptionTieredPackagePrice? = null, - private val tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice? = null, - private val unitWithPercent: NewSubscriptionUnitWithPercentPrice? = null, - private val packageWithAllocation: NewSubscriptionPackageWithAllocationPrice? = null, - private val tieredWithProration: NewSubscriptionTierWithProrationPrice? = null, - private val unitWithProration: NewSubscriptionUnitWithProrationPrice? = null, - private val groupedAllocation: NewSubscriptionGroupedAllocationPrice? = null, - private val groupedWithProratedMinimum: - NewSubscriptionGroupedWithProratedMinimumPrice? = - null, - private val bulkWithProration: NewSubscriptionBulkWithProrationPrice? = null, - private val scalableMatrixWithUnitPricing: - NewSubscriptionScalableMatrixWithUnitPricingPrice? = - null, - private val scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice? = - null, - private val cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice? = null, - private val maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice? = null, - private val groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice? = - null, - private val matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice? = null, - private val groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice? = null, - private val matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice? = null, - private val tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice? = - null, - private val groupedTiered: NewSubscriptionGroupedTieredPrice? = null, - private val _json: JsonValue? = null, - ) { + override fun toString() = + "CumulativeGroupedAllocationConfig{cumulativeAllocation=$cumulativeAllocation, groupAllocation=$groupAllocation, groupingKey=$groupingKey, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } - fun unit(): NewSubscriptionUnitPrice? = unit + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - fun package_(): NewSubscriptionPackagePrice? = package_ + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - fun matrix(): NewSubscriptionMatrixPrice? = matrix + fun toBuilder() = Builder().from(this) - fun tiered(): NewSubscriptionTieredPrice? = tiered + companion object { - fun tieredBps(): NewSubscriptionTieredBpsPrice? = tieredBps + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + fun builder() = Builder() + } - fun bps(): NewSubscriptionBpsPrice? = bps + /** A builder for [Metadata]. */ + class Builder internal constructor() { - fun bulkBps(): NewSubscriptionBulkBpsPrice? = bulkBps + private var additionalProperties: MutableMap = + mutableMapOf() - fun bulk(): NewSubscriptionBulkPrice? = bulk + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } - fun thresholdTotalAmount(): NewSubscriptionThresholdTotalAmountPrice? = - thresholdTotalAmount + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun tieredPackage(): NewSubscriptionTieredPackagePrice? = tieredPackage + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun tieredWithMinimum(): NewSubscriptionTieredWithMinimumPrice? = tieredWithMinimum + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - fun unitWithPercent(): NewSubscriptionUnitWithPercentPrice? = unitWithPercent + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun packageWithAllocation(): NewSubscriptionPackageWithAllocationPrice? = - packageWithAllocation + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun tieredWithProration(): NewSubscriptionTierWithProrationPrice? = tieredWithProration + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } - fun unitWithProration(): NewSubscriptionUnitWithProrationPrice? = unitWithProration + private var validated: Boolean = false - fun groupedAllocation(): NewSubscriptionGroupedAllocationPrice? = groupedAllocation + fun validate(): Metadata = apply { + if (validated) { + return@apply + } - fun groupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice? = - groupedWithProratedMinimum + validated = true + } - fun bulkWithProration(): NewSubscriptionBulkWithProrationPrice? = bulkWithProration + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - fun scalableMatrixWithUnitPricing(): - NewSubscriptionScalableMatrixWithUnitPricingPrice? = scalableMatrixWithUnitPricing + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } - fun scalableMatrixWithTieredPricing(): - NewSubscriptionScalableMatrixWithTieredPricingPrice? = - scalableMatrixWithTieredPricing + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun cumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice? = - cumulativeGroupedBulk + return other is Metadata && + additionalProperties == other.additionalProperties + } - fun maxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice? = - maxGroupTieredPackage + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - fun groupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice? = - groupedWithMeteredMinimum + override fun hashCode(): Int = hashCode - fun matrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice? = - matrixWithDisplayName + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } - fun groupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice? = - groupedTieredPackage + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun matrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice? = - matrixWithAllocation + return other is CumulativeGroupedAllocation && + cadence == other.cadence && + cumulativeGroupedAllocationConfig == + other.cumulativeGroupedAllocationConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } - fun tieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice? = - tieredPackageWithMinimum + private val hashCode: Int by lazy { + Objects.hash( + cadence, + cumulativeGroupedAllocationConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) + } - fun groupedTiered(): NewSubscriptionGroupedTieredPrice? = groupedTiered + override fun hashCode(): Int = hashCode - fun isUnit(): Boolean = unit != null + override fun toString() = + "CumulativeGroupedAllocation{cadence=$cadence, cumulativeGroupedAllocationConfig=$cumulativeGroupedAllocationConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" + } - fun isPackage(): Boolean = package_ != null + class Percent + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val percentConfig: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("percent_config") + @ExcludeMissing + percentConfig: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) - fun isMatrix(): Boolean = matrix != null + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - fun isTiered(): Boolean = tiered != null + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - fun isTieredBps(): Boolean = tieredBps != null + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - fun isBps(): Boolean = bps != null + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - fun isBulkBps(): Boolean = bulkBps != null + /** + * Configuration for percent pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun percentConfig(): PercentConfig = percentConfig.getRequired("percent_config") - fun isBulk(): Boolean = bulk != null + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - fun isThresholdTotalAmount(): Boolean = thresholdTotalAmount != null + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - fun isTieredPackage(): Boolean = tieredPackage != null + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - fun isTieredWithMinimum(): Boolean = tieredWithMinimum != null + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - fun isUnitWithPercent(): Boolean = unitWithPercent != null + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - fun isPackageWithAllocation(): Boolean = packageWithAllocation != null + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - fun isTieredWithProration(): Boolean = tieredWithProration != null + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - fun isUnitWithProration(): Boolean = unitWithProration != null + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - fun isGroupedAllocation(): Boolean = groupedAllocation != null + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - fun isGroupedWithProratedMinimum(): Boolean = groupedWithProratedMinimum != null + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") - fun isBulkWithProration(): Boolean = bulkWithProration != null + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - fun isScalableMatrixWithUnitPricing(): Boolean = scalableMatrixWithUnitPricing != null + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - fun isScalableMatrixWithTieredPricing(): Boolean = - scalableMatrixWithTieredPricing != null + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - fun isCumulativeGroupedBulk(): Boolean = cumulativeGroupedBulk != null + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - fun isMaxGroupTieredPackage(): Boolean = maxGroupTieredPackage != null + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - fun isGroupedWithMeteredMinimum(): Boolean = groupedWithMeteredMinimum != null + /** + * 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 - fun isMatrixWithDisplayName(): Boolean = matrixWithDisplayName != null + /** + * Returns the raw JSON value of [percentConfig]. + * + * Unlike [percentConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent_config") + @ExcludeMissing + fun _percentConfig(): JsonField = percentConfig - fun isGroupedTieredPackage(): Boolean = groupedTieredPackage != null + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - fun isMatrixWithAllocation(): Boolean = matrixWithAllocation != null + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - fun isTieredPackageWithMinimum(): Boolean = tieredPackageWithMinimum != null + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - fun isGroupedTiered(): Boolean = groupedTiered != null + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - fun asUnit(): NewSubscriptionUnitPrice = unit.getOrThrow("unit") + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - fun asPackage(): NewSubscriptionPackagePrice = package_.getOrThrow("package_") + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - fun asMatrix(): NewSubscriptionMatrixPrice = matrix.getOrThrow("matrix") + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - fun asTiered(): NewSubscriptionTieredPrice = tiered.getOrThrow("tiered") + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - fun asTieredBps(): NewSubscriptionTieredBpsPrice = tieredBps.getOrThrow("tieredBps") + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - fun asBps(): NewSubscriptionBpsPrice = bps.getOrThrow("bps") + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - fun asBulkBps(): NewSubscriptionBulkBpsPrice = bulkBps.getOrThrow("bulkBps") + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - fun asBulk(): NewSubscriptionBulkPrice = bulk.getOrThrow("bulk") + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - fun asThresholdTotalAmount(): NewSubscriptionThresholdTotalAmountPrice = - thresholdTotalAmount.getOrThrow("thresholdTotalAmount") + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - fun asTieredPackage(): NewSubscriptionTieredPackagePrice = - tieredPackage.getOrThrow("tieredPackage") + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun asTieredWithMinimum(): NewSubscriptionTieredWithMinimumPrice = - tieredWithMinimum.getOrThrow("tieredWithMinimum") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Percent]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + */ + fun builder() = Builder() + } - fun asUnitWithPercent(): NewSubscriptionUnitWithPercentPrice = - unitWithPercent.getOrThrow("unitWithPercent") + /** A builder for [Percent]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("percent") + private var name: JsonField? = null + private var percentConfig: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(percent: Percent) = apply { + cadence = percent.cadence + itemId = percent.itemId + modelType = percent.modelType + name = percent.name + percentConfig = percent.percentConfig + billableMetricId = percent.billableMetricId + billedInAdvance = percent.billedInAdvance + billingCycleConfiguration = percent.billingCycleConfiguration + conversionRate = percent.conversionRate + conversionRateConfig = percent.conversionRateConfig + currency = percent.currency + dimensionalPriceConfiguration = percent.dimensionalPriceConfiguration + externalPriceId = percent.externalPriceId + fixedPriceQuantity = percent.fixedPriceQuantity + invoiceGroupingKey = percent.invoiceGroupingKey + invoicingCycleConfiguration = percent.invoicingCycleConfiguration + metadata = percent.metadata + referenceId = percent.referenceId + additionalProperties = percent.additionalProperties.toMutableMap() + } - fun asPackageWithAllocation(): NewSubscriptionPackageWithAllocationPrice = - packageWithAllocation.getOrThrow("packageWithAllocation") + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("percent") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 } + + /** Configuration for percent pricing */ + fun percentConfig(percentConfig: PercentConfig) = + percentConfig(JsonField.of(percentConfig)) + + /** + * Sets [Builder.percentConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.percentConfig] with a well-typed + * [PercentConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun percentConfig(percentConfig: JsonField) = apply { + this.percentConfig = percentConfig + } - fun asTieredWithProration(): NewSubscriptionTierWithProrationPrice = - tieredWithProration.getOrThrow("tieredWithProration") + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - fun asUnitWithProration(): NewSubscriptionUnitWithProrationPrice = - unitWithProration.getOrThrow("unitWithProration") + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - fun asGroupedAllocation(): NewSubscriptionGroupedAllocationPrice = - groupedAllocation.getOrThrow("groupedAllocation") + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - fun asGroupedWithProratedMinimum(): NewSubscriptionGroupedWithProratedMinimumPrice = - groupedWithProratedMinimum.getOrThrow("groupedWithProratedMinimum") + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - fun asBulkWithProration(): NewSubscriptionBulkWithProrationPrice = - bulkWithProration.getOrThrow("bulkWithProration") + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - fun asScalableMatrixWithUnitPricing(): - NewSubscriptionScalableMatrixWithUnitPricingPrice = - scalableMatrixWithUnitPricing.getOrThrow("scalableMatrixWithUnitPricing") + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - fun asScalableMatrixWithTieredPricing(): - NewSubscriptionScalableMatrixWithTieredPricingPrice = - scalableMatrixWithTieredPricing.getOrThrow("scalableMatrixWithTieredPricing") + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - fun asCumulativeGroupedBulk(): NewSubscriptionCumulativeGroupedBulkPrice = - cumulativeGroupedBulk.getOrThrow("cumulativeGroupedBulk") + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - fun asMaxGroupTieredPackage(): NewSubscriptionMaxGroupTieredPackagePrice = - maxGroupTieredPackage.getOrThrow("maxGroupTieredPackage") + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - fun asGroupedWithMeteredMinimum(): NewSubscriptionGroupedWithMeteredMinimumPrice = - groupedWithMeteredMinimum.getOrThrow("groupedWithMeteredMinimum") + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - fun asMatrixWithDisplayName(): NewSubscriptionMatrixWithDisplayNamePrice = - matrixWithDisplayName.getOrThrow("matrixWithDisplayName") + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - fun asGroupedTieredPackage(): NewSubscriptionGroupedTieredPackagePrice = - groupedTieredPackage.getOrThrow("groupedTieredPackage") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun asMatrixWithAllocation(): NewSubscriptionMatrixWithAllocationPrice = - matrixWithAllocation.getOrThrow("matrixWithAllocation") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun asTieredPackageWithMinimum(): NewSubscriptionTieredPackageWithMinimumPrice = - tieredPackageWithMinimum.getOrThrow("tieredPackageWithMinimum") + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun asGroupedTiered(): NewSubscriptionGroupedTieredPrice = - groupedTiered.getOrThrow("groupedTiered") + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun _json(): JsonValue? = _json + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun accept(visitor: Visitor): T = - when { - unit != null -> visitor.visitUnit(unit) - package_ != null -> visitor.visitPackage(package_) - matrix != null -> visitor.visitMatrix(matrix) - tiered != null -> visitor.visitTiered(tiered) - tieredBps != null -> visitor.visitTieredBps(tieredBps) - bps != null -> visitor.visitBps(bps) - bulkBps != null -> visitor.visitBulkBps(bulkBps) - bulk != null -> visitor.visitBulk(bulk) - thresholdTotalAmount != null -> - visitor.visitThresholdTotalAmount(thresholdTotalAmount) - tieredPackage != null -> visitor.visitTieredPackage(tieredPackage) - tieredWithMinimum != null -> visitor.visitTieredWithMinimum(tieredWithMinimum) - unitWithPercent != null -> visitor.visitUnitWithPercent(unitWithPercent) - packageWithAllocation != null -> - visitor.visitPackageWithAllocation(packageWithAllocation) - tieredWithProration != null -> - visitor.visitTieredWithProration(tieredWithProration) - unitWithProration != null -> visitor.visitUnitWithProration(unitWithProration) - groupedAllocation != null -> visitor.visitGroupedAllocation(groupedAllocation) - groupedWithProratedMinimum != null -> - visitor.visitGroupedWithProratedMinimum(groupedWithProratedMinimum) - bulkWithProration != null -> visitor.visitBulkWithProration(bulkWithProration) - scalableMatrixWithUnitPricing != null -> - visitor.visitScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) - scalableMatrixWithTieredPricing != null -> - visitor.visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing + /** + * Returns an immutable instance of [Percent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .itemId() + * .name() + * .percentConfig() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Percent = + Percent( + checkRequired("cadence", cadence), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + checkRequired("percentConfig", percentConfig), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), ) - cumulativeGroupedBulk != null -> - visitor.visitCumulativeGroupedBulk(cumulativeGroupedBulk) - maxGroupTieredPackage != null -> - visitor.visitMaxGroupTieredPackage(maxGroupTieredPackage) - groupedWithMeteredMinimum != null -> - visitor.visitGroupedWithMeteredMinimum(groupedWithMeteredMinimum) - matrixWithDisplayName != null -> - visitor.visitMatrixWithDisplayName(matrixWithDisplayName) - groupedTieredPackage != null -> - visitor.visitGroupedTieredPackage(groupedTieredPackage) - matrixWithAllocation != null -> - visitor.visitMatrixWithAllocation(matrixWithAllocation) - tieredPackageWithMinimum != null -> - visitor.visitTieredPackageWithMinimum(tieredPackageWithMinimum) - groupedTiered != null -> visitor.visitGroupedTiered(groupedTiered) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Price = apply { - if (validated) { - return@apply } - accept( - object : Visitor { - override fun visitUnit(unit: NewSubscriptionUnitPrice) { - unit.validate() - } - - override fun visitPackage(package_: NewSubscriptionPackagePrice) { - package_.validate() - } - - override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) { - matrix.validate() - } + private var validated: Boolean = false - override fun visitTiered(tiered: NewSubscriptionTieredPrice) { - tiered.validate() - } + fun validate(): Percent = apply { + if (validated) { + return@apply + } - override fun visitTieredBps(tieredBps: NewSubscriptionTieredBpsPrice) { - tieredBps.validate() + cadence().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("percent")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") } + } + name() + percentConfig().validate() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - override fun visitBps(bps: NewSubscriptionBpsPrice) { - bps.validate() - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitBulkBps(bulkBps: NewSubscriptionBulkBpsPrice) { - bulkBps.validate() - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("percent")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (percentConfig.asKnown()?.validity() ?: 0) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - override fun visitBulk(bulk: NewSubscriptionBulkPrice) { - bulk.validate() - } + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - override fun visitThresholdTotalAmount( - thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice - ) { - thresholdTotalAmount.validate() - } + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - override fun visitTieredPackage( - tieredPackage: NewSubscriptionTieredPackagePrice - ) { - tieredPackage.validate() + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN } - override fun visitTieredWithMinimum( - tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice - ) { - tieredWithMinimum.validate() + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") } - override fun visitUnitWithPercent( - unitWithPercent: NewSubscriptionUnitWithPercentPrice - ) { - unitWithPercent.validate() + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply } - override fun visitPackageWithAllocation( - packageWithAllocation: NewSubscriptionPackageWithAllocationPrice - ) { - packageWithAllocation.validate() - } + known() + validated = true + } - override fun visitTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice - ) { - tieredWithProration.validate() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - override fun visitUnitWithProration( - unitWithProration: NewSubscriptionUnitWithProrationPrice - ) { - unitWithProration.validate() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - override fun visitGroupedAllocation( - groupedAllocation: NewSubscriptionGroupedAllocationPrice - ) { - groupedAllocation.validate() - } + return other is Cadence && value == other.value + } - override fun visitGroupedWithProratedMinimum( - groupedWithProratedMinimum: - NewSubscriptionGroupedWithProratedMinimumPrice - ) { - groupedWithProratedMinimum.validate() - } + override fun hashCode() = value.hashCode() - override fun visitBulkWithProration( - bulkWithProration: NewSubscriptionBulkWithProrationPrice - ) { - bulkWithProration.validate() - } + override fun toString() = value.toString() + } - override fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: - NewSubscriptionScalableMatrixWithUnitPricingPrice - ) { - scalableMatrixWithUnitPricing.validate() - } + /** Configuration for percent pricing */ + class PercentConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val percent: JsonField, + private val additionalProperties: MutableMap, + ) { - override fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice - ) { - scalableMatrixWithTieredPricing.validate() - } + @JsonCreator + private constructor( + @JsonProperty("percent") + @ExcludeMissing + percent: JsonField = JsonMissing.of() + ) : this(percent, mutableMapOf()) + + /** + * What percent of the component subtotals to charge + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun percent(): Double = percent.getRequired("percent") + + /** + * Returns the raw JSON value of [percent]. + * + * Unlike [percent], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("percent") + @ExcludeMissing + fun _percent(): JsonField = percent + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - override fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice - ) { - cumulativeGroupedBulk.validate() - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [PercentConfig]. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + */ + fun builder() = Builder() + } - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice - ) { - maxGroupTieredPackage.validate() - } + /** A builder for [PercentConfig]. */ + class Builder internal constructor() { - override fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice - ) { - groupedWithMeteredMinimum.validate() - } + private var percent: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice - ) { - matrixWithDisplayName.validate() + internal fun from(percentConfig: PercentConfig) = apply { + percent = percentConfig.percent + additionalProperties = percentConfig.additionalProperties.toMutableMap() } - - override fun visitGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice - ) { - groupedTieredPackage.validate() + + /** What percent of the component subtotals to charge */ + fun percent(percent: Double) = percent(JsonField.of(percent)) + + /** + * Sets [Builder.percent] to an arbitrary JSON value. + * + * You should usually call [Builder.percent] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun percent(percent: JsonField) = apply { this.percent = percent } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice - ) { - matrixWithAllocation.validate() + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ) { - tieredPackageWithMinimum.validate() + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - override fun visitGroupedTiered( - groupedTiered: NewSubscriptionGroupedTieredPrice - ) { - groupedTiered.validate() + /** + * Returns an immutable instance of [PercentConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .percent() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PercentConfig = + PercentConfig( + checkRequired("percent", percent), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PercentConfig = apply { + if (validated) { + return@apply } + + percent() + validated = true } - ) - validated = true - } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitUnit(unit: NewSubscriptionUnitPrice) = unit.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = (if (percent.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun visitPackage(package_: NewSubscriptionPackagePrice) = - package_.validity() + return other is PercentConfig && + percent == other.percent && + additionalProperties == other.additionalProperties + } - override fun visitMatrix(matrix: NewSubscriptionMatrixPrice) = - matrix.validity() + private val hashCode: Int by lazy { + Objects.hash(percent, additionalProperties) + } - override fun visitTiered(tiered: NewSubscriptionTieredPrice) = - tiered.validity() + override fun hashCode(): Int = hashCode - override fun visitTieredBps(tieredBps: NewSubscriptionTieredBpsPrice) = - tieredBps.validity() + override fun toString() = + "PercentConfig{percent=$percent, additionalProperties=$additionalProperties}" + } - override fun visitBps(bps: NewSubscriptionBpsPrice) = bps.validity() + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - override fun visitBulkBps(bulkBps: NewSubscriptionBulkBpsPrice) = - bulkBps.validity() + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - override fun visitBulk(bulk: NewSubscriptionBulkPrice) = bulk.validity() + fun toBuilder() = Builder().from(this) - override fun visitThresholdTotalAmount( - thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice - ) = thresholdTotalAmount.validity() + companion object { - override fun visitTieredPackage( - tieredPackage: NewSubscriptionTieredPackagePrice - ) = tieredPackage.validity() + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + fun builder() = Builder() + } - override fun visitTieredWithMinimum( - tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice - ) = tieredWithMinimum.validity() + /** A builder for [Metadata]. */ + class Builder internal constructor() { - override fun visitUnitWithPercent( - unitWithPercent: NewSubscriptionUnitWithPercentPrice - ) = unitWithPercent.validity() + private var additionalProperties: MutableMap = + mutableMapOf() - override fun visitPackageWithAllocation( - packageWithAllocation: NewSubscriptionPackageWithAllocationPrice - ) = packageWithAllocation.validity() + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } - override fun visitTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice - ) = tieredWithProration.validity() + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - override fun visitUnitWithProration( - unitWithProration: NewSubscriptionUnitWithProrationPrice - ) = unitWithProration.validity() + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - override fun visitGroupedAllocation( - groupedAllocation: NewSubscriptionGroupedAllocationPrice - ) = groupedAllocation.validity() + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - override fun visitGroupedWithProratedMinimum( - groupedWithProratedMinimum: - NewSubscriptionGroupedWithProratedMinimumPrice - ) = groupedWithProratedMinimum.validity() + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - override fun visitBulkWithProration( - bulkWithProration: NewSubscriptionBulkWithProrationPrice - ) = bulkWithProration.validity() + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - override fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: - NewSubscriptionScalableMatrixWithUnitPricingPrice - ) = scalableMatrixWithUnitPricing.validity() + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } - override fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice - ) = scalableMatrixWithTieredPricing.validity() + private var validated: Boolean = false - override fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice - ) = cumulativeGroupedBulk.validity() + fun validate(): Metadata = apply { + if (validated) { + return@apply + } - override fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice - ) = maxGroupTieredPackage.validity() + validated = true + } - override fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice - ) = groupedWithMeteredMinimum.validity() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } - override fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice - ) = matrixWithDisplayName.validity() + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } - override fun visitGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice - ) = groupedTieredPackage.validity() + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun visitMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice - ) = matrixWithAllocation.validity() + return other is Metadata && + additionalProperties == other.additionalProperties + } - override fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ) = tieredPackageWithMinimum.validity() + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - override fun visitGroupedTiered( - groupedTiered: NewSubscriptionGroupedTieredPrice - ) = groupedTiered.validity() + override fun hashCode(): Int = hashCode - override fun unknown(json: JsonValue?) = 0 + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - ) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + return other is Percent && + cadence == other.cadence && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + percentConfig == other.percentConfig && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + itemId, + modelType, + name, + percentConfig, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) } - return /* spotless:off */ other is Price && unit == other.unit && package_ == other.package_ && matrix == other.matrix && tiered == other.tiered && tieredBps == other.tieredBps && bps == other.bps && bulkBps == other.bulkBps && bulk == other.bulk && thresholdTotalAmount == other.thresholdTotalAmount && tieredPackage == other.tieredPackage && tieredWithMinimum == other.tieredWithMinimum && unitWithPercent == other.unitWithPercent && packageWithAllocation == other.packageWithAllocation && tieredWithProration == other.tieredWithProration && unitWithProration == other.unitWithProration && groupedAllocation == other.groupedAllocation && groupedWithProratedMinimum == other.groupedWithProratedMinimum && bulkWithProration == other.bulkWithProration && scalableMatrixWithUnitPricing == other.scalableMatrixWithUnitPricing && scalableMatrixWithTieredPricing == other.scalableMatrixWithTieredPricing && cumulativeGroupedBulk == other.cumulativeGroupedBulk && maxGroupTieredPackage == other.maxGroupTieredPackage && groupedWithMeteredMinimum == other.groupedWithMeteredMinimum && matrixWithDisplayName == other.matrixWithDisplayName && groupedTieredPackage == other.groupedTieredPackage && matrixWithAllocation == other.matrixWithAllocation && tieredPackageWithMinimum == other.tieredPackageWithMinimum && groupedTiered == other.groupedTiered /* spotless:on */ + override fun hashCode(): Int = hashCode + + override fun toString() = + "Percent{cadence=$cadence, itemId=$itemId, modelType=$modelType, name=$name, percentConfig=$percentConfig, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unit, package_, matrix, tiered, tieredBps, bps, bulkBps, bulk, thresholdTotalAmount, tieredPackage, tieredWithMinimum, unitWithPercent, packageWithAllocation, tieredWithProration, unitWithProration, groupedAllocation, groupedWithProratedMinimum, bulkWithProration, scalableMatrixWithUnitPricing, scalableMatrixWithTieredPricing, cumulativeGroupedBulk, maxGroupTieredPackage, groupedWithMeteredMinimum, matrixWithDisplayName, groupedTieredPackage, matrixWithAllocation, tieredPackageWithMinimum, groupedTiered) /* spotless:on */ + class EventOutput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val cadence: JsonField, + private val eventOutputConfig: JsonField, + private val itemId: JsonField, + private val modelType: JsonValue, + private val name: JsonField, + private val billableMetricId: JsonField, + private val billedInAdvance: JsonField, + private val billingCycleConfiguration: JsonField, + private val conversionRate: JsonField, + private val conversionRateConfig: JsonField, + private val currency: JsonField, + private val dimensionalPriceConfiguration: + JsonField, + private val externalPriceId: JsonField, + private val fixedPriceQuantity: JsonField, + private val invoiceGroupingKey: JsonField, + private val invoicingCycleConfiguration: JsonField, + private val metadata: JsonField, + private val referenceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("cadence") + @ExcludeMissing + cadence: JsonField = JsonMissing.of(), + @JsonProperty("event_output_config") + @ExcludeMissing + eventOutputConfig: JsonField = JsonMissing.of(), + @JsonProperty("item_id") + @ExcludeMissing + itemId: JsonField = JsonMissing.of(), + @JsonProperty("model_type") + @ExcludeMissing + modelType: JsonValue = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + name: JsonField = JsonMissing.of(), + @JsonProperty("billable_metric_id") + @ExcludeMissing + billableMetricId: JsonField = JsonMissing.of(), + @JsonProperty("billed_in_advance") + @ExcludeMissing + billedInAdvance: JsonField = JsonMissing.of(), + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + billingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("conversion_rate") + @ExcludeMissing + conversionRate: JsonField = JsonMissing.of(), + @JsonProperty("conversion_rate_config") + @ExcludeMissing + conversionRateConfig: JsonField = JsonMissing.of(), + @JsonProperty("currency") + @ExcludeMissing + currency: JsonField = JsonMissing.of(), + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + dimensionalPriceConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("external_price_id") + @ExcludeMissing + externalPriceId: JsonField = JsonMissing.of(), + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fixedPriceQuantity: JsonField = JsonMissing.of(), + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + invoiceGroupingKey: JsonField = JsonMissing.of(), + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + invoicingCycleConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("reference_id") + @ExcludeMissing + referenceId: JsonField = JsonMissing.of(), + ) : this( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + mutableMapOf(), + ) - override fun toString(): String = - when { - unit != null -> "Price{unit=$unit}" - package_ != null -> "Price{package_=$package_}" - matrix != null -> "Price{matrix=$matrix}" - tiered != null -> "Price{tiered=$tiered}" - tieredBps != null -> "Price{tieredBps=$tieredBps}" - bps != null -> "Price{bps=$bps}" - bulkBps != null -> "Price{bulkBps=$bulkBps}" - bulk != null -> "Price{bulk=$bulk}" - thresholdTotalAmount != null -> - "Price{thresholdTotalAmount=$thresholdTotalAmount}" - tieredPackage != null -> "Price{tieredPackage=$tieredPackage}" - tieredWithMinimum != null -> "Price{tieredWithMinimum=$tieredWithMinimum}" - unitWithPercent != null -> "Price{unitWithPercent=$unitWithPercent}" - packageWithAllocation != null -> - "Price{packageWithAllocation=$packageWithAllocation}" - tieredWithProration != null -> "Price{tieredWithProration=$tieredWithProration}" - unitWithProration != null -> "Price{unitWithProration=$unitWithProration}" - groupedAllocation != null -> "Price{groupedAllocation=$groupedAllocation}" - groupedWithProratedMinimum != null -> - "Price{groupedWithProratedMinimum=$groupedWithProratedMinimum}" - bulkWithProration != null -> "Price{bulkWithProration=$bulkWithProration}" - scalableMatrixWithUnitPricing != null -> - "Price{scalableMatrixWithUnitPricing=$scalableMatrixWithUnitPricing}" - scalableMatrixWithTieredPricing != null -> - "Price{scalableMatrixWithTieredPricing=$scalableMatrixWithTieredPricing}" - cumulativeGroupedBulk != null -> - "Price{cumulativeGroupedBulk=$cumulativeGroupedBulk}" - maxGroupTieredPackage != null -> - "Price{maxGroupTieredPackage=$maxGroupTieredPackage}" - groupedWithMeteredMinimum != null -> - "Price{groupedWithMeteredMinimum=$groupedWithMeteredMinimum}" - matrixWithDisplayName != null -> - "Price{matrixWithDisplayName=$matrixWithDisplayName}" - groupedTieredPackage != null -> - "Price{groupedTieredPackage=$groupedTieredPackage}" - matrixWithAllocation != null -> - "Price{matrixWithAllocation=$matrixWithAllocation}" - tieredPackageWithMinimum != null -> - "Price{tieredPackageWithMinimum=$tieredPackageWithMinimum}" - groupedTiered != null -> "Price{groupedTiered=$groupedTiered}" - _json != null -> "Price{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Price") - } + /** + * The cadence to bill for this price on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun cadence(): Cadence = cadence.getRequired("cadence") - companion object { + /** + * Configuration for event_output pricing + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun eventOutputConfig(): EventOutputConfig = + eventOutputConfig.getRequired("event_output_config") - fun ofUnit(unit: NewSubscriptionUnitPrice) = Price(unit = unit) + /** + * The id of the item the price will be associated with. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemId(): String = itemId.getRequired("item_id") - fun ofPackage(package_: NewSubscriptionPackagePrice) = Price(package_ = package_) + /** + * The pricing model type + * + * Expected to always return the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("model_type") @ExcludeMissing fun _modelType(): JsonValue = modelType - fun ofMatrix(matrix: NewSubscriptionMatrixPrice) = Price(matrix = matrix) + /** + * The name of the price. + * + * @throws OrbInvalidDataException if 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") - fun ofTiered(tiered: NewSubscriptionTieredPrice) = Price(tiered = tiered) + /** + * The id of the billable metric for the price. Only needed if the price is + * usage-based. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billableMetricId(): String? = billableMetricId.getNullable("billable_metric_id") - fun ofTieredBps(tieredBps: NewSubscriptionTieredBpsPrice) = - Price(tieredBps = tieredBps) + /** + * If the Price represents a fixed cost, the price will be billed in-advance if this + * is true, and in-arrears if this is false. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billedInAdvance(): Boolean? = billedInAdvance.getNullable("billed_in_advance") - fun ofBps(bps: NewSubscriptionBpsPrice) = Price(bps = bps) + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun billingCycleConfiguration(): NewBillingCycleConfiguration? = + billingCycleConfiguration.getNullable("billing_cycle_configuration") - fun ofBulkBps(bulkBps: NewSubscriptionBulkBpsPrice) = Price(bulkBps = bulkBps) + /** + * The per unit conversion rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRate(): Double? = conversionRate.getNullable("conversion_rate") - fun ofBulk(bulk: NewSubscriptionBulkPrice) = Price(bulk = bulk) + /** + * The configuration for the rate of the price currency to the invoicing currency. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun conversionRateConfig(): ConversionRateConfig? = + conversionRateConfig.getNullable("conversion_rate_config") - fun ofThresholdTotalAmount( - thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice - ) = Price(thresholdTotalAmount = thresholdTotalAmount) + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun currency(): String? = currency.getNullable("currency") - fun ofTieredPackage(tieredPackage: NewSubscriptionTieredPackagePrice) = - Price(tieredPackage = tieredPackage) + /** + * For dimensional price: specifies a price group and dimension values + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun dimensionalPriceConfiguration(): NewDimensionalPriceConfiguration? = + dimensionalPriceConfiguration.getNullable("dimensional_price_configuration") - fun ofTieredWithMinimum(tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice) = - Price(tieredWithMinimum = tieredWithMinimum) + /** + * An alias for the price. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun externalPriceId(): String? = externalPriceId.getNullable("external_price_id") - fun ofUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice) = - Price(unitWithPercent = unitWithPercent) + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fixedPriceQuantity(): Double? = + fixedPriceQuantity.getNullable("fixed_price_quantity") - fun ofPackageWithAllocation( - packageWithAllocation: NewSubscriptionPackageWithAllocationPrice - ) = Price(packageWithAllocation = packageWithAllocation) + /** + * The property used to group this price on an invoice + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoiceGroupingKey(): String? = + invoiceGroupingKey.getNullable("invoice_grouping_key") + + /** + * Within each billing cycle, specifies the cadence at which invoices are produced. + * If unspecified, a single invoice is produced per billing cycle. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun invoicingCycleConfiguration(): NewBillingCycleConfiguration? = + invoicingCycleConfiguration.getNullable("invoicing_cycle_configuration") - fun ofTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice - ) = Price(tieredWithProration = tieredWithProration) + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Metadata? = metadata.getNullable("metadata") - fun ofUnitWithProration(unitWithProration: NewSubscriptionUnitWithProrationPrice) = - Price(unitWithProration = unitWithProration) + /** + * A transient ID that can be used to reference this price when adding adjustments + * in the same API call. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun referenceId(): String? = referenceId.getNullable("reference_id") - fun ofGroupedAllocation(groupedAllocation: NewSubscriptionGroupedAllocationPrice) = - Price(groupedAllocation = groupedAllocation) + /** + * Returns the raw JSON value of [cadence]. + * + * Unlike [cadence], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cadence") + @ExcludeMissing + fun _cadence(): JsonField = cadence - fun ofGroupedWithProratedMinimum( - groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice - ) = Price(groupedWithProratedMinimum = groupedWithProratedMinimum) + /** + * Returns the raw JSON value of [eventOutputConfig]. + * + * Unlike [eventOutputConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("event_output_config") + @ExcludeMissing + fun _eventOutputConfig(): JsonField = eventOutputConfig - fun ofBulkWithProration(bulkWithProration: NewSubscriptionBulkWithProrationPrice) = - Price(bulkWithProration = bulkWithProration) + /** + * Returns the raw JSON value of [itemId]. + * + * Unlike [itemId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_id") @ExcludeMissing fun _itemId(): JsonField = itemId - fun ofScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice - ) = Price(scalableMatrixWithUnitPricing = scalableMatrixWithUnitPricing) + /** + * 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 - fun ofScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice - ) = Price(scalableMatrixWithTieredPricing = scalableMatrixWithTieredPricing) + /** + * Returns the raw JSON value of [billableMetricId]. + * + * Unlike [billableMetricId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billable_metric_id") + @ExcludeMissing + fun _billableMetricId(): JsonField = billableMetricId - fun ofCumulativeGroupedBulk( - cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice - ) = Price(cumulativeGroupedBulk = cumulativeGroupedBulk) + /** + * Returns the raw JSON value of [billedInAdvance]. + * + * Unlike [billedInAdvance], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("billed_in_advance") + @ExcludeMissing + fun _billedInAdvance(): JsonField = billedInAdvance - fun ofMaxGroupTieredPackage( - maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice - ) = Price(maxGroupTieredPackage = maxGroupTieredPackage) + /** + * Returns the raw JSON value of [billingCycleConfiguration]. + * + * Unlike [billingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("billing_cycle_configuration") + @ExcludeMissing + fun _billingCycleConfiguration(): JsonField = + billingCycleConfiguration - fun ofGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice - ) = Price(groupedWithMeteredMinimum = groupedWithMeteredMinimum) + /** + * Returns the raw JSON value of [conversionRate]. + * + * Unlike [conversionRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate") + @ExcludeMissing + fun _conversionRate(): JsonField = conversionRate - fun ofMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice - ) = Price(matrixWithDisplayName = matrixWithDisplayName) + /** + * Returns the raw JSON value of [conversionRateConfig]. + * + * Unlike [conversionRateConfig], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("conversion_rate_config") + @ExcludeMissing + fun _conversionRateConfig(): JsonField = conversionRateConfig - fun ofGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice - ) = Price(groupedTieredPackage = groupedTieredPackage) + /** + * Returns the raw JSON value of [currency]. + * + * Unlike [currency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currency") + @ExcludeMissing + fun _currency(): JsonField = currency - fun ofMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice - ) = Price(matrixWithAllocation = matrixWithAllocation) + /** + * Returns the raw JSON value of [dimensionalPriceConfiguration]. + * + * Unlike [dimensionalPriceConfiguration], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("dimensional_price_configuration") + @ExcludeMissing + fun _dimensionalPriceConfiguration(): JsonField = + dimensionalPriceConfiguration - fun ofTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ) = Price(tieredPackageWithMinimum = tieredPackageWithMinimum) + /** + * Returns the raw JSON value of [externalPriceId]. + * + * Unlike [externalPriceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("external_price_id") + @ExcludeMissing + fun _externalPriceId(): JsonField = externalPriceId - fun ofGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice) = - Price(groupedTiered = groupedTiered) - } + /** + * Returns the raw JSON value of [fixedPriceQuantity]. + * + * Unlike [fixedPriceQuantity], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("fixed_price_quantity") + @ExcludeMissing + fun _fixedPriceQuantity(): JsonField = fixedPriceQuantity - /** - * An interface that defines how to map each variant of [Price] to a value of type [T]. - */ - interface Visitor { + /** + * Returns the raw JSON value of [invoiceGroupingKey]. + * + * Unlike [invoiceGroupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("invoice_grouping_key") + @ExcludeMissing + fun _invoiceGroupingKey(): JsonField = invoiceGroupingKey - fun visitUnit(unit: NewSubscriptionUnitPrice): T + /** + * Returns the raw JSON value of [invoicingCycleConfiguration]. + * + * Unlike [invoicingCycleConfiguration], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("invoicing_cycle_configuration") + @ExcludeMissing + fun _invoicingCycleConfiguration(): JsonField = + invoicingCycleConfiguration - fun visitPackage(package_: NewSubscriptionPackagePrice): T + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - fun visitMatrix(matrix: NewSubscriptionMatrixPrice): T + /** + * Returns the raw JSON value of [referenceId]. + * + * Unlike [referenceId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reference_id") + @ExcludeMissing + fun _referenceId(): JsonField = referenceId - fun visitTiered(tiered: NewSubscriptionTieredPrice): T + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun visitTieredBps(tieredBps: NewSubscriptionTieredBpsPrice): T + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EventOutput]. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + */ + fun builder() = Builder() + } - fun visitBps(bps: NewSubscriptionBpsPrice): T + /** A builder for [EventOutput]. */ + class Builder internal constructor() { + + private var cadence: JsonField? = null + private var eventOutputConfig: JsonField? = null + private var itemId: JsonField? = null + private var modelType: JsonValue = JsonValue.from("event_output") + private var name: JsonField? = null + private var billableMetricId: JsonField = JsonMissing.of() + private var billedInAdvance: JsonField = JsonMissing.of() + private var billingCycleConfiguration: JsonField = + JsonMissing.of() + private var conversionRate: JsonField = JsonMissing.of() + private var conversionRateConfig: JsonField = + JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var dimensionalPriceConfiguration: + JsonField = + JsonMissing.of() + private var externalPriceId: JsonField = JsonMissing.of() + private var fixedPriceQuantity: JsonField = JsonMissing.of() + private var invoiceGroupingKey: JsonField = JsonMissing.of() + private var invoicingCycleConfiguration: + JsonField = + JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var referenceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(eventOutput: EventOutput) = apply { + cadence = eventOutput.cadence + eventOutputConfig = eventOutput.eventOutputConfig + itemId = eventOutput.itemId + modelType = eventOutput.modelType + name = eventOutput.name + billableMetricId = eventOutput.billableMetricId + billedInAdvance = eventOutput.billedInAdvance + billingCycleConfiguration = eventOutput.billingCycleConfiguration + conversionRate = eventOutput.conversionRate + conversionRateConfig = eventOutput.conversionRateConfig + currency = eventOutput.currency + dimensionalPriceConfiguration = eventOutput.dimensionalPriceConfiguration + externalPriceId = eventOutput.externalPriceId + fixedPriceQuantity = eventOutput.fixedPriceQuantity + invoiceGroupingKey = eventOutput.invoiceGroupingKey + invoicingCycleConfiguration = eventOutput.invoicingCycleConfiguration + metadata = eventOutput.metadata + referenceId = eventOutput.referenceId + additionalProperties = eventOutput.additionalProperties.toMutableMap() + } - fun visitBulkBps(bulkBps: NewSubscriptionBulkBpsPrice): T + /** The cadence to bill for this price on. */ + fun cadence(cadence: Cadence) = cadence(JsonField.of(cadence)) + + /** + * Sets [Builder.cadence] to an arbitrary JSON value. + * + * You should usually call [Builder.cadence] with a well-typed [Cadence] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun cadence(cadence: JsonField) = apply { this.cadence = cadence } + + /** Configuration for event_output pricing */ + fun eventOutputConfig(eventOutputConfig: EventOutputConfig) = + eventOutputConfig(JsonField.of(eventOutputConfig)) + + /** + * Sets [Builder.eventOutputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.eventOutputConfig] with a well-typed + * [EventOutputConfig] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun eventOutputConfig(eventOutputConfig: JsonField) = apply { + this.eventOutputConfig = eventOutputConfig + } - fun visitBulk(bulk: NewSubscriptionBulkPrice): T + /** The id of the item the price will be associated with. */ + fun itemId(itemId: String) = itemId(JsonField.of(itemId)) + + /** + * Sets [Builder.itemId] to an arbitrary JSON value. + * + * You should usually call [Builder.itemId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun itemId(itemId: JsonField) = apply { this.itemId = itemId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to + * the following: + * ```kotlin + * JsonValue.from("event_output") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelType(modelType: JsonValue) = apply { this.modelType = modelType } + + /** The name of the price. */ + 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 id of the billable metric for the price. Only needed if the price is + * usage-based. + */ + fun billableMetricId(billableMetricId: String?) = + billableMetricId(JsonField.ofNullable(billableMetricId)) + + /** + * Sets [Builder.billableMetricId] to an arbitrary JSON value. + * + * You should usually call [Builder.billableMetricId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billableMetricId(billableMetricId: JsonField) = apply { + this.billableMetricId = billableMetricId + } - fun visitThresholdTotalAmount( - thresholdTotalAmount: NewSubscriptionThresholdTotalAmountPrice - ): T + /** + * If the Price represents a fixed cost, the price will be billed in-advance if + * this is true, and in-arrears if this is false. + */ + fun billedInAdvance(billedInAdvance: Boolean?) = + billedInAdvance(JsonField.ofNullable(billedInAdvance)) + + /** + * Alias for [Builder.billedInAdvance]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun billedInAdvance(billedInAdvance: Boolean) = + billedInAdvance(billedInAdvance as Boolean?) + + /** + * Sets [Builder.billedInAdvance] to an arbitrary JSON value. + * + * You should usually call [Builder.billedInAdvance] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun billedInAdvance(billedInAdvance: JsonField) = apply { + this.billedInAdvance = billedInAdvance + } - fun visitTieredPackage(tieredPackage: NewSubscriptionTieredPackagePrice): T + /** + * For custom cadence: specifies the duration of the billing period in days or + * months. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: NewBillingCycleConfiguration? + ) = billingCycleConfiguration(JsonField.ofNullable(billingCycleConfiguration)) + + /** + * Sets [Builder.billingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.billingCycleConfiguration] with a well-typed + * [NewBillingCycleConfiguration] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun billingCycleConfiguration( + billingCycleConfiguration: JsonField + ) = apply { this.billingCycleConfiguration = billingCycleConfiguration } + + /** + * The per unit conversion rate of the price currency to the invoicing currency. + */ + fun conversionRate(conversionRate: Double?) = + conversionRate(JsonField.ofNullable(conversionRate)) + + /** + * Alias for [Builder.conversionRate]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun conversionRate(conversionRate: Double) = + conversionRate(conversionRate as Double?) + + /** + * Sets [Builder.conversionRate] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRate] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun conversionRate(conversionRate: JsonField) = apply { + this.conversionRate = conversionRate + } - fun visitTieredWithMinimum( - tieredWithMinimum: NewSubscriptionTieredWithMinimumPrice - ): T + /** + * The configuration for the rate of the price currency to the invoicing + * currency. + */ + fun conversionRateConfig(conversionRateConfig: ConversionRateConfig?) = + conversionRateConfig(JsonField.ofNullable(conversionRateConfig)) + + /** + * Sets [Builder.conversionRateConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.conversionRateConfig] with a well-typed + * [ConversionRateConfig] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun conversionRateConfig( + conversionRateConfig: JsonField + ) = apply { this.conversionRateConfig = conversionRateConfig } + + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofUnit(unit)`. + */ + fun conversionRateConfig(unit: UnitConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofUnit(unit)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * UnitConversionRateConfig.builder() + * .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + * .unitConfig(unitConfig) + * .build() + * ``` + */ + fun unitConversionRateConfig(unitConfig: ConversionRateUnitConfig) = + conversionRateConfig( + UnitConversionRateConfig.builder() + .conversionRateType( + UnitConversionRateConfig.ConversionRateType.UNIT + ) + .unitConfig(unitConfig) + .build() + ) - fun visitUnitWithPercent(unitWithPercent: NewSubscriptionUnitWithPercentPrice): T + /** + * Alias for calling [conversionRateConfig] with + * `ConversionRateConfig.ofTiered(tiered)`. + */ + fun conversionRateConfig(tiered: TieredConversionRateConfig) = + conversionRateConfig(ConversionRateConfig.ofTiered(tiered)) + + /** + * Alias for calling [conversionRateConfig] with the following: + * ```kotlin + * TieredConversionRateConfig.builder() + * .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + * .tieredConfig(tieredConfig) + * .build() + * ``` + */ + fun tieredConversionRateConfig(tieredConfig: ConversionRateTieredConfig) = + conversionRateConfig( + TieredConversionRateConfig.builder() + .conversionRateType( + TieredConversionRateConfig.ConversionRateType.TIERED + ) + .tieredConfig(tieredConfig) + .build() + ) - fun visitPackageWithAllocation( - packageWithAllocation: NewSubscriptionPackageWithAllocationPrice - ): T + /** + * An ISO 4217 currency string, or custom pricing unit identifier, in which this + * price is billed. + */ + fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) + + /** + * Sets [Builder.currency] to an arbitrary JSON value. + * + * You should usually call [Builder.currency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun currency(currency: JsonField) = apply { this.currency = currency } + + /** For dimensional price: specifies a price group and dimension values */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: NewDimensionalPriceConfiguration? + ) = + dimensionalPriceConfiguration( + JsonField.ofNullable(dimensionalPriceConfiguration) + ) - fun visitTieredWithProration( - tieredWithProration: NewSubscriptionTierWithProrationPrice - ): T + /** + * Sets [Builder.dimensionalPriceConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensionalPriceConfiguration] with a + * well-typed [NewDimensionalPriceConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dimensionalPriceConfiguration( + dimensionalPriceConfiguration: JsonField + ) = apply { this.dimensionalPriceConfiguration = dimensionalPriceConfiguration } + + /** An alias for the price. */ + fun externalPriceId(externalPriceId: String?) = + externalPriceId(JsonField.ofNullable(externalPriceId)) + + /** + * Sets [Builder.externalPriceId] to an arbitrary JSON value. + * + * You should usually call [Builder.externalPriceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun externalPriceId(externalPriceId: JsonField) = apply { + this.externalPriceId = externalPriceId + } - fun visitUnitWithProration( - unitWithProration: NewSubscriptionUnitWithProrationPrice - ): T + /** + * If the Price represents a fixed cost, this represents the quantity of units + * applied. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double?) = + fixedPriceQuantity(JsonField.ofNullable(fixedPriceQuantity)) + + /** + * Alias for [Builder.fixedPriceQuantity]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fixedPriceQuantity(fixedPriceQuantity: Double) = + fixedPriceQuantity(fixedPriceQuantity as Double?) + + /** + * Sets [Builder.fixedPriceQuantity] to an arbitrary JSON value. + * + * You should usually call [Builder.fixedPriceQuantity] with a well-typed + * [Double] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun fixedPriceQuantity(fixedPriceQuantity: JsonField) = apply { + this.fixedPriceQuantity = fixedPriceQuantity + } - fun visitGroupedAllocation( - groupedAllocation: NewSubscriptionGroupedAllocationPrice - ): T + /** The property used to group this price on an invoice */ + fun invoiceGroupingKey(invoiceGroupingKey: String?) = + invoiceGroupingKey(JsonField.ofNullable(invoiceGroupingKey)) + + /** + * Sets [Builder.invoiceGroupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.invoiceGroupingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun invoiceGroupingKey(invoiceGroupingKey: JsonField) = apply { + this.invoiceGroupingKey = invoiceGroupingKey + } - fun visitGroupedWithProratedMinimum( - groupedWithProratedMinimum: NewSubscriptionGroupedWithProratedMinimumPrice - ): T + /** + * Within each billing cycle, specifies the cadence at which invoices are + * produced. If unspecified, a single invoice is produced per billing cycle. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: NewBillingCycleConfiguration? + ) = + invoicingCycleConfiguration( + JsonField.ofNullable(invoicingCycleConfiguration) + ) - fun visitBulkWithProration( - bulkWithProration: NewSubscriptionBulkWithProrationPrice - ): T + /** + * Sets [Builder.invoicingCycleConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.invoicingCycleConfiguration] with a + * well-typed [NewBillingCycleConfiguration] value instead. This method is + * primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun invoicingCycleConfiguration( + invoicingCycleConfiguration: JsonField + ) = apply { this.invoicingCycleConfiguration = invoicingCycleConfiguration } + + /** + * User-specified key/value pairs for the resource. Individual keys can be + * removed by setting the value to `null`, and the entire metadata mapping can + * be cleared by setting `metadata` to `null`. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * A transient ID that can be used to reference this price when adding + * adjustments in the same API call. + */ + fun referenceId(referenceId: String?) = + referenceId(JsonField.ofNullable(referenceId)) + + /** + * Sets [Builder.referenceId] to an arbitrary JSON value. + * + * You should usually call [Builder.referenceId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun referenceId(referenceId: JsonField) = apply { + this.referenceId = referenceId + } - fun visitScalableMatrixWithUnitPricing( - scalableMatrixWithUnitPricing: NewSubscriptionScalableMatrixWithUnitPricingPrice - ): T + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun visitScalableMatrixWithTieredPricing( - scalableMatrixWithTieredPricing: - NewSubscriptionScalableMatrixWithTieredPricingPrice - ): T + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun visitCumulativeGroupedBulk( - cumulativeGroupedBulk: NewSubscriptionCumulativeGroupedBulkPrice - ): T + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun visitMaxGroupTieredPackage( - maxGroupTieredPackage: NewSubscriptionMaxGroupTieredPackagePrice - ): T + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun visitGroupedWithMeteredMinimum( - groupedWithMeteredMinimum: NewSubscriptionGroupedWithMeteredMinimumPrice - ): T + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun visitMatrixWithDisplayName( - matrixWithDisplayName: NewSubscriptionMatrixWithDisplayNamePrice - ): T + /** + * Returns an immutable instance of [EventOutput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .cadence() + * .eventOutputConfig() + * .itemId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutput = + EventOutput( + checkRequired("cadence", cadence), + checkRequired("eventOutputConfig", eventOutputConfig), + checkRequired("itemId", itemId), + modelType, + checkRequired("name", name), + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties.toMutableMap(), + ) + } - fun visitGroupedTieredPackage( - groupedTieredPackage: NewSubscriptionGroupedTieredPackagePrice - ): T + private var validated: Boolean = false - fun visitMatrixWithAllocation( - matrixWithAllocation: NewSubscriptionMatrixWithAllocationPrice - ): T + fun validate(): EventOutput = apply { + if (validated) { + return@apply + } - fun visitTieredPackageWithMinimum( - tieredPackageWithMinimum: NewSubscriptionTieredPackageWithMinimumPrice - ): T + cadence().validate() + eventOutputConfig().validate() + itemId() + _modelType().let { + if (it != JsonValue.from("event_output")) { + throw OrbInvalidDataException("'modelType' is invalid, received $it") + } + } + name() + billableMetricId() + billedInAdvance() + billingCycleConfiguration()?.validate() + conversionRate() + conversionRateConfig()?.validate() + currency() + dimensionalPriceConfiguration()?.validate() + externalPriceId() + fixedPriceQuantity() + invoiceGroupingKey() + invoicingCycleConfiguration()?.validate() + metadata()?.validate() + referenceId() + validated = true + } - fun visitGroupedTiered(groupedTiered: NewSubscriptionGroupedTieredPrice): T + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } /** - * Maps an unknown variant of [Price] to a value of type [T]. - * - * An instance of [Price] can contain an unknown variant if it was deserialized from - * data that doesn't match any known variant. For example, if the SDK is on an older - * version than the API, then the API may respond with new variants that the SDK is - * unaware of. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * @throws OrbInvalidDataException in the default implementation. + * Used for best match union deserialization. */ - fun unknown(json: JsonValue?): T { - throw OrbInvalidDataException("Unknown Price: $json") - } - } + internal fun validity(): Int = + (cadence.asKnown()?.validity() ?: 0) + + (eventOutputConfig.asKnown()?.validity() ?: 0) + + (if (itemId.asKnown() == null) 0 else 1) + + modelType.let { if (it == JsonValue.from("event_output")) 1 else 0 } + + (if (name.asKnown() == null) 0 else 1) + + (if (billableMetricId.asKnown() == null) 0 else 1) + + (if (billedInAdvance.asKnown() == null) 0 else 1) + + (billingCycleConfiguration.asKnown()?.validity() ?: 0) + + (if (conversionRate.asKnown() == null) 0 else 1) + + (conversionRateConfig.asKnown()?.validity() ?: 0) + + (if (currency.asKnown() == null) 0 else 1) + + (dimensionalPriceConfiguration.asKnown()?.validity() ?: 0) + + (if (externalPriceId.asKnown() == null) 0 else 1) + + (if (fixedPriceQuantity.asKnown() == null) 0 else 1) + + (if (invoiceGroupingKey.asKnown() == null) 0 else 1) + + (invoicingCycleConfiguration.asKnown()?.validity() ?: 0) + + (metadata.asKnown()?.validity() ?: 0) + + (if (referenceId.asKnown() == null) 0 else 1) + + /** The cadence to bill for this price on. */ + class Cadence + @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 { + + val ANNUAL = of("annual") + + val SEMI_ANNUAL = of("semi_annual") + + val MONTHLY = of("monthly") + + val QUARTERLY = of("quarterly") + + val ONE_TIME = of("one_time") + + val CUSTOM = of("custom") + + fun of(value: String) = Cadence(JsonField.of(value)) + } - internal class Deserializer : BaseDeserializer(Price::class) { + /** An enum containing [Cadence]'s known values. */ + enum class Known { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + } - override fun ObjectCodec.deserialize(node: JsonNode): Price { - val json = JsonValue.fromJsonNode(node) - val modelType = json.asObject()?.get("model_type")?.asString() + /** + * An enum containing [Cadence]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Cadence] 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 { + ANNUAL, + SEMI_ANNUAL, + MONTHLY, + QUARTERLY, + ONE_TIME, + CUSTOM, + /** + * An enum member indicating that [Cadence] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } - when (modelType) { - "unit" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(unit = it, _json = json) } ?: Price(_json = json) - } - "package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(package_ = it, _json = json) } ?: Price(_json = json) - } - "matrix" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrix = it, _json = json) } ?: Price(_json = json) - } - "tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tiered = it, _json = json) } ?: Price(_json = json) - } - "tiered_bps" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredBps = it, _json = json) } ?: Price(_json = json) - } - "bps" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bps = it, _json = json) } ?: Price(_json = json) + /** + * 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) { + ANNUAL -> Value.ANNUAL + SEMI_ANNUAL -> Value.SEMI_ANNUAL + MONTHLY -> Value.MONTHLY + QUARTERLY -> Value.QUARTERLY + ONE_TIME -> Value.ONE_TIME + CUSTOM -> Value.CUSTOM + else -> Value._UNKNOWN } - "bulk_bps" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(bulkBps = it, _json = json) } ?: Price(_json = json) + + /** + * 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 OrbInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + ANNUAL -> Known.ANNUAL + SEMI_ANNUAL -> Known.SEMI_ANNUAL + MONTHLY -> Known.MONTHLY + QUARTERLY -> Known.QUARTERLY + ONE_TIME -> Known.ONE_TIME + CUSTOM -> Known.CUSTOM + else -> throw OrbInvalidDataException("Unknown Cadence: $value") } - "bulk" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Price(bulk = it, _json = json) } ?: Price(_json = json) + + /** + * 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 OrbInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString() + ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Cadence = apply { + if (validated) { + return@apply } - "threshold_total_amount" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(thresholdTotalAmount = it, _json = json) } - ?: Price(_json = json) + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredPackage = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - "tiered_with_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredWithMinimum = it, _json = json) } - ?: Price(_json = json) + + return other is Cadence && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Configuration for event_output pricing */ + class EventOutputConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val unitRatingKey: JsonField, + private val defaultUnitRate: JsonField, + private val groupingKey: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("unit_rating_key") + @ExcludeMissing + unitRatingKey: JsonField = JsonMissing.of(), + @JsonProperty("default_unit_rate") + @ExcludeMissing + defaultUnitRate: JsonField = JsonMissing.of(), + @JsonProperty("grouping_key") + @ExcludeMissing + groupingKey: JsonField = JsonMissing.of(), + ) : this(unitRatingKey, defaultUnitRate, groupingKey, mutableMapOf()) + + /** + * The key in the event data to extract the unit rate from. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or + * is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun unitRatingKey(): String = unitRatingKey.getRequired("unit_rating_key") + + /** + * If provided, this amount will be used as the unit rate when an event does not + * have a value for the `unit_rating_key`. If not provided, events missing a + * unit rate will be ignored. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun defaultUnitRate(): String? = + defaultUnitRate.getNullable("default_unit_rate") + + /** + * An optional key in the event data to group by (e.g., event ID). All events + * will also be grouped by their unit rate. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupingKey(): String? = groupingKey.getNullable("grouping_key") + + /** + * Returns the raw JSON value of [unitRatingKey]. + * + * Unlike [unitRatingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("unit_rating_key") + @ExcludeMissing + fun _unitRatingKey(): JsonField = unitRatingKey + + /** + * Returns the raw JSON value of [defaultUnitRate]. + * + * Unlike [defaultUnitRate], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("default_unit_rate") + @ExcludeMissing + fun _defaultUnitRate(): JsonField = defaultUnitRate + + /** + * Returns the raw JSON value of [groupingKey]. + * + * Unlike [groupingKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("grouping_key") + @ExcludeMissing + fun _groupingKey(): JsonField = groupingKey + + @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 + * [EventOutputConfig]. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [EventOutputConfig]. */ + class Builder internal constructor() { + + private var unitRatingKey: JsonField? = null + private var defaultUnitRate: JsonField = JsonMissing.of() + private var groupingKey: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(eventOutputConfig: EventOutputConfig) = apply { + unitRatingKey = eventOutputConfig.unitRatingKey + defaultUnitRate = eventOutputConfig.defaultUnitRate + groupingKey = eventOutputConfig.groupingKey + additionalProperties = + eventOutputConfig.additionalProperties.toMutableMap() } - "unit_with_percent" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(unitWithPercent = it, _json = json) } - ?: Price(_json = json) + + /** The key in the event data to extract the unit rate from. */ + fun unitRatingKey(unitRatingKey: String) = + unitRatingKey(JsonField.of(unitRatingKey)) + + /** + * Sets [Builder.unitRatingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.unitRatingKey] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun unitRatingKey(unitRatingKey: JsonField) = apply { + this.unitRatingKey = unitRatingKey } - "package_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(packageWithAllocation = it, _json = json) } - ?: Price(_json = json) + + /** + * If provided, this amount will be used as the unit rate when an event does + * not have a value for the `unit_rating_key`. If not provided, events + * missing a unit rate will be ignored. + */ + fun defaultUnitRate(defaultUnitRate: String?) = + defaultUnitRate(JsonField.ofNullable(defaultUnitRate)) + + /** + * Sets [Builder.defaultUnitRate] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultUnitRate] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun defaultUnitRate(defaultUnitRate: JsonField) = apply { + this.defaultUnitRate = defaultUnitRate } - "tiered_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredWithProration = it, _json = json) } - ?: Price(_json = json) + + /** + * An optional key in the event data to group by (e.g., event ID). All + * events will also be grouped by their unit rate. + */ + fun groupingKey(groupingKey: String?) = + groupingKey(JsonField.ofNullable(groupingKey)) + + /** + * Sets [Builder.groupingKey] to an arbitrary JSON value. + * + * You should usually call [Builder.groupingKey] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun groupingKey(groupingKey: JsonField) = apply { + this.groupingKey = groupingKey } - "unit_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(unitWithProration = it, _json = json) } - ?: Price(_json = json) + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - "grouped_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedAllocation = it, _json = json) } - ?: Price(_json = json) + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - "grouped_with_prorated_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedWithProratedMinimum = it, _json = json) } - ?: Price(_json = json) + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - "bulk_with_proration" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(bulkWithProration = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns an immutable instance of [EventOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .unitRatingKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventOutputConfig = + EventOutputConfig( + checkRequired("unitRatingKey", unitRatingKey), + defaultUnitRate, + groupingKey, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventOutputConfig = apply { + if (validated) { + return@apply } - "scalable_matrix_with_unit_pricing" -> { - return tryDeserialize( - node, - jacksonTypeRef< - NewSubscriptionScalableMatrixWithUnitPricingPrice - >(), - ) - ?.let { Price(scalableMatrixWithUnitPricing = it, _json = json) } - ?: Price(_json = json) + + unitRatingKey() + defaultUnitRate() + groupingKey() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "scalable_matrix_with_tiered_pricing" -> { - return tryDeserialize( - node, - jacksonTypeRef< - NewSubscriptionScalableMatrixWithTieredPricingPrice - >(), - ) - ?.let { Price(scalableMatrixWithTieredPricing = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (unitRatingKey.asKnown() == null) 0 else 1) + + (if (defaultUnitRate.asKnown() == null) 0 else 1) + + (if (groupingKey.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - "cumulative_grouped_bulk" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(cumulativeGroupedBulk = it, _json = json) } - ?: Price(_json = json) + + return other is EventOutputConfig && + unitRatingKey == other.unitRatingKey && + defaultUnitRate == other.defaultUnitRate && + groupingKey == other.groupingKey && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + unitRatingKey, + defaultUnitRate, + groupingKey, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutputConfig{unitRatingKey=$unitRatingKey, defaultUnitRate=$defaultUnitRate, groupingKey=$groupingKey, additionalProperties=$additionalProperties}" + } + + /** + * User-specified key/value pairs for the resource. Individual keys can be removed + * by setting the value to `null`, and the entire metadata mapping can be cleared by + * setting `metadata` to `null`. + */ + class Metadata + @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 [Metadata]. */ + fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() } - "max_group_tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(maxGroupTieredPackage = it, _json = json) } - ?: Price(_json = json) + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) } - "grouped_with_metered_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedWithMeteredMinimum = it, _json = json) } - ?: Price(_json = json) + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - "matrix_with_display_name" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithDisplayName = it, _json = json) } - ?: Price(_json = json) + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - "grouped_tiered_package" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedTieredPackage = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply } - "matrix_with_allocation" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(matrixWithAllocation = it, _json = json) } - ?: Price(_json = json) + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false } - "tiered_package_with_minimum" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(tieredPackageWithMinimum = it, _json = json) } - ?: Price(_json = json) + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() } - "grouped_tiered" -> { - return tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Price(groupedTiered = it, _json = json) } - ?: Price(_json = json) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is Metadata && + additionalProperties == other.additionalProperties } - return Price(_json = json) - } - } + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - internal class Serializer : BaseSerializer(Price::class) { + override fun hashCode(): Int = hashCode - override fun serialize( - value: Price, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.unit != null -> generator.writeObject(value.unit) - value.package_ != null -> generator.writeObject(value.package_) - value.matrix != null -> generator.writeObject(value.matrix) - value.tiered != null -> generator.writeObject(value.tiered) - value.tieredBps != null -> generator.writeObject(value.tieredBps) - value.bps != null -> generator.writeObject(value.bps) - value.bulkBps != null -> generator.writeObject(value.bulkBps) - value.bulk != null -> generator.writeObject(value.bulk) - value.thresholdTotalAmount != null -> - generator.writeObject(value.thresholdTotalAmount) - value.tieredPackage != null -> generator.writeObject(value.tieredPackage) - value.tieredWithMinimum != null -> - generator.writeObject(value.tieredWithMinimum) - value.unitWithPercent != null -> - generator.writeObject(value.unitWithPercent) - value.packageWithAllocation != null -> - generator.writeObject(value.packageWithAllocation) - value.tieredWithProration != null -> - generator.writeObject(value.tieredWithProration) - value.unitWithProration != null -> - generator.writeObject(value.unitWithProration) - value.groupedAllocation != null -> - generator.writeObject(value.groupedAllocation) - value.groupedWithProratedMinimum != null -> - generator.writeObject(value.groupedWithProratedMinimum) - value.bulkWithProration != null -> - generator.writeObject(value.bulkWithProration) - value.scalableMatrixWithUnitPricing != null -> - generator.writeObject(value.scalableMatrixWithUnitPricing) - value.scalableMatrixWithTieredPricing != null -> - generator.writeObject(value.scalableMatrixWithTieredPricing) - value.cumulativeGroupedBulk != null -> - generator.writeObject(value.cumulativeGroupedBulk) - value.maxGroupTieredPackage != null -> - generator.writeObject(value.maxGroupTieredPackage) - value.groupedWithMeteredMinimum != null -> - generator.writeObject(value.groupedWithMeteredMinimum) - value.matrixWithDisplayName != null -> - generator.writeObject(value.matrixWithDisplayName) - value.groupedTieredPackage != null -> - generator.writeObject(value.groupedTieredPackage) - value.matrixWithAllocation != null -> - generator.writeObject(value.matrixWithAllocation) - value.tieredPackageWithMinimum != null -> - generator.writeObject(value.tieredPackageWithMinimum) - value.groupedTiered != null -> generator.writeObject(value.groupedTiered) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Price") + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } + + return other is EventOutput && + cadence == other.cadence && + eventOutputConfig == other.eventOutputConfig && + itemId == other.itemId && + modelType == other.modelType && + name == other.name && + billableMetricId == other.billableMetricId && + billedInAdvance == other.billedInAdvance && + billingCycleConfiguration == other.billingCycleConfiguration && + conversionRate == other.conversionRate && + conversionRateConfig == other.conversionRateConfig && + currency == other.currency && + dimensionalPriceConfiguration == other.dimensionalPriceConfiguration && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + invoiceGroupingKey == other.invoiceGroupingKey && + invoicingCycleConfiguration == other.invoicingCycleConfiguration && + metadata == other.metadata && + referenceId == other.referenceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cadence, + eventOutputConfig, + itemId, + modelType, + name, + billableMetricId, + billedInAdvance, + billingCycleConfiguration, + conversionRate, + conversionRateConfig, + currency, + dimensionalPriceConfiguration, + externalPriceId, + fixedPriceQuantity, + invoiceGroupingKey, + invoicingCycleConfiguration, + metadata, + referenceId, + additionalProperties, + ) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventOutput{cadence=$cadence, eventOutputConfig=$eventOutputConfig, itemId=$itemId, modelType=$modelType, name=$name, billableMetricId=$billableMetricId, billedInAdvance=$billedInAdvance, billingCycleConfiguration=$billingCycleConfiguration, conversionRate=$conversionRate, conversionRateConfig=$conversionRateConfig, currency=$currency, dimensionalPriceConfiguration=$dimensionalPriceConfiguration, externalPriceId=$externalPriceId, fixedPriceQuantity=$fixedPriceQuantity, invoiceGroupingKey=$invoiceGroupingKey, invoicingCycleConfiguration=$invoicingCycleConfiguration, metadata=$metadata, referenceId=$referenceId, additionalProperties=$additionalProperties}" } } @@ -8408,12 +29573,33 @@ private constructor( return true } - return /* spotless:off */ other is ReplacePrice && replacesPriceId == other.replacesPriceId && allocationPrice == other.allocationPrice && discounts == other.discounts && externalPriceId == other.externalPriceId && fixedPriceQuantity == other.fixedPriceQuantity && maximumAmount == other.maximumAmount && minimumAmount == other.minimumAmount && price == other.price && priceId == other.priceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ReplacePrice && + replacesPriceId == other.replacesPriceId && + allocationPrice == other.allocationPrice && + discounts == other.discounts && + externalPriceId == other.externalPriceId && + fixedPriceQuantity == other.fixedPriceQuantity && + maximumAmount == other.maximumAmount && + minimumAmount == other.minimumAmount && + price == other.price && + priceId == other.priceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(replacesPriceId, allocationPrice, discounts, externalPriceId, fixedPriceQuantity, maximumAmount, minimumAmount, price, priceId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + replacesPriceId, + allocationPrice, + discounts, + externalPriceId, + fixedPriceQuantity, + maximumAmount, + minimumAmount, + price, + priceId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -8426,10 +29612,15 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionSchedulePlanChangeParams && subscriptionId == other.subscriptionId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionSchedulePlanChangeParams && + subscriptionId == other.subscriptionId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) override fun toString() = "SubscriptionSchedulePlanChangeParams{subscriptionId=$subscriptionId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionTrialInfo.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionTrialInfo.kt index 0b3f517a6..8a1682d0c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionTrialInfo.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionTrialInfo.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class SubscriptionTrialInfo +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val endDate: JsonField, private val additionalProperties: MutableMap, @@ -158,12 +159,12 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionTrialInfo && endDate == other.endDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SubscriptionTrialInfo && + endDate == other.endDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(endDate, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionTriggerPhaseParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionTriggerPhaseParams.kt index 4f94f92fd..6da97359f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionTriggerPhaseParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionTriggerPhaseParams.kt @@ -300,6 +300,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val allowInvoiceCreditOrVoid: JsonField, private val effectiveDate: JsonField, @@ -495,12 +496,15 @@ private constructor( return true } - return /* spotless:off */ other is Body && allowInvoiceCreditOrVoid == other.allowInvoiceCreditOrVoid && effectiveDate == other.effectiveDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + allowInvoiceCreditOrVoid == other.allowInvoiceCreditOrVoid && + effectiveDate == other.effectiveDate && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(allowInvoiceCreditOrVoid, effectiveDate, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(allowInvoiceCreditOrVoid, effectiveDate, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -513,10 +517,15 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionTriggerPhaseParams && subscriptionId == other.subscriptionId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionTriggerPhaseParams && + subscriptionId == other.subscriptionId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) override fun toString() = "SubscriptionTriggerPhaseParams{subscriptionId=$subscriptionId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUnscheduleCancellationParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUnscheduleCancellationParams.kt index 2b0176c8b..b956b9b28 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUnscheduleCancellationParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUnscheduleCancellationParams.kt @@ -221,10 +221,20 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionUnscheduleCancellationParams && subscriptionId == other.subscriptionId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is SubscriptionUnscheduleCancellationParams && + subscriptionId == other.subscriptionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + subscriptionId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) override fun toString() = "SubscriptionUnscheduleCancellationParams{subscriptionId=$subscriptionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUnscheduleFixedFeeQuantityUpdatesParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUnscheduleFixedFeeQuantityUpdatesParams.kt index 181d72d21..38c5ef573 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUnscheduleFixedFeeQuantityUpdatesParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUnscheduleFixedFeeQuantityUpdatesParams.kt @@ -267,6 +267,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val priceId: JsonField, private val additionalProperties: MutableMap, @@ -407,12 +408,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && priceId == other.priceId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + priceId == other.priceId && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(priceId, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -425,10 +426,15 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionUnscheduleFixedFeeQuantityUpdatesParams && subscriptionId == other.subscriptionId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionUnscheduleFixedFeeQuantityUpdatesParams && + subscriptionId == other.subscriptionId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) override fun toString() = "SubscriptionUnscheduleFixedFeeQuantityUpdatesParams{subscriptionId=$subscriptionId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUnschedulePendingPlanChangesParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUnschedulePendingPlanChangesParams.kt index 4afad67ff..37af8f2a7 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUnschedulePendingPlanChangesParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUnschedulePendingPlanChangesParams.kt @@ -220,10 +220,20 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionUnschedulePendingPlanChangesParams && subscriptionId == other.subscriptionId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is SubscriptionUnschedulePendingPlanChangesParams && + subscriptionId == other.subscriptionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + subscriptionId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) override fun toString() = "SubscriptionUnschedulePendingPlanChangesParams{subscriptionId=$subscriptionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUpdateFixedFeeQuantityParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUpdateFixedFeeQuantityParams.kt index ae6df52d5..4b4e0f576 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUpdateFixedFeeQuantityParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUpdateFixedFeeQuantityParams.kt @@ -421,6 +421,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val priceId: JsonField, private val quantity: JsonField, @@ -759,13 +760,26 @@ private constructor( return true } - return /* spotless:off */ other is Body && priceId == other.priceId && quantity == other.quantity && allowInvoiceCreditOrVoid == other.allowInvoiceCreditOrVoid && changeOption == other.changeOption && effectiveDate == other.effectiveDate && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + priceId == other.priceId && + quantity == other.quantity && + allowInvoiceCreditOrVoid == other.allowInvoiceCreditOrVoid && + changeOption == other.changeOption && + effectiveDate == other.effectiveDate && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + priceId, + quantity, + allowInvoiceCreditOrVoid, + changeOption, + effectiveDate, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(priceId, quantity, allowInvoiceCreditOrVoid, changeOption, effectiveDate, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = @@ -902,7 +916,7 @@ private constructor( return true } - return /* spotless:off */ other is ChangeOption && value == other.value /* spotless:on */ + return other is ChangeOption && value == other.value } override fun hashCode() = value.hashCode() @@ -915,10 +929,15 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionUpdateFixedFeeQuantityParams && subscriptionId == other.subscriptionId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionUpdateFixedFeeQuantityParams && + subscriptionId == other.subscriptionId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) override fun toString() = "SubscriptionUpdateFixedFeeQuantityParams{subscriptionId=$subscriptionId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUpdateParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUpdateParams.kt index e7f2475b4..0998c1de4 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUpdateParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUpdateParams.kt @@ -412,6 +412,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val autoCollection: JsonField, private val defaultInvoiceMemo: JsonField, @@ -754,13 +755,26 @@ private constructor( return true } - return /* spotless:off */ other is Body && autoCollection == other.autoCollection && defaultInvoiceMemo == other.defaultInvoiceMemo && invoicingThreshold == other.invoicingThreshold && metadata == other.metadata && netTerms == other.netTerms && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + autoCollection == other.autoCollection && + defaultInvoiceMemo == other.defaultInvoiceMemo && + invoicingThreshold == other.invoicingThreshold && + metadata == other.metadata && + netTerms == other.netTerms && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + autoCollection, + defaultInvoiceMemo, + invoicingThreshold, + metadata, + netTerms, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(autoCollection, defaultInvoiceMemo, invoicingThreshold, metadata, netTerms, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = @@ -859,12 +873,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -876,10 +888,15 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionUpdateParams && subscriptionId == other.subscriptionId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionUpdateParams && + subscriptionId == other.subscriptionId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) override fun toString() = "SubscriptionUpdateParams{subscriptionId=$subscriptionId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUpdateTrialParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUpdateTrialParams.kt index ed565f827..c6389573c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUpdateTrialParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUpdateTrialParams.kt @@ -336,6 +336,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val trialEndDate: JsonField, private val shift: JsonField, @@ -541,12 +542,15 @@ private constructor( return true } - return /* spotless:off */ other is Body && trialEndDate == other.trialEndDate && shift == other.shift && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + trialEndDate == other.trialEndDate && + shift == other.shift && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(trialEndDate, shift, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(trialEndDate, shift, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -638,10 +642,12 @@ private constructor( return true } - return /* spotless:off */ other is TrialEndDate && offsetDateTime == other.offsetDateTime && unionMember1 == other.unionMember1 /* spotless:on */ + return other is TrialEndDate && + offsetDateTime == other.offsetDateTime && + unionMember1 == other.unionMember1 } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(offsetDateTime, unionMember1) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(offsetDateTime, unionMember1) override fun toString(): String = when { @@ -846,7 +852,7 @@ private constructor( return true } - return /* spotless:off */ other is UnionMember1 && value == other.value /* spotless:on */ + return other is UnionMember1 && value == other.value } override fun hashCode() = value.hashCode() @@ -860,10 +866,15 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionUpdateTrialParams && subscriptionId == other.subscriptionId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SubscriptionUpdateTrialParams && + subscriptionId == other.subscriptionId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(subscriptionId, body, additionalHeaders, additionalQueryParams) override fun toString() = "SubscriptionUpdateTrialParams{subscriptionId=$subscriptionId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUsage.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUsage.kt index d92e4d587..257da5315 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUsage.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/SubscriptionUsage.kt @@ -111,10 +111,12 @@ private constructor( return true } - return /* spotless:off */ other is SubscriptionUsage && ungrouped == other.ungrouped && grouped == other.grouped /* spotless:on */ + return other is SubscriptionUsage && + ungrouped == other.ungrouped && + grouped == other.grouped } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(ungrouped, grouped) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(ungrouped, grouped) override fun toString(): String = when { @@ -203,6 +205,7 @@ private constructor( } class UngroupedSubscriptionUsage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val additionalProperties: MutableMap, @@ -355,6 +358,7 @@ private constructor( internal fun validity(): Int = (data.asKnown()?.sumOf { it.validity().toInt() } ?: 0) class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val billableMetric: JsonField, private val usage: JsonField>, @@ -593,6 +597,7 @@ private constructor( (viewMode.asKnown()?.validity() ?: 0) class BillableMetric + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -772,12 +777,13 @@ private constructor( return true } - return /* spotless:off */ other is BillableMetric && id == other.id && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BillableMetric && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, name, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -786,6 +792,7 @@ private constructor( } class Usage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val quantity: JsonField, private val timeframeEnd: JsonField, @@ -1020,12 +1027,16 @@ private constructor( return true } - return /* spotless:off */ other is Usage && quantity == other.quantity && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Usage && + quantity == other.quantity && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(quantity, timeframeEnd, timeframeStart, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(quantity, timeframeEnd, timeframeStart, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1154,7 +1165,7 @@ private constructor( return true } - return /* spotless:off */ other is ViewMode && value == other.value /* spotless:on */ + return other is ViewMode && value == other.value } override fun hashCode() = value.hashCode() @@ -1167,12 +1178,16 @@ private constructor( return true } - return /* spotless:off */ other is Data && billableMetric == other.billableMetric && usage == other.usage && viewMode == other.viewMode && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Data && + billableMetric == other.billableMetric && + usage == other.usage && + viewMode == other.viewMode && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(billableMetric, usage, viewMode, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(billableMetric, usage, viewMode, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1185,12 +1200,12 @@ private constructor( return true } - return /* spotless:off */ other is UngroupedSubscriptionUsage && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UngroupedSubscriptionUsage && + data == other.data && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1199,6 +1214,7 @@ private constructor( } class GroupedSubscriptionUsage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -1390,6 +1406,7 @@ private constructor( (paginationMetadata.asKnown()?.validity() ?: 0) class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val billableMetric: JsonField, private val metricGroup: JsonField, @@ -1669,6 +1686,7 @@ private constructor( (viewMode.asKnown()?.validity() ?: 0) class BillableMetric + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -1848,12 +1866,13 @@ private constructor( return true } - return /* spotless:off */ other is BillableMetric && id == other.id && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is BillableMetric && + id == other.id && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, name, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1862,6 +1881,7 @@ private constructor( } class MetricGroup + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val propertyKey: JsonField, private val propertyValue: JsonField, @@ -2056,12 +2076,15 @@ private constructor( return true } - return /* spotless:off */ other is MetricGroup && propertyKey == other.propertyKey && propertyValue == other.propertyValue && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MetricGroup && + propertyKey == other.propertyKey && + propertyValue == other.propertyValue && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(propertyKey, propertyValue, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(propertyKey, propertyValue, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2070,6 +2093,7 @@ private constructor( } class Usage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val quantity: JsonField, private val timeframeEnd: JsonField, @@ -2304,12 +2328,16 @@ private constructor( return true } - return /* spotless:off */ other is Usage && quantity == other.quantity && timeframeEnd == other.timeframeEnd && timeframeStart == other.timeframeStart && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Usage && + quantity == other.quantity && + timeframeEnd == other.timeframeEnd && + timeframeStart == other.timeframeStart && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(quantity, timeframeEnd, timeframeStart, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(quantity, timeframeEnd, timeframeStart, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2438,7 +2466,7 @@ private constructor( return true } - return /* spotless:off */ other is ViewMode && value == other.value /* spotless:on */ + return other is ViewMode && value == other.value } override fun hashCode() = value.hashCode() @@ -2451,12 +2479,17 @@ private constructor( return true } - return /* spotless:off */ other is Data && billableMetric == other.billableMetric && metricGroup == other.metricGroup && usage == other.usage && viewMode == other.viewMode && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Data && + billableMetric == other.billableMetric && + metricGroup == other.metricGroup && + usage == other.usage && + viewMode == other.viewMode && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(billableMetric, metricGroup, usage, viewMode, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(billableMetric, metricGroup, usage, viewMode, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2469,12 +2502,15 @@ private constructor( return true } - return /* spotless:off */ other is GroupedSubscriptionUsage && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupedSubscriptionUsage && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Subscriptions.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Subscriptions.kt index 399ea5b05..52fa8d023 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Subscriptions.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Subscriptions.kt @@ -18,6 +18,7 @@ import java.util.Collections import java.util.Objects class Subscriptions +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val paginationMetadata: JsonField, @@ -216,12 +217,15 @@ private constructor( return true } - return /* spotless:off */ other is Subscriptions && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Subscriptions && + data == other.data && + paginationMetadata == other.paginationMetadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(data, paginationMetadata, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TaxAmount.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TaxAmount.kt index 64a24bf74..ae94b814d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TaxAmount.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TaxAmount.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class TaxAmount +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val taxRateDescription: JsonField, @@ -246,12 +247,16 @@ private constructor( return true } - return /* spotless:off */ other is TaxAmount && amount == other.amount && taxRateDescription == other.taxRateDescription && taxRatePercentage == other.taxRatePercentage && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TaxAmount && + amount == other.amount && + taxRateDescription == other.taxRateDescription && + taxRatePercentage == other.taxRatePercentage && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, taxRateDescription, taxRatePercentage, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(amount, taxRateDescription, taxRatePercentage, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Threshold.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Threshold.kt index 3b4c7853b..383b0107e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Threshold.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Threshold.kt @@ -17,6 +17,7 @@ import java.util.Objects /** Thresholds are used to define the conditions under which an alert will be triggered. */ class Threshold +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val value: JsonField, private val additionalProperties: MutableMap, @@ -160,12 +161,12 @@ private constructor( return true } - return /* spotless:off */ other is Threshold && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Threshold && + value == other.value && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(value, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Tier.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Tier.kt index 1aeee742f..150266f14 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Tier.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/Tier.kt @@ -15,7 +15,9 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects +/** Configuration for a single tier */ class Tier +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val firstUnit: JsonField, private val unitAmount: JsonField, @@ -49,7 +51,7 @@ private constructor( fun unitAmount(): String = unitAmount.getRequired("unit_amount") /** - * Inclusive tier ending value. If null, this is treated as the last tier + * Inclusive tier ending value. This value is null if and only if this is the last tier. * * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). @@ -142,7 +144,7 @@ private constructor( */ fun unitAmount(unitAmount: JsonField) = apply { this.unitAmount = unitAmount } - /** Inclusive tier ending value. If null, this is treated as the last tier */ + /** Inclusive tier ending value. This value is null if and only if this is the last tier. */ fun lastUnit(lastUnit: Double?) = lastUnit(JsonField.ofNullable(lastUnit)) /** @@ -237,12 +239,16 @@ private constructor( return true } - return /* spotless:off */ other is Tier && firstUnit == other.firstUnit && unitAmount == other.unitAmount && lastUnit == other.lastUnit && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Tier && + firstUnit == other.firstUnit && + unitAmount == other.unitAmount && + lastUnit == other.lastUnit && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(firstUnit, unitAmount, lastUnit, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(firstUnit, unitAmount, lastUnit, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TierConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TierConfig.kt deleted file mode 100644 index a331ed3f7..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TierConfig.kt +++ /dev/null @@ -1,244 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -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.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkRequired -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class TierConfig -private constructor( - private val firstUnit: JsonField, - private val lastUnit: JsonField, - private val unitAmount: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("first_unit") @ExcludeMissing firstUnit: JsonField = JsonMissing.of(), - @JsonProperty("last_unit") @ExcludeMissing lastUnit: JsonField = JsonMissing.of(), - @JsonProperty("unit_amount") - @ExcludeMissing - unitAmount: JsonField = JsonMissing.of(), - ) : this(firstUnit, lastUnit, unitAmount, mutableMapOf()) - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun firstUnit(): Double = firstUnit.getRequired("first_unit") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server - * responded with an unexpected value). - */ - fun lastUnit(): Double? = lastUnit.getNullable("last_unit") - - /** - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun unitAmount(): String = unitAmount.getRequired("unit_amount") - - /** - * Returns the raw JSON value of [firstUnit]. - * - * Unlike [firstUnit], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("first_unit") @ExcludeMissing fun _firstUnit(): JsonField = firstUnit - - /** - * Returns the raw JSON value of [lastUnit]. - * - * Unlike [lastUnit], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("last_unit") @ExcludeMissing fun _lastUnit(): JsonField = lastUnit - - /** - * Returns the raw JSON value of [unitAmount]. - * - * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("unit_amount") @ExcludeMissing fun _unitAmount(): JsonField = unitAmount - - @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 [TierConfig]. - * - * The following fields are required: - * ```kotlin - * .firstUnit() - * .lastUnit() - * .unitAmount() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [TierConfig]. */ - class Builder internal constructor() { - - private var firstUnit: JsonField? = null - private var lastUnit: JsonField? = null - private var unitAmount: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(tierConfig: TierConfig) = apply { - firstUnit = tierConfig.firstUnit - lastUnit = tierConfig.lastUnit - unitAmount = tierConfig.unitAmount - additionalProperties = tierConfig.additionalProperties.toMutableMap() - } - - fun firstUnit(firstUnit: Double) = firstUnit(JsonField.of(firstUnit)) - - /** - * Sets [Builder.firstUnit] to an arbitrary JSON value. - * - * You should usually call [Builder.firstUnit] with a well-typed [Double] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun firstUnit(firstUnit: JsonField) = apply { this.firstUnit = firstUnit } - - fun lastUnit(lastUnit: Double?) = lastUnit(JsonField.ofNullable(lastUnit)) - - /** - * Alias for [Builder.lastUnit]. - * - * This unboxed primitive overload exists for backwards compatibility. - */ - fun lastUnit(lastUnit: Double) = lastUnit(lastUnit as Double?) - - /** - * Sets [Builder.lastUnit] to an arbitrary JSON value. - * - * You should usually call [Builder.lastUnit] with a well-typed [Double] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun lastUnit(lastUnit: JsonField) = apply { this.lastUnit = lastUnit } - - fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) - - /** - * Sets [Builder.unitAmount] to an arbitrary JSON value. - * - * You should usually call [Builder.unitAmount] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun unitAmount(unitAmount: JsonField) = apply { this.unitAmount = unitAmount } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [TierConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .firstUnit() - * .lastUnit() - * .unitAmount() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): TierConfig = - TierConfig( - checkRequired("firstUnit", firstUnit), - checkRequired("lastUnit", lastUnit), - checkRequired("unitAmount", unitAmount), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): TierConfig = apply { - if (validated) { - return@apply - } - - firstUnit() - lastUnit() - unitAmount() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (if (firstUnit.asKnown() == null) 0 else 1) + - (if (lastUnit.asKnown() == null) 0 else 1) + - (if (unitAmount.asKnown() == null) 0 else 1) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TierConfig && firstUnit == other.firstUnit && lastUnit == other.lastUnit && unitAmount == other.unitAmount && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(firstUnit, lastUnit, unitAmount, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "TierConfig{firstUnit=$firstUnit, lastUnit=$lastUnit, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TierSubLineItem.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TierSubLineItem.kt index 05b1a9ede..b4a02b4f3 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TierSubLineItem.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TierSubLineItem.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class TierSubLineItem +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val amount: JsonField, private val grouping: JsonField, @@ -324,6 +325,247 @@ private constructor( (tierConfig.asKnown()?.validity() ?: 0) + (type.asKnown()?.validity() ?: 0) + class TierConfig + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val firstUnit: JsonField, + private val lastUnit: JsonField, + private val unitAmount: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("first_unit") + @ExcludeMissing + firstUnit: JsonField = JsonMissing.of(), + @JsonProperty("last_unit") + @ExcludeMissing + lastUnit: JsonField = JsonMissing.of(), + @JsonProperty("unit_amount") + @ExcludeMissing + unitAmount: JsonField = JsonMissing.of(), + ) : this(firstUnit, lastUnit, unitAmount, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun firstUnit(): Double = firstUnit.getRequired("first_unit") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastUnit(): Double? = lastUnit.getNullable("last_unit") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun unitAmount(): String = unitAmount.getRequired("unit_amount") + + /** + * Returns the raw JSON value of [firstUnit]. + * + * Unlike [firstUnit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_unit") @ExcludeMissing fun _firstUnit(): JsonField = firstUnit + + /** + * Returns the raw JSON value of [lastUnit]. + * + * Unlike [lastUnit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_unit") @ExcludeMissing fun _lastUnit(): JsonField = lastUnit + + /** + * Returns the raw JSON value of [unitAmount]. + * + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("unit_amount") + @ExcludeMissing + fun _unitAmount(): JsonField = unitAmount + + @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 [TierConfig]. + * + * The following fields are required: + * ```kotlin + * .firstUnit() + * .lastUnit() + * .unitAmount() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [TierConfig]. */ + class Builder internal constructor() { + + private var firstUnit: JsonField? = null + private var lastUnit: JsonField? = null + private var unitAmount: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(tierConfig: TierConfig) = apply { + firstUnit = tierConfig.firstUnit + lastUnit = tierConfig.lastUnit + unitAmount = tierConfig.unitAmount + additionalProperties = tierConfig.additionalProperties.toMutableMap() + } + + fun firstUnit(firstUnit: Double) = firstUnit(JsonField.of(firstUnit)) + + /** + * Sets [Builder.firstUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.firstUnit] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun firstUnit(firstUnit: JsonField) = apply { this.firstUnit = firstUnit } + + fun lastUnit(lastUnit: Double?) = lastUnit(JsonField.ofNullable(lastUnit)) + + /** + * Alias for [Builder.lastUnit]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun lastUnit(lastUnit: Double) = lastUnit(lastUnit as Double?) + + /** + * Sets [Builder.lastUnit] to an arbitrary JSON value. + * + * You should usually call [Builder.lastUnit] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastUnit(lastUnit: JsonField) = apply { this.lastUnit = lastUnit } + + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) + + /** + * Sets [Builder.unitAmount] to an arbitrary JSON value. + * + * You should usually call [Builder.unitAmount] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun unitAmount(unitAmount: JsonField) = apply { this.unitAmount = unitAmount } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TierConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .firstUnit() + * .lastUnit() + * .unitAmount() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TierConfig = + TierConfig( + checkRequired("firstUnit", firstUnit), + checkRequired("lastUnit", lastUnit), + checkRequired("unitAmount", unitAmount), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TierConfig = apply { + if (validated) { + return@apply + } + + firstUnit() + lastUnit() + unitAmount() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (if (firstUnit.asKnown() == null) 0 else 1) + + (if (lastUnit.asKnown() == null) 0 else 1) + + (if (unitAmount.asKnown() == null) 0 else 1) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TierConfig && + firstUnit == other.firstUnit && + lastUnit == other.lastUnit && + unitAmount == other.unitAmount && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(firstUnit, lastUnit, unitAmount, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TierConfig{firstUnit=$firstUnit, lastUnit=$lastUnit, unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -434,7 +676,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -447,12 +689,19 @@ private constructor( return true } - return /* spotless:off */ other is TierSubLineItem && amount == other.amount && grouping == other.grouping && name == other.name && quantity == other.quantity && tierConfig == other.tierConfig && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TierSubLineItem && + amount == other.amount && + grouping == other.grouping && + name == other.name && + quantity == other.quantity && + tierConfig == other.tierConfig && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, grouping, name, quantity, tierConfig, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(amount, grouping, name, quantity, tierConfig, type, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TieredBpsConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TieredBpsConfig.kt deleted file mode 100644 index d71fdf064..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TieredBpsConfig.kt +++ /dev/null @@ -1,186 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -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.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkKnown -import com.withorb.api.core.checkRequired -import com.withorb.api.core.toImmutable -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class TieredBpsConfig -private constructor( - private val tiers: JsonField>, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of() - ) : this(tiers, mutableMapOf()) - - /** - * Tiers for a Graduated BPS pricing model, where usage is bucketed into specified tiers - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun tiers(): List = tiers.getRequired("tiers") - - /** - * 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 [TieredBpsConfig]. - * - * The following fields are required: - * ```kotlin - * .tiers() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [TieredBpsConfig]. */ - class Builder internal constructor() { - - private var tiers: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(tieredBpsConfig: TieredBpsConfig) = apply { - tiers = tieredBpsConfig.tiers.map { it.toMutableList() } - additionalProperties = tieredBpsConfig.additionalProperties.toMutableMap() - } - - /** Tiers for a Graduated BPS pricing model, where usage is bucketed into specified tiers */ - 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 [BpsTier] to [tiers]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addTier(tier: BpsTier) = 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 [TieredBpsConfig]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .tiers() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): TieredBpsConfig = - TieredBpsConfig( - checkRequired("tiers", tiers).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): TieredBpsConfig = apply { - if (validated) { - return@apply - } - - tiers().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TieredBpsConfig && tiers == other.tiers && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "TieredBpsConfig{tiers=$tiers, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TieredConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TieredConfig.kt index 030f133bf..6d1f3fe74 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TieredConfig.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TieredConfig.kt @@ -17,16 +17,20 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects +/** Configuration for tiered pricing */ class TieredConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val tiers: JsonField>, + private val prorated: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of() - ) : this(tiers, mutableMapOf()) + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + @JsonProperty("prorated") @ExcludeMissing prorated: JsonField = JsonMissing.of(), + ) : this(tiers, prorated, mutableMapOf()) /** * Tiers for rating based on total usage quantities into the specified tier @@ -36,6 +40,14 @@ private constructor( */ fun tiers(): List = tiers.getRequired("tiers") + /** + * If true, subtotals from this price are prorated based on the service period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun prorated(): Boolean? = prorated.getNullable("prorated") + /** * Returns the raw JSON value of [tiers]. * @@ -43,6 +55,13 @@ private constructor( */ @JsonProperty("tiers") @ExcludeMissing fun _tiers(): JsonField> = tiers + /** + * Returns the raw JSON value of [prorated]. + * + * Unlike [prorated], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorated") @ExcludeMissing fun _prorated(): JsonField = prorated + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -72,10 +91,12 @@ private constructor( class Builder internal constructor() { private var tiers: JsonField>? = null + private var prorated: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(tieredConfig: TieredConfig) = apply { tiers = tieredConfig.tiers.map { it.toMutableList() } + prorated = tieredConfig.prorated additionalProperties = tieredConfig.additionalProperties.toMutableMap() } @@ -103,6 +124,18 @@ private constructor( (tiers ?: JsonField.of(mutableListOf())).also { checkKnown("tiers", it).add(tier) } } + /** If true, subtotals from this price are prorated based on the service period */ + fun prorated(prorated: Boolean) = prorated(JsonField.of(prorated)) + + /** + * Sets [Builder.prorated] to an arbitrary JSON value. + * + * You should usually call [Builder.prorated] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun prorated(prorated: JsonField) = apply { this.prorated = prorated } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -137,6 +170,7 @@ private constructor( fun build(): TieredConfig = TieredConfig( checkRequired("tiers", tiers).map { it.toImmutable() }, + prorated, additionalProperties.toMutableMap(), ) } @@ -149,6 +183,7 @@ private constructor( } tiers().forEach { it.validate() } + prorated() validated = true } @@ -165,22 +200,25 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + internal fun validity(): Int = + (tiers.asKnown()?.sumOf { it.validity().toInt() } ?: 0) + + (if (prorated.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is TieredConfig && tiers == other.tiers && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TieredConfig && + tiers == other.tiers && + prorated == other.prorated && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(tiers, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { Objects.hash(tiers, prorated, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "TieredConfig{tiers=$tiers, additionalProperties=$additionalProperties}" + "TieredConfig{tiers=$tiers, prorated=$prorated, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TieredConversionRateConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TieredConversionRateConfig.kt index 8af22ee18..f1cc5d2c5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TieredConversionRateConfig.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TieredConversionRateConfig.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class TieredConversionRateConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val conversionRateType: JsonField, private val tieredConfig: JsonField, @@ -315,7 +316,7 @@ private constructor( return true } - return /* spotless:off */ other is ConversionRateType && value == other.value /* spotless:on */ + return other is ConversionRateType && value == other.value } override fun hashCode() = value.hashCode() @@ -328,12 +329,15 @@ private constructor( return true } - return /* spotless:off */ other is TieredConversionRateConfig && conversionRateType == other.conversionRateType && tieredConfig == other.tieredConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TieredConversionRateConfig && + conversionRateType == other.conversionRateType && + tieredConfig == other.tieredConfig && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(conversionRateType, tieredConfig, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(conversionRateType, tieredConfig, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TopLevelPingParams.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TopLevelPingParams.kt index 8c5904188..954802fdd 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TopLevelPingParams.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TopLevelPingParams.kt @@ -163,10 +163,12 @@ private constructor( return true } - return /* spotless:off */ other is TopLevelPingParams && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is TopLevelPingParams && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(additionalHeaders, additionalQueryParams) override fun toString() = "TopLevelPingParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TopLevelPingResponse.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TopLevelPingResponse.kt index 68145b423..7c41350c0 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TopLevelPingResponse.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TopLevelPingResponse.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class TopLevelPingResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val response: JsonField, private val additionalProperties: MutableMap, @@ -154,12 +155,12 @@ private constructor( return true } - return /* spotless:off */ other is TopLevelPingResponse && response == other.response && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TopLevelPingResponse && + response == other.response && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(response, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TopUpInvoiceSettings.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TopUpInvoiceSettings.kt index 9be36f269..82792f392 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TopUpInvoiceSettings.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TopUpInvoiceSettings.kt @@ -16,6 +16,7 @@ import java.util.Collections import java.util.Objects class TopUpInvoiceSettings +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val autoCollection: JsonField, private val netTerms: JsonField, @@ -290,12 +291,17 @@ private constructor( return true } - return /* spotless:off */ other is TopUpInvoiceSettings && autoCollection == other.autoCollection && netTerms == other.netTerms && memo == other.memo && requireSuccessfulPayment == other.requireSuccessfulPayment && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TopUpInvoiceSettings && + autoCollection == other.autoCollection && + netTerms == other.netTerms && + memo == other.memo && + requireSuccessfulPayment == other.requireSuccessfulPayment && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(autoCollection, netTerms, memo, requireSuccessfulPayment, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(autoCollection, netTerms, memo, requireSuccessfulPayment, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TransformPriceFilter.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TransformPriceFilter.kt deleted file mode 100644 index c179d5c2f..000000000 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TransformPriceFilter.kt +++ /dev/null @@ -1,529 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -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.withorb.api.core.Enum -import com.withorb.api.core.ExcludeMissing -import com.withorb.api.core.JsonField -import com.withorb.api.core.JsonMissing -import com.withorb.api.core.JsonValue -import com.withorb.api.core.checkKnown -import com.withorb.api.core.checkRequired -import com.withorb.api.core.toImmutable -import com.withorb.api.errors.OrbInvalidDataException -import java.util.Collections -import java.util.Objects - -class TransformPriceFilter -private constructor( - private val field: JsonField, - private val operator: JsonField, - private val values: JsonField>, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), - @JsonProperty("operator") @ExcludeMissing operator: JsonField = JsonMissing.of(), - @JsonProperty("values") @ExcludeMissing values: JsonField> = JsonMissing.of(), - ) : this(field, operator, values, mutableMapOf()) - - /** - * The property of the price to filter on. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun field(): Field = field.getRequired("field") - - /** - * Should prices that match the filter be included or excluded. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun operator(): Operator = operator.getRequired("operator") - - /** - * The IDs or values that match this filter. - * - * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). - */ - fun values(): List = values.getRequired("values") - - /** - * Returns the raw JSON value of [field]. - * - * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field - - /** - * Returns the raw JSON value of [operator]. - * - * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator - - /** - * Returns the raw JSON value of [values]. - * - * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values - - @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 [TransformPriceFilter]. - * - * The following fields are required: - * ```kotlin - * .field() - * .operator() - * .values() - * ``` - */ - fun builder() = Builder() - } - - /** A builder for [TransformPriceFilter]. */ - class Builder internal constructor() { - - private var field: JsonField? = null - private var operator: JsonField? = null - private var values: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - internal fun from(transformPriceFilter: TransformPriceFilter) = apply { - field = transformPriceFilter.field - operator = transformPriceFilter.operator - values = transformPriceFilter.values.map { it.toMutableList() } - additionalProperties = transformPriceFilter.additionalProperties.toMutableMap() - } - - /** The property of the price to filter on. */ - fun field(field: Field) = field(JsonField.of(field)) - - /** - * Sets [Builder.field] to an arbitrary JSON value. - * - * You should usually call [Builder.field] with a well-typed [Field] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun field(field: JsonField) = apply { this.field = field } - - /** Should prices that match the filter be included or excluded. */ - fun operator(operator: Operator) = operator(JsonField.of(operator)) - - /** - * Sets [Builder.operator] to an arbitrary JSON value. - * - * You should usually call [Builder.operator] with a well-typed [Operator] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun operator(operator: JsonField) = apply { this.operator = operator } - - /** The IDs or values that match this filter. */ - fun values(values: List) = values(JsonField.of(values)) - - /** - * Sets [Builder.values] to an arbitrary JSON value. - * - * You should usually call [Builder.values] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun values(values: JsonField>) = apply { - this.values = values.map { it.toMutableList() } - } - - /** - * Adds a single [String] to [values]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addValue(value: String) = apply { - values = - (values ?: JsonField.of(mutableListOf())).also { - checkKnown("values", it).add(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 [TransformPriceFilter]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```kotlin - * .field() - * .operator() - * .values() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): TransformPriceFilter = - TransformPriceFilter( - checkRequired("field", field), - checkRequired("operator", operator), - checkRequired("values", values).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): TransformPriceFilter = apply { - if (validated) { - return@apply - } - - field().validate() - operator().validate() - values() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = - (field.asKnown()?.validity() ?: 0) + - (operator.asKnown()?.validity() ?: 0) + - (values.asKnown()?.size ?: 0) - - /** The property of the price to filter on. */ - class Field @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 { - - val PRICE_ID = of("price_id") - - val ITEM_ID = of("item_id") - - val PRICE_TYPE = of("price_type") - - val CURRENCY = of("currency") - - val PRICING_UNIT_ID = of("pricing_unit_id") - - fun of(value: String) = Field(JsonField.of(value)) - } - - /** An enum containing [Field]'s known values. */ - enum class Known { - PRICE_ID, - ITEM_ID, - PRICE_TYPE, - CURRENCY, - PRICING_UNIT_ID, - } - - /** - * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Field] 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 { - PRICE_ID, - ITEM_ID, - PRICE_TYPE, - CURRENCY, - PRICING_UNIT_ID, - /** An enum member indicating that [Field] 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) { - PRICE_ID -> Value.PRICE_ID - ITEM_ID -> Value.ITEM_ID - PRICE_TYPE -> Value.PRICE_TYPE - CURRENCY -> Value.CURRENCY - PRICING_UNIT_ID -> Value.PRICING_UNIT_ID - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and don't - * want to throw for the unknown case. - * - * @throws OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - PRICE_ID -> Known.PRICE_ID - ITEM_ID -> Known.ITEM_ID - PRICE_TYPE -> Known.PRICE_TYPE - CURRENCY -> Known.CURRENCY - PRICING_UNIT_ID -> Known.PRICING_UNIT_ID - else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): Field = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Field && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** Should prices that match the filter be included or excluded. */ - class Operator @JsonCreator private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that doesn't - * match any known member, and you want to know that value. For example, if the SDK is on an - * older version than the API, then the API may respond with new members that the SDK is - * unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - val INCLUDES = of("includes") - - val EXCLUDES = of("excludes") - - fun of(value: String) = Operator(JsonField.of(value)) - } - - /** An enum containing [Operator]'s known values. */ - enum class Known { - INCLUDES, - EXCLUDES, - } - - /** - * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Operator] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, if the - * SDK is on an older version than the API, then the API may respond with new members that - * the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - INCLUDES, - EXCLUDES, - /** An enum member indicating that [Operator] was instantiated with an unknown value. */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] - * if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if you want - * to throw for the unknown case. - */ - fun value(): Value = - when (this) { - INCLUDES -> Value.INCLUDES - EXCLUDES -> Value.EXCLUDES - 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 OrbInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - INCLUDES -> Known.INCLUDES - EXCLUDES -> Known.EXCLUDES - else -> throw OrbInvalidDataException("Unknown Operator: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for debugging - * and generally doesn't throw. - * - * @throws OrbInvalidDataException if this class instance's value does not have the expected - * primitive type. - */ - fun asString(): String = - _value().asString() ?: throw OrbInvalidDataException("Value is not a String") - - private var validated: Boolean = false - - fun validate(): Operator = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Operator && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TransformPriceFilter && field == other.field && operator == other.operator && values == other.values && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(field, operator, values, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "TransformPriceFilter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" -} diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TrialDiscount.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TrialDiscount.kt index e4d8717da..03c20d6e0 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TrialDiscount.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/TrialDiscount.kt @@ -19,10 +19,11 @@ import java.util.Collections import java.util.Objects class TrialDiscount +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val discountType: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val reason: JsonField, private val trialAmountDiscount: JsonField, private val trialPercentageDiscount: JsonField, @@ -39,7 +40,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("reason") @ExcludeMissing reason: JsonField = JsonMissing.of(), @JsonProperty("trial_amount_discount") @ExcludeMissing @@ -78,7 +79,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). */ - fun filters(): List? = filters.getNullable("filters") + fun filters(): List? = filters.getNullable("filters") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server @@ -127,9 +128,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [reason]. @@ -188,7 +187,7 @@ private constructor( private var discountType: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var reason: JsonField = JsonMissing.of() private var trialAmountDiscount: JsonField = JsonMissing.of() private var trialPercentageDiscount: JsonField = JsonMissing.of() @@ -248,25 +247,25 @@ private constructor( } /** The filters that determine which prices to apply this discount to. */ - fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -514,7 +513,7 @@ private constructor( return true } - return /* spotless:off */ other is DiscountType && value == other.value /* spotless:on */ + return other is DiscountType && value == other.value } override fun hashCode() = value.hashCode() @@ -522,17 +521,560 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is TrialDiscount && discountType == other.discountType && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && reason == other.reason && trialAmountDiscount == other.trialAmountDiscount && trialPercentageDiscount == other.trialPercentageDiscount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is TrialDiscount && + discountType == other.discountType && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + reason == other.reason && + trialAmountDiscount == other.trialAmountDiscount && + trialPercentageDiscount == other.trialPercentageDiscount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(discountType, appliesToPriceIds, filters, reason, trialAmountDiscount, trialPercentageDiscount, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + discountType, + appliesToPriceIds, + filters, + reason, + trialAmountDiscount, + trialPercentageDiscount, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UnitConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UnitConfig.kt index 11d558d38..bdcb64b01 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UnitConfig.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UnitConfig.kt @@ -15,9 +15,12 @@ import com.withorb.api.errors.OrbInvalidDataException import java.util.Collections import java.util.Objects +/** Configuration for unit pricing */ class UnitConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val unitAmount: JsonField, + private val prorated: JsonField, private val additionalProperties: MutableMap, ) { @@ -25,8 +28,9 @@ private constructor( private constructor( @JsonProperty("unit_amount") @ExcludeMissing - unitAmount: JsonField = JsonMissing.of() - ) : this(unitAmount, mutableMapOf()) + unitAmount: JsonField = JsonMissing.of(), + @JsonProperty("prorated") @ExcludeMissing prorated: JsonField = JsonMissing.of(), + ) : this(unitAmount, prorated, mutableMapOf()) /** * Rate per unit of usage @@ -36,6 +40,14 @@ private constructor( */ fun unitAmount(): String = unitAmount.getRequired("unit_amount") + /** + * If true, subtotals from this price are prorated based on the service period + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server + * responded with an unexpected value). + */ + fun prorated(): Boolean? = prorated.getNullable("prorated") + /** * Returns the raw JSON value of [unitAmount]. * @@ -43,6 +55,13 @@ private constructor( */ @JsonProperty("unit_amount") @ExcludeMissing fun _unitAmount(): JsonField = unitAmount + /** + * Returns the raw JSON value of [prorated]. + * + * Unlike [prorated], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prorated") @ExcludeMissing fun _prorated(): JsonField = prorated + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -72,10 +91,12 @@ private constructor( class Builder internal constructor() { private var unitAmount: JsonField? = null + private var prorated: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(unitConfig: UnitConfig) = apply { unitAmount = unitConfig.unitAmount + prorated = unitConfig.prorated additionalProperties = unitConfig.additionalProperties.toMutableMap() } @@ -91,6 +112,18 @@ private constructor( */ fun unitAmount(unitAmount: JsonField) = apply { this.unitAmount = unitAmount } + /** If true, subtotals from this price are prorated based on the service period */ + fun prorated(prorated: Boolean) = prorated(JsonField.of(prorated)) + + /** + * Sets [Builder.prorated] to an arbitrary JSON value. + * + * You should usually call [Builder.prorated] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun prorated(prorated: JsonField) = apply { this.prorated = prorated } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -123,7 +156,11 @@ private constructor( * @throws IllegalStateException if any required field is unset. */ fun build(): UnitConfig = - UnitConfig(checkRequired("unitAmount", unitAmount), additionalProperties.toMutableMap()) + UnitConfig( + checkRequired("unitAmount", unitAmount), + prorated, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -134,6 +171,7 @@ private constructor( } unitAmount() + prorated() validated = true } @@ -150,22 +188,24 @@ private constructor( * * Used for best match union deserialization. */ - internal fun validity(): Int = (if (unitAmount.asKnown() == null) 0 else 1) + internal fun validity(): Int = + (if (unitAmount.asKnown() == null) 0 else 1) + (if (prorated.asKnown() == null) 0 else 1) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is UnitConfig && unitAmount == other.unitAmount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UnitConfig && + unitAmount == other.unitAmount && + prorated == other.prorated && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(unitAmount, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { Objects.hash(unitAmount, prorated, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "UnitConfig{unitAmount=$unitAmount, additionalProperties=$additionalProperties}" + "UnitConfig{unitAmount=$unitAmount, prorated=$prorated, additionalProperties=$additionalProperties}" } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UnitConversionRateConfig.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UnitConversionRateConfig.kt index 5e1df6b81..f5737831d 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UnitConversionRateConfig.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UnitConversionRateConfig.kt @@ -17,6 +17,7 @@ import java.util.Collections import java.util.Objects class UnitConversionRateConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val conversionRateType: JsonField, private val unitConfig: JsonField, @@ -314,7 +315,7 @@ private constructor( return true } - return /* spotless:off */ other is ConversionRateType && value == other.value /* spotless:on */ + return other is ConversionRateType && value == other.value } override fun hashCode() = value.hashCode() @@ -327,12 +328,15 @@ private constructor( return true } - return /* spotless:off */ other is UnitConversionRateConfig && conversionRateType == other.conversionRateType && unitConfig == other.unitConfig && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UnitConversionRateConfig && + conversionRateType == other.conversionRateType && + unitConfig == other.unitConfig && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(conversionRateType, unitConfig, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(conversionRateType, unitConfig, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UsageDiscount.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UsageDiscount.kt index 8d51d9793..96af476b1 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UsageDiscount.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UsageDiscount.kt @@ -19,11 +19,12 @@ import java.util.Collections import java.util.Objects class UsageDiscount +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val discountType: JsonField, private val usageDiscount: JsonField, private val appliesToPriceIds: JsonField>, - private val filters: JsonField>, + private val filters: JsonField>, private val reason: JsonField, private val additionalProperties: MutableMap, ) { @@ -41,7 +42,7 @@ private constructor( appliesToPriceIds: JsonField> = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("reason") @ExcludeMissing reason: JsonField = JsonMissing.of(), ) : this(discountType, usageDiscount, appliesToPriceIds, filters, reason, mutableMapOf()) @@ -74,7 +75,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server * responded with an unexpected value). */ - fun filters(): List? = filters.getNullable("filters") + fun filters(): List? = filters.getNullable("filters") /** * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server @@ -115,9 +116,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [reason]. @@ -158,7 +157,7 @@ private constructor( private var discountType: JsonField? = null private var usageDiscount: JsonField? = null private var appliesToPriceIds: JsonField>? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var reason: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -232,25 +231,25 @@ private constructor( } /** The filters that determine which prices to apply this discount to. */ - fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) + fun filters(filters: List?) = filters(JsonField.ofNullable(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -458,7 +457,7 @@ private constructor( return true } - return /* spotless:off */ other is DiscountType && value == other.value /* spotless:on */ + return other is DiscountType && value == other.value } override fun hashCode() = value.hashCode() @@ -466,17 +465,558 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is UsageDiscount && discountType == other.discountType && usageDiscount == other.usageDiscount && appliesToPriceIds == other.appliesToPriceIds && filters == other.filters && reason == other.reason && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UsageDiscount && + discountType == other.discountType && + usageDiscount == other.usageDiscount && + appliesToPriceIds == other.appliesToPriceIds && + filters == other.filters && + reason == other.reason && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(discountType, usageDiscount, appliesToPriceIds, filters, reason, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + discountType, + usageDiscount, + appliesToPriceIds, + filters, + reason, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UsageDiscountInterval.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UsageDiscountInterval.kt index cc3fc79d3..b5b874985 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UsageDiscountInterval.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/UsageDiscountInterval.kt @@ -20,11 +20,12 @@ import java.util.Collections import java.util.Objects class UsageDiscountInterval +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val appliesToPriceIntervalIds: JsonField>, private val discountType: JsonField, private val endDate: JsonField, - private val filters: JsonField>, + private val filters: JsonField>, private val startDate: JsonField, private val usageDiscount: JsonField, private val additionalProperties: MutableMap, @@ -43,7 +44,7 @@ private constructor( endDate: JsonField = JsonMissing.of(), @JsonProperty("filters") @ExcludeMissing - filters: JsonField> = JsonMissing.of(), + filters: JsonField> = JsonMissing.of(), @JsonProperty("start_date") @ExcludeMissing startDate: JsonField = JsonMissing.of(), @@ -89,7 +90,7 @@ private constructor( * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly * missing or null (e.g. if the server responded with an unexpected value). */ - fun filters(): List = filters.getRequired("filters") + fun filters(): List = filters.getRequired("filters") /** * The start date of the discount interval. @@ -138,9 +139,7 @@ private constructor( * * Unlike [filters], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("filters") - @ExcludeMissing - fun _filters(): JsonField> = filters + @JsonProperty("filters") @ExcludeMissing fun _filters(): JsonField> = filters /** * Returns the raw JSON value of [startDate]. @@ -196,7 +195,7 @@ private constructor( private var appliesToPriceIntervalIds: JsonField>? = null private var discountType: JsonField? = null private var endDate: JsonField? = null - private var filters: JsonField>? = null + private var filters: JsonField>? = null private var startDate: JsonField? = null private var usageDiscount: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -265,25 +264,25 @@ private constructor( fun endDate(endDate: JsonField) = apply { this.endDate = endDate } /** The filters that determine which prices this discount interval applies to. */ - fun filters(filters: List) = filters(JsonField.of(filters)) + fun filters(filters: List) = filters(JsonField.of(filters)) /** * Sets [Builder.filters] to an arbitrary JSON value. * - * You should usually call [Builder.filters] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * You should usually call [Builder.filters] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun filters(filters: JsonField>) = apply { + fun filters(filters: JsonField>) = apply { this.filters = filters.map { it.toMutableList() } } /** - * Adds a single [TransformPriceFilter] to [filters]. + * Adds a single [Filter] to [filters]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addFilter(filter: TransformPriceFilter) = apply { + fun addFilter(filter: Filter) = apply { filters = (filters ?: JsonField.of(mutableListOf())).also { checkKnown("filters", it).add(filter) @@ -519,7 +518,7 @@ private constructor( return true } - return /* spotless:off */ other is DiscountType && value == other.value /* spotless:on */ + return other is DiscountType && value == other.value } override fun hashCode() = value.hashCode() @@ -527,17 +526,560 @@ private constructor( override fun toString() = value.toString() } + class Filter + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val field: JsonField, + private val operator: JsonField, + private val values: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("field") @ExcludeMissing field: JsonField = JsonMissing.of(), + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("values") + @ExcludeMissing + values: JsonField> = JsonMissing.of(), + ) : this(field, operator, values, mutableMapOf()) + + /** + * The property of the price to filter on. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun field(): Field = field.getRequired("field") + + /** + * Should prices that match the filter be included or excluded. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operator(): Operator = operator.getRequired("operator") + + /** + * The IDs or values that match this filter. + * + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun values(): List = values.getRequired("values") + + /** + * Returns the raw JSON value of [field]. + * + * Unlike [field], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("field") @ExcludeMissing fun _field(): JsonField = field + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operator") @ExcludeMissing fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [values]. + * + * Unlike [values], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("values") @ExcludeMissing fun _values(): JsonField> = values + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Filter]. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + */ + fun builder() = Builder() + } + + /** A builder for [Filter]. */ + class Builder internal constructor() { + + private var field: JsonField? = null + private var operator: JsonField? = null + private var values: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(filter: Filter) = apply { + field = filter.field + operator = filter.operator + values = filter.values.map { it.toMutableList() } + additionalProperties = filter.additionalProperties.toMutableMap() + } + + /** The property of the price to filter on. */ + fun field(field: Field) = field(JsonField.of(field)) + + /** + * Sets [Builder.field] to an arbitrary JSON value. + * + * You should usually call [Builder.field] with a well-typed [Field] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun field(field: JsonField) = apply { this.field = field } + + /** Should prices that match the filter be included or excluded. */ + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + /** The IDs or values that match this filter. */ + fun values(values: List) = values(JsonField.of(values)) + + /** + * Sets [Builder.values] to an arbitrary JSON value. + * + * You should usually call [Builder.values] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun values(values: JsonField>) = apply { + this.values = values.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [values]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addValue(value: String) = apply { + values = + (values ?: JsonField.of(mutableListOf())).also { + checkKnown("values", it).add(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 [Filter]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```kotlin + * .field() + * .operator() + * .values() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Filter = + Filter( + checkRequired("field", field), + checkRequired("operator", operator), + checkRequired("values", values).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Filter = apply { + if (validated) { + return@apply + } + + field().validate() + operator().validate() + values() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = + (field.asKnown()?.validity() ?: 0) + + (operator.asKnown()?.validity() ?: 0) + + (values.asKnown()?.size ?: 0) + + /** The property of the price to filter on. */ + class Field @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 { + + val PRICE_ID = of("price_id") + + val ITEM_ID = of("item_id") + + val PRICE_TYPE = of("price_type") + + val CURRENCY = of("currency") + + val PRICING_UNIT_ID = of("pricing_unit_id") + + fun of(value: String) = Field(JsonField.of(value)) + } + + /** An enum containing [Field]'s known values. */ + enum class Known { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + } + + /** + * An enum containing [Field]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Field] 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 { + PRICE_ID, + ITEM_ID, + PRICE_TYPE, + CURRENCY, + PRICING_UNIT_ID, + /** + * An enum member indicating that [Field] 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) { + PRICE_ID -> Value.PRICE_ID + ITEM_ID -> Value.ITEM_ID + PRICE_TYPE -> Value.PRICE_TYPE + CURRENCY -> Value.CURRENCY + PRICING_UNIT_ID -> Value.PRICING_UNIT_ID + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + PRICE_ID -> Known.PRICE_ID + ITEM_ID -> Known.ITEM_ID + PRICE_TYPE -> Known.PRICE_TYPE + CURRENCY -> Known.CURRENCY + PRICING_UNIT_ID -> Known.PRICING_UNIT_ID + else -> throw OrbInvalidDataException("Unknown Field: $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 OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Field = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + 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 Field && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Should prices that match the filter be included or excluded. */ + class Operator @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + val INCLUDES = of("includes") + + val EXCLUDES = of("excludes") + + fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + INCLUDES, + EXCLUDES, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INCLUDES, + EXCLUDES, + /** + * An enum member indicating that [Operator] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INCLUDES -> Value.INCLUDES + EXCLUDES -> Value.EXCLUDES + 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 OrbInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INCLUDES -> Known.INCLUDES + EXCLUDES -> Known.EXCLUDES + else -> throw OrbInvalidDataException("Unknown Operator: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OrbInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString() ?: throw OrbInvalidDataException("Value is not a String") + + private var validated: Boolean = false + + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Filter && + field == other.field && + operator == other.operator && + values == other.values && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(field, operator, values, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Filter{field=$field, operator=$operator, values=$values, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is UsageDiscountInterval && appliesToPriceIntervalIds == other.appliesToPriceIntervalIds && discountType == other.discountType && endDate == other.endDate && filters == other.filters && startDate == other.startDate && usageDiscount == other.usageDiscount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UsageDiscountInterval && + appliesToPriceIntervalIds == other.appliesToPriceIntervalIds && + discountType == other.discountType && + endDate == other.endDate && + filters == other.filters && + startDate == other.startDate && + usageDiscount == other.usageDiscount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(appliesToPriceIntervalIds, discountType, endDate, filters, startDate, usageDiscount, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + appliesToPriceIntervalIds, + discountType, + endDate, + filters, + startDate, + usageDiscount, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/VoidInitiatedLedgerEntry.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/VoidInitiatedLedgerEntry.kt index ad9d2a45b..7871bcf7e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/VoidInitiatedLedgerEntry.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/VoidInitiatedLedgerEntry.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class VoidInitiatedLedgerEntry +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, @@ -850,7 +851,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryStatus && value == other.value /* spotless:on */ + return other is EntryStatus && value == other.value } override fun hashCode() = value.hashCode() @@ -970,7 +971,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryType && value == other.value /* spotless:on */ + return other is EntryType && value == other.value } override fun hashCode() = value.hashCode() @@ -1070,12 +1071,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1087,12 +1086,47 @@ private constructor( return true } - return /* spotless:off */ other is VoidInitiatedLedgerEntry && id == other.id && amount == other.amount && createdAt == other.createdAt && creditBlock == other.creditBlock && currency == other.currency && customer == other.customer && description == other.description && endingBalance == other.endingBalance && entryStatus == other.entryStatus && entryType == other.entryType && ledgerSequenceNumber == other.ledgerSequenceNumber && metadata == other.metadata && newBlockExpiryDate == other.newBlockExpiryDate && startingBalance == other.startingBalance && voidAmount == other.voidAmount && voidReason == other.voidReason && additionalProperties == other.additionalProperties /* spotless:on */ + return other is VoidInitiatedLedgerEntry && + id == other.id && + amount == other.amount && + createdAt == other.createdAt && + creditBlock == other.creditBlock && + currency == other.currency && + customer == other.customer && + description == other.description && + endingBalance == other.endingBalance && + entryStatus == other.entryStatus && + entryType == other.entryType && + ledgerSequenceNumber == other.ledgerSequenceNumber && + metadata == other.metadata && + newBlockExpiryDate == other.newBlockExpiryDate && + startingBalance == other.startingBalance && + voidAmount == other.voidAmount && + voidReason == other.voidReason && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, createdAt, creditBlock, currency, customer, description, endingBalance, entryStatus, entryType, ledgerSequenceNumber, metadata, newBlockExpiryDate, startingBalance, voidAmount, voidReason, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + createdAt, + creditBlock, + currency, + customer, + description, + endingBalance, + entryStatus, + entryType, + ledgerSequenceNumber, + metadata, + newBlockExpiryDate, + startingBalance, + voidAmount, + voidReason, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/VoidLedgerEntry.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/VoidLedgerEntry.kt index a55ba790c..ada0c53b7 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/VoidLedgerEntry.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/models/VoidLedgerEntry.kt @@ -19,6 +19,7 @@ import java.util.Collections import java.util.Objects class VoidLedgerEntry +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val amount: JsonField, @@ -807,7 +808,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryStatus && value == other.value /* spotless:on */ + return other is EntryStatus && value == other.value } override fun hashCode() = value.hashCode() @@ -927,7 +928,7 @@ private constructor( return true } - return /* spotless:off */ other is EntryType && value == other.value /* spotless:on */ + return other is EntryType && value == other.value } override fun hashCode() = value.hashCode() @@ -1027,12 +1028,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1044,12 +1043,45 @@ private constructor( return true } - return /* spotless:off */ other is VoidLedgerEntry && id == other.id && amount == other.amount && createdAt == other.createdAt && creditBlock == other.creditBlock && currency == other.currency && customer == other.customer && description == other.description && endingBalance == other.endingBalance && entryStatus == other.entryStatus && entryType == other.entryType && ledgerSequenceNumber == other.ledgerSequenceNumber && metadata == other.metadata && startingBalance == other.startingBalance && voidAmount == other.voidAmount && voidReason == other.voidReason && additionalProperties == other.additionalProperties /* spotless:on */ + return other is VoidLedgerEntry && + id == other.id && + amount == other.amount && + createdAt == other.createdAt && + creditBlock == other.creditBlock && + currency == other.currency && + customer == other.customer && + description == other.description && + endingBalance == other.endingBalance && + entryStatus == other.entryStatus && + entryType == other.entryType && + ledgerSequenceNumber == other.ledgerSequenceNumber && + metadata == other.metadata && + startingBalance == other.startingBalance && + voidAmount == other.voidAmount && + voidReason == other.voidReason && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, amount, createdAt, creditBlock, currency, customer, description, endingBalance, entryStatus, entryType, ledgerSequenceNumber, metadata, startingBalance, voidAmount, voidReason, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + amount, + createdAt, + creditBlock, + currency, + customer, + description, + endingBalance, + entryStatus, + entryType, + ledgerSequenceNumber, + metadata, + startingBalance, + voidAmount, + voidReason, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/AlertServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/AlertServiceAsync.kt index ddb4835ce..aa938149e 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/AlertServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/AlertServiceAsync.kt @@ -70,8 +70,8 @@ interface AlertServiceAsync { * * The request must specify one of `customer_id`, `external_customer_id`, or `subscription_id`. * - * If querying by subscripion_id, the endpoint will return the subscription level alerts as well - * as the plan level alerts associated with the subscription. + * If querying by subscription_id, the endpoint will return the subscription level alerts as + * well as the plan level alerts associated with the subscription. * * The list of alerts is ordered starting from the most recently created alert. This endpoint * follows Orb's [standardized pagination format](/api-reference/pagination). diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/BetaServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/BetaServiceAsync.kt index e922e4a07..e7bbc4072 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/BetaServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/BetaServiceAsync.kt @@ -29,12 +29,7 @@ interface BetaServiceAsync { fun externalPlanId(): ExternalPlanIdServiceAsync - /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in - * test mode. - * - * This endpoint allows the creation of a new plan version for an existing plan. - */ + /** This endpoint allows the creation of a new plan version for an existing plan. */ suspend fun createPlanVersion( planId: String, params: BetaCreatePlanVersionParams, @@ -48,9 +43,6 @@ interface BetaServiceAsync { ): PlanVersion /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in - * test mode. - * * This endpoint is used to fetch a plan version. It returns the phases, prices, and adjustments * present on this version of the plan. */ @@ -66,12 +58,7 @@ interface BetaServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): PlanVersion - /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in - * test mode. - * - * This endpoint allows setting the default version of a plan. - */ + /** This endpoint allows setting the default version of a plan. */ suspend fun setDefaultPlanVersion( planId: String, params: BetaSetDefaultPlanVersionParams, diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/CustomerServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/CustomerServiceAsync.kt index 80627f858..fda804288 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/CustomerServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/CustomerServiceAsync.kt @@ -48,11 +48,11 @@ interface CustomerServiceAsync { * resource. * * This endpoint is critical in the following Orb functionality: - * - Automated charges can be configured by setting `payment_provider` and `payment_provider_id` + * * Automated charges can be configured by setting `payment_provider` and `payment_provider_id` * to automatically issue invoices - * - [Customer ID Aliases](/events-and-metrics/customer-aliases) can be configured by setting + * * [Customer ID Aliases](/events-and-metrics/customer-aliases) can be configured by setting * `external_customer_id` - * - [Timezone localization](/essentials/timezones) can be configured on a per-customer basis by + * * [Timezone localization](/essentials/timezones) can be configured on a per-customer basis by * setting the `timezone` parameter */ suspend fun create( diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/DimensionalPriceGroupServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/DimensionalPriceGroupServiceAsync.kt index 873325dfd..2b31fdbc5 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/DimensionalPriceGroupServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/DimensionalPriceGroupServiceAsync.kt @@ -32,7 +32,7 @@ interface DimensionalPriceGroupServiceAsync { /** * A dimensional price group is used to partition the result of a billable metric by a set of - * dimensions. Prices in a price group must specify the parition used to derive their usage. + * dimensions. Prices in a price group must specify the partition used to derive their usage. * * For example, suppose we have a billable metric that measures the number of widgets used and * we want to charge differently depending on the color of the widget. We can create a price diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/EventServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/EventServiceAsync.kt index 356bc960a..997d016de 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/EventServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/EventServiceAsync.kt @@ -48,8 +48,8 @@ interface EventServiceAsync { * * This is a powerful and audit-safe mechanism to retroactively update a single event in cases * where you need to: - * - update an event with new metadata as you iterate on your pricing model - * - update an event based on the result of an external API call (e.g. call to a payment gateway + * * update an event with new metadata as you iterate on your pricing model + * * update an event based on the result of an external API call (e.g. call to a payment gateway * succeeded or failed) * * This amendment API is always audit-safe. The process will still retain the original event, @@ -57,22 +57,22 @@ interface EventServiceAsync { * Orb never overwrites or permanently deletes ingested usage data. * * ## Request validation - * - The `timestamp` of the new event must match the `timestamp` of the existing event already + * * The `timestamp` of the new event must match the `timestamp` of the existing event already * ingested. As with ingestion, all timestamps must be sent in ISO8601 format with UTC * timezone offset. - * - The `customer_id` or `external_customer_id` of the new event must match the `customer_id` + * * The `customer_id` or `external_customer_id` of the new event must match the `customer_id` * or `external_customer_id` of the existing event already ingested. Exactly one of * `customer_id` and `external_customer_id` should be specified, and similar to ingestion, the * ID must identify a Customer resource within Orb. Unlike ingestion, for event amendment, we * strictly enforce that the Customer must be in the Orb system, even during the initial * integration period. We do not allow updating the `Customer` an event is associated with. - * - Orb does not accept an `idempotency_key` with the event in this endpoint, since this + * * Orb does not accept an `idempotency_key` with the event in this endpoint, since this * request is by design idempotent. On retryable errors, you should retry the request and * assume the amendment operation has not succeeded until receipt of a 2xx. - * - The event's `timestamp` must fall within the customer's current subscription's billing + * * The event's `timestamp` must fall within the customer's current subscription's billing * period, or within the grace period of the customer's current subscription's previous * billing period. - * - By default, no more than 100 events can be amended for a single customer in a 100 day + * * By default, no more than 100 events can be amended for a single customer in a 100 day * period. For higher volume updates, consider using the [event backfill](create-backfill) * endpoint. */ @@ -97,8 +97,8 @@ interface EventServiceAsync { * * This is a powerful and audit-safe mechanism to retroactively deprecate a single event in * cases where you need to: - * - no longer bill for an event that was improperly reported - * - no longer bill for an event based on the result of an external API call (e.g. call to a + * * no longer bill for an event that was improperly reported + * * no longer bill for an event based on the result of an external API call (e.g. call to a * payment gateway failed and the user should not be billed) * * If you want to only change specific properties of an event, but keep the event as part of the @@ -109,18 +109,18 @@ interface EventServiceAsync { * overwrites or permanently deletes ingested usage data. * * ## Request validation - * - Orb does not accept an `idempotency_key` with the event in this endpoint, since this + * * Orb does not accept an `idempotency_key` with the event in this endpoint, since this * request is by design idempotent. On retryable errors, you should retry the request and * assume the deprecation operation has not succeeded until receipt of a 2xx. - * - The event's `timestamp` must fall within the customer's current subscription's billing + * * The event's `timestamp` must fall within the customer's current subscription's billing * period, or within the grace period of the customer's current subscription's previous * billing period. Orb does not allow deprecating events for billing periods that have already * invoiced customers. - * - The `customer_id` or the `external_customer_id` of the original event ingestion request + * * The `customer_id` or the `external_customer_id` of the original event ingestion request * must identify a Customer resource within Orb, even if this event was ingested during the * initial integration period. We do not allow deprecating events for customers not in the Orb * system. - * - By default, no more than 100 events can be deprecated for a single customer in a 100 day + * * By default, no more than 100 events can be deprecated for a single customer in a 100 day * period. For higher volume updates, consider using the [event backfill](create-backfill) * endpoint. */ @@ -199,7 +199,6 @@ interface EventServiceAsync { * ``` * * ## Required fields - * * Because events streamed to Orb are meant to be as flexible as possible, there are only a few * required fields in every event. * - We recommend that `idempotency_key` are unique strings that you generated with V4 UUIDs, @@ -229,7 +228,6 @@ interface EventServiceAsync { * aggregate should be of numeric type in the event. * * ## Determining event timestamp - * * For cases where usage is being reported in real time as it is occurring, timestamp should * correspond to the time that usage occurred. * @@ -284,7 +282,6 @@ interface EventServiceAsync { * requests should be retried in their entirety. * * ## API usage and limits - * * The ingestion API is designed made for real-time streaming ingestion and architected for high * throughput. Even if events are later deemed unnecessary or filtered out, we encourage you to * log them to Orb if they may be relevant to billing calculations in the future. @@ -299,7 +296,6 @@ interface EventServiceAsync { * magnitude from initial setup. * * ## Testing in debug mode - * * The ingestion API supports a debug mode, which returns additional verbose output to indicate * which event idempotency keys were newly ingested or duplicates from previous requests. To * enable this mode, mark `debug=true` as a query parameter. @@ -318,7 +314,11 @@ interface EventServiceAsync { * { * "debug": { * "duplicate": [], - * "ingested": ["B7E83HDMfJPAunXW", "SJs5DQJ3TnwSqEZE", "8SivfDsNKwCeAXim"] + * "ingested": [ + * "B7E83HDMfJPAunXW", + * "SJs5DQJ3TnwSqEZE", + * "8SivfDsNKwCeAXim" + * ] * }, * "validation_failed": [] * } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/InvoiceLineItemServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/InvoiceLineItemServiceAsync.kt index 0dcf26f95..eb20e781c 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/InvoiceLineItemServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/InvoiceLineItemServiceAsync.kt @@ -26,6 +26,15 @@ interface InvoiceLineItemServiceAsync { /** * This creates a one-off fixed fee invoice line item on an Invoice. This can only be done for * invoices that are in a `draft` status. + * + * The behavior depends on which parameters are provided: + * - If `item_id` is provided without `name`: The item is looked up by ID, and the item's name + * is used for the line item. + * - If `name` is provided without `item_id`: An item with the given name is searched for in the + * account. If found, that item is used. If not found, a new item is created with that name. + * The new item's name is used for the line item. + * - If both `item_id` and `name` are provided: The item is looked up by ID for association, but + * the provided `name` is used for the line item (not the item's name). */ suspend fun create( params: InvoiceLineItemCreateParams, diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/InvoiceServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/InvoiceServiceAsync.kt index 8635b4ab6..0dabda5b3 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/InvoiceServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/InvoiceServiceAsync.kt @@ -40,12 +40,13 @@ interface InvoiceServiceAsync { ): Invoice /** - * This endpoint allows you to update the `metadata`, `net_terms`, and `due_date` properties on - * an invoice. If you pass null for the metadata value, it will clear any existing metadata for - * that invoice. + * This endpoint allows you to update the `metadata`, `net_terms`, `due_date`, and + * `invoice_date` properties on an invoice. If you pass null for the metadata value, it will + * clear any existing metadata for that invoice. * - * `metadata` can be modified regardless of invoice state. `net_terms` and `due_date` can only - * be modified if the invoice is in a `draft` state. + * `metadata` can be modified regardless of invoice state. `net_terms`, `due_date`, and + * `invoice_date` can only be modified if the invoice is in a `draft` state. `invoice_date` can + * only be modified for non-subscription invoices. */ suspend fun update( invoiceId: String, @@ -138,8 +139,8 @@ interface InvoiceServiceAsync { issue(invoiceId, InvoiceIssueParams.none(), requestOptions) /** - * This endpoint allows an invoice's status to be set the `paid` status. This can only be done - * to invoices that are in the `issued` status. + * This endpoint allows an invoice's status to be set to the `paid` status. This can only be + * done to invoices that are in the `issued` or `synced` status. */ suspend fun markPaid( invoiceId: String, @@ -174,8 +175,8 @@ interface InvoiceServiceAsync { pay(invoiceId, InvoicePayParams.none(), requestOptions) /** - * This endpoint allows an invoice's status to be set the `void` status. This can only be done - * to invoices that are in the `issued` status. + * This endpoint allows an invoice's status to be set to the `void` status. This can only be + * done to invoices that are in the `issued` status. * * If the associated invoice has used the customer balance to change the amount due, the * customer balance operation will be reverted. For example, if the invoice used \$10 of diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/PlanServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/PlanServiceAsync.kt index 080bff190..e0adc82db 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/PlanServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/PlanServiceAsync.kt @@ -79,7 +79,6 @@ interface PlanServiceAsync { * configuration, as well as the product that the plan is attached to. * * ## Serialized prices - * * Orb supports a few different pricing models out of the box. Each of these models is * serialized differently in a given [Price](/core-concepts#plan-and-price) object. The * `model_type` field determines the key for the configuration object that is present. A @@ -87,7 +86,6 @@ interface PlanServiceAsync { * [Price schema](/core-concepts#plan-and-price). * * ## Phases - * * Orb supports plan phases, also known as contract ramps. For plans with phases, the serialized * prices refer to all prices across all phases. */ diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionServiceAsync.kt index 2288fb74d..70f4ff403 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionServiceAsync.kt @@ -186,7 +186,6 @@ interface SubscriptionServiceAsync { * cadence, type, and name of a price can not be overridden. * * ### Maximums and Minimums - * * Minimums and maximums, much like price overrides, can be useful when a new customer has * negotiated a new or different minimum or maximum spend cap than the default for a given * price. If one exists for a price and null is provided for the minimum/maximum override on @@ -231,7 +230,6 @@ interface SubscriptionServiceAsync { * ``` * * ### Discounts - * * Discounts, like price overrides, can be useful when a new customer has negotiated a new or * different discount than the default for a price. If a discount exists for a price and a null * discount is provided on creation, then there will be no discount on the new subscription. @@ -281,6 +279,9 @@ interface SubscriptionServiceAsync { * enable threshold billing, pass in an `invoicing_threshold`, which is specified in the * subscription's invoicing currency, when creating a subscription. E.g. pass in `10.00` to * issue an invoice when usage amounts hit \$10.00 for a subscription that invoices in USD. + * + * ## Limits + * By default, Orb limits the number of subscriptions per customer to 100. */ suspend fun create( params: SubscriptionCreateParams = SubscriptionCreateParams.none(), @@ -376,7 +377,6 @@ interface SubscriptionServiceAsync { * `end_date` equal to the `start_date` upon cancellation. * * ## Backdated cancellations - * * Orb allows you to cancel a subscription in the past as long as there are no paid invoices * between the `requested_date` and the current time. If the cancellation is after the latest * issued invoice, Orb will generate a balance refund for the current period. If the @@ -485,7 +485,6 @@ interface SubscriptionServiceAsync { * of the customer's billing period. * * ### Default response shape - * * Orb returns a `data` array with an object corresponding to each billable metric. Nested * within this object is a `usage` array which has a `quantity` value and a corresponding * `timeframe_start` and `timeframe_end`. The `quantity` value represents the calculated usage @@ -502,7 +501,6 @@ interface SubscriptionServiceAsync { * conjunction_ with each other, e.g. to display grouped usage on a custom timeframe. * * ## Custom timeframe - * * In order to view usage for a custom timeframe rather than the current billing period, specify * a `timeframe_start` and `timeframe_end`. This will calculate quantities for usage incurred * between timeframe_start (inclusive) and timeframe_end (exclusive), i.e. `[timeframe_start, @@ -514,7 +512,6 @@ interface SubscriptionServiceAsync { * - Both parameters must be specified if either is specified. * * ## Grouping by custom attributes - * * In order to view a single metric grouped by a specific _attribute_ that each event is tagged * with (e.g. `cluster`), you must additionally specify a `billable_metric_id` and a `group_by` * key. The `group_by` key denotes the event property on which to group. @@ -564,7 +561,6 @@ interface SubscriptionServiceAsync { * ``` * * ## Windowed usage - * * The `granularity` parameter can be used to _window_ the usage `quantity` value into periods. * When not specified, usage is returned for the entirety of the time range. * @@ -619,7 +615,6 @@ interface SubscriptionServiceAsync { * ``` * * ## Decomposable vs. non-decomposable metrics - * * Billable metrics fall into one of two categories: decomposable and non-decomposable. A * decomposable billable metric, such as a sum or a count, can be displayed and aggregated * across arbitrary timescales. On the other hand, a non-decomposable metric is not meaningful @@ -638,7 +633,6 @@ interface SubscriptionServiceAsync { * key. If no invoice grouping key is present, the metric does not support `group_by`. * * ## Matrix prices - * * When a billable metric is attached to a price that uses matrix pricing, it's important to * view usage grouped by those matrix dimensions. In this case, use the query parameters * `first_dimension_key`, `first_dimension_value` and `second_dimension_key`, @@ -721,7 +715,6 @@ interface SubscriptionServiceAsync { * `start_date`. * * ## Fixed fee quantity transitions - * * The fixed fee quantity transitions for a fixed fee price interval can also be specified when * adding or editing by passing an array for `fixed_fee_quantity_transitions`. A fixed fee * quantity transition must have a `quantity` and an `effective_date`, which is the date after @@ -776,8 +769,8 @@ interface SubscriptionServiceAsync { * This endpoint can be used to change an existing subscription's plan. It returns the * serialized updated subscription object. * - * The body parameter `change_option` determines when the plan change occurrs. Orb supports - * three options: + * The body parameter `change_option` determines when the plan change occurs. Orb supports three + * options: * - `end_of_subscription_term`: changes the plan at the end of the existing plan's term. * - Issuing this plan change request for a monthly subscription will keep the existing plan * active until the start of the subsequent month. Issuing this plan change request for a @@ -920,7 +913,6 @@ interface SubscriptionServiceAsync { * cadence, type, and name of a price can not be overridden. * * ### Maximums, and minimums - * * Price overrides are used to update some or all prices in the target plan. Minimums and * maximums, much like price overrides, can be useful when a new customer has negotiated a new * or different minimum or maximum spend cap than the default for the plan. The request format @@ -928,12 +920,10 @@ interface SubscriptionServiceAsync { * [subscription creation](create-subscription). * * ## Scheduling multiple plan changes - * * When scheduling multiple plan changes with the same date, the latest plan change on that day * takes effect. * * ## Prorations for in-advance fees - * * By default, Orb calculates the prorated difference in any fixed fees when making a plan * change, adjusting the customer balance as needed. For details on this behavior, see * [Modifying subscriptions](/product-catalog/modifying-subscriptions#prorations-for-in-advance-fees). diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/beta/ExternalPlanIdServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/beta/ExternalPlanIdServiceAsync.kt index 5bee1ad76..c8a502ad8 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/beta/ExternalPlanIdServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/beta/ExternalPlanIdServiceAsync.kt @@ -26,12 +26,7 @@ interface ExternalPlanIdServiceAsync { */ fun withOptions(modifier: (ClientOptions.Builder) -> Unit): ExternalPlanIdServiceAsync - /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in - * test mode. - * - * This endpoint allows the creation of a new plan version for an existing plan. - */ + /** This endpoint allows the creation of a new plan version for an existing plan. */ suspend fun createPlanVersion( externalPlanId: String, params: BetaExternalPlanIdCreatePlanVersionParams, @@ -46,9 +41,6 @@ interface ExternalPlanIdServiceAsync { ): PlanVersion /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in - * test mode. - * * This endpoint is used to fetch a plan version. It returns the phases, prices, and adjustments * present on this version of the plan. */ @@ -64,12 +56,7 @@ interface ExternalPlanIdServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): PlanVersion - /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in - * test mode. - * - * This endpoint allows setting the default version of a plan. - */ + /** This endpoint allows setting the default version of a plan. */ suspend fun setDefaultPlanVersion( externalPlanId: String, params: BetaExternalPlanIdSetDefaultPlanVersionParams, diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/customers/CostServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/customers/CostServiceAsync.kt index 558767a4a..330f3190f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/customers/CostServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/customers/CostServiceAsync.kt @@ -45,7 +45,6 @@ interface CostServiceAsync { * minimum committed spend. * * ## Fetching subscriptions - * * By default, this endpoint fetches the currently active subscription for the customer, and * returns cost information for the subscription's current billing period, broken down by each * participating price. If there are no currently active subscriptions, this will instead @@ -58,18 +57,16 @@ interface CostServiceAsync { * summed, and prices for both subscriptions will be included in the breakdown. * * ## Prepaid plans - * * For plans that include prices which deduct credits rather than accrue in-arrears charges in a * billable currency, this endpoint will return the total deduction amount, in credits, for the * specified timeframe. * * ## Cumulative subtotals and totals - * * Since the subtotal and total must factor in any billing-period level discounts and minimums, * it's most meaningful to consider costs relative to the start of the subscription's billing * period. As a result, by default this endpoint returns cumulative totals since the beginning * of the billing period. In particular, the `timeframe_start` of a returned timeframe window is - * _always_ the beginning of the billing period and `timeframe_end` is incremented one day at a + * *always* the beginning of the billing period and `timeframe_end` is incremented one day at a * time to build the result. * * A customer that uses a few API calls a day but has a minimum commitment might exhibit the @@ -87,7 +84,6 @@ interface CostServiceAsync { * | 2023-02-01 | 2023-02-06 | 36 | \$90.00 | \$90.00 | * * ### Periodic values - * * When the query parameter `view_mode=periodic` is specified, Orb will return an incremental * day-by-day view of costs. In this case, there will always be a one-day difference between * `timeframe_start` and `timeframe_end` for the timeframes returned. This is a transform on top @@ -97,7 +93,6 @@ interface CostServiceAsync { * to the total cost. * * ## Timeframe bounds - * * For an active subscription, both timeframes should be specified in the request. If a * subscription starts or ends within the timeframe, the response will only include windows * where the subscription is active. If a subscription has ended, no timeframe bounds need to be @@ -129,7 +124,6 @@ interface CostServiceAsync { * You can see this sliced timeframe visualized [here](https://i.imgur.com/TXhYgme.png). * * ### Matrix prices - * * When a price uses matrix pricing, it's important to view costs grouped by those matrix * dimensions. Orb will return `price_groups` with the `grouping_key` and * `secondary_grouping_key` based on the matrix price definition, for each `grouping_value` and @@ -172,7 +166,6 @@ interface CostServiceAsync { * minimum committed spend. * * ## Fetching subscriptions - * * By default, this endpoint fetches the currently active subscription for the customer, and * returns cost information for the subscription's current billing period, broken down by each * participating price. If there are no currently active subscriptions, this will instead @@ -185,18 +178,16 @@ interface CostServiceAsync { * summed, and prices for both subscriptions will be included in the breakdown. * * ## Prepaid plans - * * For plans that include prices which deduct credits rather than accrue in-arrears charges in a * billable currency, this endpoint will return the total deduction amount, in credits, for the * specified timeframe. * * ## Cumulative subtotals and totals - * * Since the subtotal and total must factor in any billing-period level discounts and minimums, * it's most meaningful to consider costs relative to the start of the subscription's billing * period. As a result, by default this endpoint returns cumulative totals since the beginning * of the billing period. In particular, the `timeframe_start` of a returned timeframe window is - * _always_ the beginning of the billing period and `timeframe_end` is incremented one day at a + * *always* the beginning of the billing period and `timeframe_end` is incremented one day at a * time to build the result. * * A customer that uses a few API calls a day but has a minimum commitment might exhibit the @@ -214,7 +205,6 @@ interface CostServiceAsync { * | 2023-02-01 | 2023-02-06 | 36 | \$90.00 | \$90.00 | * * ### Periodic values - * * When the query parameter `view_mode=periodic` is specified, Orb will return an incremental * day-by-day view of costs. In this case, there will always be a one-day difference between * `timeframe_start` and `timeframe_end` for the timeframes returned. This is a transform on top @@ -224,7 +214,6 @@ interface CostServiceAsync { * to the total cost. * * ## Timeframe bounds - * * For an active subscription, both timeframes should be specified in the request. If a * subscription starts or ends within the timeframe, the response will only include windows * where the subscription is active. If a subscription has ended, no timeframe bounds need to be @@ -256,7 +245,6 @@ interface CostServiceAsync { * You can see this sliced timeframe visualized [here](https://i.imgur.com/TXhYgme.png). * * ### Matrix prices - * * When a price uses matrix pricing, it's important to view costs grouped by those matrix * dimensions. Orb will return `price_groups` with the `grouping_key` and * `secondary_grouping_key` based on the matrix price definition, for each `grouping_value` and diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsync.kt index f314cb94e..d54a5d0a3 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsync.kt @@ -41,14 +41,12 @@ interface LedgerServiceAsync { * There are four major types of modifications to credit balance, detailed below. * * ## Increment - * * Credits (which optionally expire on a future date) can be added via the API ([Add Ledger * Entry](create-ledger-entry)). The ledger entry for such an action will always contain the * total eligible starting and ending balance for the customer at the time the entry was added * to the ledger. * * ## Decrement - * * Deductions can occur as a result of an API call to create a ledger entry (see * [Add Ledger Entry](create-ledger-entry)), or automatically as a result of incurring usage. * Both ledger entries present the `decrement` entry type. @@ -60,14 +58,14 @@ interface LedgerServiceAsync { * the `event_id` at the time of ingestion, used to pinpoint _why_ credit deduction took place * and to ensure that credits are never deducted without an associated usage event. * - * By default, Orb uses an algorithm that automatically deducts from the _soonest expiring - * credit block_ first in order to ensure that all credits are utilized appropriately. As an + * By default, Orb uses an algorithm that automatically deducts from the *soonest expiring + * credit block* first in order to ensure that all credits are utilized appropriately. As an * example, if trial credits with an expiration date of 2 weeks from now are present for a * customer, they will be used before any deductions take place from a non-expiring credit * block. * * If there are multiple blocks with the same expiration date, Orb will deduct from the block - * with the _lower cost basis_ first (e.g. trial credits with a \$0 cost basis before paid + * with the *lower cost basis* first (e.g. trial credits with a \$0 cost basis before paid * credits with a \$5.00 cost basis). * * It's also possible for a single usage event's deduction to _span_ credit blocks. In this @@ -77,34 +75,29 @@ interface LedgerServiceAsync { * can be negative as a result of a decrement. * * ## Expiration change - * * The expiry of credits can be changed as a result of the API (See * [Add Ledger Entry](create-ledger-entry)). This will create a ledger entry that specifies the * balance as well as the initial and target expiry dates. * * Note that for this entry type, `starting_balance` will equal `ending_balance`, and the * `amount` represents the balance transferred. The credit block linked to the ledger entry is - * the source credit block from which there was an expiration change + * the source credit block from which there was an expiration change. * * ## Credits expiry - * * When a set of credits expire on pre-set expiration date, the customer's balance automatically * reflects this change and adds an entry to the ledger indicating this event. Note that credit * expiry should always happen close to a date boundary in the customer's timezone. * * ## Void initiated - * * Credit blocks can be voided via the API. The `amount` on this entry corresponds to the number * of credits that were remaining in the block at time of void. `void_reason` will be populated * if the void is created with a reason. * * ## Void - * * When a set of credits is voided, the customer's balance automatically reflects this change * and adds an entry to the ledger indicating this event. * * ## Amendment - * * When credits are added to a customer's balance as a result of a correction, this entry will * be added to the ledger to indicate the adjustment of credits. */ @@ -144,7 +137,6 @@ interface LedgerServiceAsync { * the credits (based on `amount` and `per_unit_cost_basis`). * * ## Adding credits - * * Adding credits is done by creating an entry of type `increment`. This requires the caller to * specify a number of credits as well as an optional expiry date in `YYYY-MM-DD` format. Orb * also recommends specifying a description to assist with auditing. When adding credits, the @@ -168,7 +160,6 @@ interface LedgerServiceAsync { * blocks before adding the remaining amount to the desired credit block. * * ### Invoicing for credits - * * By default, Orb manipulates the credit ledger but does not charge for credits. However, if * you pass `invoice_settings` in the body of this request, Orb will also generate a one-off * invoice for the customer for the credits pre-purchase. Note that you _must_ provide the @@ -176,7 +167,6 @@ interface LedgerServiceAsync { * the cost basis with the number of credit units added. * * ## Deducting Credits - * * Orb allows you to deduct credits from a customer by creating an entry of type `decrement`. * Orb matches the algorithm for automatic deductions for determining which credit blocks to * decrement from. In the case that the deduction leads to multiple ledger entries, the response @@ -194,7 +184,6 @@ interface LedgerServiceAsync { * ``` * * ## Changing credits expiry - * * If you'd like to change when existing credits expire, you should create a ledger entry of * type `expiration_change`. For this entry, the required parameter `expiry_date` identifies the * _originating_ block, and the required parameter `target_expiry_date` identifies when the @@ -260,7 +249,6 @@ interface LedgerServiceAsync { * the credits (based on `amount` and `per_unit_cost_basis`). * * ## Adding credits - * * Adding credits is done by creating an entry of type `increment`. This requires the caller to * specify a number of credits as well as an optional expiry date in `YYYY-MM-DD` format. Orb * also recommends specifying a description to assist with auditing. When adding credits, the @@ -284,7 +272,6 @@ interface LedgerServiceAsync { * blocks before adding the remaining amount to the desired credit block. * * ### Invoicing for credits - * * By default, Orb manipulates the credit ledger but does not charge for credits. However, if * you pass `invoice_settings` in the body of this request, Orb will also generate a one-off * invoice for the customer for the credits pre-purchase. Note that you _must_ provide the @@ -292,7 +279,6 @@ interface LedgerServiceAsync { * the cost basis with the number of credit units added. * * ## Deducting Credits - * * Orb allows you to deduct credits from a customer by creating an entry of type `decrement`. * Orb matches the algorithm for automatic deductions for determining which credit blocks to * decrement from. In the case that the deduction leads to multiple ledger entries, the response @@ -310,7 +296,6 @@ interface LedgerServiceAsync { * ``` * * ## Changing credits expiry - * * If you'd like to change when existing credits expire, you should create a ledger entry of * type `expiration_change`. For this entry, the required parameter `expiry_date` identifies the * _originating_ block, and the required parameter `target_expiry_date` identifies when the @@ -375,14 +360,12 @@ interface LedgerServiceAsync { * There are four major types of modifications to credit balance, detailed below. * * ## Increment - * * Credits (which optionally expire on a future date) can be added via the API ([Add Ledger * Entry](create-ledger-entry)). The ledger entry for such an action will always contain the * total eligible starting and ending balance for the customer at the time the entry was added * to the ledger. * * ## Decrement - * * Deductions can occur as a result of an API call to create a ledger entry (see * [Add Ledger Entry](create-ledger-entry)), or automatically as a result of incurring usage. * Both ledger entries present the `decrement` entry type. @@ -394,14 +377,14 @@ interface LedgerServiceAsync { * the `event_id` at the time of ingestion, used to pinpoint _why_ credit deduction took place * and to ensure that credits are never deducted without an associated usage event. * - * By default, Orb uses an algorithm that automatically deducts from the _soonest expiring - * credit block_ first in order to ensure that all credits are utilized appropriately. As an + * By default, Orb uses an algorithm that automatically deducts from the *soonest expiring + * credit block* first in order to ensure that all credits are utilized appropriately. As an * example, if trial credits with an expiration date of 2 weeks from now are present for a * customer, they will be used before any deductions take place from a non-expiring credit * block. * * If there are multiple blocks with the same expiration date, Orb will deduct from the block - * with the _lower cost basis_ first (e.g. trial credits with a \$0 cost basis before paid + * with the *lower cost basis* first (e.g. trial credits with a \$0 cost basis before paid * credits with a \$5.00 cost basis). * * It's also possible for a single usage event's deduction to _span_ credit blocks. In this @@ -411,34 +394,29 @@ interface LedgerServiceAsync { * can be negative as a result of a decrement. * * ## Expiration change - * * The expiry of credits can be changed as a result of the API (See * [Add Ledger Entry](create-ledger-entry)). This will create a ledger entry that specifies the * balance as well as the initial and target expiry dates. * * Note that for this entry type, `starting_balance` will equal `ending_balance`, and the * `amount` represents the balance transferred. The credit block linked to the ledger entry is - * the source credit block from which there was an expiration change + * the source credit block from which there was an expiration change. * * ## Credits expiry - * * When a set of credits expire on pre-set expiration date, the customer's balance automatically * reflects this change and adds an entry to the ledger indicating this event. Note that credit * expiry should always happen close to a date boundary in the customer's timezone. * * ## Void initiated - * * Credit blocks can be voided via the API. The `amount` on this entry corresponds to the number * of credits that were remaining in the block at time of void. `void_reason` will be populated * if the void is created with a reason. * * ## Void - * * When a set of credits is voided, the customer's balance automatically reflects this change * and adds an entry to the ledger indicating this event. * * ## Amendment - * * When credits are added to a customer's balance as a result of a correction, this entry will * be added to the ledger to indicate the adjustment of credits. */ diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/events/BackfillServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/events/BackfillServiceAsync.kt index 6eaa43321..23c302c3f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/events/BackfillServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/events/BackfillServiceAsync.kt @@ -56,10 +56,13 @@ interface BackfillServiceAsync { * * When `replace_existing_events` is `true`, this indicates that existing events in the * timeframe should no longer be counted towards invoiced usage. In this scenario, the parameter - * `filter` can be optionally added which enables filtering using + * `deprecation_filter` can be optionally added which enables filtering using * [computed properties](/extensibility/advanced-metrics#computed-properties). The * expressiveness of computed properties allows you to deprecate existing events based on both a * period of time and specific property values. + * + * You may not have multiple backfills in a pending or pending_revert state with overlapping + * timeframes. */ suspend fun create( params: EventBackfillCreateParams, diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/plans/ExternalPlanIdServiceAsync.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/plans/ExternalPlanIdServiceAsync.kt index 81dea5025..65eef1201 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/plans/ExternalPlanIdServiceAsync.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/async/plans/ExternalPlanIdServiceAsync.kt @@ -57,7 +57,6 @@ interface ExternalPlanIdServiceAsync { * created plan. * * ## Serialized prices - * * Orb supports a few different pricing models out of the box. Each of these models is * serialized differently in a given [Price](/core-concepts#plan-and-price) object. The * `model_type` field determines the key for the configuration object that is present. A diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/AlertService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/AlertService.kt index 46a1cd43e..151142084 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/AlertService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/AlertService.kt @@ -70,8 +70,8 @@ interface AlertService { * * The request must specify one of `customer_id`, `external_customer_id`, or `subscription_id`. * - * If querying by subscripion_id, the endpoint will return the subscription level alerts as well - * as the plan level alerts associated with the subscription. + * If querying by subscription_id, the endpoint will return the subscription level alerts as + * well as the plan level alerts associated with the subscription. * * The list of alerts is ordered starting from the most recently created alert. This endpoint * follows Orb's [standardized pagination format](/api-reference/pagination). diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/BetaService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/BetaService.kt index f9dac8e7b..81f7b22c4 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/BetaService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/BetaService.kt @@ -29,12 +29,7 @@ interface BetaService { fun externalPlanId(): ExternalPlanIdService - /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in - * test mode. - * - * This endpoint allows the creation of a new plan version for an existing plan. - */ + /** This endpoint allows the creation of a new plan version for an existing plan. */ fun createPlanVersion( planId: String, params: BetaCreatePlanVersionParams, @@ -48,9 +43,6 @@ interface BetaService { ): PlanVersion /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in - * test mode. - * * This endpoint is used to fetch a plan version. It returns the phases, prices, and adjustments * present on this version of the plan. */ @@ -66,12 +58,7 @@ interface BetaService { requestOptions: RequestOptions = RequestOptions.none(), ): PlanVersion - /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in - * test mode. - * - * This endpoint allows setting the default version of a plan. - */ + /** This endpoint allows setting the default version of a plan. */ fun setDefaultPlanVersion( planId: String, params: BetaSetDefaultPlanVersionParams, diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/CustomerService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/CustomerService.kt index 4ef4554c4..bc4ade3dc 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/CustomerService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/CustomerService.kt @@ -48,11 +48,11 @@ interface CustomerService { * resource. * * This endpoint is critical in the following Orb functionality: - * - Automated charges can be configured by setting `payment_provider` and `payment_provider_id` + * * Automated charges can be configured by setting `payment_provider` and `payment_provider_id` * to automatically issue invoices - * - [Customer ID Aliases](/events-and-metrics/customer-aliases) can be configured by setting + * * [Customer ID Aliases](/events-and-metrics/customer-aliases) can be configured by setting * `external_customer_id` - * - [Timezone localization](/essentials/timezones) can be configured on a per-customer basis by + * * [Timezone localization](/essentials/timezones) can be configured on a per-customer basis by * setting the `timezone` parameter */ fun create( diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/DimensionalPriceGroupService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/DimensionalPriceGroupService.kt index cb8d062ae..e623d277f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/DimensionalPriceGroupService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/DimensionalPriceGroupService.kt @@ -32,7 +32,7 @@ interface DimensionalPriceGroupService { /** * A dimensional price group is used to partition the result of a billable metric by a set of - * dimensions. Prices in a price group must specify the parition used to derive their usage. + * dimensions. Prices in a price group must specify the partition used to derive their usage. * * For example, suppose we have a billable metric that measures the number of widgets used and * we want to charge differently depending on the color of the widget. We can create a price diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/EventService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/EventService.kt index be75f242c..34966dccd 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/EventService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/EventService.kt @@ -48,8 +48,8 @@ interface EventService { * * This is a powerful and audit-safe mechanism to retroactively update a single event in cases * where you need to: - * - update an event with new metadata as you iterate on your pricing model - * - update an event based on the result of an external API call (e.g. call to a payment gateway + * * update an event with new metadata as you iterate on your pricing model + * * update an event based on the result of an external API call (e.g. call to a payment gateway * succeeded or failed) * * This amendment API is always audit-safe. The process will still retain the original event, @@ -57,22 +57,22 @@ interface EventService { * Orb never overwrites or permanently deletes ingested usage data. * * ## Request validation - * - The `timestamp` of the new event must match the `timestamp` of the existing event already + * * The `timestamp` of the new event must match the `timestamp` of the existing event already * ingested. As with ingestion, all timestamps must be sent in ISO8601 format with UTC * timezone offset. - * - The `customer_id` or `external_customer_id` of the new event must match the `customer_id` + * * The `customer_id` or `external_customer_id` of the new event must match the `customer_id` * or `external_customer_id` of the existing event already ingested. Exactly one of * `customer_id` and `external_customer_id` should be specified, and similar to ingestion, the * ID must identify a Customer resource within Orb. Unlike ingestion, for event amendment, we * strictly enforce that the Customer must be in the Orb system, even during the initial * integration period. We do not allow updating the `Customer` an event is associated with. - * - Orb does not accept an `idempotency_key` with the event in this endpoint, since this + * * Orb does not accept an `idempotency_key` with the event in this endpoint, since this * request is by design idempotent. On retryable errors, you should retry the request and * assume the amendment operation has not succeeded until receipt of a 2xx. - * - The event's `timestamp` must fall within the customer's current subscription's billing + * * The event's `timestamp` must fall within the customer's current subscription's billing * period, or within the grace period of the customer's current subscription's previous * billing period. - * - By default, no more than 100 events can be amended for a single customer in a 100 day + * * By default, no more than 100 events can be amended for a single customer in a 100 day * period. For higher volume updates, consider using the [event backfill](create-backfill) * endpoint. */ @@ -97,8 +97,8 @@ interface EventService { * * This is a powerful and audit-safe mechanism to retroactively deprecate a single event in * cases where you need to: - * - no longer bill for an event that was improperly reported - * - no longer bill for an event based on the result of an external API call (e.g. call to a + * * no longer bill for an event that was improperly reported + * * no longer bill for an event based on the result of an external API call (e.g. call to a * payment gateway failed and the user should not be billed) * * If you want to only change specific properties of an event, but keep the event as part of the @@ -109,18 +109,18 @@ interface EventService { * overwrites or permanently deletes ingested usage data. * * ## Request validation - * - Orb does not accept an `idempotency_key` with the event in this endpoint, since this + * * Orb does not accept an `idempotency_key` with the event in this endpoint, since this * request is by design idempotent. On retryable errors, you should retry the request and * assume the deprecation operation has not succeeded until receipt of a 2xx. - * - The event's `timestamp` must fall within the customer's current subscription's billing + * * The event's `timestamp` must fall within the customer's current subscription's billing * period, or within the grace period of the customer's current subscription's previous * billing period. Orb does not allow deprecating events for billing periods that have already * invoiced customers. - * - The `customer_id` or the `external_customer_id` of the original event ingestion request + * * The `customer_id` or the `external_customer_id` of the original event ingestion request * must identify a Customer resource within Orb, even if this event was ingested during the * initial integration period. We do not allow deprecating events for customers not in the Orb * system. - * - By default, no more than 100 events can be deprecated for a single customer in a 100 day + * * By default, no more than 100 events can be deprecated for a single customer in a 100 day * period. For higher volume updates, consider using the [event backfill](create-backfill) * endpoint. */ @@ -199,7 +199,6 @@ interface EventService { * ``` * * ## Required fields - * * Because events streamed to Orb are meant to be as flexible as possible, there are only a few * required fields in every event. * - We recommend that `idempotency_key` are unique strings that you generated with V4 UUIDs, @@ -229,7 +228,6 @@ interface EventService { * aggregate should be of numeric type in the event. * * ## Determining event timestamp - * * For cases where usage is being reported in real time as it is occurring, timestamp should * correspond to the time that usage occurred. * @@ -284,7 +282,6 @@ interface EventService { * requests should be retried in their entirety. * * ## API usage and limits - * * The ingestion API is designed made for real-time streaming ingestion and architected for high * throughput. Even if events are later deemed unnecessary or filtered out, we encourage you to * log them to Orb if they may be relevant to billing calculations in the future. @@ -299,7 +296,6 @@ interface EventService { * magnitude from initial setup. * * ## Testing in debug mode - * * The ingestion API supports a debug mode, which returns additional verbose output to indicate * which event idempotency keys were newly ingested or duplicates from previous requests. To * enable this mode, mark `debug=true` as a query parameter. @@ -318,7 +314,11 @@ interface EventService { * { * "debug": { * "duplicate": [], - * "ingested": ["B7E83HDMfJPAunXW", "SJs5DQJ3TnwSqEZE", "8SivfDsNKwCeAXim"] + * "ingested": [ + * "B7E83HDMfJPAunXW", + * "SJs5DQJ3TnwSqEZE", + * "8SivfDsNKwCeAXim" + * ] * }, * "validation_failed": [] * } diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceLineItemService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceLineItemService.kt index 30c0ea492..2080f3901 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceLineItemService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceLineItemService.kt @@ -26,6 +26,15 @@ interface InvoiceLineItemService { /** * This creates a one-off fixed fee invoice line item on an Invoice. This can only be done for * invoices that are in a `draft` status. + * + * The behavior depends on which parameters are provided: + * - If `item_id` is provided without `name`: The item is looked up by ID, and the item's name + * is used for the line item. + * - If `name` is provided without `item_id`: An item with the given name is searched for in the + * account. If found, that item is used. If not found, a new item is created with that name. + * The new item's name is used for the line item. + * - If both `item_id` and `name` are provided: The item is looked up by ID for association, but + * the provided `name` is used for the line item (not the item's name). */ fun create( params: InvoiceLineItemCreateParams, diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceService.kt index e32d5f19c..2aecb22c4 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceService.kt @@ -40,12 +40,13 @@ interface InvoiceService { ): Invoice /** - * This endpoint allows you to update the `metadata`, `net_terms`, and `due_date` properties on - * an invoice. If you pass null for the metadata value, it will clear any existing metadata for - * that invoice. + * This endpoint allows you to update the `metadata`, `net_terms`, `due_date`, and + * `invoice_date` properties on an invoice. If you pass null for the metadata value, it will + * clear any existing metadata for that invoice. * - * `metadata` can be modified regardless of invoice state. `net_terms` and `due_date` can only - * be modified if the invoice is in a `draft` state. + * `metadata` can be modified regardless of invoice state. `net_terms`, `due_date`, and + * `invoice_date` can only be modified if the invoice is in a `draft` state. `invoice_date` can + * only be modified for non-subscription invoices. */ fun update( invoiceId: String, @@ -138,8 +139,8 @@ interface InvoiceService { issue(invoiceId, InvoiceIssueParams.none(), requestOptions) /** - * This endpoint allows an invoice's status to be set the `paid` status. This can only be done - * to invoices that are in the `issued` status. + * This endpoint allows an invoice's status to be set to the `paid` status. This can only be + * done to invoices that are in the `issued` or `synced` status. */ fun markPaid( invoiceId: String, @@ -174,8 +175,8 @@ interface InvoiceService { pay(invoiceId, InvoicePayParams.none(), requestOptions) /** - * This endpoint allows an invoice's status to be set the `void` status. This can only be done - * to invoices that are in the `issued` status. + * This endpoint allows an invoice's status to be set to the `void` status. This can only be + * done to invoices that are in the `issued` status. * * If the associated invoice has used the customer balance to change the amount due, the * customer balance operation will be reverted. For example, if the invoice used \$10 of diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/PlanService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/PlanService.kt index 022634e48..29f7ccd39 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/PlanService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/PlanService.kt @@ -79,7 +79,6 @@ interface PlanService { * configuration, as well as the product that the plan is attached to. * * ## Serialized prices - * * Orb supports a few different pricing models out of the box. Each of these models is * serialized differently in a given [Price](/core-concepts#plan-and-price) object. The * `model_type` field determines the key for the configuration object that is present. A @@ -87,7 +86,6 @@ interface PlanService { * [Price schema](/core-concepts#plan-and-price). * * ## Phases - * * Orb supports plan phases, also known as contract ramps. For plans with phases, the serialized * prices refer to all prices across all phases. */ diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionService.kt index bc144afc1..85fe68e11 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionService.kt @@ -186,7 +186,6 @@ interface SubscriptionService { * cadence, type, and name of a price can not be overridden. * * ### Maximums and Minimums - * * Minimums and maximums, much like price overrides, can be useful when a new customer has * negotiated a new or different minimum or maximum spend cap than the default for a given * price. If one exists for a price and null is provided for the minimum/maximum override on @@ -231,7 +230,6 @@ interface SubscriptionService { * ``` * * ### Discounts - * * Discounts, like price overrides, can be useful when a new customer has negotiated a new or * different discount than the default for a price. If a discount exists for a price and a null * discount is provided on creation, then there will be no discount on the new subscription. @@ -281,6 +279,9 @@ interface SubscriptionService { * enable threshold billing, pass in an `invoicing_threshold`, which is specified in the * subscription's invoicing currency, when creating a subscription. E.g. pass in `10.00` to * issue an invoice when usage amounts hit \$10.00 for a subscription that invoices in USD. + * + * ## Limits + * By default, Orb limits the number of subscriptions per customer to 100. */ fun create( params: SubscriptionCreateParams = SubscriptionCreateParams.none(), @@ -376,7 +377,6 @@ interface SubscriptionService { * `end_date` equal to the `start_date` upon cancellation. * * ## Backdated cancellations - * * Orb allows you to cancel a subscription in the past as long as there are no paid invoices * between the `requested_date` and the current time. If the cancellation is after the latest * issued invoice, Orb will generate a balance refund for the current period. If the @@ -485,7 +485,6 @@ interface SubscriptionService { * of the customer's billing period. * * ### Default response shape - * * Orb returns a `data` array with an object corresponding to each billable metric. Nested * within this object is a `usage` array which has a `quantity` value and a corresponding * `timeframe_start` and `timeframe_end`. The `quantity` value represents the calculated usage @@ -502,7 +501,6 @@ interface SubscriptionService { * conjunction_ with each other, e.g. to display grouped usage on a custom timeframe. * * ## Custom timeframe - * * In order to view usage for a custom timeframe rather than the current billing period, specify * a `timeframe_start` and `timeframe_end`. This will calculate quantities for usage incurred * between timeframe_start (inclusive) and timeframe_end (exclusive), i.e. `[timeframe_start, @@ -514,7 +512,6 @@ interface SubscriptionService { * - Both parameters must be specified if either is specified. * * ## Grouping by custom attributes - * * In order to view a single metric grouped by a specific _attribute_ that each event is tagged * with (e.g. `cluster`), you must additionally specify a `billable_metric_id` and a `group_by` * key. The `group_by` key denotes the event property on which to group. @@ -564,7 +561,6 @@ interface SubscriptionService { * ``` * * ## Windowed usage - * * The `granularity` parameter can be used to _window_ the usage `quantity` value into periods. * When not specified, usage is returned for the entirety of the time range. * @@ -619,7 +615,6 @@ interface SubscriptionService { * ``` * * ## Decomposable vs. non-decomposable metrics - * * Billable metrics fall into one of two categories: decomposable and non-decomposable. A * decomposable billable metric, such as a sum or a count, can be displayed and aggregated * across arbitrary timescales. On the other hand, a non-decomposable metric is not meaningful @@ -638,7 +633,6 @@ interface SubscriptionService { * key. If no invoice grouping key is present, the metric does not support `group_by`. * * ## Matrix prices - * * When a billable metric is attached to a price that uses matrix pricing, it's important to * view usage grouped by those matrix dimensions. In this case, use the query parameters * `first_dimension_key`, `first_dimension_value` and `second_dimension_key`, @@ -718,7 +712,6 @@ interface SubscriptionService { * `start_date`. * * ## Fixed fee quantity transitions - * * The fixed fee quantity transitions for a fixed fee price interval can also be specified when * adding or editing by passing an array for `fixed_fee_quantity_transitions`. A fixed fee * quantity transition must have a `quantity` and an `effective_date`, which is the date after @@ -773,8 +766,8 @@ interface SubscriptionService { * This endpoint can be used to change an existing subscription's plan. It returns the * serialized updated subscription object. * - * The body parameter `change_option` determines when the plan change occurrs. Orb supports - * three options: + * The body parameter `change_option` determines when the plan change occurs. Orb supports three + * options: * - `end_of_subscription_term`: changes the plan at the end of the existing plan's term. * - Issuing this plan change request for a monthly subscription will keep the existing plan * active until the start of the subsequent month. Issuing this plan change request for a @@ -917,7 +910,6 @@ interface SubscriptionService { * cadence, type, and name of a price can not be overridden. * * ### Maximums, and minimums - * * Price overrides are used to update some or all prices in the target plan. Minimums and * maximums, much like price overrides, can be useful when a new customer has negotiated a new * or different minimum or maximum spend cap than the default for the plan. The request format @@ -925,12 +917,10 @@ interface SubscriptionService { * [subscription creation](create-subscription). * * ## Scheduling multiple plan changes - * * When scheduling multiple plan changes with the same date, the latest plan change on that day * takes effect. * * ## Prorations for in-advance fees - * * By default, Orb calculates the prorated difference in any fixed fees when making a plan * change, adjusting the customer balance as needed. For details on this behavior, see * [Modifying subscriptions](/product-catalog/modifying-subscriptions#prorations-for-in-advance-fees). diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/beta/ExternalPlanIdService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/beta/ExternalPlanIdService.kt index debd080e3..85ce049dc 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/beta/ExternalPlanIdService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/beta/ExternalPlanIdService.kt @@ -26,12 +26,7 @@ interface ExternalPlanIdService { */ fun withOptions(modifier: (ClientOptions.Builder) -> Unit): ExternalPlanIdService - /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in - * test mode. - * - * This endpoint allows the creation of a new plan version for an existing plan. - */ + /** This endpoint allows the creation of a new plan version for an existing plan. */ fun createPlanVersion( externalPlanId: String, params: BetaExternalPlanIdCreatePlanVersionParams, @@ -46,9 +41,6 @@ interface ExternalPlanIdService { ): PlanVersion /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in - * test mode. - * * This endpoint is used to fetch a plan version. It returns the phases, prices, and adjustments * present on this version of the plan. */ @@ -64,12 +56,7 @@ interface ExternalPlanIdService { requestOptions: RequestOptions = RequestOptions.none(), ): PlanVersion - /** - * This API endpoint is in beta and its interface may change. It is recommended for use only in - * test mode. - * - * This endpoint allows setting the default version of a plan. - */ + /** This endpoint allows setting the default version of a plan. */ fun setDefaultPlanVersion( externalPlanId: String, params: BetaExternalPlanIdSetDefaultPlanVersionParams, diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CostService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CostService.kt index fa039e1c6..55da94ad8 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CostService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CostService.kt @@ -45,7 +45,6 @@ interface CostService { * minimum committed spend. * * ## Fetching subscriptions - * * By default, this endpoint fetches the currently active subscription for the customer, and * returns cost information for the subscription's current billing period, broken down by each * participating price. If there are no currently active subscriptions, this will instead @@ -58,18 +57,16 @@ interface CostService { * summed, and prices for both subscriptions will be included in the breakdown. * * ## Prepaid plans - * * For plans that include prices which deduct credits rather than accrue in-arrears charges in a * billable currency, this endpoint will return the total deduction amount, in credits, for the * specified timeframe. * * ## Cumulative subtotals and totals - * * Since the subtotal and total must factor in any billing-period level discounts and minimums, * it's most meaningful to consider costs relative to the start of the subscription's billing * period. As a result, by default this endpoint returns cumulative totals since the beginning * of the billing period. In particular, the `timeframe_start` of a returned timeframe window is - * _always_ the beginning of the billing period and `timeframe_end` is incremented one day at a + * *always* the beginning of the billing period and `timeframe_end` is incremented one day at a * time to build the result. * * A customer that uses a few API calls a day but has a minimum commitment might exhibit the @@ -87,7 +84,6 @@ interface CostService { * | 2023-02-01 | 2023-02-06 | 36 | \$90.00 | \$90.00 | * * ### Periodic values - * * When the query parameter `view_mode=periodic` is specified, Orb will return an incremental * day-by-day view of costs. In this case, there will always be a one-day difference between * `timeframe_start` and `timeframe_end` for the timeframes returned. This is a transform on top @@ -97,7 +93,6 @@ interface CostService { * to the total cost. * * ## Timeframe bounds - * * For an active subscription, both timeframes should be specified in the request. If a * subscription starts or ends within the timeframe, the response will only include windows * where the subscription is active. If a subscription has ended, no timeframe bounds need to be @@ -129,7 +124,6 @@ interface CostService { * You can see this sliced timeframe visualized [here](https://i.imgur.com/TXhYgme.png). * * ### Matrix prices - * * When a price uses matrix pricing, it's important to view costs grouped by those matrix * dimensions. Orb will return `price_groups` with the `grouping_key` and * `secondary_grouping_key` based on the matrix price definition, for each `grouping_value` and @@ -172,7 +166,6 @@ interface CostService { * minimum committed spend. * * ## Fetching subscriptions - * * By default, this endpoint fetches the currently active subscription for the customer, and * returns cost information for the subscription's current billing period, broken down by each * participating price. If there are no currently active subscriptions, this will instead @@ -185,18 +178,16 @@ interface CostService { * summed, and prices for both subscriptions will be included in the breakdown. * * ## Prepaid plans - * * For plans that include prices which deduct credits rather than accrue in-arrears charges in a * billable currency, this endpoint will return the total deduction amount, in credits, for the * specified timeframe. * * ## Cumulative subtotals and totals - * * Since the subtotal and total must factor in any billing-period level discounts and minimums, * it's most meaningful to consider costs relative to the start of the subscription's billing * period. As a result, by default this endpoint returns cumulative totals since the beginning * of the billing period. In particular, the `timeframe_start` of a returned timeframe window is - * _always_ the beginning of the billing period and `timeframe_end` is incremented one day at a + * *always* the beginning of the billing period and `timeframe_end` is incremented one day at a * time to build the result. * * A customer that uses a few API calls a day but has a minimum commitment might exhibit the @@ -214,7 +205,6 @@ interface CostService { * | 2023-02-01 | 2023-02-06 | 36 | \$90.00 | \$90.00 | * * ### Periodic values - * * When the query parameter `view_mode=periodic` is specified, Orb will return an incremental * day-by-day view of costs. In this case, there will always be a one-day difference between * `timeframe_start` and `timeframe_end` for the timeframes returned. This is a transform on top @@ -224,7 +214,6 @@ interface CostService { * to the total cost. * * ## Timeframe bounds - * * For an active subscription, both timeframes should be specified in the request. If a * subscription starts or ends within the timeframe, the response will only include windows * where the subscription is active. If a subscription has ended, no timeframe bounds need to be @@ -256,7 +245,6 @@ interface CostService { * You can see this sliced timeframe visualized [here](https://i.imgur.com/TXhYgme.png). * * ### Matrix prices - * * When a price uses matrix pricing, it's important to view costs grouped by those matrix * dimensions. Orb will return `price_groups` with the `grouping_key` and * `secondary_grouping_key` based on the matrix price definition, for each `grouping_value` and diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerService.kt index 2368f1358..4f474397f 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerService.kt @@ -41,14 +41,12 @@ interface LedgerService { * There are four major types of modifications to credit balance, detailed below. * * ## Increment - * * Credits (which optionally expire on a future date) can be added via the API ([Add Ledger * Entry](create-ledger-entry)). The ledger entry for such an action will always contain the * total eligible starting and ending balance for the customer at the time the entry was added * to the ledger. * * ## Decrement - * * Deductions can occur as a result of an API call to create a ledger entry (see * [Add Ledger Entry](create-ledger-entry)), or automatically as a result of incurring usage. * Both ledger entries present the `decrement` entry type. @@ -60,14 +58,14 @@ interface LedgerService { * the `event_id` at the time of ingestion, used to pinpoint _why_ credit deduction took place * and to ensure that credits are never deducted without an associated usage event. * - * By default, Orb uses an algorithm that automatically deducts from the _soonest expiring - * credit block_ first in order to ensure that all credits are utilized appropriately. As an + * By default, Orb uses an algorithm that automatically deducts from the *soonest expiring + * credit block* first in order to ensure that all credits are utilized appropriately. As an * example, if trial credits with an expiration date of 2 weeks from now are present for a * customer, they will be used before any deductions take place from a non-expiring credit * block. * * If there are multiple blocks with the same expiration date, Orb will deduct from the block - * with the _lower cost basis_ first (e.g. trial credits with a \$0 cost basis before paid + * with the *lower cost basis* first (e.g. trial credits with a \$0 cost basis before paid * credits with a \$5.00 cost basis). * * It's also possible for a single usage event's deduction to _span_ credit blocks. In this @@ -77,34 +75,29 @@ interface LedgerService { * can be negative as a result of a decrement. * * ## Expiration change - * * The expiry of credits can be changed as a result of the API (See * [Add Ledger Entry](create-ledger-entry)). This will create a ledger entry that specifies the * balance as well as the initial and target expiry dates. * * Note that for this entry type, `starting_balance` will equal `ending_balance`, and the * `amount` represents the balance transferred. The credit block linked to the ledger entry is - * the source credit block from which there was an expiration change + * the source credit block from which there was an expiration change. * * ## Credits expiry - * * When a set of credits expire on pre-set expiration date, the customer's balance automatically * reflects this change and adds an entry to the ledger indicating this event. Note that credit * expiry should always happen close to a date boundary in the customer's timezone. * * ## Void initiated - * * Credit blocks can be voided via the API. The `amount` on this entry corresponds to the number * of credits that were remaining in the block at time of void. `void_reason` will be populated * if the void is created with a reason. * * ## Void - * * When a set of credits is voided, the customer's balance automatically reflects this change * and adds an entry to the ledger indicating this event. * * ## Amendment - * * When credits are added to a customer's balance as a result of a correction, this entry will * be added to the ledger to indicate the adjustment of credits. */ @@ -141,7 +134,6 @@ interface LedgerService { * the credits (based on `amount` and `per_unit_cost_basis`). * * ## Adding credits - * * Adding credits is done by creating an entry of type `increment`. This requires the caller to * specify a number of credits as well as an optional expiry date in `YYYY-MM-DD` format. Orb * also recommends specifying a description to assist with auditing. When adding credits, the @@ -165,7 +157,6 @@ interface LedgerService { * blocks before adding the remaining amount to the desired credit block. * * ### Invoicing for credits - * * By default, Orb manipulates the credit ledger but does not charge for credits. However, if * you pass `invoice_settings` in the body of this request, Orb will also generate a one-off * invoice for the customer for the credits pre-purchase. Note that you _must_ provide the @@ -173,7 +164,6 @@ interface LedgerService { * the cost basis with the number of credit units added. * * ## Deducting Credits - * * Orb allows you to deduct credits from a customer by creating an entry of type `decrement`. * Orb matches the algorithm for automatic deductions for determining which credit blocks to * decrement from. In the case that the deduction leads to multiple ledger entries, the response @@ -191,7 +181,6 @@ interface LedgerService { * ``` * * ## Changing credits expiry - * * If you'd like to change when existing credits expire, you should create a ledger entry of * type `expiration_change`. For this entry, the required parameter `expiry_date` identifies the * _originating_ block, and the required parameter `target_expiry_date` identifies when the @@ -257,7 +246,6 @@ interface LedgerService { * the credits (based on `amount` and `per_unit_cost_basis`). * * ## Adding credits - * * Adding credits is done by creating an entry of type `increment`. This requires the caller to * specify a number of credits as well as an optional expiry date in `YYYY-MM-DD` format. Orb * also recommends specifying a description to assist with auditing. When adding credits, the @@ -281,7 +269,6 @@ interface LedgerService { * blocks before adding the remaining amount to the desired credit block. * * ### Invoicing for credits - * * By default, Orb manipulates the credit ledger but does not charge for credits. However, if * you pass `invoice_settings` in the body of this request, Orb will also generate a one-off * invoice for the customer for the credits pre-purchase. Note that you _must_ provide the @@ -289,7 +276,6 @@ interface LedgerService { * the cost basis with the number of credit units added. * * ## Deducting Credits - * * Orb allows you to deduct credits from a customer by creating an entry of type `decrement`. * Orb matches the algorithm for automatic deductions for determining which credit blocks to * decrement from. In the case that the deduction leads to multiple ledger entries, the response @@ -307,7 +293,6 @@ interface LedgerService { * ``` * * ## Changing credits expiry - * * If you'd like to change when existing credits expire, you should create a ledger entry of * type `expiration_change`. For this entry, the required parameter `expiry_date` identifies the * _originating_ block, and the required parameter `target_expiry_date` identifies when the @@ -372,14 +357,12 @@ interface LedgerService { * There are four major types of modifications to credit balance, detailed below. * * ## Increment - * * Credits (which optionally expire on a future date) can be added via the API ([Add Ledger * Entry](create-ledger-entry)). The ledger entry for such an action will always contain the * total eligible starting and ending balance for the customer at the time the entry was added * to the ledger. * * ## Decrement - * * Deductions can occur as a result of an API call to create a ledger entry (see * [Add Ledger Entry](create-ledger-entry)), or automatically as a result of incurring usage. * Both ledger entries present the `decrement` entry type. @@ -391,14 +374,14 @@ interface LedgerService { * the `event_id` at the time of ingestion, used to pinpoint _why_ credit deduction took place * and to ensure that credits are never deducted without an associated usage event. * - * By default, Orb uses an algorithm that automatically deducts from the _soonest expiring - * credit block_ first in order to ensure that all credits are utilized appropriately. As an + * By default, Orb uses an algorithm that automatically deducts from the *soonest expiring + * credit block* first in order to ensure that all credits are utilized appropriately. As an * example, if trial credits with an expiration date of 2 weeks from now are present for a * customer, they will be used before any deductions take place from a non-expiring credit * block. * * If there are multiple blocks with the same expiration date, Orb will deduct from the block - * with the _lower cost basis_ first (e.g. trial credits with a \$0 cost basis before paid + * with the *lower cost basis* first (e.g. trial credits with a \$0 cost basis before paid * credits with a \$5.00 cost basis). * * It's also possible for a single usage event's deduction to _span_ credit blocks. In this @@ -408,34 +391,29 @@ interface LedgerService { * can be negative as a result of a decrement. * * ## Expiration change - * * The expiry of credits can be changed as a result of the API (See * [Add Ledger Entry](create-ledger-entry)). This will create a ledger entry that specifies the * balance as well as the initial and target expiry dates. * * Note that for this entry type, `starting_balance` will equal `ending_balance`, and the * `amount` represents the balance transferred. The credit block linked to the ledger entry is - * the source credit block from which there was an expiration change + * the source credit block from which there was an expiration change. * * ## Credits expiry - * * When a set of credits expire on pre-set expiration date, the customer's balance automatically * reflects this change and adds an entry to the ledger indicating this event. Note that credit * expiry should always happen close to a date boundary in the customer's timezone. * * ## Void initiated - * * Credit blocks can be voided via the API. The `amount` on this entry corresponds to the number * of credits that were remaining in the block at time of void. `void_reason` will be populated * if the void is created with a reason. * * ## Void - * * When a set of credits is voided, the customer's balance automatically reflects this change * and adds an entry to the ledger indicating this event. * * ## Amendment - * * When credits are added to a customer's balance as a result of a correction, this entry will * be added to the ledger to indicate the adjustment of credits. */ diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/events/BackfillService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/events/BackfillService.kt index 2dbaa7a8d..20e067321 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/events/BackfillService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/events/BackfillService.kt @@ -56,10 +56,13 @@ interface BackfillService { * * When `replace_existing_events` is `true`, this indicates that existing events in the * timeframe should no longer be counted towards invoiced usage. In this scenario, the parameter - * `filter` can be optionally added which enables filtering using + * `deprecation_filter` can be optionally added which enables filtering using * [computed properties](/extensibility/advanced-metrics#computed-properties). The * expressiveness of computed properties allows you to deprecate existing events based on both a * period of time and specific property values. + * + * You may not have multiple backfills in a pending or pending_revert state with overlapping + * timeframes. */ fun create( params: EventBackfillCreateParams, diff --git a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/plans/ExternalPlanIdService.kt b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/plans/ExternalPlanIdService.kt index bcc8e244c..1c1f345d6 100644 --- a/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/plans/ExternalPlanIdService.kt +++ b/orb-kotlin-core/src/main/kotlin/com/withorb/api/services/blocking/plans/ExternalPlanIdService.kt @@ -57,7 +57,6 @@ interface ExternalPlanIdService { * created plan. * * ## Serialized prices - * * Orb supports a few different pricing models out of the box. Each of these models is * serialized differently in a given [Price](/core-concepts#plan-and-price) object. The * `model_type` field determines the key for the configuration object that is present. A diff --git a/orb-kotlin-core/src/main/resources/META-INF/proguard/orb-kotlin-core.pro b/orb-kotlin-core/src/main/resources/META-INF/proguard/orb-kotlin-core.pro new file mode 100644 index 000000000..ac5f62da4 --- /dev/null +++ b/orb-kotlin-core/src/main/resources/META-INF/proguard/orb-kotlin-core.pro @@ -0,0 +1,32 @@ +# Jackson uses reflection and depends heavily on runtime attributes. +-keepattributes Exceptions,InnerClasses,Signature,Deprecated,*Annotation* + +# Jackson uses Kotlin reflection utilities, which themselves use reflection to access things. +-keep class kotlin.reflect.** { *; } +-keep class kotlin.Metadata { *; } + +# Jackson uses reflection to access enum members (e.g. via `java.lang.Class.getEnumConstants()`). +-keepclassmembers class com.fasterxml.jackson.** extends java.lang.Enum { + ; + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +# Jackson uses reflection to access annotation members. +-keepclassmembers @interface com.fasterxml.jackson.annotation.** { + *; +} + +# Jackson uses reified type information to serialize and deserialize our classes (via `TypeReference`). +-keep class com.fasterxml.jackson.core.type.TypeReference { *; } +-keep class * extends com.fasterxml.jackson.core.type.TypeReference { *; } + +# Jackson uses reflection to access our class serializers and deserializers. +-keep @com.fasterxml.jackson.databind.annotation.JsonSerialize class com.withorb.api.** { *; } +-keep @com.fasterxml.jackson.databind.annotation.JsonDeserialize class com.withorb.api.** { *; } + +# Jackson uses reflection to serialize and deserialize our classes based on their constructors and annotated members. +-keepclassmembers class com.withorb.api.** { + (...); + @com.fasterxml.jackson.annotation.* *; +} \ No newline at end of file diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/core/http/RetryingHttpClientTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/core/http/RetryingHttpClientTest.kt index b6bb4a629..e0b8d001c 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/core/http/RetryingHttpClientTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/core/http/RetryingHttpClientTest.kt @@ -6,6 +6,8 @@ import com.github.tomakehurst.wiremock.junit5.WireMockTest import com.github.tomakehurst.wiremock.stubbing.Scenario import com.withorb.api.client.okhttp.OkHttpClient import com.withorb.api.core.RequestOptions +import com.withorb.api.core.Sleeper +import com.withorb.api.errors.OrbRetryableException import java.io.InputStream import java.time.Duration import kotlinx.coroutines.runBlocking @@ -250,16 +252,91 @@ internal class RetryingHttpClientTest { assertNoResponseLeaks() } + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun execute_withRetryableException(async: Boolean) { + stubFor(post(urlPathEqualTo("/something")).willReturn(ok())) + + var callCount = 0 + val failingHttpClient = + object : HttpClient { + override fun execute( + request: HttpRequest, + requestOptions: RequestOptions, + ): HttpResponse { + callCount++ + if (callCount == 1) { + throw OrbRetryableException("Simulated retryable failure") + } + return httpClient.execute(request, requestOptions) + } + + override suspend fun executeAsync( + request: HttpRequest, + requestOptions: RequestOptions, + ): HttpResponse { + callCount++ + if (callCount == 1) { + throw OrbRetryableException("Simulated retryable failure") + } + return httpClient.executeAsync(request, requestOptions) + } + + override fun close() = httpClient.close() + } + + val retryingClient = + RetryingHttpClient.builder() + .httpClient(failingHttpClient) + .maxRetries(2) + .sleeper( + object : Sleeper { + + override fun sleep(duration: Duration) {} + + override suspend fun sleepAsync(duration: Duration) {} + + override fun close() {} + } + ) + .build() + + val response = + retryingClient.execute( + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(baseUrl) + .addPathSegment("something") + .build(), + async, + ) + + assertThat(response.statusCode()).isEqualTo(200) + verify( + 1, + postRequestedFor(urlPathEqualTo("/something")) + .withHeader("x-stainless-retry-count", equalTo("1")), + ) + verify( + 0, + postRequestedFor(urlPathEqualTo("/something")) + .withHeader("x-stainless-retry-count", equalTo("0")), + ) + assertNoResponseLeaks() + } + private fun retryingHttpClientBuilder() = RetryingHttpClient.builder() .httpClient(httpClient) // Use a no-op `Sleeper` to make the test fast. .sleeper( - object : RetryingHttpClient.Sleeper { + object : Sleeper { override fun sleep(duration: Duration) {} override suspend fun sleepAsync(duration: Duration) {} + + override fun close() {} } ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AdjustmentIntervalTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AdjustmentIntervalTest.kt index d65ea1e19..113614f26 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AdjustmentIntervalTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AdjustmentIntervalTest.kt @@ -23,9 +23,9 @@ internal class AdjustmentIntervalTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -52,9 +52,9 @@ internal class AdjustmentIntervalTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -87,9 +87,9 @@ internal class AdjustmentIntervalTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AffectedBlockTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AffectedBlockTest.kt index 06d3e4c3f..72ea64455 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AffectedBlockTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AffectedBlockTest.kt @@ -16,12 +16,27 @@ internal class AffectedBlockTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() assertThat(affectedBlock.id()).isEqualTo("id") assertThat(affectedBlock.expiryDate()) .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(affectedBlock.filters()) + .containsExactly( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) assertThat(affectedBlock.perUnitCostBasis()).isEqualTo("per_unit_cost_basis") } @@ -32,6 +47,13 @@ internal class AffectedBlockTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AggregatedCostTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AggregatedCostTest.kt index f62a16ed1..49e22110c 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AggregatedCostTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AggregatedCostTest.kt @@ -18,7 +18,7 @@ internal class AggregatedCostTest { .addPerPriceCost( PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -27,7 +27,17 @@ internal class AggregatedCostTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -45,6 +55,13 @@ internal class AggregatedCostTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -55,9 +72,11 @@ internal class AggregatedCostTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -77,9 +96,9 @@ internal class AggregatedCostTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -88,7 +107,7 @@ internal class AggregatedCostTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -96,9 +115,9 @@ internal class AggregatedCostTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -108,9 +127,14 @@ internal class AggregatedCostTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -135,7 +159,7 @@ internal class AggregatedCostTest { .containsExactly( PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -144,7 +168,17 @@ internal class AggregatedCostTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -160,6 +194,13 @@ internal class AggregatedCostTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -170,9 +211,9 @@ internal class AggregatedCostTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -192,9 +233,9 @@ internal class AggregatedCostTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -203,7 +244,7 @@ internal class AggregatedCostTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -211,9 +252,9 @@ internal class AggregatedCostTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -223,9 +264,14 @@ internal class AggregatedCostTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -256,7 +302,7 @@ internal class AggregatedCostTest { .addPerPriceCost( PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -265,7 +311,17 @@ internal class AggregatedCostTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -283,6 +339,13 @@ internal class AggregatedCostTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -293,9 +356,11 @@ internal class AggregatedCostTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -315,9 +380,9 @@ internal class AggregatedCostTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -326,7 +391,7 @@ internal class AggregatedCostTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -334,9 +399,9 @@ internal class AggregatedCostTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -346,9 +411,14 @@ internal class AggregatedCostTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AllocationTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AllocationTest.kt index cdfd4fd9f..4af9f1f77 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AllocationTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AllocationTest.kt @@ -21,6 +21,13 @@ internal class AllocationTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() assertThat(allocation.allowsRollover()).isEqualTo(true) @@ -32,6 +39,14 @@ internal class AllocationTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + assertThat(allocation.filters()) + .containsExactly( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) } @Test @@ -47,6 +62,13 @@ internal class AllocationTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() val roundtrippedAllocation = diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AmendmentLedgerEntryTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AmendmentLedgerEntryTest.kt index cc4b7e787..bc610d8e2 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AmendmentLedgerEntryTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AmendmentLedgerEntryTest.kt @@ -22,6 +22,13 @@ internal class AmendmentLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -54,6 +61,13 @@ internal class AmendmentLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -93,6 +107,13 @@ internal class AmendmentLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AmountDiscountIntervalTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AmountDiscountIntervalTest.kt index 035130c18..7e1631690 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AmountDiscountIntervalTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AmountDiscountIntervalTest.kt @@ -19,9 +19,9 @@ internal class AmountDiscountIntervalTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -36,9 +36,9 @@ internal class AmountDiscountIntervalTest { .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(amountDiscountInterval.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -56,9 +56,9 @@ internal class AmountDiscountIntervalTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AmountDiscountTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AmountDiscountTest.kt index 43b88c98f..cb748300d 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AmountDiscountTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/AmountDiscountTest.kt @@ -18,9 +18,9 @@ internal class AmountDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscount.Filter.builder() + .field(AmountDiscount.Filter.Field.PRICE_ID) + .operator(AmountDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -33,9 +33,9 @@ internal class AmountDiscountTest { .containsExactly("h74gfhdjvn7ujokd", "7hfgtgjnbvc3ujkl") assertThat(amountDiscount.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscount.Filter.builder() + .field(AmountDiscount.Filter.Field.PRICE_ID) + .operator(AmountDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -52,9 +52,9 @@ internal class AmountDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscount.Filter.builder() + .field(AmountDiscount.Filter.Field.PRICE_ID) + .operator(AmountDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BetaCreatePlanVersionParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BetaCreatePlanVersionParamsTest.kt index 641af6239..459c41e11 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BetaCreatePlanVersionParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BetaCreatePlanVersionParamsTest.kt @@ -28,9 +28,9 @@ internal class BetaCreatePlanVersionParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -55,6 +55,15 @@ internal class BetaCreatePlanVersionParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -64,7 +73,12 @@ internal class BetaCreatePlanVersionParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -133,9 +147,9 @@ internal class BetaCreatePlanVersionParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -162,6 +176,15 @@ internal class BetaCreatePlanVersionParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -171,7 +194,12 @@ internal class BetaCreatePlanVersionParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -247,9 +275,9 @@ internal class BetaCreatePlanVersionParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -274,6 +302,15 @@ internal class BetaCreatePlanVersionParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -283,7 +320,12 @@ internal class BetaCreatePlanVersionParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -354,9 +396,9 @@ internal class BetaCreatePlanVersionParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -383,6 +425,15 @@ internal class BetaCreatePlanVersionParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -392,7 +443,12 @@ internal class BetaCreatePlanVersionParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -458,9 +514,9 @@ internal class BetaCreatePlanVersionParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -486,6 +542,15 @@ internal class BetaCreatePlanVersionParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -495,7 +560,12 @@ internal class BetaCreatePlanVersionParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -567,9 +637,9 @@ internal class BetaCreatePlanVersionParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -597,6 +667,15 @@ internal class BetaCreatePlanVersionParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -606,7 +685,12 @@ internal class BetaCreatePlanVersionParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BetaExternalPlanIdCreatePlanVersionParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BetaExternalPlanIdCreatePlanVersionParamsTest.kt index c05f7acc8..22acc6b4a 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BetaExternalPlanIdCreatePlanVersionParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BetaExternalPlanIdCreatePlanVersionParamsTest.kt @@ -28,9 +28,9 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -55,6 +55,15 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -64,7 +73,12 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -133,9 +147,9 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -162,6 +176,15 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -171,7 +194,12 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -251,9 +279,9 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -278,6 +306,15 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -287,7 +324,12 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -358,9 +400,9 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -387,6 +429,15 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -396,7 +447,12 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -462,9 +518,9 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -490,6 +546,15 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -499,7 +564,12 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -571,9 +641,9 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -601,6 +671,15 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -610,7 +689,12 @@ internal class BetaExternalPlanIdCreatePlanVersionParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BillableMetricTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BillableMetricTest.kt index c6327f899..887177dbb 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BillableMetricTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BillableMetricTest.kt @@ -35,6 +35,7 @@ internal class BillableMetricTest { .build() ) .name("name") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .metadata( @@ -67,6 +68,7 @@ internal class BillableMetricTest { .build() ) .name("name") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) assertThat(billableMetric.metadata()) @@ -104,6 +106,7 @@ internal class BillableMetricTest { .build() ) .name("name") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .metadata( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BpsConfigTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BpsConfigTest.kt deleted file mode 100644 index 0c5056b3f..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BpsConfigTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class BpsConfigTest { - - @Test - fun create() { - val bpsConfig = BpsConfig.builder().bps(0.0).perUnitMaximum("per_unit_maximum").build() - - assertThat(bpsConfig.bps()).isEqualTo(0.0) - assertThat(bpsConfig.perUnitMaximum()).isEqualTo("per_unit_maximum") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val bpsConfig = BpsConfig.builder().bps(0.0).perUnitMaximum("per_unit_maximum").build() - - val roundtrippedBpsConfig = - jsonMapper.readValue( - jsonMapper.writeValueAsString(bpsConfig), - jacksonTypeRef(), - ) - - assertThat(roundtrippedBpsConfig).isEqualTo(bpsConfig) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BpsTierTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BpsTierTest.kt deleted file mode 100644 index 068a3488b..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BpsTierTest.kt +++ /dev/null @@ -1,44 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class BpsTierTest { - - @Test - fun create() { - val bpsTier = - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - - assertThat(bpsTier.bps()).isEqualTo(0.0) - assertThat(bpsTier.minimumAmount()).isEqualTo("minimum_amount") - assertThat(bpsTier.maximumAmount()).isEqualTo("maximum_amount") - assertThat(bpsTier.perUnitMaximum()).isEqualTo("per_unit_maximum") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val bpsTier = - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - - val roundtrippedBpsTier = - jsonMapper.readValue(jsonMapper.writeValueAsString(bpsTier), jacksonTypeRef()) - - assertThat(roundtrippedBpsTier).isEqualTo(bpsTier) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BulkBpsConfigTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BulkBpsConfigTest.kt deleted file mode 100644 index 8ff08186e..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BulkBpsConfigTest.kt +++ /dev/null @@ -1,57 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class BulkBpsConfigTest { - - @Test - fun create() { - val bulkBpsConfig = - BulkBpsConfig.builder() - .addTier( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - - assertThat(bulkBpsConfig.tiers()) - .containsExactly( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val bulkBpsConfig = - BulkBpsConfig.builder() - .addTier( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - - val roundtrippedBulkBpsConfig = - jsonMapper.readValue( - jsonMapper.writeValueAsString(bulkBpsConfig), - jacksonTypeRef(), - ) - - assertThat(roundtrippedBulkBpsConfig).isEqualTo(bulkBpsConfig) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BulkBpsTierTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BulkBpsTierTest.kt deleted file mode 100644 index 426b9b50a..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/BulkBpsTierTest.kt +++ /dev/null @@ -1,44 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class BulkBpsTierTest { - - @Test - fun create() { - val bulkBpsTier = - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - - assertThat(bulkBpsTier.bps()).isEqualTo(0.0) - assertThat(bulkBpsTier.maximumAmount()).isEqualTo("maximum_amount") - assertThat(bulkBpsTier.perUnitMaximum()).isEqualTo("per_unit_maximum") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val bulkBpsTier = - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - - val roundtrippedBulkBpsTier = - jsonMapper.readValue( - jsonMapper.writeValueAsString(bulkBpsTier), - jacksonTypeRef(), - ) - - assertThat(roundtrippedBulkBpsTier).isEqualTo(bulkBpsTier) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ChangedSubscriptionResourcesTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ChangedSubscriptionResourcesTest.kt index 05ee64f7c..a013bd44b 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ChangedSubscriptionResourcesTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ChangedSubscriptionResourcesTest.kt @@ -102,11 +102,11 @@ internal class ChangedSubscriptionResourcesTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice.AutoCollection.builder() .enabled(true) .nextAttemptAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .numAttempts(0L) @@ -127,7 +127,7 @@ internal class ChangedSubscriptionResourcesTest { ) .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote.builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -145,10 +145,14 @@ internal class ChangedSubscriptionResourcesTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice.CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action.APPLIED_TO_INVOICE + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action + .APPLIED_TO_INVOICE ) .amount("11.00") .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) @@ -157,7 +161,12 @@ internal class ChangedSubscriptionResourcesTest { .endingBalance("22.00") .invoice(InvoiceTiny.builder().id("gXcsPTVyC4YZa3Sc").build()) .startingBalance("33.00") - .type(Invoice.CustomerBalanceTransaction.Type.INCREMENT) + .type( + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type + .INCREMENT + ) .build() ) .customerTaxId( @@ -175,9 +184,9 @@ internal class ChangedSubscriptionResourcesTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -192,11 +201,14 @@ internal class ChangedSubscriptionResourcesTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice.InvoiceSource.SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem.builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -209,9 +221,15 @@ internal class ChangedSubscriptionResourcesTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -223,57 +241,13 @@ internal class ChangedSubscriptionResourcesTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -286,7 +260,21 @@ internal class ChangedSubscriptionResourcesTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -306,6 +294,15 @@ internal class ChangedSubscriptionResourcesTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -318,10 +315,13 @@ internal class ChangedSubscriptionResourcesTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -344,11 +344,9 @@ internal class ChangedSubscriptionResourcesTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -357,7 +355,7 @@ internal class ChangedSubscriptionResourcesTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -368,11 +366,9 @@ internal class ChangedSubscriptionResourcesTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -382,10 +378,13 @@ internal class ChangedSubscriptionResourcesTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -416,6 +415,7 @@ internal class ChangedSubscriptionResourcesTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -433,9 +433,9 @@ internal class ChangedSubscriptionResourcesTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -445,7 +445,7 @@ internal class ChangedSubscriptionResourcesTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -453,9 +453,9 @@ internal class ChangedSubscriptionResourcesTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -465,12 +465,19 @@ internal class ChangedSubscriptionResourcesTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice.PaymentAttempt.builder() .id("id") .amount("amount") .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) - .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) + .paymentProvider( + ChangedSubscriptionResources.CreatedInvoice.PaymentAttempt + .PaymentProvider + .STRIPE + ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -487,7 +494,7 @@ internal class ChangedSubscriptionResourcesTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status(ChangedSubscriptionResources.CreatedInvoice.Status.ISSUED) .subscription(SubscriptionMinified.builder().id("VDGsT23osdLb84KD").build()) .subtotal("8.00") .syncFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) @@ -656,9 +663,9 @@ internal class ChangedSubscriptionResourcesTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -690,9 +697,15 @@ internal class ChangedSubscriptionResourcesTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -704,57 +717,13 @@ internal class ChangedSubscriptionResourcesTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -767,7 +736,21 @@ internal class ChangedSubscriptionResourcesTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -787,6 +770,15 @@ internal class ChangedSubscriptionResourcesTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -799,10 +791,13 @@ internal class ChangedSubscriptionResourcesTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -825,11 +820,9 @@ internal class ChangedSubscriptionResourcesTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -838,7 +831,7 @@ internal class ChangedSubscriptionResourcesTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -849,11 +842,9 @@ internal class ChangedSubscriptionResourcesTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -863,10 +854,13 @@ internal class ChangedSubscriptionResourcesTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -897,6 +891,7 @@ internal class ChangedSubscriptionResourcesTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -914,9 +909,9 @@ internal class ChangedSubscriptionResourcesTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -934,9 +929,9 @@ internal class ChangedSubscriptionResourcesTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -952,6 +947,9 @@ internal class ChangedSubscriptionResourcesTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -1066,11 +1064,11 @@ internal class ChangedSubscriptionResourcesTest { ) assertThat(changedSubscriptionResources.createdInvoices()) .containsExactly( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice.AutoCollection.builder() .enabled(true) .nextAttemptAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .numAttempts(0L) @@ -1089,7 +1087,7 @@ internal class ChangedSubscriptionResourcesTest { ) .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote.builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -1107,9 +1105,15 @@ internal class ChangedSubscriptionResourcesTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice.CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") - .action(Invoice.CustomerBalanceTransaction.Action.APPLIED_TO_INVOICE) + .action( + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action + .APPLIED_TO_INVOICE + ) .amount("11.00") .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) .creditNote(CreditNoteTiny.builder().id("id").build()) @@ -1117,7 +1121,12 @@ internal class ChangedSubscriptionResourcesTest { .endingBalance("22.00") .invoice(InvoiceTiny.builder().id("gXcsPTVyC4YZa3Sc").build()) .startingBalance("33.00") - .type(Invoice.CustomerBalanceTransaction.Type.INCREMENT) + .type( + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type + .INCREMENT + ) .build() ) .customerTaxId( @@ -1135,9 +1144,9 @@ internal class ChangedSubscriptionResourcesTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1152,11 +1161,14 @@ internal class ChangedSubscriptionResourcesTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice.InvoiceSource.SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem.builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -1169,9 +1181,15 @@ internal class ChangedSubscriptionResourcesTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -1183,57 +1201,13 @@ internal class ChangedSubscriptionResourcesTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1244,7 +1218,20 @@ internal class ChangedSubscriptionResourcesTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1262,6 +1249,13 @@ internal class ChangedSubscriptionResourcesTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1274,10 +1268,10 @@ internal class ChangedSubscriptionResourcesTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -1300,11 +1294,9 @@ internal class ChangedSubscriptionResourcesTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1313,7 +1305,7 @@ internal class ChangedSubscriptionResourcesTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1321,11 +1313,9 @@ internal class ChangedSubscriptionResourcesTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1335,10 +1325,13 @@ internal class ChangedSubscriptionResourcesTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -1367,6 +1360,7 @@ internal class ChangedSubscriptionResourcesTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1384,9 +1378,9 @@ internal class ChangedSubscriptionResourcesTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1396,7 +1390,7 @@ internal class ChangedSubscriptionResourcesTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1404,9 +1398,9 @@ internal class ChangedSubscriptionResourcesTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1416,12 +1410,19 @@ internal class ChangedSubscriptionResourcesTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice.PaymentAttempt.builder() .id("id") .amount("amount") .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) - .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) + .paymentProvider( + ChangedSubscriptionResources.CreatedInvoice.PaymentAttempt + .PaymentProvider + .STRIPE + ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -1438,7 +1439,7 @@ internal class ChangedSubscriptionResourcesTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status(ChangedSubscriptionResources.CreatedInvoice.Status.ISSUED) .subscription(SubscriptionMinified.builder().id("VDGsT23osdLb84KD").build()) .subtotal("8.00") .syncFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) @@ -1603,9 +1604,9 @@ internal class ChangedSubscriptionResourcesTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1637,9 +1638,15 @@ internal class ChangedSubscriptionResourcesTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -1651,57 +1658,13 @@ internal class ChangedSubscriptionResourcesTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1712,7 +1675,20 @@ internal class ChangedSubscriptionResourcesTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1730,6 +1706,13 @@ internal class ChangedSubscriptionResourcesTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1742,10 +1725,10 @@ internal class ChangedSubscriptionResourcesTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -1768,11 +1751,9 @@ internal class ChangedSubscriptionResourcesTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1781,7 +1762,7 @@ internal class ChangedSubscriptionResourcesTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1789,11 +1770,9 @@ internal class ChangedSubscriptionResourcesTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1803,10 +1782,13 @@ internal class ChangedSubscriptionResourcesTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -1835,6 +1817,7 @@ internal class ChangedSubscriptionResourcesTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1852,9 +1835,9 @@ internal class ChangedSubscriptionResourcesTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1872,9 +1855,9 @@ internal class ChangedSubscriptionResourcesTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1890,6 +1873,9 @@ internal class ChangedSubscriptionResourcesTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -2009,11 +1995,11 @@ internal class ChangedSubscriptionResourcesTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice.AutoCollection.builder() .enabled(true) .nextAttemptAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .numAttempts(0L) @@ -2034,7 +2020,7 @@ internal class ChangedSubscriptionResourcesTest { ) .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote.builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -2052,10 +2038,14 @@ internal class ChangedSubscriptionResourcesTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice.CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action.APPLIED_TO_INVOICE + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action + .APPLIED_TO_INVOICE ) .amount("11.00") .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) @@ -2064,7 +2054,12 @@ internal class ChangedSubscriptionResourcesTest { .endingBalance("22.00") .invoice(InvoiceTiny.builder().id("gXcsPTVyC4YZa3Sc").build()) .startingBalance("33.00") - .type(Invoice.CustomerBalanceTransaction.Type.INCREMENT) + .type( + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type + .INCREMENT + ) .build() ) .customerTaxId( @@ -2082,9 +2077,9 @@ internal class ChangedSubscriptionResourcesTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2099,11 +2094,14 @@ internal class ChangedSubscriptionResourcesTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice.InvoiceSource.SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem.builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -2116,9 +2114,15 @@ internal class ChangedSubscriptionResourcesTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -2130,57 +2134,13 @@ internal class ChangedSubscriptionResourcesTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -2193,7 +2153,21 @@ internal class ChangedSubscriptionResourcesTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -2213,6 +2187,15 @@ internal class ChangedSubscriptionResourcesTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2225,10 +2208,13 @@ internal class ChangedSubscriptionResourcesTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -2251,11 +2237,9 @@ internal class ChangedSubscriptionResourcesTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2264,7 +2248,7 @@ internal class ChangedSubscriptionResourcesTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -2275,11 +2259,9 @@ internal class ChangedSubscriptionResourcesTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2289,10 +2271,13 @@ internal class ChangedSubscriptionResourcesTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -2323,6 +2308,7 @@ internal class ChangedSubscriptionResourcesTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -2340,9 +2326,9 @@ internal class ChangedSubscriptionResourcesTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2352,7 +2338,7 @@ internal class ChangedSubscriptionResourcesTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2360,9 +2346,9 @@ internal class ChangedSubscriptionResourcesTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2372,12 +2358,19 @@ internal class ChangedSubscriptionResourcesTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice.PaymentAttempt.builder() .id("id") .amount("amount") .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) - .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) + .paymentProvider( + ChangedSubscriptionResources.CreatedInvoice.PaymentAttempt + .PaymentProvider + .STRIPE + ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -2394,7 +2387,7 @@ internal class ChangedSubscriptionResourcesTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status(ChangedSubscriptionResources.CreatedInvoice.Status.ISSUED) .subscription(SubscriptionMinified.builder().id("VDGsT23osdLb84KD").build()) .subtotal("8.00") .syncFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) @@ -2563,9 +2556,9 @@ internal class ChangedSubscriptionResourcesTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2597,9 +2590,15 @@ internal class ChangedSubscriptionResourcesTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -2611,57 +2610,13 @@ internal class ChangedSubscriptionResourcesTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -2674,7 +2629,21 @@ internal class ChangedSubscriptionResourcesTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -2694,6 +2663,15 @@ internal class ChangedSubscriptionResourcesTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2706,10 +2684,13 @@ internal class ChangedSubscriptionResourcesTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -2732,11 +2713,9 @@ internal class ChangedSubscriptionResourcesTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2745,7 +2724,7 @@ internal class ChangedSubscriptionResourcesTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -2756,11 +2735,9 @@ internal class ChangedSubscriptionResourcesTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2770,10 +2747,13 @@ internal class ChangedSubscriptionResourcesTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -2804,6 +2784,7 @@ internal class ChangedSubscriptionResourcesTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -2821,9 +2802,9 @@ internal class ChangedSubscriptionResourcesTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2841,9 +2822,9 @@ internal class ChangedSubscriptionResourcesTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2859,6 +2840,9 @@ internal class ChangedSubscriptionResourcesTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ConversionRateConfigTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ConversionRateConfigTest.kt new file mode 100644 index 000000000..cd6b8912e --- /dev/null +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ConversionRateConfigTest.kt @@ -0,0 +1,124 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.JsonValue +import com.withorb.api.core.jsonMapper +import com.withorb.api.errors.OrbInvalidDataException +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +internal class ConversionRateConfigTest { + + @Test + fun ofUnit() { + val unit = + UnitConversionRateConfig.builder() + .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + .unitConfig(ConversionRateUnitConfig.builder().unitAmount("unit_amount").build()) + .build() + + val conversionRateConfig = ConversionRateConfig.ofUnit(unit) + + assertThat(conversionRateConfig.unit()).isEqualTo(unit) + assertThat(conversionRateConfig.tiered()).isNull() + } + + @Test + fun ofUnitRoundtrip() { + val jsonMapper = jsonMapper() + val conversionRateConfig = + ConversionRateConfig.ofUnit( + UnitConversionRateConfig.builder() + .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + .unitConfig( + ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() + ) + .build() + ) + + val roundtrippedConversionRateConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(conversionRateConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedConversionRateConfig).isEqualTo(conversionRateConfig) + } + + @Test + fun ofTiered() { + val tiered = + TieredConversionRateConfig.builder() + .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + .tieredConfig( + ConversionRateTieredConfig.builder() + .addTier( + ConversionRateTier.builder() + .firstUnit(0.0) + .unitAmount("unit_amount") + .lastUnit(0.0) + .build() + ) + .build() + ) + .build() + + val conversionRateConfig = ConversionRateConfig.ofTiered(tiered) + + assertThat(conversionRateConfig.unit()).isNull() + assertThat(conversionRateConfig.tiered()).isEqualTo(tiered) + } + + @Test + fun ofTieredRoundtrip() { + val jsonMapper = jsonMapper() + val conversionRateConfig = + ConversionRateConfig.ofTiered( + TieredConversionRateConfig.builder() + .conversionRateType(TieredConversionRateConfig.ConversionRateType.TIERED) + .tieredConfig( + ConversionRateTieredConfig.builder() + .addTier( + ConversionRateTier.builder() + .firstUnit(0.0) + .unitAmount("unit_amount") + .lastUnit(0.0) + .build() + ) + .build() + ) + .build() + ) + + val roundtrippedConversionRateConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(conversionRateConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedConversionRateConfig).isEqualTo(conversionRateConfig) + } + + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { + BOOLEAN(JsonValue.from(false)), + STRING(JsonValue.from("invalid")), + INTEGER(JsonValue.from(-1)), + FLOAT(JsonValue.from(3.14)), + ARRAY(JsonValue.from(listOf("invalid", "array"))), + } + + @ParameterizedTest + @EnumSource + fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { + val conversionRateConfig = + jsonMapper().convertValue(testCase.value, jacksonTypeRef()) + + val e = assertThrows { conversionRateConfig.validate() } + assertThat(e).hasMessageStartingWith("Unknown ") + } +} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CouponListPageResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CouponListPageResponseTest.kt index f452c3109..d89b824cf 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CouponListPageResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CouponListPageResponseTest.kt @@ -25,9 +25,9 @@ internal class CouponListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -57,9 +57,9 @@ internal class CouponListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -92,9 +92,9 @@ internal class CouponListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CouponTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CouponTest.kt index 73a5ec822..f354410bd 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CouponTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CouponTest.kt @@ -23,9 +23,9 @@ internal class CouponTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -49,9 +49,9 @@ internal class CouponTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -79,9 +79,9 @@ internal class CouponTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CreditBlockExpiryLedgerEntryTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CreditBlockExpiryLedgerEntryTest.kt index 2e59cc5b4..4a015a24f 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CreditBlockExpiryLedgerEntryTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CreditBlockExpiryLedgerEntryTest.kt @@ -22,6 +22,13 @@ internal class CreditBlockExpiryLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -54,6 +61,13 @@ internal class CreditBlockExpiryLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -93,6 +107,13 @@ internal class CreditBlockExpiryLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCostListByExternalIdResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCostListByExternalIdResponseTest.kt index 21dd041d4..390cc855b 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCostListByExternalIdResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCostListByExternalIdResponseTest.kt @@ -20,7 +20,7 @@ internal class CustomerCostListByExternalIdResponseTest { .addPerPriceCost( PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -33,7 +33,21 @@ internal class CustomerCostListByExternalIdResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -53,6 +67,15 @@ internal class CustomerCostListByExternalIdResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -65,10 +88,13 @@ internal class CustomerCostListByExternalIdResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -91,11 +117,9 @@ internal class CustomerCostListByExternalIdResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -104,7 +128,7 @@ internal class CustomerCostListByExternalIdResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -115,11 +139,9 @@ internal class CustomerCostListByExternalIdResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -129,10 +151,13 @@ internal class CustomerCostListByExternalIdResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -164,7 +189,7 @@ internal class CustomerCostListByExternalIdResponseTest { .addPerPriceCost( PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -175,7 +200,20 @@ internal class CustomerCostListByExternalIdResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -193,6 +231,13 @@ internal class CustomerCostListByExternalIdResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -205,10 +250,10 @@ internal class CustomerCostListByExternalIdResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -231,11 +276,9 @@ internal class CustomerCostListByExternalIdResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -244,7 +287,7 @@ internal class CustomerCostListByExternalIdResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -252,11 +295,9 @@ internal class CustomerCostListByExternalIdResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -266,10 +307,13 @@ internal class CustomerCostListByExternalIdResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -303,7 +347,7 @@ internal class CustomerCostListByExternalIdResponseTest { .addPerPriceCost( PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -316,7 +360,21 @@ internal class CustomerCostListByExternalIdResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -336,6 +394,15 @@ internal class CustomerCostListByExternalIdResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -348,10 +415,13 @@ internal class CustomerCostListByExternalIdResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -374,11 +444,9 @@ internal class CustomerCostListByExternalIdResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -387,7 +455,7 @@ internal class CustomerCostListByExternalIdResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -398,11 +466,9 @@ internal class CustomerCostListByExternalIdResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -412,10 +478,13 @@ internal class CustomerCostListByExternalIdResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCostListResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCostListResponseTest.kt index d6bcaf783..c27926b62 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCostListResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCostListResponseTest.kt @@ -20,7 +20,7 @@ internal class CustomerCostListResponseTest { .addPerPriceCost( PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -33,7 +33,21 @@ internal class CustomerCostListResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -53,6 +67,15 @@ internal class CustomerCostListResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -65,10 +88,13 @@ internal class CustomerCostListResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -91,11 +117,9 @@ internal class CustomerCostListResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -104,7 +128,7 @@ internal class CustomerCostListResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -115,11 +139,9 @@ internal class CustomerCostListResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -129,10 +151,13 @@ internal class CustomerCostListResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -164,7 +189,7 @@ internal class CustomerCostListResponseTest { .addPerPriceCost( PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -175,7 +200,20 @@ internal class CustomerCostListResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -193,6 +231,13 @@ internal class CustomerCostListResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -205,10 +250,10 @@ internal class CustomerCostListResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -231,11 +276,9 @@ internal class CustomerCostListResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -244,7 +287,7 @@ internal class CustomerCostListResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -252,11 +295,9 @@ internal class CustomerCostListResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -266,10 +307,13 @@ internal class CustomerCostListResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -303,7 +347,7 @@ internal class CustomerCostListResponseTest { .addPerPriceCost( PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -316,7 +360,21 @@ internal class CustomerCostListResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -336,6 +394,15 @@ internal class CustomerCostListResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -348,10 +415,13 @@ internal class CustomerCostListResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -374,11 +444,9 @@ internal class CustomerCostListResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -387,7 +455,7 @@ internal class CustomerCostListResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -398,11 +466,9 @@ internal class CustomerCostListResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -412,10 +478,13 @@ internal class CustomerCostListResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreateParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreateParamsTest.kt index 163b89ce3..cae6f5600 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreateParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreateParamsTest.kt @@ -26,6 +26,7 @@ internal class CustomerCreateParamsTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -50,6 +51,20 @@ internal class CustomerCreateParamsTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider.builder() + .providerType( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration(NewReportingConfiguration.builder().exempt(true).build()) @@ -67,6 +82,7 @@ internal class CustomerCreateParamsTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -100,6 +116,7 @@ internal class CustomerCreateParamsTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -124,6 +141,20 @@ internal class CustomerCreateParamsTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider.builder() + .providerType( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration(NewReportingConfiguration.builder().exempt(true).build()) @@ -141,6 +172,7 @@ internal class CustomerCreateParamsTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -172,6 +204,7 @@ internal class CustomerCreateParamsTest { ) assertThat(body.additionalEmails()).containsExactly("dev@stainless.com") assertThat(body.autoCollection()).isEqualTo(true) + assertThat(body.autoIssuance()).isEqualTo(true) assertThat(body.billingAddress()) .isEqualTo( AddressInput.builder() @@ -199,6 +232,21 @@ internal class CustomerCreateParamsTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + assertThat(body.paymentConfiguration()) + .isEqualTo( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider.builder() + .providerType( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) assertThat(body.paymentProvider()) .isEqualTo(CustomerCreateParams.PaymentProvider.QUICKBOOKS) assertThat(body.paymentProviderId()).isEqualTo("payment_provider_id") @@ -221,6 +269,7 @@ internal class CustomerCreateParamsTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParamsTest.kt index 23a9caafa..8d29cb30a 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParamsTest.kt @@ -21,14 +21,34 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdParamsTest { .description("description") .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment.Filter + .builder() + .field( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment + .Filter + .Field + .ITEM_ID + ) + .operator( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment + .Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .invoiceSettings( CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment .InvoiceSettings .builder() .autoCollection(true) - .netTerms(0L) + .customDueDate(LocalDate.parse("2019-12-27")) .invoiceDate(LocalDate.parse("2019-12-27")) + .itemId("item_id") .memo("memo") + .netTerms(0L) .requireSuccessfulPayment(true) .build() ) @@ -69,14 +89,34 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdParamsTest { .description("description") .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment.Filter + .builder() + .field( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment + .Filter + .Field + .ITEM_ID + ) + .operator( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment + .Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .invoiceSettings( CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment .InvoiceSettings .builder() .autoCollection(true) - .netTerms(0L) + .customDueDate(LocalDate.parse("2019-12-27")) .invoiceDate(LocalDate.parse("2019-12-27")) + .itemId("item_id") .memo("memo") + .netTerms(0L) .requireSuccessfulPayment(true) .build() ) @@ -103,14 +143,34 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdParamsTest { .description("description") .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment.Filter + .builder() + .field( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment + .Filter + .Field + .ITEM_ID + ) + .operator( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment + .Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .invoiceSettings( CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment .InvoiceSettings .builder() .autoCollection(true) - .netTerms(0L) + .customDueDate(LocalDate.parse("2019-12-27")) .invoiceDate(LocalDate.parse("2019-12-27")) + .itemId("item_id") .memo("memo") + .netTerms(0L) .requireSuccessfulPayment(true) .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdResponseTest.kt index 46ce457c6..3248e833b 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdResponseTest.kt @@ -26,6 +26,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -121,9 +128,9 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -155,9 +162,15 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -169,57 +182,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -232,7 +201,21 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -252,6 +235,15 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -264,10 +256,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -290,11 +285,9 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -303,7 +296,7 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -314,11 +307,9 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -328,10 +319,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -362,6 +356,7 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -379,9 +374,9 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -399,9 +394,9 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -417,6 +412,9 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -470,6 +468,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -565,9 +570,9 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -599,10 +604,15 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -615,65 +625,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -686,7 +644,22 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -708,6 +681,15 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -720,12 +702,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field.PRICE_ID + PercentageDiscount.Filter.Field + .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter.Operator .INCLUDES ) .addValue("string") @@ -749,13 +732,10 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -765,7 +745,7 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -776,13 +756,10 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -793,11 +770,12 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -829,6 +807,7 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -846,9 +825,9 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -866,9 +845,9 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -884,6 +863,9 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -935,6 +917,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -987,6 +976,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1035,6 +1031,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1085,6 +1088,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1131,6 +1141,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1182,6 +1199,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1227,6 +1251,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1277,6 +1308,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1324,6 +1362,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1376,6 +1421,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1424,6 +1476,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1473,6 +1532,13 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParamsTest.kt index 615cba892..0cf4b256e 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParamsTest.kt @@ -21,13 +21,28 @@ internal class CustomerCreditLedgerCreateEntryParamsTest { .description("description") .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter.builder() + .field( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter.Field + .ITEM_ID + ) + .operator( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .invoiceSettings( CustomerCreditLedgerCreateEntryParams.Body.Increment.InvoiceSettings .builder() .autoCollection(true) - .netTerms(0L) + .customDueDate(LocalDate.parse("2019-12-27")) .invoiceDate(LocalDate.parse("2019-12-27")) + .itemId("item_id") .memo("memo") + .netTerms(0L) .requireSuccessfulPayment(true) .build() ) @@ -67,13 +82,30 @@ internal class CustomerCreditLedgerCreateEntryParamsTest { .description("description") .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter.builder() + .field( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter + .Field + .ITEM_ID + ) + .operator( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .invoiceSettings( CustomerCreditLedgerCreateEntryParams.Body.Increment.InvoiceSettings .builder() .autoCollection(true) - .netTerms(0L) + .customDueDate(LocalDate.parse("2019-12-27")) .invoiceDate(LocalDate.parse("2019-12-27")) + .itemId("item_id") .memo("memo") + .netTerms(0L) .requireSuccessfulPayment(true) .build() ) @@ -98,13 +130,30 @@ internal class CustomerCreditLedgerCreateEntryParamsTest { .description("description") .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter.builder() + .field( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter + .Field + .ITEM_ID + ) + .operator( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .invoiceSettings( CustomerCreditLedgerCreateEntryParams.Body.Increment.InvoiceSettings .builder() .autoCollection(true) - .netTerms(0L) + .customDueDate(LocalDate.parse("2019-12-27")) .invoiceDate(LocalDate.parse("2019-12-27")) + .itemId("item_id") .memo("memo") + .netTerms(0L) .requireSuccessfulPayment(true) .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryResponseTest.kt index e2e396c26..7a4064066 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryResponseTest.kt @@ -26,6 +26,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -121,9 +128,9 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -155,9 +162,15 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -169,57 +182,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -232,7 +201,21 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -252,6 +235,15 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -264,10 +256,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -290,11 +285,9 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -303,7 +296,7 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -314,11 +307,9 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -328,10 +319,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -362,6 +356,7 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -379,9 +374,9 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -399,9 +394,9 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -417,6 +412,9 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -469,6 +467,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -564,9 +569,9 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -598,10 +603,15 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -614,65 +624,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -685,7 +643,22 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -707,6 +680,15 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -719,12 +701,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field.PRICE_ID + PercentageDiscount.Filter.Field + .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter.Operator .INCLUDES ) .addValue("string") @@ -748,13 +731,10 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -764,7 +744,7 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -775,13 +755,10 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -792,11 +769,12 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -828,6 +806,7 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -845,9 +824,9 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -865,9 +844,9 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -883,6 +862,9 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -934,6 +916,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -985,6 +974,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1033,6 +1029,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1083,6 +1086,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1129,6 +1139,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1178,6 +1195,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1223,6 +1247,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1273,6 +1304,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1320,6 +1358,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1371,6 +1416,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1419,6 +1471,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1467,6 +1526,13 @@ internal class CustomerCreditLedgerCreateEntryResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponseTest.kt index 79e0ce7ee..02d6d0a49 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponseTest.kt @@ -24,6 +24,13 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -126,9 +133,11 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -160,10 +169,16 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter + .Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -176,65 +191,13 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -248,7 +211,23 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -271,6 +250,18 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field.PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -284,13 +275,14 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter + .Operator .INCLUDES ) .addValue("string") @@ -317,14 +309,12 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Maximum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -334,7 +324,7 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -345,14 +335,12 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Minimum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -363,11 +351,12 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -401,6 +390,7 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -418,9 +408,9 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -438,9 +428,9 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -458,6 +448,9 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -503,6 +496,13 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -605,9 +605,11 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -639,10 +641,16 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter + .Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -655,65 +663,13 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -727,7 +683,23 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -750,6 +722,18 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field.PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -763,13 +747,14 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter + .Operator .INCLUDES ) .addValue("string") @@ -796,14 +781,12 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Maximum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -813,7 +796,7 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -824,14 +807,12 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Minimum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -842,11 +823,12 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -880,6 +862,7 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -897,9 +880,9 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -917,9 +900,9 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -937,6 +920,9 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -985,6 +971,13 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1087,9 +1080,11 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -1121,10 +1116,16 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter + .Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -1137,65 +1138,13 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -1209,7 +1158,23 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1232,6 +1197,18 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field.PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1245,13 +1222,14 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter + .Operator .INCLUDES ) .addValue("string") @@ -1278,14 +1256,12 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Maximum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -1295,7 +1271,7 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1306,14 +1282,12 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Minimum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -1324,11 +1298,12 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -1362,6 +1337,7 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1379,9 +1355,9 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1399,9 +1375,9 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1419,6 +1395,9 @@ internal class CustomerCreditLedgerListByExternalIdPageResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdResponseTest.kt index fa7b31859..f4a670bc0 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdResponseTest.kt @@ -26,6 +26,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -121,9 +128,9 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -155,9 +162,15 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -169,57 +182,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -232,7 +201,21 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -252,6 +235,15 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -264,10 +256,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -290,11 +285,9 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -303,7 +296,7 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -314,11 +307,9 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -328,10 +319,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -362,6 +356,7 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -379,9 +374,9 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -399,9 +394,9 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -417,6 +412,9 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -469,6 +467,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -564,9 +569,9 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -598,10 +603,15 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -614,65 +624,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -685,7 +643,22 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -707,6 +680,15 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -719,12 +701,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field.PRICE_ID + PercentageDiscount.Filter.Field + .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter.Operator .INCLUDES ) .addValue("string") @@ -748,13 +731,10 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -764,7 +744,7 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -775,13 +755,10 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -792,11 +769,12 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -828,6 +806,7 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -845,9 +824,9 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -865,9 +844,9 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -883,6 +862,9 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -934,6 +916,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -985,6 +974,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1033,6 +1029,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1083,6 +1086,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1129,6 +1139,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1178,6 +1195,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1223,6 +1247,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1273,6 +1304,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1320,6 +1358,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1372,6 +1417,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1420,6 +1472,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1468,6 +1527,13 @@ internal class CustomerCreditLedgerListByExternalIdResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponseTest.kt index 3c66b293a..d58df0af6 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponseTest.kt @@ -24,6 +24,13 @@ internal class CustomerCreditLedgerListPageResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -126,9 +133,11 @@ internal class CustomerCreditLedgerListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -160,10 +169,16 @@ internal class CustomerCreditLedgerListPageResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter + .Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -176,65 +191,13 @@ internal class CustomerCreditLedgerListPageResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -248,7 +211,23 @@ internal class CustomerCreditLedgerListPageResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -271,6 +250,18 @@ internal class CustomerCreditLedgerListPageResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field.PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -284,13 +275,14 @@ internal class CustomerCreditLedgerListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter + .Operator .INCLUDES ) .addValue("string") @@ -317,14 +309,12 @@ internal class CustomerCreditLedgerListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Maximum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -334,7 +324,7 @@ internal class CustomerCreditLedgerListPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -345,14 +335,12 @@ internal class CustomerCreditLedgerListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Minimum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -363,11 +351,12 @@ internal class CustomerCreditLedgerListPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -401,6 +390,7 @@ internal class CustomerCreditLedgerListPageResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -418,9 +408,9 @@ internal class CustomerCreditLedgerListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -438,9 +428,9 @@ internal class CustomerCreditLedgerListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -458,6 +448,9 @@ internal class CustomerCreditLedgerListPageResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -503,6 +496,13 @@ internal class CustomerCreditLedgerListPageResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -605,9 +605,11 @@ internal class CustomerCreditLedgerListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -639,10 +641,16 @@ internal class CustomerCreditLedgerListPageResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter + .Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -655,65 +663,13 @@ internal class CustomerCreditLedgerListPageResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -727,7 +683,23 @@ internal class CustomerCreditLedgerListPageResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -750,6 +722,18 @@ internal class CustomerCreditLedgerListPageResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field.PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -763,13 +747,14 @@ internal class CustomerCreditLedgerListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter + .Operator .INCLUDES ) .addValue("string") @@ -796,14 +781,12 @@ internal class CustomerCreditLedgerListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Maximum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -813,7 +796,7 @@ internal class CustomerCreditLedgerListPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -824,14 +807,12 @@ internal class CustomerCreditLedgerListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Minimum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -842,11 +823,12 @@ internal class CustomerCreditLedgerListPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -880,6 +862,7 @@ internal class CustomerCreditLedgerListPageResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -897,9 +880,9 @@ internal class CustomerCreditLedgerListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -917,9 +900,9 @@ internal class CustomerCreditLedgerListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -937,6 +920,9 @@ internal class CustomerCreditLedgerListPageResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -985,6 +971,13 @@ internal class CustomerCreditLedgerListPageResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1087,9 +1080,11 @@ internal class CustomerCreditLedgerListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -1121,10 +1116,16 @@ internal class CustomerCreditLedgerListPageResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter + .Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -1137,65 +1138,13 @@ internal class CustomerCreditLedgerListPageResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -1209,7 +1158,23 @@ internal class CustomerCreditLedgerListPageResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1232,6 +1197,18 @@ internal class CustomerCreditLedgerListPageResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field.PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1245,13 +1222,14 @@ internal class CustomerCreditLedgerListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter + .Operator .INCLUDES ) .addValue("string") @@ -1278,14 +1256,12 @@ internal class CustomerCreditLedgerListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Maximum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -1295,7 +1271,7 @@ internal class CustomerCreditLedgerListPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1306,14 +1282,12 @@ internal class CustomerCreditLedgerListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Minimum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -1324,11 +1298,12 @@ internal class CustomerCreditLedgerListPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -1362,6 +1337,7 @@ internal class CustomerCreditLedgerListPageResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1379,9 +1355,9 @@ internal class CustomerCreditLedgerListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1399,9 +1375,9 @@ internal class CustomerCreditLedgerListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1419,6 +1395,9 @@ internal class CustomerCreditLedgerListPageResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListResponseTest.kt index c0a2f5eb7..04143323e 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListResponseTest.kt @@ -26,6 +26,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -121,9 +128,9 @@ internal class CustomerCreditLedgerListResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -155,9 +162,15 @@ internal class CustomerCreditLedgerListResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -169,57 +182,13 @@ internal class CustomerCreditLedgerListResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -232,7 +201,21 @@ internal class CustomerCreditLedgerListResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -252,6 +235,15 @@ internal class CustomerCreditLedgerListResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -264,10 +256,13 @@ internal class CustomerCreditLedgerListResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -290,11 +285,9 @@ internal class CustomerCreditLedgerListResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -303,7 +296,7 @@ internal class CustomerCreditLedgerListResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -314,11 +307,9 @@ internal class CustomerCreditLedgerListResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -328,10 +319,13 @@ internal class CustomerCreditLedgerListResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -362,6 +356,7 @@ internal class CustomerCreditLedgerListResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -379,9 +374,9 @@ internal class CustomerCreditLedgerListResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -399,9 +394,9 @@ internal class CustomerCreditLedgerListResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -417,6 +412,9 @@ internal class CustomerCreditLedgerListResponseTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -469,6 +467,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -564,9 +569,9 @@ internal class CustomerCreditLedgerListResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -598,10 +603,15 @@ internal class CustomerCreditLedgerListResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -614,65 +624,13 @@ internal class CustomerCreditLedgerListResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -685,7 +643,22 @@ internal class CustomerCreditLedgerListResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -707,6 +680,15 @@ internal class CustomerCreditLedgerListResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -719,12 +701,13 @@ internal class CustomerCreditLedgerListResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field.PRICE_ID + PercentageDiscount.Filter.Field + .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter.Operator .INCLUDES ) .addValue("string") @@ -748,13 +731,10 @@ internal class CustomerCreditLedgerListResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -764,7 +744,7 @@ internal class CustomerCreditLedgerListResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -775,13 +755,10 @@ internal class CustomerCreditLedgerListResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -792,11 +769,12 @@ internal class CustomerCreditLedgerListResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -828,6 +806,7 @@ internal class CustomerCreditLedgerListResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -845,9 +824,9 @@ internal class CustomerCreditLedgerListResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -865,9 +844,9 @@ internal class CustomerCreditLedgerListResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -883,6 +862,9 @@ internal class CustomerCreditLedgerListResponseTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -934,6 +916,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -985,6 +974,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1033,6 +1029,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1082,6 +1085,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1128,6 +1138,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1177,6 +1194,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1222,6 +1246,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1271,6 +1302,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1318,6 +1356,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1369,6 +1414,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1417,6 +1469,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -1465,6 +1524,13 @@ internal class CustomerCreditLedgerListResponseTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponseTest.kt index d9fcc1804..add48b6d5 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponseTest.kt @@ -20,6 +20,15 @@ internal class CustomerCreditListByExternalIdPageResponseTest { .balance(0.0) .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditListByExternalIdResponse.Filter.builder() + .field(CustomerCreditListByExternalIdResponse.Filter.Field.ITEM_ID) + .operator( + CustomerCreditListByExternalIdResponse.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .maximumInitialBalance(0.0) .perUnitCostBasis("per_unit_cost_basis") .status(CustomerCreditListByExternalIdResponse.Status.ACTIVE) @@ -37,6 +46,15 @@ internal class CustomerCreditListByExternalIdPageResponseTest { .balance(0.0) .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditListByExternalIdResponse.Filter.builder() + .field(CustomerCreditListByExternalIdResponse.Filter.Field.ITEM_ID) + .operator( + CustomerCreditListByExternalIdResponse.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .maximumInitialBalance(0.0) .perUnitCostBasis("per_unit_cost_basis") .status(CustomerCreditListByExternalIdResponse.Status.ACTIVE) @@ -57,6 +75,15 @@ internal class CustomerCreditListByExternalIdPageResponseTest { .balance(0.0) .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditListByExternalIdResponse.Filter.builder() + .field(CustomerCreditListByExternalIdResponse.Filter.Field.ITEM_ID) + .operator( + CustomerCreditListByExternalIdResponse.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .maximumInitialBalance(0.0) .perUnitCostBasis("per_unit_cost_basis") .status(CustomerCreditListByExternalIdResponse.Status.ACTIVE) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdResponseTest.kt index 10131bce3..dc3c6207c 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdResponseTest.kt @@ -18,6 +18,13 @@ internal class CustomerCreditListByExternalIdResponseTest { .balance(0.0) .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditListByExternalIdResponse.Filter.builder() + .field(CustomerCreditListByExternalIdResponse.Filter.Field.ITEM_ID) + .operator(CustomerCreditListByExternalIdResponse.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .maximumInitialBalance(0.0) .perUnitCostBasis("per_unit_cost_basis") .status(CustomerCreditListByExternalIdResponse.Status.ACTIVE) @@ -29,6 +36,14 @@ internal class CustomerCreditListByExternalIdResponseTest { .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(customerCreditListByExternalIdResponse.expiryDate()) .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(customerCreditListByExternalIdResponse.filters()) + .containsExactly( + CustomerCreditListByExternalIdResponse.Filter.builder() + .field(CustomerCreditListByExternalIdResponse.Filter.Field.ITEM_ID) + .operator(CustomerCreditListByExternalIdResponse.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) assertThat(customerCreditListByExternalIdResponse.maximumInitialBalance()).isEqualTo(0.0) assertThat(customerCreditListByExternalIdResponse.perUnitCostBasis()) .isEqualTo("per_unit_cost_basis") @@ -45,6 +60,13 @@ internal class CustomerCreditListByExternalIdResponseTest { .balance(0.0) .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditListByExternalIdResponse.Filter.builder() + .field(CustomerCreditListByExternalIdResponse.Filter.Field.ITEM_ID) + .operator(CustomerCreditListByExternalIdResponse.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .maximumInitialBalance(0.0) .perUnitCostBasis("per_unit_cost_basis") .status(CustomerCreditListByExternalIdResponse.Status.ACTIVE) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListPageResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListPageResponseTest.kt index 3d5abe3f9..86c3c5fce 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListPageResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListPageResponseTest.kt @@ -20,6 +20,13 @@ internal class CustomerCreditListPageResponseTest { .balance(0.0) .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditListResponse.Filter.builder() + .field(CustomerCreditListResponse.Filter.Field.ITEM_ID) + .operator(CustomerCreditListResponse.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .maximumInitialBalance(0.0) .perUnitCostBasis("per_unit_cost_basis") .status(CustomerCreditListResponse.Status.ACTIVE) @@ -37,6 +44,13 @@ internal class CustomerCreditListPageResponseTest { .balance(0.0) .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditListResponse.Filter.builder() + .field(CustomerCreditListResponse.Filter.Field.ITEM_ID) + .operator(CustomerCreditListResponse.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .maximumInitialBalance(0.0) .perUnitCostBasis("per_unit_cost_basis") .status(CustomerCreditListResponse.Status.ACTIVE) @@ -57,6 +71,13 @@ internal class CustomerCreditListPageResponseTest { .balance(0.0) .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditListResponse.Filter.builder() + .field(CustomerCreditListResponse.Filter.Field.ITEM_ID) + .operator(CustomerCreditListResponse.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .maximumInitialBalance(0.0) .perUnitCostBasis("per_unit_cost_basis") .status(CustomerCreditListResponse.Status.ACTIVE) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListResponseTest.kt index daabed930..25792b1ee 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListResponseTest.kt @@ -18,6 +18,13 @@ internal class CustomerCreditListResponseTest { .balance(0.0) .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditListResponse.Filter.builder() + .field(CustomerCreditListResponse.Filter.Field.ITEM_ID) + .operator(CustomerCreditListResponse.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .maximumInitialBalance(0.0) .perUnitCostBasis("per_unit_cost_basis") .status(CustomerCreditListResponse.Status.ACTIVE) @@ -29,6 +36,14 @@ internal class CustomerCreditListResponseTest { .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(customerCreditListResponse.expiryDate()) .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(customerCreditListResponse.filters()) + .containsExactly( + CustomerCreditListResponse.Filter.builder() + .field(CustomerCreditListResponse.Filter.Field.ITEM_ID) + .operator(CustomerCreditListResponse.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) assertThat(customerCreditListResponse.maximumInitialBalance()).isEqualTo(0.0) assertThat(customerCreditListResponse.perUnitCostBasis()).isEqualTo("per_unit_cost_basis") assertThat(customerCreditListResponse.status()) @@ -44,6 +59,13 @@ internal class CustomerCreditListResponseTest { .balance(0.0) .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditListResponse.Filter.builder() + .field(CustomerCreditListResponse.Filter.Field.ITEM_ID) + .operator(CustomerCreditListResponse.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .maximumInitialBalance(0.0) .perUnitCostBasis("per_unit_cost_basis") .status(CustomerCreditListResponse.Status.ACTIVE) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerListPageResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerListPageResponseTest.kt index bb3c672cb..94a0f1744 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerListPageResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerListPageResponseTest.kt @@ -20,6 +20,7 @@ internal class CustomerListPageResponseTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -96,6 +97,21 @@ internal class CustomerListPageResponseTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -112,6 +128,7 @@ internal class CustomerListPageResponseTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -187,6 +204,20 @@ internal class CustomerListPageResponseTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider.ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -206,6 +237,7 @@ internal class CustomerListPageResponseTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -282,6 +314,21 @@ internal class CustomerListPageResponseTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerTest.kt index 736e7d60f..2ec513af7 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerTest.kt @@ -18,6 +18,7 @@ internal class CustomerTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -93,6 +94,20 @@ internal class CustomerTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider.ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -101,6 +116,7 @@ internal class CustomerTest { assertThat(customer.id()).isEqualTo("id") assertThat(customer.additionalEmails()).containsExactly("string") assertThat(customer.autoCollection()).isEqualTo(true) + assertThat(customer.autoIssuance()).isEqualTo(true) assertThat(customer.balance()).isEqualTo("balance") assertThat(customer.billingAddress()) .isEqualTo( @@ -181,6 +197,20 @@ internal class CustomerTest { .excluded(true) .build() ) + assertThat(customer.automaticTaxEnabled()).isEqualTo(true) + assertThat(customer.paymentConfiguration()) + .isEqualTo( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider.ProviderType.STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) assertThat(customer.reportingConfiguration()) .isEqualTo(Customer.ReportingConfiguration.builder().exempt(true).build()) } @@ -193,6 +223,7 @@ internal class CustomerTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -268,6 +299,20 @@ internal class CustomerTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider.ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerUpdateByExternalIdParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerUpdateByExternalIdParamsTest.kt index 0f8e918f0..8ad7c6acc 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerUpdateByExternalIdParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerUpdateByExternalIdParamsTest.kt @@ -25,6 +25,7 @@ internal class CustomerUpdateByExternalIdParamsTest { ) .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -51,6 +52,22 @@ internal class CustomerUpdateByExternalIdParamsTest { .build() ) .name("name") + .paymentConfiguration( + CustomerUpdateByExternalIdParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerUpdateByExternalIdParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerUpdateByExternalIdParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerUpdateByExternalIdParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration(NewReportingConfiguration.builder().exempt(true).build()) @@ -68,6 +85,7 @@ internal class CustomerUpdateByExternalIdParamsTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -108,6 +126,7 @@ internal class CustomerUpdateByExternalIdParamsTest { ) .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -134,6 +153,22 @@ internal class CustomerUpdateByExternalIdParamsTest { .build() ) .name("name") + .paymentConfiguration( + CustomerUpdateByExternalIdParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerUpdateByExternalIdParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerUpdateByExternalIdParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerUpdateByExternalIdParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration(NewReportingConfiguration.builder().exempt(true).build()) @@ -151,6 +186,7 @@ internal class CustomerUpdateByExternalIdParamsTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -179,6 +215,7 @@ internal class CustomerUpdateByExternalIdParamsTest { ) assertThat(body.additionalEmails()).containsExactly("string") assertThat(body.autoCollection()).isEqualTo(true) + assertThat(body.autoIssuance()).isEqualTo(true) assertThat(body.billingAddress()) .isEqualTo( AddressInput.builder() @@ -208,6 +245,23 @@ internal class CustomerUpdateByExternalIdParamsTest { .build() ) assertThat(body.name()).isEqualTo("name") + assertThat(body.paymentConfiguration()) + .isEqualTo( + CustomerUpdateByExternalIdParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerUpdateByExternalIdParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerUpdateByExternalIdParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) assertThat(body.paymentProvider()) .isEqualTo(CustomerUpdateByExternalIdParams.PaymentProvider.QUICKBOOKS) assertThat(body.paymentProviderId()).isEqualTo("payment_provider_id") @@ -230,6 +284,7 @@ internal class CustomerUpdateByExternalIdParamsTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerUpdateParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerUpdateParamsTest.kt index e4f795630..823e476a7 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerUpdateParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/CustomerUpdateParamsTest.kt @@ -25,6 +25,7 @@ internal class CustomerUpdateParamsTest { ) .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -51,6 +52,20 @@ internal class CustomerUpdateParamsTest { .build() ) .name("name") + .paymentConfiguration( + CustomerUpdateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerUpdateParams.PaymentConfiguration.PaymentProvider.builder() + .providerType( + CustomerUpdateParams.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerUpdateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration(NewReportingConfiguration.builder().exempt(true).build()) @@ -68,6 +83,7 @@ internal class CustomerUpdateParamsTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -108,6 +124,7 @@ internal class CustomerUpdateParamsTest { ) .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -134,6 +151,20 @@ internal class CustomerUpdateParamsTest { .build() ) .name("name") + .paymentConfiguration( + CustomerUpdateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerUpdateParams.PaymentConfiguration.PaymentProvider.builder() + .providerType( + CustomerUpdateParams.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerUpdateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration(NewReportingConfiguration.builder().exempt(true).build()) @@ -151,6 +182,7 @@ internal class CustomerUpdateParamsTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -179,6 +211,7 @@ internal class CustomerUpdateParamsTest { ) assertThat(body.additionalEmails()).containsExactly("string") assertThat(body.autoCollection()).isEqualTo(true) + assertThat(body.autoIssuance()).isEqualTo(true) assertThat(body.billingAddress()) .isEqualTo( AddressInput.builder() @@ -208,6 +241,21 @@ internal class CustomerUpdateParamsTest { .build() ) assertThat(body.name()).isEqualTo("name") + assertThat(body.paymentConfiguration()) + .isEqualTo( + CustomerUpdateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerUpdateParams.PaymentConfiguration.PaymentProvider.builder() + .providerType( + CustomerUpdateParams.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) assertThat(body.paymentProvider()) .isEqualTo(CustomerUpdateParams.PaymentProvider.QUICKBOOKS) assertThat(body.paymentProviderId()).isEqualTo("payment_provider_id") @@ -230,6 +278,7 @@ internal class CustomerUpdateParamsTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/DecrementLedgerEntryTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/DecrementLedgerEntryTest.kt index 43b2841eb..64e63d76f 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/DecrementLedgerEntryTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/DecrementLedgerEntryTest.kt @@ -22,6 +22,13 @@ internal class DecrementLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -57,6 +64,13 @@ internal class DecrementLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -99,6 +113,13 @@ internal class DecrementLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/DiscountTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/DiscountTest.kt index ddb6c9284..cd9b79dff 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/DiscountTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/DiscountTest.kt @@ -23,9 +23,9 @@ internal class DiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -51,9 +51,9 @@ internal class DiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -78,9 +78,9 @@ internal class DiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + TrialDiscount.Filter.builder() + .field(TrialDiscount.Filter.Field.PRICE_ID) + .operator(TrialDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -107,9 +107,9 @@ internal class DiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + TrialDiscount.Filter.builder() + .field(TrialDiscount.Filter.Field.PRICE_ID) + .operator(TrialDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -137,9 +137,9 @@ internal class DiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + UsageDiscount.Filter.builder() + .field(UsageDiscount.Filter.Field.PRICE_ID) + .operator(UsageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -165,9 +165,9 @@ internal class DiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + UsageDiscount.Filter.builder() + .field(UsageDiscount.Filter.Field.PRICE_ID) + .operator(UsageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -193,9 +193,9 @@ internal class DiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscount.Filter.builder() + .field(AmountDiscount.Filter.Field.PRICE_ID) + .operator(AmountDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -221,9 +221,9 @@ internal class DiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscount.Filter.builder() + .field(AmountDiscount.Filter.Field.PRICE_ID) + .operator(AmountDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ExpirationChangeLedgerEntryTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ExpirationChangeLedgerEntryTest.kt index 04ea2eccb..052d1aef2 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ExpirationChangeLedgerEntryTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ExpirationChangeLedgerEntryTest.kt @@ -22,6 +22,13 @@ internal class ExpirationChangeLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -55,6 +62,13 @@ internal class ExpirationChangeLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -96,6 +110,13 @@ internal class ExpirationChangeLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/IncrementLedgerEntryTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/IncrementLedgerEntryTest.kt index 9a2ad5039..b5519405f 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/IncrementLedgerEntryTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/IncrementLedgerEntryTest.kt @@ -22,6 +22,13 @@ internal class IncrementLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -117,9 +124,9 @@ internal class IncrementLedgerEntryTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -151,9 +158,15 @@ internal class IncrementLedgerEntryTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -165,57 +178,13 @@ internal class IncrementLedgerEntryTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -228,7 +197,21 @@ internal class IncrementLedgerEntryTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -248,6 +231,15 @@ internal class IncrementLedgerEntryTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -260,10 +252,13 @@ internal class IncrementLedgerEntryTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -286,11 +281,9 @@ internal class IncrementLedgerEntryTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -299,7 +292,7 @@ internal class IncrementLedgerEntryTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -310,11 +303,9 @@ internal class IncrementLedgerEntryTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -324,10 +315,13 @@ internal class IncrementLedgerEntryTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -358,6 +352,7 @@ internal class IncrementLedgerEntryTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -375,9 +370,9 @@ internal class IncrementLedgerEntryTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -395,9 +390,9 @@ internal class IncrementLedgerEntryTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -413,6 +408,9 @@ internal class IncrementLedgerEntryTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -449,6 +447,13 @@ internal class IncrementLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -545,9 +550,9 @@ internal class IncrementLedgerEntryTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -579,9 +584,15 @@ internal class IncrementLedgerEntryTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -593,57 +604,13 @@ internal class IncrementLedgerEntryTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -654,7 +621,20 @@ internal class IncrementLedgerEntryTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -672,6 +652,13 @@ internal class IncrementLedgerEntryTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -684,10 +671,10 @@ internal class IncrementLedgerEntryTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -710,11 +697,9 @@ internal class IncrementLedgerEntryTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -723,7 +708,7 @@ internal class IncrementLedgerEntryTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -731,11 +716,9 @@ internal class IncrementLedgerEntryTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -745,10 +728,13 @@ internal class IncrementLedgerEntryTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -777,6 +763,7 @@ internal class IncrementLedgerEntryTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -794,9 +781,9 @@ internal class IncrementLedgerEntryTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -814,9 +801,9 @@ internal class IncrementLedgerEntryTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -832,6 +819,9 @@ internal class IncrementLedgerEntryTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -871,6 +861,13 @@ internal class IncrementLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -966,9 +963,9 @@ internal class IncrementLedgerEntryTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1000,9 +997,15 @@ internal class IncrementLedgerEntryTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -1014,57 +1017,13 @@ internal class IncrementLedgerEntryTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -1077,7 +1036,21 @@ internal class IncrementLedgerEntryTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1097,6 +1070,15 @@ internal class IncrementLedgerEntryTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1109,10 +1091,13 @@ internal class IncrementLedgerEntryTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -1135,11 +1120,9 @@ internal class IncrementLedgerEntryTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1148,7 +1131,7 @@ internal class IncrementLedgerEntryTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1159,11 +1142,9 @@ internal class IncrementLedgerEntryTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1173,10 +1154,13 @@ internal class IncrementLedgerEntryTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -1207,6 +1191,7 @@ internal class IncrementLedgerEntryTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1224,9 +1209,9 @@ internal class IncrementLedgerEntryTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1244,9 +1229,9 @@ internal class IncrementLedgerEntryTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1262,6 +1247,9 @@ internal class IncrementLedgerEntryTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceCreateParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceCreateParamsTest.kt index 17f7b38bb..94c7f4107 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceCreateParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceCreateParamsTest.kt @@ -23,7 +23,9 @@ internal class InvoiceCreateParamsTest { .name("Line Item Name") .quantity(1.0) .startDate(LocalDate.parse("2023-09-22")) - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .build() ) .customerId("4khy3nwzktxv7") @@ -34,15 +36,16 @@ internal class InvoiceCreateParamsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) .reason("reason") .build() ) + .dueDate(LocalDate.parse("2023-09-22")) .externalCustomerId("external-customer-id") .memo("An optional memo for my invoice.") .metadata( @@ -69,7 +72,9 @@ internal class InvoiceCreateParamsTest { .name("Line Item Name") .quantity(1.0) .startDate(LocalDate.parse("2023-09-22")) - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .build() ) .customerId("4khy3nwzktxv7") @@ -80,15 +85,16 @@ internal class InvoiceCreateParamsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) .reason("reason") .build() ) + .dueDate(LocalDate.parse("2023-09-22")) .externalCustomerId("external-customer-id") .memo("An optional memo for my invoice.") .metadata( @@ -113,7 +119,9 @@ internal class InvoiceCreateParamsTest { .name("Line Item Name") .quantity(1.0) .startDate(LocalDate.parse("2023-09-22")) - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .build() ) assertThat(body.customerId()).isEqualTo("4khy3nwzktxv7") @@ -126,9 +134,9 @@ internal class InvoiceCreateParamsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -136,6 +144,8 @@ internal class InvoiceCreateParamsTest { .build() ) ) + assertThat(body.dueDate()) + .isEqualTo(InvoiceCreateParams.DueDate.ofDate(LocalDate.parse("2023-09-22"))) assertThat(body.externalCustomerId()).isEqualTo("external-customer-id") assertThat(body.memo()).isEqualTo("An optional memo for my invoice.") assertThat(body.metadata()) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceFetchUpcomingResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceFetchUpcomingResponseTest.kt index f61e5573b..c3b22d840 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceFetchUpcomingResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceFetchUpcomingResponseTest.kt @@ -88,9 +88,9 @@ internal class InvoiceFetchUpcomingResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -118,9 +118,13 @@ internal class InvoiceFetchUpcomingResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -132,57 +136,13 @@ internal class InvoiceFetchUpcomingResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -191,7 +151,17 @@ internal class InvoiceFetchUpcomingResponseTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -209,6 +179,13 @@ internal class InvoiceFetchUpcomingResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -219,9 +196,11 @@ internal class InvoiceFetchUpcomingResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -241,9 +220,9 @@ internal class InvoiceFetchUpcomingResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -252,7 +231,7 @@ internal class InvoiceFetchUpcomingResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -260,9 +239,9 @@ internal class InvoiceFetchUpcomingResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -272,9 +251,14 @@ internal class InvoiceFetchUpcomingResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -302,6 +286,7 @@ internal class InvoiceFetchUpcomingResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -319,9 +304,9 @@ internal class InvoiceFetchUpcomingResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -339,9 +324,9 @@ internal class InvoiceFetchUpcomingResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -359,6 +344,9 @@ internal class InvoiceFetchUpcomingResponseTest { InvoiceFetchUpcomingResponse.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -466,9 +454,9 @@ internal class InvoiceFetchUpcomingResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -504,9 +492,11 @@ internal class InvoiceFetchUpcomingResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field(MonetaryUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -518,57 +508,13 @@ internal class InvoiceFetchUpcomingResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -577,7 +523,17 @@ internal class InvoiceFetchUpcomingResponseTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -593,6 +549,13 @@ internal class InvoiceFetchUpcomingResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -603,9 +566,9 @@ internal class InvoiceFetchUpcomingResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -625,9 +588,9 @@ internal class InvoiceFetchUpcomingResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -636,7 +599,7 @@ internal class InvoiceFetchUpcomingResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -644,9 +607,9 @@ internal class InvoiceFetchUpcomingResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -656,9 +619,14 @@ internal class InvoiceFetchUpcomingResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -683,6 +651,7 @@ internal class InvoiceFetchUpcomingResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -701,9 +670,9 @@ internal class InvoiceFetchUpcomingResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -723,9 +692,9 @@ internal class InvoiceFetchUpcomingResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -745,6 +714,9 @@ internal class InvoiceFetchUpcomingResponseTest { InvoiceFetchUpcomingResponse.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -858,9 +830,9 @@ internal class InvoiceFetchUpcomingResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -888,9 +860,13 @@ internal class InvoiceFetchUpcomingResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -902,57 +878,13 @@ internal class InvoiceFetchUpcomingResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -961,7 +893,17 @@ internal class InvoiceFetchUpcomingResponseTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -979,6 +921,13 @@ internal class InvoiceFetchUpcomingResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -989,9 +938,11 @@ internal class InvoiceFetchUpcomingResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -1011,9 +962,9 @@ internal class InvoiceFetchUpcomingResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1022,7 +973,7 @@ internal class InvoiceFetchUpcomingResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1030,9 +981,9 @@ internal class InvoiceFetchUpcomingResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1042,9 +993,14 @@ internal class InvoiceFetchUpcomingResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -1072,6 +1028,7 @@ internal class InvoiceFetchUpcomingResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1089,9 +1046,9 @@ internal class InvoiceFetchUpcomingResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1109,9 +1066,9 @@ internal class InvoiceFetchUpcomingResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1129,6 +1086,9 @@ internal class InvoiceFetchUpcomingResponseTest { InvoiceFetchUpcomingResponse.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceLevelDiscountTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceLevelDiscountTest.kt index da7c3d505..f768a98e1 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceLevelDiscountTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceLevelDiscountTest.kt @@ -23,9 +23,9 @@ internal class InvoiceLevelDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -50,9 +50,9 @@ internal class InvoiceLevelDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -78,9 +78,9 @@ internal class InvoiceLevelDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscount.Filter.builder() + .field(AmountDiscount.Filter.Field.PRICE_ID) + .operator(AmountDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -105,9 +105,9 @@ internal class InvoiceLevelDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscount.Filter.builder() + .field(AmountDiscount.Filter.Field.PRICE_ID) + .operator(AmountDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -132,9 +132,9 @@ internal class InvoiceLevelDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + TrialDiscount.Filter.builder() + .field(TrialDiscount.Filter.Field.PRICE_ID) + .operator(TrialDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -160,9 +160,9 @@ internal class InvoiceLevelDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + TrialDiscount.Filter.builder() + .field(TrialDiscount.Filter.Field.PRICE_ID) + .operator(TrialDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceLineItemCreateParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceLineItemCreateParamsTest.kt index 4854317ef..71753142f 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceLineItemCreateParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceLineItemCreateParamsTest.kt @@ -14,9 +14,10 @@ internal class InvoiceLineItemCreateParamsTest { .amount("12.00") .endDate(LocalDate.parse("2023-09-22")) .invoiceId("4khy3nwzktxv7") - .name("Item Name") .quantity(1.0) .startDate(LocalDate.parse("2023-09-22")) + .itemId("4khy3nwzktxv7") + .name("Item Name") .build() } @@ -27,9 +28,10 @@ internal class InvoiceLineItemCreateParamsTest { .amount("12.00") .endDate(LocalDate.parse("2023-09-22")) .invoiceId("4khy3nwzktxv7") - .name("Item Name") .quantity(1.0) .startDate(LocalDate.parse("2023-09-22")) + .itemId("4khy3nwzktxv7") + .name("Item Name") .build() val body = params._body() @@ -37,7 +39,28 @@ internal class InvoiceLineItemCreateParamsTest { assertThat(body.amount()).isEqualTo("12.00") assertThat(body.endDate()).isEqualTo(LocalDate.parse("2023-09-22")) assertThat(body.invoiceId()).isEqualTo("4khy3nwzktxv7") + assertThat(body.quantity()).isEqualTo(1.0) + assertThat(body.startDate()).isEqualTo(LocalDate.parse("2023-09-22")) + assertThat(body.itemId()).isEqualTo("4khy3nwzktxv7") assertThat(body.name()).isEqualTo("Item Name") + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + InvoiceLineItemCreateParams.builder() + .amount("12.00") + .endDate(LocalDate.parse("2023-09-22")) + .invoiceId("4khy3nwzktxv7") + .quantity(1.0) + .startDate(LocalDate.parse("2023-09-22")) + .build() + + val body = params._body() + + assertThat(body.amount()).isEqualTo("12.00") + assertThat(body.endDate()).isEqualTo(LocalDate.parse("2023-09-22")) + assertThat(body.invoiceId()).isEqualTo("4khy3nwzktxv7") assertThat(body.quantity()).isEqualTo(1.0) assertThat(body.startDate()).isEqualTo(LocalDate.parse("2023-09-22")) } diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceLineItemCreateResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceLineItemCreateResponseTest.kt index 6a6fde78b..4e23973a1 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceLineItemCreateResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceLineItemCreateResponseTest.kt @@ -26,9 +26,9 @@ internal class InvoiceLineItemCreateResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field(MonetaryUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -40,57 +40,13 @@ internal class InvoiceLineItemCreateResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -99,7 +55,15 @@ internal class InvoiceLineItemCreateResponseTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -115,6 +79,13 @@ internal class InvoiceLineItemCreateResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -125,9 +96,9 @@ internal class InvoiceLineItemCreateResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -147,9 +118,9 @@ internal class InvoiceLineItemCreateResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -158,7 +129,7 @@ internal class InvoiceLineItemCreateResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -166,9 +137,9 @@ internal class InvoiceLineItemCreateResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -178,9 +149,11 @@ internal class InvoiceLineItemCreateResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -201,6 +174,7 @@ internal class InvoiceLineItemCreateResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -227,9 +201,9 @@ internal class InvoiceLineItemCreateResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field(MonetaryUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -242,65 +216,16 @@ internal class InvoiceLineItemCreateResponseTest { ) assertThat(invoiceLineItemCreateResponse.amount()).isEqualTo("7.00") assertThat(invoiceLineItemCreateResponse.creditsApplied()).isEqualTo("6.00") - assertThat(invoiceLineItemCreateResponse.discount()) - .isEqualTo( - Discount.ofPercentage( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) - ) assertThat(invoiceLineItemCreateResponse.endDate()) .isEqualTo(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) assertThat(invoiceLineItemCreateResponse.filter()).isEqualTo("filter") assertThat(invoiceLineItemCreateResponse.grouping()).isEqualTo("grouping") - assertThat(invoiceLineItemCreateResponse.maximum()) - .isEqualTo( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - assertThat(invoiceLineItemCreateResponse.maximumAmount()).isEqualTo("maximum_amount") - assertThat(invoiceLineItemCreateResponse.minimum()) - .isEqualTo( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - assertThat(invoiceLineItemCreateResponse.minimumAmount()).isEqualTo("minimum_amount") assertThat(invoiceLineItemCreateResponse.name()).isEqualTo("Fixed Fee") assertThat(invoiceLineItemCreateResponse.partiallyInvoicedAmount()).isEqualTo("4.00") assertThat(invoiceLineItemCreateResponse.price()) .isEqualTo( Price.ofUnit( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -309,7 +234,15 @@ internal class InvoiceLineItemCreateResponseTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -325,6 +258,13 @@ internal class InvoiceLineItemCreateResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -335,9 +275,9 @@ internal class InvoiceLineItemCreateResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -357,9 +297,9 @@ internal class InvoiceLineItemCreateResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -368,7 +308,7 @@ internal class InvoiceLineItemCreateResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -376,9 +316,9 @@ internal class InvoiceLineItemCreateResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -388,9 +328,11 @@ internal class InvoiceLineItemCreateResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -415,6 +357,7 @@ internal class InvoiceLineItemCreateResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) ) @@ -446,9 +389,9 @@ internal class InvoiceLineItemCreateResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field(MonetaryUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -460,57 +403,13 @@ internal class InvoiceLineItemCreateResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -519,7 +418,15 @@ internal class InvoiceLineItemCreateResponseTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -535,6 +442,13 @@ internal class InvoiceLineItemCreateResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -545,9 +459,9 @@ internal class InvoiceLineItemCreateResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -567,9 +481,9 @@ internal class InvoiceLineItemCreateResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -578,7 +492,7 @@ internal class InvoiceLineItemCreateResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -586,9 +500,9 @@ internal class InvoiceLineItemCreateResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -598,9 +512,11 @@ internal class InvoiceLineItemCreateResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -621,6 +537,7 @@ internal class InvoiceLineItemCreateResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceListPageResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceListPageResponseTest.kt index 56d7eff0b..d29aa1314 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceListPageResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceListPageResponseTest.kt @@ -89,9 +89,9 @@ internal class InvoiceListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -123,9 +123,15 @@ internal class InvoiceListPageResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -137,57 +143,13 @@ internal class InvoiceListPageResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -200,7 +162,21 @@ internal class InvoiceListPageResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -220,6 +196,15 @@ internal class InvoiceListPageResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -232,10 +217,13 @@ internal class InvoiceListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -258,11 +246,9 @@ internal class InvoiceListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -271,7 +257,7 @@ internal class InvoiceListPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -282,11 +268,9 @@ internal class InvoiceListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -296,10 +280,13 @@ internal class InvoiceListPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -330,6 +317,7 @@ internal class InvoiceListPageResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -347,9 +335,9 @@ internal class InvoiceListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -367,9 +355,9 @@ internal class InvoiceListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -385,6 +373,9 @@ internal class InvoiceListPageResponseTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -486,9 +477,9 @@ internal class InvoiceListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -520,9 +511,15 @@ internal class InvoiceListPageResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -534,57 +531,13 @@ internal class InvoiceListPageResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -595,7 +548,20 @@ internal class InvoiceListPageResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -613,6 +579,13 @@ internal class InvoiceListPageResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -625,10 +598,10 @@ internal class InvoiceListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -651,11 +624,9 @@ internal class InvoiceListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -664,7 +635,7 @@ internal class InvoiceListPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -672,11 +643,9 @@ internal class InvoiceListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -686,10 +655,13 @@ internal class InvoiceListPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -718,6 +690,7 @@ internal class InvoiceListPageResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -735,9 +708,9 @@ internal class InvoiceListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -755,9 +728,9 @@ internal class InvoiceListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -773,6 +746,9 @@ internal class InvoiceListPageResponseTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -881,9 +857,9 @@ internal class InvoiceListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -915,9 +891,15 @@ internal class InvoiceListPageResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -929,57 +911,13 @@ internal class InvoiceListPageResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -992,7 +930,21 @@ internal class InvoiceListPageResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1012,6 +964,15 @@ internal class InvoiceListPageResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1024,10 +985,13 @@ internal class InvoiceListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -1050,11 +1014,9 @@ internal class InvoiceListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1063,7 +1025,7 @@ internal class InvoiceListPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1074,11 +1036,9 @@ internal class InvoiceListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1088,10 +1048,13 @@ internal class InvoiceListPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -1122,6 +1085,7 @@ internal class InvoiceListPageResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1139,9 +1103,9 @@ internal class InvoiceListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1159,9 +1123,9 @@ internal class InvoiceListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1177,6 +1141,9 @@ internal class InvoiceListPageResponseTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceTest.kt index ebf4fffba..3043b7df2 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceTest.kt @@ -83,9 +83,9 @@ internal class InvoiceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -114,9 +114,13 @@ internal class InvoiceTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -128,57 +132,13 @@ internal class InvoiceTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -187,7 +147,17 @@ internal class InvoiceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -205,6 +175,13 @@ internal class InvoiceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -215,9 +192,11 @@ internal class InvoiceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -237,9 +216,9 @@ internal class InvoiceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -248,7 +227,7 @@ internal class InvoiceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -256,9 +235,9 @@ internal class InvoiceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -268,9 +247,14 @@ internal class InvoiceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -298,6 +282,7 @@ internal class InvoiceTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -315,9 +300,9 @@ internal class InvoiceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -335,9 +320,9 @@ internal class InvoiceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -353,6 +338,9 @@ internal class InvoiceTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -454,9 +442,9 @@ internal class InvoiceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -491,9 +479,11 @@ internal class InvoiceTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field(MonetaryUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -505,57 +495,13 @@ internal class InvoiceTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -564,7 +510,17 @@ internal class InvoiceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -580,6 +536,13 @@ internal class InvoiceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -590,9 +553,9 @@ internal class InvoiceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -612,9 +575,9 @@ internal class InvoiceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -623,7 +586,7 @@ internal class InvoiceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -631,9 +594,9 @@ internal class InvoiceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -643,9 +606,14 @@ internal class InvoiceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -670,6 +638,7 @@ internal class InvoiceTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -688,9 +657,9 @@ internal class InvoiceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -710,9 +679,9 @@ internal class InvoiceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -729,6 +698,9 @@ internal class InvoiceTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -833,9 +805,9 @@ internal class InvoiceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -864,9 +836,13 @@ internal class InvoiceTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + MonetaryUsageDiscountAdjustment.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -878,57 +854,13 @@ internal class InvoiceTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType(PercentageDiscount.DiscountType.PERCENTAGE) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -937,7 +869,17 @@ internal class InvoiceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -955,6 +897,13 @@ internal class InvoiceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -965,9 +914,11 @@ internal class InvoiceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -987,9 +938,9 @@ internal class InvoiceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -998,7 +949,7 @@ internal class InvoiceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1006,9 +957,9 @@ internal class InvoiceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1018,9 +969,14 @@ internal class InvoiceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -1048,6 +1004,7 @@ internal class InvoiceTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1065,9 +1022,9 @@ internal class InvoiceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1085,9 +1042,9 @@ internal class InvoiceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1103,6 +1060,9 @@ internal class InvoiceTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceUpdateParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceUpdateParamsTest.kt index 26b3f3cca..4578f5f69 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceUpdateParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/InvoiceUpdateParamsTest.kt @@ -3,6 +3,7 @@ package com.withorb.api.models import com.withorb.api.core.JsonValue +import java.time.LocalDate import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -12,11 +13,14 @@ internal class InvoiceUpdateParamsTest { fun create() { InvoiceUpdateParams.builder() .invoiceId("invoice_id") + .dueDate(LocalDate.parse("2023-09-22")) + .invoiceDate(LocalDate.parse("2023-09-22")) .metadata( InvoiceUpdateParams.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .netTerms(0L) .build() } @@ -34,21 +38,29 @@ internal class InvoiceUpdateParamsTest { val params = InvoiceUpdateParams.builder() .invoiceId("invoice_id") + .dueDate(LocalDate.parse("2023-09-22")) + .invoiceDate(LocalDate.parse("2023-09-22")) .metadata( InvoiceUpdateParams.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .netTerms(0L) .build() val body = params._body() + assertThat(body.dueDate()) + .isEqualTo(InvoiceUpdateParams.DueDate.ofDate(LocalDate.parse("2023-09-22"))) + assertThat(body.invoiceDate()) + .isEqualTo(InvoiceUpdateParams.InvoiceDate.ofDate(LocalDate.parse("2023-09-22"))) assertThat(body.metadata()) .isEqualTo( InvoiceUpdateParams.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + assertThat(body.netTerms()).isEqualTo(0L) } @Test diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ItemListPageResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ItemListPageResponseTest.kt index 9304e36be..38156b7d5 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ItemListPageResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ItemListPageResponseTest.kt @@ -33,6 +33,7 @@ internal class ItemListPageResponseTest { .build() ) .name("name") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .paginationMetadata( @@ -59,6 +60,7 @@ internal class ItemListPageResponseTest { .build() ) .name("name") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) assertThat(itemListPageResponse.paginationMetadata()) @@ -88,6 +90,7 @@ internal class ItemListPageResponseTest { .build() ) .name("name") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .paginationMetadata( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ItemTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ItemTest.kt index 7d2118f26..fe546ed3e 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ItemTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/ItemTest.kt @@ -31,6 +31,7 @@ internal class ItemTest { .build() ) .name("name") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() assertThat(item.id()).isEqualTo("id") @@ -49,6 +50,7 @@ internal class ItemTest { .build() ) assertThat(item.name()).isEqualTo("name") + assertThat(item.archivedAt()).isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) } @Test @@ -72,6 +74,7 @@ internal class ItemTest { .build() ) .name("name") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() val roundtrippedItem = diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MatrixSubLineItemTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MatrixSubLineItemTest.kt index 1347f76e2..5744b22ce 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MatrixSubLineItemTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MatrixSubLineItemTest.kt @@ -19,6 +19,7 @@ internal class MatrixSubLineItemTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() assertThat(matrixSubLineItem.amount()).isEqualTo("9.00") @@ -29,6 +30,7 @@ internal class MatrixSubLineItemTest { assertThat(matrixSubLineItem.name()).isEqualTo("Tier One") assertThat(matrixSubLineItem.quantity()).isEqualTo(5.0) assertThat(matrixSubLineItem.type()).isEqualTo(MatrixSubLineItem.Type.MATRIX) + assertThat(matrixSubLineItem.scaledQuantity()).isEqualTo(0.0) } @Test @@ -42,6 +44,7 @@ internal class MatrixSubLineItemTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() val roundtrippedMatrixSubLineItem = diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MatrixWithAllocationConfigTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MatrixWithAllocationConfigTest.kt index 8f3374699..7afd7e9d6 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MatrixWithAllocationConfigTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MatrixWithAllocationConfigTest.kt @@ -13,23 +13,26 @@ internal class MatrixWithAllocationConfigTest { fun create() { val matrixWithAllocationConfig = MatrixWithAllocationConfig.builder() - .allocation(0.0) + .allocation("allocation") .defaultUnitAmount("default_unit_amount") .addDimension("string") .addMatrixValue( - MatrixValue.builder() + MatrixWithAllocationConfig.MatrixValue.builder() .addDimensionValue("string") .unitAmount("unit_amount") .build() ) .build() - assertThat(matrixWithAllocationConfig.allocation()).isEqualTo(0.0) + assertThat(matrixWithAllocationConfig.allocation()).isEqualTo("allocation") assertThat(matrixWithAllocationConfig.defaultUnitAmount()).isEqualTo("default_unit_amount") assertThat(matrixWithAllocationConfig.dimensions()).containsExactly("string") assertThat(matrixWithAllocationConfig.matrixValues()) .containsExactly( - MatrixValue.builder().addDimensionValue("string").unitAmount("unit_amount").build() + MatrixWithAllocationConfig.MatrixValue.builder() + .addDimensionValue("string") + .unitAmount("unit_amount") + .build() ) } @@ -38,11 +41,11 @@ internal class MatrixWithAllocationConfigTest { val jsonMapper = jsonMapper() val matrixWithAllocationConfig = MatrixWithAllocationConfig.builder() - .allocation(0.0) + .allocation("allocation") .defaultUnitAmount("default_unit_amount") .addDimension("string") .addMatrixValue( - MatrixValue.builder() + MatrixWithAllocationConfig.MatrixValue.builder() .addDimensionValue("string") .unitAmount("unit_amount") .build() diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MaximumIntervalTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MaximumIntervalTest.kt index 435bde6cc..50c44837d 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MaximumIntervalTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MaximumIntervalTest.kt @@ -17,9 +17,9 @@ internal class MaximumIntervalTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -32,9 +32,9 @@ internal class MaximumIntervalTest { .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(maximumInterval.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -51,9 +51,9 @@ internal class MaximumIntervalTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MaximumTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MaximumTest.kt index 1eb179e04..876cb92b7 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MaximumTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MaximumTest.kt @@ -15,9 +15,9 @@ internal class MaximumTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -27,9 +27,9 @@ internal class MaximumTest { assertThat(maximum.appliesToPriceIds()).containsExactly("string") assertThat(maximum.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -43,9 +43,9 @@ internal class MaximumTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MetricListPageResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MetricListPageResponseTest.kt index f2eaba159..4f47b1738 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MetricListPageResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MetricListPageResponseTest.kt @@ -37,6 +37,7 @@ internal class MetricListPageResponseTest { .build() ) .name("name") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .metadata( @@ -76,6 +77,7 @@ internal class MetricListPageResponseTest { .build() ) .name("name") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .metadata( @@ -118,6 +120,7 @@ internal class MetricListPageResponseTest { .build() ) .name("name") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .metadata( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MinimumIntervalTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MinimumIntervalTest.kt index 989cd05ed..71c4ced4b 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MinimumIntervalTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MinimumIntervalTest.kt @@ -17,9 +17,9 @@ internal class MinimumIntervalTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -32,9 +32,9 @@ internal class MinimumIntervalTest { .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(minimumInterval.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -51,9 +51,9 @@ internal class MinimumIntervalTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MinimumTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MinimumTest.kt index c39afb724..f8aef3afa 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MinimumTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MinimumTest.kt @@ -15,9 +15,9 @@ internal class MinimumTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -27,9 +27,9 @@ internal class MinimumTest { assertThat(minimum.appliesToPriceIds()).containsExactly("string") assertThat(minimum.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -43,9 +43,9 @@ internal class MinimumTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryAmountDiscountAdjustmentTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryAmountDiscountAdjustmentTest.kt index 3c4211a1e..cf05942cb 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryAmountDiscountAdjustmentTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryAmountDiscountAdjustmentTest.kt @@ -19,9 +19,9 @@ internal class MonetaryAmountDiscountAdjustmentTest { .amountDiscount("amount_discount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryAmountDiscountAdjustment.Filter.builder() + .field(MonetaryAmountDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryAmountDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -38,9 +38,9 @@ internal class MonetaryAmountDiscountAdjustmentTest { assertThat(monetaryAmountDiscountAdjustment.appliesToPriceIds()).containsExactly("string") assertThat(monetaryAmountDiscountAdjustment.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryAmountDiscountAdjustment.Filter.builder() + .field(MonetaryAmountDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryAmountDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -61,9 +61,9 @@ internal class MonetaryAmountDiscountAdjustmentTest { .amountDiscount("amount_discount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryAmountDiscountAdjustment.Filter.builder() + .field(MonetaryAmountDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryAmountDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryMaximumAdjustmentTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryMaximumAdjustmentTest.kt index 9727617a6..eff274b1b 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryMaximumAdjustmentTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryMaximumAdjustmentTest.kt @@ -18,9 +18,9 @@ internal class MonetaryMaximumAdjustmentTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryMaximumAdjustment.Filter.builder() + .field(MonetaryMaximumAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryMaximumAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -37,9 +37,9 @@ internal class MonetaryMaximumAdjustmentTest { assertThat(monetaryMaximumAdjustment.appliesToPriceIds()).containsExactly("string") assertThat(monetaryMaximumAdjustment.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryMaximumAdjustment.Filter.builder() + .field(MonetaryMaximumAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryMaximumAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -60,9 +60,9 @@ internal class MonetaryMaximumAdjustmentTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryMaximumAdjustment.Filter.builder() + .field(MonetaryMaximumAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryMaximumAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryMinimumAdjustmentTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryMinimumAdjustmentTest.kt index 5cfc9fd9a..e5f79084f 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryMinimumAdjustmentTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryMinimumAdjustmentTest.kt @@ -18,9 +18,9 @@ internal class MonetaryMinimumAdjustmentTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryMinimumAdjustment.Filter.builder() + .field(MonetaryMinimumAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryMinimumAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -38,9 +38,9 @@ internal class MonetaryMinimumAdjustmentTest { assertThat(monetaryMinimumAdjustment.appliesToPriceIds()).containsExactly("string") assertThat(monetaryMinimumAdjustment.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryMinimumAdjustment.Filter.builder() + .field(MonetaryMinimumAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryMinimumAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -62,9 +62,9 @@ internal class MonetaryMinimumAdjustmentTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryMinimumAdjustment.Filter.builder() + .field(MonetaryMinimumAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryMinimumAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryPercentageDiscountAdjustmentTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryPercentageDiscountAdjustmentTest.kt index 532a8f1a0..349207152 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryPercentageDiscountAdjustmentTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryPercentageDiscountAdjustmentTest.kt @@ -20,9 +20,9 @@ internal class MonetaryPercentageDiscountAdjustmentTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryPercentageDiscountAdjustment.Filter.builder() + .field(MonetaryPercentageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryPercentageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -40,9 +40,9 @@ internal class MonetaryPercentageDiscountAdjustmentTest { .containsExactly("string") assertThat(monetaryPercentageDiscountAdjustment.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryPercentageDiscountAdjustment.Filter.builder() + .field(MonetaryPercentageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryPercentageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -65,9 +65,9 @@ internal class MonetaryPercentageDiscountAdjustmentTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryPercentageDiscountAdjustment.Filter.builder() + .field(MonetaryPercentageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryPercentageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryUsageDiscountAdjustmentTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryUsageDiscountAdjustmentTest.kt index 5b797a57e..c9b564e07 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryUsageDiscountAdjustmentTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MonetaryUsageDiscountAdjustmentTest.kt @@ -18,9 +18,9 @@ internal class MonetaryUsageDiscountAdjustmentTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field(MonetaryUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -37,9 +37,9 @@ internal class MonetaryUsageDiscountAdjustmentTest { assertThat(monetaryUsageDiscountAdjustment.appliesToPriceIds()).containsExactly("string") assertThat(monetaryUsageDiscountAdjustment.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field(MonetaryUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -60,9 +60,9 @@ internal class MonetaryUsageDiscountAdjustmentTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field(MonetaryUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(MonetaryUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MutatedSubscriptionTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MutatedSubscriptionTest.kt index 46b0fd258..ecbe2b472 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MutatedSubscriptionTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/MutatedSubscriptionTest.kt @@ -28,9 +28,14 @@ internal class MutatedSubscriptionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -59,6 +64,7 @@ internal class MutatedSubscriptionTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -135,6 +141,21 @@ internal class MutatedSubscriptionTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -148,9 +169,9 @@ internal class MutatedSubscriptionTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -172,9 +193,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -192,9 +213,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -216,9 +237,14 @@ internal class MutatedSubscriptionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -248,9 +274,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -263,9 +289,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -282,9 +308,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -305,9 +331,11 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -320,9 +348,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -334,9 +362,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -349,7 +377,7 @@ internal class MutatedSubscriptionTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -358,7 +386,17 @@ internal class MutatedSubscriptionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -376,6 +414,13 @@ internal class MutatedSubscriptionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -386,9 +431,11 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -408,9 +455,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -419,7 +466,7 @@ internal class MutatedSubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -427,9 +474,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -439,9 +486,14 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -471,6 +523,7 @@ internal class MutatedSubscriptionTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -487,7 +540,7 @@ internal class MutatedSubscriptionTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -496,7 +549,17 @@ internal class MutatedSubscriptionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -514,6 +577,13 @@ internal class MutatedSubscriptionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -524,9 +594,11 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -546,9 +618,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -557,7 +629,7 @@ internal class MutatedSubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -565,9 +637,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -577,9 +649,14 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -700,11 +777,12 @@ internal class MutatedSubscriptionTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice.AutoCollection + .builder() .enabled(true) .nextAttemptAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") @@ -727,7 +805,7 @@ internal class MutatedSubscriptionTest { ) .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote.builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -745,10 +823,14 @@ internal class MutatedSubscriptionTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action .APPLIED_TO_INVOICE ) .amount("11.00") @@ -762,7 +844,12 @@ internal class MutatedSubscriptionTest { InvoiceTiny.builder().id("gXcsPTVyC4YZa3Sc").build() ) .startingBalance("33.00") - .type(Invoice.CustomerBalanceTransaction.Type.INCREMENT) + .type( + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type + .INCREMENT + ) .build() ) .customerTaxId( @@ -780,9 +867,11 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -797,11 +886,15 @@ internal class MutatedSubscriptionTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice.InvoiceSource + .SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem.builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -814,10 +907,16 @@ internal class MutatedSubscriptionTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter + .Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -830,65 +929,13 @@ internal class MutatedSubscriptionTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -902,7 +949,23 @@ internal class MutatedSubscriptionTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -925,6 +988,18 @@ internal class MutatedSubscriptionTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field.PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -938,13 +1013,14 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter + .Operator .INCLUDES ) .addValue("string") @@ -971,14 +1047,12 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Maximum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -988,7 +1062,7 @@ internal class MutatedSubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -999,14 +1073,12 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Minimum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -1017,11 +1089,12 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -1055,6 +1128,7 @@ internal class MutatedSubscriptionTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1072,9 +1146,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1084,7 +1158,7 @@ internal class MutatedSubscriptionTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1092,9 +1166,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1104,14 +1178,21 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice.PaymentAttempt + .builder() .id("id") .amount("amount") .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider( - Invoice.PaymentAttempt.PaymentProvider.STRIPE + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .PaymentProvider + .STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -1128,7 +1209,7 @@ internal class MutatedSubscriptionTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status(ChangedSubscriptionResources.CreatedInvoice.Status.ISSUED) .subscription( SubscriptionMinified.builder().id("VDGsT23osdLb84KD").build() ) @@ -1311,9 +1392,11 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -1345,10 +1428,16 @@ internal class MutatedSubscriptionTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter + .Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -1361,65 +1450,13 @@ internal class MutatedSubscriptionTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -1433,7 +1470,23 @@ internal class MutatedSubscriptionTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1456,6 +1509,18 @@ internal class MutatedSubscriptionTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field.PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1469,13 +1534,14 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter + .Operator .INCLUDES ) .addValue("string") @@ -1502,14 +1568,12 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Maximum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -1519,7 +1583,7 @@ internal class MutatedSubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1530,14 +1594,12 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Minimum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -1548,11 +1610,12 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -1586,6 +1649,7 @@ internal class MutatedSubscriptionTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1603,9 +1667,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1623,9 +1687,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1643,6 +1707,9 @@ internal class MutatedSubscriptionTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -1688,9 +1755,11 @@ internal class MutatedSubscriptionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -1722,6 +1791,7 @@ internal class MutatedSubscriptionTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -1797,6 +1867,20 @@ internal class MutatedSubscriptionTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider.ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -1812,9 +1896,9 @@ internal class MutatedSubscriptionTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1840,9 +1924,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1862,9 +1946,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1888,9 +1972,11 @@ internal class MutatedSubscriptionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -1920,9 +2006,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1935,9 +2021,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1954,9 +2040,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1977,9 +2063,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1992,9 +2078,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2006,9 +2092,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2021,7 +2107,7 @@ internal class MutatedSubscriptionTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2030,7 +2116,17 @@ internal class MutatedSubscriptionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -2046,6 +2142,13 @@ internal class MutatedSubscriptionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2056,9 +2159,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2078,9 +2181,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2089,7 +2192,7 @@ internal class MutatedSubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2097,9 +2200,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2109,9 +2212,14 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -2142,6 +2250,7 @@ internal class MutatedSubscriptionTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .currentBillingPeriodStartDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) @@ -2154,7 +2263,7 @@ internal class MutatedSubscriptionTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2163,7 +2272,17 @@ internal class MutatedSubscriptionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -2179,6 +2298,13 @@ internal class MutatedSubscriptionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2189,9 +2315,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2211,9 +2337,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2222,7 +2348,7 @@ internal class MutatedSubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2230,9 +2356,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2242,9 +2368,14 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -2366,11 +2497,11 @@ internal class MutatedSubscriptionTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice.AutoCollection.builder() .enabled(true) .nextAttemptAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .numAttempts(0L) @@ -2391,7 +2522,7 @@ internal class MutatedSubscriptionTest { ) .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote.builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -2409,10 +2540,15 @@ internal class MutatedSubscriptionTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action.APPLIED_TO_INVOICE + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action + .APPLIED_TO_INVOICE ) .amount("11.00") .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) @@ -2421,7 +2557,12 @@ internal class MutatedSubscriptionTest { .endingBalance("22.00") .invoice(InvoiceTiny.builder().id("gXcsPTVyC4YZa3Sc").build()) .startingBalance("33.00") - .type(Invoice.CustomerBalanceTransaction.Type.INCREMENT) + .type( + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type + .INCREMENT + ) .build() ) .customerTaxId( @@ -2439,9 +2580,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2456,11 +2597,15 @@ internal class MutatedSubscriptionTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice.InvoiceSource + .SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem.builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -2473,10 +2618,15 @@ internal class MutatedSubscriptionTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -2489,65 +2639,13 @@ internal class MutatedSubscriptionTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -2560,7 +2658,22 @@ internal class MutatedSubscriptionTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -2582,6 +2695,15 @@ internal class MutatedSubscriptionTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2594,12 +2716,13 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field.PRICE_ID + PercentageDiscount.Filter.Field + .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter.Operator .INCLUDES ) .addValue("string") @@ -2623,13 +2746,10 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2639,7 +2759,7 @@ internal class MutatedSubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -2650,13 +2770,10 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2667,11 +2784,12 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -2703,6 +2821,7 @@ internal class MutatedSubscriptionTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -2720,9 +2839,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2732,7 +2851,7 @@ internal class MutatedSubscriptionTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2740,9 +2859,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2752,12 +2871,19 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice.PaymentAttempt.builder() .id("id") .amount("amount") .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) - .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) + .paymentProvider( + ChangedSubscriptionResources.CreatedInvoice.PaymentAttempt + .PaymentProvider + .STRIPE + ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -2774,7 +2900,7 @@ internal class MutatedSubscriptionTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status(ChangedSubscriptionResources.CreatedInvoice.Status.ISSUED) .subscription( SubscriptionMinified.builder().id("VDGsT23osdLb84KD").build() ) @@ -2947,9 +3073,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2981,10 +3107,15 @@ internal class MutatedSubscriptionTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -2997,65 +3128,13 @@ internal class MutatedSubscriptionTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -3068,7 +3147,22 @@ internal class MutatedSubscriptionTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -3090,6 +3184,15 @@ internal class MutatedSubscriptionTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3102,12 +3205,13 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field.PRICE_ID + PercentageDiscount.Filter.Field + .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter.Operator .INCLUDES ) .addValue("string") @@ -3131,13 +3235,10 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -3147,7 +3248,7 @@ internal class MutatedSubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -3158,13 +3259,10 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -3175,11 +3273,12 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -3211,6 +3310,7 @@ internal class MutatedSubscriptionTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -3228,9 +3328,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3248,9 +3348,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3266,6 +3366,9 @@ internal class MutatedSubscriptionTest { .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -3315,9 +3418,14 @@ internal class MutatedSubscriptionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -3346,6 +3454,7 @@ internal class MutatedSubscriptionTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -3422,6 +3531,21 @@ internal class MutatedSubscriptionTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -3435,9 +3559,9 @@ internal class MutatedSubscriptionTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3459,9 +3583,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3479,9 +3603,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3503,9 +3627,14 @@ internal class MutatedSubscriptionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -3535,9 +3664,9 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3550,9 +3679,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3569,9 +3698,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3592,9 +3721,11 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -3607,9 +3738,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3621,9 +3752,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3636,7 +3767,7 @@ internal class MutatedSubscriptionTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -3645,7 +3776,17 @@ internal class MutatedSubscriptionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -3663,6 +3804,13 @@ internal class MutatedSubscriptionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3673,9 +3821,11 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -3695,9 +3845,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3706,7 +3856,7 @@ internal class MutatedSubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -3714,9 +3864,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3726,9 +3876,14 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -3758,6 +3913,7 @@ internal class MutatedSubscriptionTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -3774,7 +3930,7 @@ internal class MutatedSubscriptionTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -3783,7 +3939,17 @@ internal class MutatedSubscriptionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -3801,6 +3967,13 @@ internal class MutatedSubscriptionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3811,9 +3984,11 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -3833,9 +4008,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3844,7 +4019,7 @@ internal class MutatedSubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -3852,9 +4027,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3864,9 +4039,14 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -3987,11 +4167,12 @@ internal class MutatedSubscriptionTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice.AutoCollection + .builder() .enabled(true) .nextAttemptAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") @@ -4014,7 +4195,7 @@ internal class MutatedSubscriptionTest { ) .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote.builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -4032,10 +4213,14 @@ internal class MutatedSubscriptionTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action .APPLIED_TO_INVOICE ) .amount("11.00") @@ -4049,7 +4234,12 @@ internal class MutatedSubscriptionTest { InvoiceTiny.builder().id("gXcsPTVyC4YZa3Sc").build() ) .startingBalance("33.00") - .type(Invoice.CustomerBalanceTransaction.Type.INCREMENT) + .type( + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type + .INCREMENT + ) .build() ) .customerTaxId( @@ -4067,9 +4257,11 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -4084,11 +4276,15 @@ internal class MutatedSubscriptionTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice.InvoiceSource + .SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem.builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -4101,10 +4297,16 @@ internal class MutatedSubscriptionTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter + .Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -4117,65 +4319,13 @@ internal class MutatedSubscriptionTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -4189,7 +4339,23 @@ internal class MutatedSubscriptionTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -4212,6 +4378,18 @@ internal class MutatedSubscriptionTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field.PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4225,13 +4403,14 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter + .Operator .INCLUDES ) .addValue("string") @@ -4258,14 +4437,12 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Maximum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -4275,7 +4452,7 @@ internal class MutatedSubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4286,14 +4463,12 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Minimum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -4304,11 +4479,12 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -4342,6 +4518,7 @@ internal class MutatedSubscriptionTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -4359,9 +4536,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4371,7 +4548,7 @@ internal class MutatedSubscriptionTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -4379,9 +4556,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4391,14 +4568,21 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice.PaymentAttempt + .builder() .id("id") .amount("amount") .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .paymentProvider( - Invoice.PaymentAttempt.PaymentProvider.STRIPE + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .PaymentProvider + .STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -4415,7 +4599,7 @@ internal class MutatedSubscriptionTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status(ChangedSubscriptionResources.CreatedInvoice.Status.ISSUED) .subscription( SubscriptionMinified.builder().id("VDGsT23osdLb84KD").build() ) @@ -4598,9 +4782,11 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -4632,10 +4818,16 @@ internal class MutatedSubscriptionTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + MonetaryUsageDiscountAdjustment.Filter.builder() + .field( + MonetaryUsageDiscountAdjustment.Filter + .Field + .PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + MonetaryUsageDiscountAdjustment.Filter + .Operator + .INCLUDES ) .addValue("string") .build() @@ -4648,65 +4840,13 @@ internal class MutatedSubscriptionTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -4720,7 +4860,23 @@ internal class MutatedSubscriptionTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -4743,6 +4899,18 @@ internal class MutatedSubscriptionTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field.PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4756,13 +4924,14 @@ internal class MutatedSubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + PercentageDiscount.Filter + .Operator .INCLUDES ) .addValue("string") @@ -4789,14 +4958,12 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Maximum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Maximum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -4806,7 +4973,7 @@ internal class MutatedSubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4817,14 +4984,12 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field - .PRICE_ID + Minimum.Filter.Field.PRICE_ID ) .operator( - TransformPriceFilter.Operator - .INCLUDES + Minimum.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -4835,11 +5000,12 @@ internal class MutatedSubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -4873,6 +5039,7 @@ internal class MutatedSubscriptionTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -4890,9 +5057,9 @@ internal class MutatedSubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4910,9 +5077,9 @@ internal class MutatedSubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4930,6 +5097,9 @@ internal class MutatedSubscriptionTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewAllocationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewAllocationPriceTest.kt index 56b70a58f..a03182267 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewAllocationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewAllocationPriceTest.kt @@ -23,6 +23,15 @@ internal class NewAllocationPriceTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() assertThat(newAllocationPrice.amount()).isEqualTo("10.00") @@ -36,6 +45,16 @@ internal class NewAllocationPriceTest { .build() ) assertThat(newAllocationPrice.expiresAtEndOfCadence()).isEqualTo(true) + assertThat(newAllocationPrice.filters()) + .containsExactly( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + assertThat(newAllocationPrice.itemId()).isEqualTo("item_id") + assertThat(newAllocationPrice.perUnitCostBasis()).isEqualTo("per_unit_cost_basis") } @Test @@ -53,6 +72,15 @@ internal class NewAllocationPriceTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() val roundtrippedNewAllocationPrice = diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewAmountDiscountTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewAmountDiscountTest.kt index 41ff51be5..c93ed9f39 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewAmountDiscountTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewAmountDiscountTest.kt @@ -22,9 +22,9 @@ internal class NewAmountDiscountTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewAmountDiscount.Filter.builder() + .field(NewAmountDiscount.Filter.Field.PRICE_ID) + .operator(NewAmountDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -41,9 +41,9 @@ internal class NewAmountDiscountTest { assertThat(newAmountDiscount.currency()).isEqualTo("currency") assertThat(newAmountDiscount.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewAmountDiscount.Filter.builder() + .field(NewAmountDiscount.Filter.Field.PRICE_ID) + .operator(NewAmountDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -65,9 +65,9 @@ internal class NewAmountDiscountTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewAmountDiscount.Filter.builder() + .field(NewAmountDiscount.Filter.Field.PRICE_ID) + .operator(NewAmountDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewAvalaraTaxConfigurationTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewAvalaraTaxConfigurationTest.kt index 58b62648d..6a60f8e06 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewAvalaraTaxConfigurationTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewAvalaraTaxConfigurationTest.kt @@ -15,12 +15,14 @@ internal class NewAvalaraTaxConfigurationTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() assertThat(newAvalaraTaxConfiguration.taxExempt()).isEqualTo(true) assertThat(newAvalaraTaxConfiguration.taxProvider()) .isEqualTo(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + assertThat(newAvalaraTaxConfiguration.automaticTaxEnabled()).isEqualTo(true) assertThat(newAvalaraTaxConfiguration.taxExemptionCode()).isEqualTo("tax_exemption_code") } @@ -31,6 +33,7 @@ internal class NewAvalaraTaxConfigurationTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBpsPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBpsPriceTest.kt deleted file mode 100644 index 402181b76..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBpsPriceTest.kt +++ /dev/null @@ -1,166 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.JsonValue -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class NewFloatingBpsPriceTest { - - @Test - fun create() { - val newFloatingBpsPrice = - NewFloatingBpsPrice.builder() - .bpsConfig(BpsConfig.builder().bps(0.0).perUnitMaximum("per_unit_maximum").build()) - .cadence(NewFloatingBpsPrice.Cadence.ANNUAL) - .currency("currency") - .itemId("item_id") - .modelType(NewFloatingBpsPrice.ModelType.BPS) - .name("Annual fee") - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewFloatingBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .build() - - assertThat(newFloatingBpsPrice.bpsConfig()) - .isEqualTo(BpsConfig.builder().bps(0.0).perUnitMaximum("per_unit_maximum").build()) - assertThat(newFloatingBpsPrice.cadence()).isEqualTo(NewFloatingBpsPrice.Cadence.ANNUAL) - assertThat(newFloatingBpsPrice.currency()).isEqualTo("currency") - assertThat(newFloatingBpsPrice.itemId()).isEqualTo("item_id") - assertThat(newFloatingBpsPrice.modelType()).isEqualTo(NewFloatingBpsPrice.ModelType.BPS) - assertThat(newFloatingBpsPrice.name()).isEqualTo("Annual fee") - assertThat(newFloatingBpsPrice.billableMetricId()).isEqualTo("billable_metric_id") - assertThat(newFloatingBpsPrice.billedInAdvance()).isEqualTo(true) - assertThat(newFloatingBpsPrice.billingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newFloatingBpsPrice.conversionRate()).isEqualTo(0.0) - assertThat(newFloatingBpsPrice.conversionRateConfig()) - .isEqualTo( - NewFloatingBpsPrice.ConversionRateConfig.ofUnit( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .build() - ) - ) - assertThat(newFloatingBpsPrice.dimensionalPriceConfiguration()) - .isEqualTo( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - assertThat(newFloatingBpsPrice.externalPriceId()).isEqualTo("external_price_id") - assertThat(newFloatingBpsPrice.fixedPriceQuantity()).isEqualTo(0.0) - assertThat(newFloatingBpsPrice.invoiceGroupingKey()).isEqualTo("x") - assertThat(newFloatingBpsPrice.invoicingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newFloatingBpsPrice.metadata()) - .isEqualTo( - NewFloatingBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val newFloatingBpsPrice = - NewFloatingBpsPrice.builder() - .bpsConfig(BpsConfig.builder().bps(0.0).perUnitMaximum("per_unit_maximum").build()) - .cadence(NewFloatingBpsPrice.Cadence.ANNUAL) - .currency("currency") - .itemId("item_id") - .modelType(NewFloatingBpsPrice.ModelType.BPS) - .name("Annual fee") - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewFloatingBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .build() - - val roundtrippedNewFloatingBpsPrice = - jsonMapper.readValue( - jsonMapper.writeValueAsString(newFloatingBpsPrice), - jacksonTypeRef(), - ) - - assertThat(roundtrippedNewFloatingBpsPrice).isEqualTo(newFloatingBpsPrice) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBulkPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBulkPriceTest.kt index 62455b517..f5e6f0403 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBulkPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBulkPriceTest.kt @@ -84,7 +84,7 @@ internal class NewFloatingBulkPriceTest { assertThat(newFloatingBulkPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingBulkPrice.conversionRateConfig()) .isEqualTo( - NewFloatingBulkPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBulkWithProrationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBulkWithProrationPriceTest.kt index 4e63b73b5..1326341ce 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBulkWithProrationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBulkWithProrationPriceTest.kt @@ -16,7 +16,18 @@ internal class NewFloatingBulkWithProrationPriceTest { NewFloatingBulkWithProrationPrice.builder() .bulkWithProrationConfig( NewFloatingBulkWithProrationPrice.BulkWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewFloatingBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewFloatingBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .cadence(NewFloatingBulkWithProrationPrice.Cadence.ANNUAL) @@ -62,7 +73,18 @@ internal class NewFloatingBulkWithProrationPriceTest { assertThat(newFloatingBulkWithProrationPrice.bulkWithProrationConfig()) .isEqualTo( NewFloatingBulkWithProrationPrice.BulkWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewFloatingBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewFloatingBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) assertThat(newFloatingBulkWithProrationPrice.cadence()) @@ -85,7 +107,7 @@ internal class NewFloatingBulkWithProrationPriceTest { assertThat(newFloatingBulkWithProrationPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingBulkWithProrationPrice.conversionRateConfig()) .isEqualTo( - NewFloatingBulkWithProrationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -128,7 +150,18 @@ internal class NewFloatingBulkWithProrationPriceTest { NewFloatingBulkWithProrationPrice.builder() .bulkWithProrationConfig( NewFloatingBulkWithProrationPrice.BulkWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewFloatingBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewFloatingBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .cadence(NewFloatingBulkWithProrationPrice.Cadence.ANNUAL) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingCumulativeGroupedBulkPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingCumulativeGroupedBulkPriceTest.kt index ba7b242cc..bc31d68ab 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingCumulativeGroupedBulkPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingCumulativeGroupedBulkPriceTest.kt @@ -17,7 +17,16 @@ internal class NewFloatingCumulativeGroupedBulkPriceTest { .cadence(NewFloatingCumulativeGroupedBulkPrice.Cadence.ANNUAL) .cumulativeGroupedBulkConfig( NewFloatingCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addDimensionValue( + NewFloatingCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig + .DimensionValue + .builder() + .groupingKey("x") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .group("group") .build() ) .currency("currency") @@ -64,7 +73,16 @@ internal class NewFloatingCumulativeGroupedBulkPriceTest { assertThat(newFloatingCumulativeGroupedBulkPrice.cumulativeGroupedBulkConfig()) .isEqualTo( NewFloatingCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addDimensionValue( + NewFloatingCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig + .DimensionValue + .builder() + .groupingKey("x") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .group("group") .build() ) assertThat(newFloatingCumulativeGroupedBulkPrice.currency()).isEqualTo("currency") @@ -85,7 +103,7 @@ internal class NewFloatingCumulativeGroupedBulkPriceTest { assertThat(newFloatingCumulativeGroupedBulkPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingCumulativeGroupedBulkPrice.conversionRateConfig()) .isEqualTo( - NewFloatingCumulativeGroupedBulkPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -129,7 +147,16 @@ internal class NewFloatingCumulativeGroupedBulkPriceTest { .cadence(NewFloatingCumulativeGroupedBulkPrice.Cadence.ANNUAL) .cumulativeGroupedBulkConfig( NewFloatingCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addDimensionValue( + NewFloatingCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig + .DimensionValue + .builder() + .groupingKey("x") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .group("group") .build() ) .currency("currency") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedAllocationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedAllocationPriceTest.kt index 268c406ad..cebafb107 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedAllocationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedAllocationPriceTest.kt @@ -18,7 +18,9 @@ internal class NewFloatingGroupedAllocationPriceTest { .currency("currency") .groupedAllocationConfig( NewFloatingGroupedAllocationPrice.GroupedAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .groupingKey("x") + .overageUnitRate("overage_unit_rate") .build() ) .itemId("item_id") @@ -65,7 +67,9 @@ internal class NewFloatingGroupedAllocationPriceTest { assertThat(newFloatingGroupedAllocationPrice.groupedAllocationConfig()) .isEqualTo( NewFloatingGroupedAllocationPrice.GroupedAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .groupingKey("x") + .overageUnitRate("overage_unit_rate") .build() ) assertThat(newFloatingGroupedAllocationPrice.itemId()).isEqualTo("item_id") @@ -85,7 +89,7 @@ internal class NewFloatingGroupedAllocationPriceTest { assertThat(newFloatingGroupedAllocationPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingGroupedAllocationPrice.conversionRateConfig()) .isEqualTo( - NewFloatingGroupedAllocationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -130,7 +134,9 @@ internal class NewFloatingGroupedAllocationPriceTest { .currency("currency") .groupedAllocationConfig( NewFloatingGroupedAllocationPrice.GroupedAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .groupingKey("x") + .overageUnitRate("overage_unit_rate") .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPackagePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPackagePriceTest.kt index 38ff8f11f..5024114f4 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPackagePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPackagePriceTest.kt @@ -18,7 +18,22 @@ internal class NewFloatingGroupedTieredPackagePriceTest { .currency("currency") .groupedTieredPackageConfig( NewFloatingGroupedTieredPackagePrice.GroupedTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewFloatingGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewFloatingGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .itemId("item_id") @@ -65,7 +80,22 @@ internal class NewFloatingGroupedTieredPackagePriceTest { assertThat(newFloatingGroupedTieredPackagePrice.groupedTieredPackageConfig()) .isEqualTo( NewFloatingGroupedTieredPackagePrice.GroupedTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewFloatingGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewFloatingGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) assertThat(newFloatingGroupedTieredPackagePrice.itemId()).isEqualTo("item_id") @@ -85,7 +115,7 @@ internal class NewFloatingGroupedTieredPackagePriceTest { assertThat(newFloatingGroupedTieredPackagePrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingGroupedTieredPackagePrice.conversionRateConfig()) .isEqualTo( - NewFloatingGroupedTieredPackagePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -130,7 +160,22 @@ internal class NewFloatingGroupedTieredPackagePriceTest { .currency("currency") .groupedTieredPackageConfig( NewFloatingGroupedTieredPackagePrice.GroupedTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewFloatingGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewFloatingGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPriceTest.kt index bfa46363a..2c5b7e5b4 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedTieredPriceTest.kt @@ -18,7 +18,19 @@ internal class NewFloatingGroupedTieredPriceTest { .currency("currency") .groupedTieredConfig( NewFloatingGroupedTieredPrice.GroupedTieredConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .addTier( + NewFloatingGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewFloatingGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .itemId("item_id") @@ -65,7 +77,19 @@ internal class NewFloatingGroupedTieredPriceTest { assertThat(newFloatingGroupedTieredPrice.groupedTieredConfig()) .isEqualTo( NewFloatingGroupedTieredPrice.GroupedTieredConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .addTier( + NewFloatingGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewFloatingGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) assertThat(newFloatingGroupedTieredPrice.itemId()).isEqualTo("item_id") @@ -84,7 +108,7 @@ internal class NewFloatingGroupedTieredPriceTest { assertThat(newFloatingGroupedTieredPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingGroupedTieredPrice.conversionRateConfig()) .isEqualTo( - NewFloatingGroupedTieredPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -128,7 +152,19 @@ internal class NewFloatingGroupedTieredPriceTest { .currency("currency") .groupedTieredConfig( NewFloatingGroupedTieredPrice.GroupedTieredConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .addTier( + NewFloatingGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewFloatingGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedWithMeteredMinimumPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedWithMeteredMinimumPriceTest.kt index 8fe4853f4..086f81e57 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedWithMeteredMinimumPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedWithMeteredMinimumPriceTest.kt @@ -19,7 +19,28 @@ internal class NewFloatingGroupedWithMeteredMinimumPriceTest { .groupedWithMeteredMinimumConfig( NewFloatingGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimumUnitAmount("minimum_unit_amount") + .pricingKey("pricing_key") + .addScalingFactor( + NewFloatingGroupedWithMeteredMinimumPrice + .GroupedWithMeteredMinimumConfig + .ScalingFactor + .builder() + .scalingFactor("scaling_factor") + .scalingValue("scaling_value") + .build() + ) + .scalingKey("scaling_key") + .addUnitAmount( + NewFloatingGroupedWithMeteredMinimumPrice + .GroupedWithMeteredMinimumConfig + .UnitAmount + .builder() + .pricingValue("pricing_value") + .unitAmount("unit_amount") + .build() + ) .build() ) .itemId("item_id") @@ -68,7 +89,26 @@ internal class NewFloatingGroupedWithMeteredMinimumPriceTest { assertThat(newFloatingGroupedWithMeteredMinimumPrice.groupedWithMeteredMinimumConfig()) .isEqualTo( NewFloatingGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimumUnitAmount("minimum_unit_amount") + .pricingKey("pricing_key") + .addScalingFactor( + NewFloatingGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig + .ScalingFactor + .builder() + .scalingFactor("scaling_factor") + .scalingValue("scaling_value") + .build() + ) + .scalingKey("scaling_key") + .addUnitAmount( + NewFloatingGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig + .UnitAmount + .builder() + .pricingValue("pricing_value") + .unitAmount("unit_amount") + .build() + ) .build() ) assertThat(newFloatingGroupedWithMeteredMinimumPrice.itemId()).isEqualTo("item_id") @@ -90,7 +130,7 @@ internal class NewFloatingGroupedWithMeteredMinimumPriceTest { assertThat(newFloatingGroupedWithMeteredMinimumPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingGroupedWithMeteredMinimumPrice.conversionRateConfig()) .isEqualTo( - NewFloatingGroupedWithMeteredMinimumPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -136,7 +176,28 @@ internal class NewFloatingGroupedWithMeteredMinimumPriceTest { .groupedWithMeteredMinimumConfig( NewFloatingGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimumUnitAmount("minimum_unit_amount") + .pricingKey("pricing_key") + .addScalingFactor( + NewFloatingGroupedWithMeteredMinimumPrice + .GroupedWithMeteredMinimumConfig + .ScalingFactor + .builder() + .scalingFactor("scaling_factor") + .scalingValue("scaling_value") + .build() + ) + .scalingKey("scaling_key") + .addUnitAmount( + NewFloatingGroupedWithMeteredMinimumPrice + .GroupedWithMeteredMinimumConfig + .UnitAmount + .builder() + .pricingValue("pricing_value") + .unitAmount("unit_amount") + .build() + ) .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedWithProratedMinimumPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedWithProratedMinimumPriceTest.kt index beecb65bd..c3483007b 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedWithProratedMinimumPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingGroupedWithProratedMinimumPriceTest.kt @@ -19,7 +19,9 @@ internal class NewFloatingGroupedWithProratedMinimumPriceTest { .groupedWithProratedMinimumConfig( NewFloatingGroupedWithProratedMinimumPrice.GroupedWithProratedMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimum("minimum") + .unitRate("unit_rate") .build() ) .itemId("item_id") @@ -70,7 +72,9 @@ internal class NewFloatingGroupedWithProratedMinimumPriceTest { .isEqualTo( NewFloatingGroupedWithProratedMinimumPrice.GroupedWithProratedMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimum("minimum") + .unitRate("unit_rate") .build() ) assertThat(newFloatingGroupedWithProratedMinimumPrice.itemId()).isEqualTo("item_id") @@ -92,7 +96,7 @@ internal class NewFloatingGroupedWithProratedMinimumPriceTest { assertThat(newFloatingGroupedWithProratedMinimumPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingGroupedWithProratedMinimumPrice.conversionRateConfig()) .isEqualTo( - NewFloatingGroupedWithProratedMinimumPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -138,7 +142,9 @@ internal class NewFloatingGroupedWithProratedMinimumPriceTest { .groupedWithProratedMinimumConfig( NewFloatingGroupedWithProratedMinimumPrice.GroupedWithProratedMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimum("minimum") + .unitRate("unit_rate") .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMatrixPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMatrixPriceTest.kt index 0c105fd7d..c0acf01a6 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMatrixPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMatrixPriceTest.kt @@ -98,7 +98,7 @@ internal class NewFloatingMatrixPriceTest { assertThat(newFloatingMatrixPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingMatrixPrice.conversionRateConfig()) .isEqualTo( - NewFloatingMatrixPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMatrixWithAllocationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMatrixWithAllocationPriceTest.kt index 8e30b3be0..52190e650 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMatrixWithAllocationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMatrixWithAllocationPriceTest.kt @@ -19,11 +19,11 @@ internal class NewFloatingMatrixWithAllocationPriceTest { .itemId("item_id") .matrixWithAllocationConfig( MatrixWithAllocationConfig.builder() - .allocation(0.0) + .allocation("allocation") .defaultUnitAmount("default_unit_amount") .addDimension("string") .addMatrixValue( - MatrixValue.builder() + MatrixWithAllocationConfig.MatrixValue.builder() .addDimensionValue("string") .unitAmount("unit_amount") .build() @@ -74,11 +74,11 @@ internal class NewFloatingMatrixWithAllocationPriceTest { assertThat(newFloatingMatrixWithAllocationPrice.matrixWithAllocationConfig()) .isEqualTo( MatrixWithAllocationConfig.builder() - .allocation(0.0) + .allocation("allocation") .defaultUnitAmount("default_unit_amount") .addDimension("string") .addMatrixValue( - MatrixValue.builder() + MatrixWithAllocationConfig.MatrixValue.builder() .addDimensionValue("string") .unitAmount("unit_amount") .build() @@ -101,7 +101,7 @@ internal class NewFloatingMatrixWithAllocationPriceTest { assertThat(newFloatingMatrixWithAllocationPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingMatrixWithAllocationPrice.conversionRateConfig()) .isEqualTo( - NewFloatingMatrixWithAllocationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -147,11 +147,11 @@ internal class NewFloatingMatrixWithAllocationPriceTest { .itemId("item_id") .matrixWithAllocationConfig( MatrixWithAllocationConfig.builder() - .allocation(0.0) + .allocation("allocation") .defaultUnitAmount("default_unit_amount") .addDimension("string") .addMatrixValue( - MatrixValue.builder() + MatrixWithAllocationConfig.MatrixValue.builder() .addDimensionValue("string") .unitAmount("unit_amount") .build() diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMatrixWithDisplayNamePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMatrixWithDisplayNamePriceTest.kt index 622a93f47..ab4dc60e7 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMatrixWithDisplayNamePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMatrixWithDisplayNamePriceTest.kt @@ -19,7 +19,16 @@ internal class NewFloatingMatrixWithDisplayNamePriceTest { .itemId("item_id") .matrixWithDisplayNameConfig( NewFloatingMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .dimension("dimension") + .addUnitAmount( + NewFloatingMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig + .UnitAmount + .builder() + .dimensionValue("dimension_value") + .displayName("display_name") + .unitAmount("unit_amount") + .build() + ) .build() ) .modelType(NewFloatingMatrixWithDisplayNamePrice.ModelType.MATRIX_WITH_DISPLAY_NAME) @@ -66,7 +75,15 @@ internal class NewFloatingMatrixWithDisplayNamePriceTest { assertThat(newFloatingMatrixWithDisplayNamePrice.matrixWithDisplayNameConfig()) .isEqualTo( NewFloatingMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .dimension("dimension") + .addUnitAmount( + NewFloatingMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig.UnitAmount + .builder() + .dimensionValue("dimension_value") + .displayName("display_name") + .unitAmount("unit_amount") + .build() + ) .build() ) assertThat(newFloatingMatrixWithDisplayNamePrice.modelType()) @@ -85,7 +102,7 @@ internal class NewFloatingMatrixWithDisplayNamePriceTest { assertThat(newFloatingMatrixWithDisplayNamePrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingMatrixWithDisplayNamePrice.conversionRateConfig()) .isEqualTo( - NewFloatingMatrixWithDisplayNamePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -131,7 +148,16 @@ internal class NewFloatingMatrixWithDisplayNamePriceTest { .itemId("item_id") .matrixWithDisplayNameConfig( NewFloatingMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .dimension("dimension") + .addUnitAmount( + NewFloatingMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig + .UnitAmount + .builder() + .dimensionValue("dimension_value") + .displayName("display_name") + .unitAmount("unit_amount") + .build() + ) .build() ) .modelType(NewFloatingMatrixWithDisplayNamePrice.ModelType.MATRIX_WITH_DISPLAY_NAME) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMaxGroupTieredPackagePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMaxGroupTieredPackagePriceTest.kt index c3cef3cba..bb504e15b 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMaxGroupTieredPackagePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMaxGroupTieredPackagePriceTest.kt @@ -19,7 +19,22 @@ internal class NewFloatingMaxGroupTieredPackagePriceTest { .itemId("item_id") .maxGroupTieredPackageConfig( NewFloatingMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewFloatingMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewFloatingMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .modelType(NewFloatingMaxGroupTieredPackagePrice.ModelType.MAX_GROUP_TIERED_PACKAGE) @@ -66,7 +81,22 @@ internal class NewFloatingMaxGroupTieredPackagePriceTest { assertThat(newFloatingMaxGroupTieredPackagePrice.maxGroupTieredPackageConfig()) .isEqualTo( NewFloatingMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewFloatingMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewFloatingMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) assertThat(newFloatingMaxGroupTieredPackagePrice.modelType()) @@ -85,7 +115,7 @@ internal class NewFloatingMaxGroupTieredPackagePriceTest { assertThat(newFloatingMaxGroupTieredPackagePrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingMaxGroupTieredPackagePrice.conversionRateConfig()) .isEqualTo( - NewFloatingMaxGroupTieredPackagePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -131,7 +161,22 @@ internal class NewFloatingMaxGroupTieredPackagePriceTest { .itemId("item_id") .maxGroupTieredPackageConfig( NewFloatingMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewFloatingMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewFloatingMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .modelType(NewFloatingMaxGroupTieredPackagePrice.ModelType.MAX_GROUP_TIERED_PACKAGE) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBulkBpsPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMinimumCompositePriceTest.kt similarity index 60% rename from orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBulkBpsPriceTest.kt rename to orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMinimumCompositePriceTest.kt index 2a1e26faf..9106d3c6e 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingBulkBpsPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingMinimumCompositePriceTest.kt @@ -8,27 +8,22 @@ import com.withorb.api.core.jsonMapper import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -internal class NewFloatingBulkBpsPriceTest { +internal class NewFloatingMinimumCompositePriceTest { @Test fun create() { - val newFloatingBulkBpsPrice = - NewFloatingBulkBpsPrice.builder() - .bulkBpsConfig( - BulkBpsConfig.builder() - .addTier( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - .cadence(NewFloatingBulkBpsPrice.Cadence.ANNUAL) + val newFloatingMinimumCompositePrice = + NewFloatingMinimumCompositePrice.builder() + .cadence(NewFloatingMinimumCompositePrice.Cadence.ANNUAL) .currency("currency") .itemId("item_id") - .modelType(NewFloatingBulkBpsPrice.ModelType.BULK_BPS) + .minimumConfig( + NewFloatingMinimumCompositePrice.MinimumConfig.builder() + .minimumAmount("minimum_amount") + .prorated(true) + .build() + ) + .modelType(NewFloatingMinimumCompositePrice.ModelType.MINIMUM) .name("Annual fee") .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -59,44 +54,40 @@ internal class NewFloatingBulkBpsPriceTest { .build() ) .metadata( - NewFloatingBulkBpsPrice.Metadata.builder() + NewFloatingMinimumCompositePrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) .build() - assertThat(newFloatingBulkBpsPrice.bulkBpsConfig()) + assertThat(newFloatingMinimumCompositePrice.cadence()) + .isEqualTo(NewFloatingMinimumCompositePrice.Cadence.ANNUAL) + assertThat(newFloatingMinimumCompositePrice.currency()).isEqualTo("currency") + assertThat(newFloatingMinimumCompositePrice.itemId()).isEqualTo("item_id") + assertThat(newFloatingMinimumCompositePrice.minimumConfig()) .isEqualTo( - BulkBpsConfig.builder() - .addTier( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) + NewFloatingMinimumCompositePrice.MinimumConfig.builder() + .minimumAmount("minimum_amount") + .prorated(true) .build() ) - assertThat(newFloatingBulkBpsPrice.cadence()) - .isEqualTo(NewFloatingBulkBpsPrice.Cadence.ANNUAL) - assertThat(newFloatingBulkBpsPrice.currency()).isEqualTo("currency") - assertThat(newFloatingBulkBpsPrice.itemId()).isEqualTo("item_id") - assertThat(newFloatingBulkBpsPrice.modelType()) - .isEqualTo(NewFloatingBulkBpsPrice.ModelType.BULK_BPS) - assertThat(newFloatingBulkBpsPrice.name()).isEqualTo("Annual fee") - assertThat(newFloatingBulkBpsPrice.billableMetricId()).isEqualTo("billable_metric_id") - assertThat(newFloatingBulkBpsPrice.billedInAdvance()).isEqualTo(true) - assertThat(newFloatingBulkBpsPrice.billingCycleConfiguration()) + assertThat(newFloatingMinimumCompositePrice.modelType()) + .isEqualTo(NewFloatingMinimumCompositePrice.ModelType.MINIMUM) + assertThat(newFloatingMinimumCompositePrice.name()).isEqualTo("Annual fee") + assertThat(newFloatingMinimumCompositePrice.billableMetricId()) + .isEqualTo("billable_metric_id") + assertThat(newFloatingMinimumCompositePrice.billedInAdvance()).isEqualTo(true) + assertThat(newFloatingMinimumCompositePrice.billingCycleConfiguration()) .isEqualTo( NewBillingCycleConfiguration.builder() .duration(0L) .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) .build() ) - assertThat(newFloatingBulkBpsPrice.conversionRate()).isEqualTo(0.0) - assertThat(newFloatingBulkBpsPrice.conversionRateConfig()) + assertThat(newFloatingMinimumCompositePrice.conversionRate()).isEqualTo(0.0) + assertThat(newFloatingMinimumCompositePrice.conversionRateConfig()) .isEqualTo( - NewFloatingBulkBpsPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -105,7 +96,7 @@ internal class NewFloatingBulkBpsPriceTest { .build() ) ) - assertThat(newFloatingBulkBpsPrice.dimensionalPriceConfiguration()) + assertThat(newFloatingMinimumCompositePrice.dimensionalPriceConfiguration()) .isEqualTo( NewDimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -113,19 +104,20 @@ internal class NewFloatingBulkBpsPriceTest { .externalDimensionalPriceGroupId("external_dimensional_price_group_id") .build() ) - assertThat(newFloatingBulkBpsPrice.externalPriceId()).isEqualTo("external_price_id") - assertThat(newFloatingBulkBpsPrice.fixedPriceQuantity()).isEqualTo(0.0) - assertThat(newFloatingBulkBpsPrice.invoiceGroupingKey()).isEqualTo("x") - assertThat(newFloatingBulkBpsPrice.invoicingCycleConfiguration()) + assertThat(newFloatingMinimumCompositePrice.externalPriceId()) + .isEqualTo("external_price_id") + assertThat(newFloatingMinimumCompositePrice.fixedPriceQuantity()).isEqualTo(0.0) + assertThat(newFloatingMinimumCompositePrice.invoiceGroupingKey()).isEqualTo("x") + assertThat(newFloatingMinimumCompositePrice.invoicingCycleConfiguration()) .isEqualTo( NewBillingCycleConfiguration.builder() .duration(0L) .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) .build() ) - assertThat(newFloatingBulkBpsPrice.metadata()) + assertThat(newFloatingMinimumCompositePrice.metadata()) .isEqualTo( - NewFloatingBulkBpsPrice.Metadata.builder() + NewFloatingMinimumCompositePrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -134,23 +126,18 @@ internal class NewFloatingBulkBpsPriceTest { @Test fun roundtrip() { val jsonMapper = jsonMapper() - val newFloatingBulkBpsPrice = - NewFloatingBulkBpsPrice.builder() - .bulkBpsConfig( - BulkBpsConfig.builder() - .addTier( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - .cadence(NewFloatingBulkBpsPrice.Cadence.ANNUAL) + val newFloatingMinimumCompositePrice = + NewFloatingMinimumCompositePrice.builder() + .cadence(NewFloatingMinimumCompositePrice.Cadence.ANNUAL) .currency("currency") .itemId("item_id") - .modelType(NewFloatingBulkBpsPrice.ModelType.BULK_BPS) + .minimumConfig( + NewFloatingMinimumCompositePrice.MinimumConfig.builder() + .minimumAmount("minimum_amount") + .prorated(true) + .build() + ) + .modelType(NewFloatingMinimumCompositePrice.ModelType.MINIMUM) .name("Annual fee") .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -181,18 +168,19 @@ internal class NewFloatingBulkBpsPriceTest { .build() ) .metadata( - NewFloatingBulkBpsPrice.Metadata.builder() + NewFloatingMinimumCompositePrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) .build() - val roundtrippedNewFloatingBulkBpsPrice = + val roundtrippedNewFloatingMinimumCompositePrice = jsonMapper.readValue( - jsonMapper.writeValueAsString(newFloatingBulkBpsPrice), - jacksonTypeRef(), + jsonMapper.writeValueAsString(newFloatingMinimumCompositePrice), + jacksonTypeRef(), ) - assertThat(roundtrippedNewFloatingBulkBpsPrice).isEqualTo(newFloatingBulkBpsPrice) + assertThat(roundtrippedNewFloatingMinimumCompositePrice) + .isEqualTo(newFloatingMinimumCompositePrice) } } diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingPackagePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingPackagePriceTest.kt index 0f5972689..f19650a2a 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingPackagePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingPackagePriceTest.kt @@ -20,7 +20,7 @@ internal class NewFloatingPackagePriceTest { .modelType(NewFloatingPackagePrice.ModelType.PACKAGE) .name("Annual fee") .packageConfig( - PackageConfig.builder().packageAmount("package_amount").packageSize(0L).build() + PackageConfig.builder().packageAmount("package_amount").packageSize(1L).build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -66,7 +66,7 @@ internal class NewFloatingPackagePriceTest { assertThat(newFloatingPackagePrice.name()).isEqualTo("Annual fee") assertThat(newFloatingPackagePrice.packageConfig()) .isEqualTo( - PackageConfig.builder().packageAmount("package_amount").packageSize(0L).build() + PackageConfig.builder().packageAmount("package_amount").packageSize(1L).build() ) assertThat(newFloatingPackagePrice.billableMetricId()).isEqualTo("billable_metric_id") assertThat(newFloatingPackagePrice.billedInAdvance()).isEqualTo(true) @@ -80,7 +80,7 @@ internal class NewFloatingPackagePriceTest { assertThat(newFloatingPackagePrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingPackagePrice.conversionRateConfig()) .isEqualTo( - NewFloatingPackagePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -126,7 +126,7 @@ internal class NewFloatingPackagePriceTest { .modelType(NewFloatingPackagePrice.ModelType.PACKAGE) .name("Annual fee") .packageConfig( - PackageConfig.builder().packageAmount("package_amount").packageSize(0L).build() + PackageConfig.builder().packageAmount("package_amount").packageSize(1L).build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingPackageWithAllocationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingPackageWithAllocationPriceTest.kt index 0dbd1ccbc..29e99f0e2 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingPackageWithAllocationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingPackageWithAllocationPriceTest.kt @@ -21,7 +21,9 @@ internal class NewFloatingPackageWithAllocationPriceTest { .name("Annual fee") .packageWithAllocationConfig( NewFloatingPackageWithAllocationPrice.PackageWithAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .packageAmount("package_amount") + .packageSize("package_size") .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +71,9 @@ internal class NewFloatingPackageWithAllocationPriceTest { assertThat(newFloatingPackageWithAllocationPrice.packageWithAllocationConfig()) .isEqualTo( NewFloatingPackageWithAllocationPrice.PackageWithAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .packageAmount("package_amount") + .packageSize("package_size") .build() ) assertThat(newFloatingPackageWithAllocationPrice.billableMetricId()) @@ -85,7 +89,7 @@ internal class NewFloatingPackageWithAllocationPriceTest { assertThat(newFloatingPackageWithAllocationPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingPackageWithAllocationPrice.conversionRateConfig()) .isEqualTo( - NewFloatingPackageWithAllocationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -133,7 +137,9 @@ internal class NewFloatingPackageWithAllocationPriceTest { .name("Annual fee") .packageWithAllocationConfig( NewFloatingPackageWithAllocationPrice.PackageWithAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .packageAmount("package_amount") + .packageSize("package_size") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithTieredPricingPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithTieredPricingPriceTest.kt index dddcaca46..b7c746752 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithTieredPricingPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithTieredPricingPriceTest.kt @@ -26,7 +26,36 @@ internal class NewFloatingScalableMatrixWithTieredPricingPriceTest { NewFloatingScalableMatrixWithTieredPricingPrice .ScalableMatrixWithTieredPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewFloatingScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .addTier( + NewFloatingScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewFloatingScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .secondDimension("second_dimension") .build() ) .billableMetricId("billable_metric_id") @@ -82,7 +111,36 @@ internal class NewFloatingScalableMatrixWithTieredPricingPriceTest { NewFloatingScalableMatrixWithTieredPricingPrice .ScalableMatrixWithTieredPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewFloatingScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .addTier( + NewFloatingScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewFloatingScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .secondDimension("second_dimension") .build() ) assertThat(newFloatingScalableMatrixWithTieredPricingPrice.billableMetricId()) @@ -99,7 +157,7 @@ internal class NewFloatingScalableMatrixWithTieredPricingPriceTest { assertThat(newFloatingScalableMatrixWithTieredPricingPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingScalableMatrixWithTieredPricingPrice.conversionRateConfig()) .isEqualTo( - NewFloatingScalableMatrixWithTieredPricingPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -154,7 +212,36 @@ internal class NewFloatingScalableMatrixWithTieredPricingPriceTest { NewFloatingScalableMatrixWithTieredPricingPrice .ScalableMatrixWithTieredPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewFloatingScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .addTier( + NewFloatingScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewFloatingScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .secondDimension("second_dimension") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithUnitPricingPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithUnitPricingPriceTest.kt index 5b4615121..a387a2126 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithUnitPricingPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingScalableMatrixWithUnitPricingPriceTest.kt @@ -26,7 +26,20 @@ internal class NewFloatingScalableMatrixWithUnitPricingPriceTest { NewFloatingScalableMatrixWithUnitPricingPrice .ScalableMatrixWithUnitPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewFloatingScalableMatrixWithUnitPricingPrice + .ScalableMatrixWithUnitPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .unitPrice("unit_price") + .prorate(true) + .secondDimension("second_dimension") .build() ) .billableMetricId("billable_metric_id") @@ -80,7 +93,20 @@ internal class NewFloatingScalableMatrixWithUnitPricingPriceTest { .isEqualTo( NewFloatingScalableMatrixWithUnitPricingPrice.ScalableMatrixWithUnitPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewFloatingScalableMatrixWithUnitPricingPrice + .ScalableMatrixWithUnitPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .unitPrice("unit_price") + .prorate(true) + .secondDimension("second_dimension") .build() ) assertThat(newFloatingScalableMatrixWithUnitPricingPrice.billableMetricId()) @@ -96,7 +122,7 @@ internal class NewFloatingScalableMatrixWithUnitPricingPriceTest { assertThat(newFloatingScalableMatrixWithUnitPricingPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingScalableMatrixWithUnitPricingPrice.conversionRateConfig()) .isEqualTo( - NewFloatingScalableMatrixWithUnitPricingPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -151,7 +177,20 @@ internal class NewFloatingScalableMatrixWithUnitPricingPriceTest { NewFloatingScalableMatrixWithUnitPricingPrice .ScalableMatrixWithUnitPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewFloatingScalableMatrixWithUnitPricingPrice + .ScalableMatrixWithUnitPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .unitPrice("unit_price") + .prorate(true) + .secondDimension("second_dimension") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingThresholdTotalAmountPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingThresholdTotalAmountPriceTest.kt index 19391f580..e40323719 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingThresholdTotalAmountPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingThresholdTotalAmountPriceTest.kt @@ -21,7 +21,23 @@ internal class NewFloatingThresholdTotalAmountPriceTest { .name("Annual fee") .thresholdTotalAmountConfig( NewFloatingThresholdTotalAmountPrice.ThresholdTotalAmountConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addConsumptionTable( + NewFloatingThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .addConsumptionTable( + NewFloatingThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .prorate(true) .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +85,23 @@ internal class NewFloatingThresholdTotalAmountPriceTest { assertThat(newFloatingThresholdTotalAmountPrice.thresholdTotalAmountConfig()) .isEqualTo( NewFloatingThresholdTotalAmountPrice.ThresholdTotalAmountConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addConsumptionTable( + NewFloatingThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .addConsumptionTable( + NewFloatingThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .prorate(true) .build() ) assertThat(newFloatingThresholdTotalAmountPrice.billableMetricId()) @@ -85,7 +117,7 @@ internal class NewFloatingThresholdTotalAmountPriceTest { assertThat(newFloatingThresholdTotalAmountPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingThresholdTotalAmountPrice.conversionRateConfig()) .isEqualTo( - NewFloatingThresholdTotalAmountPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -133,7 +165,23 @@ internal class NewFloatingThresholdTotalAmountPriceTest { .name("Annual fee") .thresholdTotalAmountConfig( NewFloatingThresholdTotalAmountPrice.ThresholdTotalAmountConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addConsumptionTable( + NewFloatingThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .addConsumptionTable( + NewFloatingThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .prorate(true) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredBpsPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredBpsPriceTest.kt deleted file mode 100644 index d4c737c4b..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredBpsPriceTest.kt +++ /dev/null @@ -1,201 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.JsonValue -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class NewFloatingTieredBpsPriceTest { - - @Test - fun create() { - val newFloatingTieredBpsPrice = - NewFloatingTieredBpsPrice.builder() - .cadence(NewFloatingTieredBpsPrice.Cadence.ANNUAL) - .currency("currency") - .itemId("item_id") - .modelType(NewFloatingTieredBpsPrice.ModelType.TIERED_BPS) - .name("Annual fee") - .tieredBpsConfig( - TieredBpsConfig.builder() - .addTier( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewFloatingTieredBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .build() - - assertThat(newFloatingTieredBpsPrice.cadence()) - .isEqualTo(NewFloatingTieredBpsPrice.Cadence.ANNUAL) - assertThat(newFloatingTieredBpsPrice.currency()).isEqualTo("currency") - assertThat(newFloatingTieredBpsPrice.itemId()).isEqualTo("item_id") - assertThat(newFloatingTieredBpsPrice.modelType()) - .isEqualTo(NewFloatingTieredBpsPrice.ModelType.TIERED_BPS) - assertThat(newFloatingTieredBpsPrice.name()).isEqualTo("Annual fee") - assertThat(newFloatingTieredBpsPrice.tieredBpsConfig()) - .isEqualTo( - TieredBpsConfig.builder() - .addTier( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - assertThat(newFloatingTieredBpsPrice.billableMetricId()).isEqualTo("billable_metric_id") - assertThat(newFloatingTieredBpsPrice.billedInAdvance()).isEqualTo(true) - assertThat(newFloatingTieredBpsPrice.billingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newFloatingTieredBpsPrice.conversionRate()).isEqualTo(0.0) - assertThat(newFloatingTieredBpsPrice.conversionRateConfig()) - .isEqualTo( - NewFloatingTieredBpsPrice.ConversionRateConfig.ofUnit( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .build() - ) - ) - assertThat(newFloatingTieredBpsPrice.dimensionalPriceConfiguration()) - .isEqualTo( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - assertThat(newFloatingTieredBpsPrice.externalPriceId()).isEqualTo("external_price_id") - assertThat(newFloatingTieredBpsPrice.fixedPriceQuantity()).isEqualTo(0.0) - assertThat(newFloatingTieredBpsPrice.invoiceGroupingKey()).isEqualTo("x") - assertThat(newFloatingTieredBpsPrice.invoicingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newFloatingTieredBpsPrice.metadata()) - .isEqualTo( - NewFloatingTieredBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val newFloatingTieredBpsPrice = - NewFloatingTieredBpsPrice.builder() - .cadence(NewFloatingTieredBpsPrice.Cadence.ANNUAL) - .currency("currency") - .itemId("item_id") - .modelType(NewFloatingTieredBpsPrice.ModelType.TIERED_BPS) - .name("Annual fee") - .tieredBpsConfig( - TieredBpsConfig.builder() - .addTier( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewFloatingTieredBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .build() - - val roundtrippedNewFloatingTieredBpsPrice = - jsonMapper.readValue( - jsonMapper.writeValueAsString(newFloatingTieredBpsPrice), - jacksonTypeRef(), - ) - - assertThat(roundtrippedNewFloatingTieredBpsPrice).isEqualTo(newFloatingTieredBpsPrice) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredPackagePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredPackagePriceTest.kt index 831424b33..9222c9858 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredPackagePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredPackagePriceTest.kt @@ -21,7 +21,19 @@ internal class NewFloatingTieredPackagePriceTest { .name("Annual fee") .tieredPackageConfig( NewFloatingTieredPackagePrice.TieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize("package_size") + .addTier( + NewFloatingTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewFloatingTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +81,19 @@ internal class NewFloatingTieredPackagePriceTest { assertThat(newFloatingTieredPackagePrice.tieredPackageConfig()) .isEqualTo( NewFloatingTieredPackagePrice.TieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize("package_size") + .addTier( + NewFloatingTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewFloatingTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) assertThat(newFloatingTieredPackagePrice.billableMetricId()).isEqualTo("billable_metric_id") @@ -84,7 +108,7 @@ internal class NewFloatingTieredPackagePriceTest { assertThat(newFloatingTieredPackagePrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingTieredPackagePrice.conversionRateConfig()) .isEqualTo( - NewFloatingTieredPackagePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -131,7 +155,19 @@ internal class NewFloatingTieredPackagePriceTest { .name("Annual fee") .tieredPackageConfig( NewFloatingTieredPackagePrice.TieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize("package_size") + .addTier( + NewFloatingTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewFloatingTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredPackageWithMinimumPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredPackageWithMinimumPriceTest.kt index 8499014e2..70db94c44 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredPackageWithMinimumPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredPackageWithMinimumPriceTest.kt @@ -24,7 +24,25 @@ internal class NewFloatingTieredPackageWithMinimumPriceTest { .tieredPackageWithMinimumConfig( NewFloatingTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize(0.0) + .addTier( + NewFloatingTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig + .Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewFloatingTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig + .Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .billableMetricId("billable_metric_id") @@ -74,7 +92,23 @@ internal class NewFloatingTieredPackageWithMinimumPriceTest { assertThat(newFloatingTieredPackageWithMinimumPrice.tieredPackageWithMinimumConfig()) .isEqualTo( NewFloatingTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize(0.0) + .addTier( + NewFloatingTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewFloatingTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) assertThat(newFloatingTieredPackageWithMinimumPrice.billableMetricId()) @@ -90,7 +124,7 @@ internal class NewFloatingTieredPackageWithMinimumPriceTest { assertThat(newFloatingTieredPackageWithMinimumPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingTieredPackageWithMinimumPrice.conversionRateConfig()) .isEqualTo( - NewFloatingTieredPackageWithMinimumPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -141,7 +175,25 @@ internal class NewFloatingTieredPackageWithMinimumPriceTest { .tieredPackageWithMinimumConfig( NewFloatingTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize(0.0) + .addTier( + NewFloatingTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig + .Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewFloatingTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig + .Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredPriceTest.kt index 0ed7ba70f..0b1ad1505 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredPriceTest.kt @@ -28,6 +28,7 @@ internal class NewFloatingTieredPriceTest { .lastUnit(0.0) .build() ) + .prorated(true) .build() ) .billableMetricId("billable_metric_id") @@ -82,6 +83,7 @@ internal class NewFloatingTieredPriceTest { .lastUnit(0.0) .build() ) + .prorated(true) .build() ) assertThat(newFloatingTieredPrice.billableMetricId()).isEqualTo("billable_metric_id") @@ -96,7 +98,7 @@ internal class NewFloatingTieredPriceTest { assertThat(newFloatingTieredPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingTieredPrice.conversionRateConfig()) .isEqualTo( - NewFloatingTieredPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -150,6 +152,7 @@ internal class NewFloatingTieredPriceTest { .lastUnit(0.0) .build() ) + .prorated(true) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredWithMinimumPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredWithMinimumPriceTest.kt index 5a52045cd..4c1244951 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredWithMinimumPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredWithMinimumPriceTest.kt @@ -21,7 +21,22 @@ internal class NewFloatingTieredWithMinimumPriceTest { .name("Annual fee") .tieredWithMinimumConfig( NewFloatingTieredWithMinimumPrice.TieredWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewFloatingTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewFloatingTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .hideZeroAmountTiers(true) + .prorate(true) .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +84,22 @@ internal class NewFloatingTieredWithMinimumPriceTest { assertThat(newFloatingTieredWithMinimumPrice.tieredWithMinimumConfig()) .isEqualTo( NewFloatingTieredWithMinimumPrice.TieredWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewFloatingTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewFloatingTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .hideZeroAmountTiers(true) + .prorate(true) .build() ) assertThat(newFloatingTieredWithMinimumPrice.billableMetricId()) @@ -85,7 +115,7 @@ internal class NewFloatingTieredWithMinimumPriceTest { assertThat(newFloatingTieredWithMinimumPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingTieredWithMinimumPrice.conversionRateConfig()) .isEqualTo( - NewFloatingTieredWithMinimumPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -133,7 +163,22 @@ internal class NewFloatingTieredWithMinimumPriceTest { .name("Annual fee") .tieredWithMinimumConfig( NewFloatingTieredWithMinimumPrice.TieredWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewFloatingTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewFloatingTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .hideZeroAmountTiers(true) + .prorate(true) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredWithProrationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredWithProrationPriceTest.kt index 9bebd954b..a2fce3448 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredWithProrationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingTieredWithProrationPriceTest.kt @@ -21,7 +21,13 @@ internal class NewFloatingTieredWithProrationPriceTest { .name("Annual fee") .tieredWithProrationConfig( NewFloatingTieredWithProrationPrice.TieredWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewFloatingTieredWithProrationPrice.TieredWithProrationConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +75,12 @@ internal class NewFloatingTieredWithProrationPriceTest { assertThat(newFloatingTieredWithProrationPrice.tieredWithProrationConfig()) .isEqualTo( NewFloatingTieredWithProrationPrice.TieredWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewFloatingTieredWithProrationPrice.TieredWithProrationConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) assertThat(newFloatingTieredWithProrationPrice.billableMetricId()) @@ -85,7 +96,7 @@ internal class NewFloatingTieredWithProrationPriceTest { assertThat(newFloatingTieredWithProrationPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingTieredWithProrationPrice.conversionRateConfig()) .isEqualTo( - NewFloatingTieredWithProrationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -133,7 +144,13 @@ internal class NewFloatingTieredWithProrationPriceTest { .name("Annual fee") .tieredWithProrationConfig( NewFloatingTieredWithProrationPrice.TieredWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewFloatingTieredWithProrationPrice.TieredWithProrationConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingUnitPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingUnitPriceTest.kt index d6bd5c35e..a74d263b9 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingUnitPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingUnitPriceTest.kt @@ -19,7 +19,7 @@ internal class NewFloatingUnitPriceTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig(UnitConfig.builder().unitAmount("unit_amount").prorated(true).build()) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -61,7 +61,7 @@ internal class NewFloatingUnitPriceTest { assertThat(newFloatingUnitPrice.modelType()).isEqualTo(NewFloatingUnitPrice.ModelType.UNIT) assertThat(newFloatingUnitPrice.name()).isEqualTo("Annual fee") assertThat(newFloatingUnitPrice.unitConfig()) - .isEqualTo(UnitConfig.builder().unitAmount("unit_amount").build()) + .isEqualTo(UnitConfig.builder().unitAmount("unit_amount").prorated(true).build()) assertThat(newFloatingUnitPrice.billableMetricId()).isEqualTo("billable_metric_id") assertThat(newFloatingUnitPrice.billedInAdvance()).isEqualTo(true) assertThat(newFloatingUnitPrice.billingCycleConfiguration()) @@ -74,7 +74,7 @@ internal class NewFloatingUnitPriceTest { assertThat(newFloatingUnitPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingUnitPrice.conversionRateConfig()) .isEqualTo( - NewFloatingUnitPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -119,7 +119,7 @@ internal class NewFloatingUnitPriceTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig(UnitConfig.builder().unitAmount("unit_amount").prorated(true).build()) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingUnitWithPercentPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingUnitWithPercentPriceTest.kt index 754a70b63..b27455cc1 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingUnitWithPercentPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingUnitWithPercentPriceTest.kt @@ -21,7 +21,8 @@ internal class NewFloatingUnitWithPercentPriceTest { .name("Annual fee") .unitWithPercentConfig( NewFloatingUnitWithPercentPrice.UnitWithPercentConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .percent("percent") + .unitAmount("unit_amount") .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +70,8 @@ internal class NewFloatingUnitWithPercentPriceTest { assertThat(newFloatingUnitWithPercentPrice.unitWithPercentConfig()) .isEqualTo( NewFloatingUnitWithPercentPrice.UnitWithPercentConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .percent("percent") + .unitAmount("unit_amount") .build() ) assertThat(newFloatingUnitWithPercentPrice.billableMetricId()) @@ -85,7 +87,7 @@ internal class NewFloatingUnitWithPercentPriceTest { assertThat(newFloatingUnitWithPercentPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingUnitWithPercentPrice.conversionRateConfig()) .isEqualTo( - NewFloatingUnitWithPercentPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -132,7 +134,8 @@ internal class NewFloatingUnitWithPercentPriceTest { .name("Annual fee") .unitWithPercentConfig( NewFloatingUnitWithPercentPrice.UnitWithPercentConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .percent("percent") + .unitAmount("unit_amount") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingUnitWithProrationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingUnitWithProrationPriceTest.kt index 9f8934888..5d92ac1a6 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingUnitWithProrationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewFloatingUnitWithProrationPriceTest.kt @@ -21,7 +21,7 @@ internal class NewFloatingUnitWithProrationPriceTest { .name("Annual fee") .unitWithProrationConfig( NewFloatingUnitWithProrationPrice.UnitWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .unitAmount("unit_amount") .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +69,7 @@ internal class NewFloatingUnitWithProrationPriceTest { assertThat(newFloatingUnitWithProrationPrice.unitWithProrationConfig()) .isEqualTo( NewFloatingUnitWithProrationPrice.UnitWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .unitAmount("unit_amount") .build() ) assertThat(newFloatingUnitWithProrationPrice.billableMetricId()) @@ -85,7 +85,7 @@ internal class NewFloatingUnitWithProrationPriceTest { assertThat(newFloatingUnitWithProrationPrice.conversionRate()).isEqualTo(0.0) assertThat(newFloatingUnitWithProrationPrice.conversionRateConfig()) .isEqualTo( - NewFloatingUnitWithProrationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -133,7 +133,7 @@ internal class NewFloatingUnitWithProrationPriceTest { .name("Annual fee") .unitWithProrationConfig( NewFloatingUnitWithProrationPrice.UnitWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .unitAmount("unit_amount") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewMaximumTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewMaximumTest.kt index 712322afe..a16ed798d 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewMaximumTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewMaximumTest.kt @@ -22,9 +22,9 @@ internal class NewMaximumTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewMaximum.Filter.builder() + .field(NewMaximum.Filter.Field.PRICE_ID) + .operator(NewMaximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -40,9 +40,9 @@ internal class NewMaximumTest { assertThat(newMaximum.currency()).isEqualTo("currency") assertThat(newMaximum.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewMaximum.Filter.builder() + .field(NewMaximum.Filter.Field.PRICE_ID) + .operator(NewMaximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -64,9 +64,9 @@ internal class NewMaximumTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewMaximum.Filter.builder() + .field(NewMaximum.Filter.Field.PRICE_ID) + .operator(NewMaximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewMinimumTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewMinimumTest.kt index 83f59818d..573a860dd 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewMinimumTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewMinimumTest.kt @@ -23,9 +23,9 @@ internal class NewMinimumTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewMinimum.Filter.builder() + .field(NewMinimum.Filter.Field.PRICE_ID) + .operator(NewMinimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -42,9 +42,9 @@ internal class NewMinimumTest { assertThat(newMinimum.currency()).isEqualTo("currency") assertThat(newMinimum.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewMinimum.Filter.builder() + .field(NewMinimum.Filter.Field.PRICE_ID) + .operator(NewMinimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -67,9 +67,9 @@ internal class NewMinimumTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewMinimum.Filter.builder() + .field(NewMinimum.Filter.Field.PRICE_ID) + .operator(NewMinimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPercentageDiscountTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPercentageDiscountTest.kt index ed131c8dd..7ba4d8dcb 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPercentageDiscountTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPercentageDiscountTest.kt @@ -22,9 +22,9 @@ internal class NewPercentageDiscountTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -42,9 +42,9 @@ internal class NewPercentageDiscountTest { assertThat(newPercentageDiscount.currency()).isEqualTo("currency") assertThat(newPercentageDiscount.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -67,9 +67,9 @@ internal class NewPercentageDiscountTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBpsPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBpsPriceTest.kt deleted file mode 100644 index 3a93cf0f9..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBpsPriceTest.kt +++ /dev/null @@ -1,169 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.JsonValue -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class NewPlanBpsPriceTest { - - @Test - fun create() { - val newPlanBpsPrice = - NewPlanBpsPrice.builder() - .bpsConfig(BpsConfig.builder().bps(0.0).perUnitMaximum("per_unit_maximum").build()) - .cadence(NewPlanBpsPrice.Cadence.ANNUAL) - .itemId("item_id") - .modelType(NewPlanBpsPrice.ModelType.BPS) - .name("Annual fee") - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .currency("currency") - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewPlanBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .referenceId("reference_id") - .build() - - assertThat(newPlanBpsPrice.bpsConfig()) - .isEqualTo(BpsConfig.builder().bps(0.0).perUnitMaximum("per_unit_maximum").build()) - assertThat(newPlanBpsPrice.cadence()).isEqualTo(NewPlanBpsPrice.Cadence.ANNUAL) - assertThat(newPlanBpsPrice.itemId()).isEqualTo("item_id") - assertThat(newPlanBpsPrice.modelType()).isEqualTo(NewPlanBpsPrice.ModelType.BPS) - assertThat(newPlanBpsPrice.name()).isEqualTo("Annual fee") - assertThat(newPlanBpsPrice.billableMetricId()).isEqualTo("billable_metric_id") - assertThat(newPlanBpsPrice.billedInAdvance()).isEqualTo(true) - assertThat(newPlanBpsPrice.billingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newPlanBpsPrice.conversionRate()).isEqualTo(0.0) - assertThat(newPlanBpsPrice.conversionRateConfig()) - .isEqualTo( - NewPlanBpsPrice.ConversionRateConfig.ofUnit( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .build() - ) - ) - assertThat(newPlanBpsPrice.currency()).isEqualTo("currency") - assertThat(newPlanBpsPrice.dimensionalPriceConfiguration()) - .isEqualTo( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - assertThat(newPlanBpsPrice.externalPriceId()).isEqualTo("external_price_id") - assertThat(newPlanBpsPrice.fixedPriceQuantity()).isEqualTo(0.0) - assertThat(newPlanBpsPrice.invoiceGroupingKey()).isEqualTo("x") - assertThat(newPlanBpsPrice.invoicingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newPlanBpsPrice.metadata()) - .isEqualTo( - NewPlanBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - assertThat(newPlanBpsPrice.referenceId()).isEqualTo("reference_id") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val newPlanBpsPrice = - NewPlanBpsPrice.builder() - .bpsConfig(BpsConfig.builder().bps(0.0).perUnitMaximum("per_unit_maximum").build()) - .cadence(NewPlanBpsPrice.Cadence.ANNUAL) - .itemId("item_id") - .modelType(NewPlanBpsPrice.ModelType.BPS) - .name("Annual fee") - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .currency("currency") - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewPlanBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .referenceId("reference_id") - .build() - - val roundtrippedNewPlanBpsPrice = - jsonMapper.readValue( - jsonMapper.writeValueAsString(newPlanBpsPrice), - jacksonTypeRef(), - ) - - assertThat(roundtrippedNewPlanBpsPrice).isEqualTo(newPlanBpsPrice) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBulkBpsPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBulkBpsPriceTest.kt deleted file mode 100644 index 4be6b39eb..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBulkBpsPriceTest.kt +++ /dev/null @@ -1,200 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.JsonValue -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class NewPlanBulkBpsPriceTest { - - @Test - fun create() { - val newPlanBulkBpsPrice = - NewPlanBulkBpsPrice.builder() - .bulkBpsConfig( - BulkBpsConfig.builder() - .addTier( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - .cadence(NewPlanBulkBpsPrice.Cadence.ANNUAL) - .itemId("item_id") - .modelType(NewPlanBulkBpsPrice.ModelType.BULK_BPS) - .name("Annual fee") - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .currency("currency") - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewPlanBulkBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .referenceId("reference_id") - .build() - - assertThat(newPlanBulkBpsPrice.bulkBpsConfig()) - .isEqualTo( - BulkBpsConfig.builder() - .addTier( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - assertThat(newPlanBulkBpsPrice.cadence()).isEqualTo(NewPlanBulkBpsPrice.Cadence.ANNUAL) - assertThat(newPlanBulkBpsPrice.itemId()).isEqualTo("item_id") - assertThat(newPlanBulkBpsPrice.modelType()) - .isEqualTo(NewPlanBulkBpsPrice.ModelType.BULK_BPS) - assertThat(newPlanBulkBpsPrice.name()).isEqualTo("Annual fee") - assertThat(newPlanBulkBpsPrice.billableMetricId()).isEqualTo("billable_metric_id") - assertThat(newPlanBulkBpsPrice.billedInAdvance()).isEqualTo(true) - assertThat(newPlanBulkBpsPrice.billingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newPlanBulkBpsPrice.conversionRate()).isEqualTo(0.0) - assertThat(newPlanBulkBpsPrice.conversionRateConfig()) - .isEqualTo( - NewPlanBulkBpsPrice.ConversionRateConfig.ofUnit( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .build() - ) - ) - assertThat(newPlanBulkBpsPrice.currency()).isEqualTo("currency") - assertThat(newPlanBulkBpsPrice.dimensionalPriceConfiguration()) - .isEqualTo( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - assertThat(newPlanBulkBpsPrice.externalPriceId()).isEqualTo("external_price_id") - assertThat(newPlanBulkBpsPrice.fixedPriceQuantity()).isEqualTo(0.0) - assertThat(newPlanBulkBpsPrice.invoiceGroupingKey()).isEqualTo("x") - assertThat(newPlanBulkBpsPrice.invoicingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newPlanBulkBpsPrice.metadata()) - .isEqualTo( - NewPlanBulkBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - assertThat(newPlanBulkBpsPrice.referenceId()).isEqualTo("reference_id") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val newPlanBulkBpsPrice = - NewPlanBulkBpsPrice.builder() - .bulkBpsConfig( - BulkBpsConfig.builder() - .addTier( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - .cadence(NewPlanBulkBpsPrice.Cadence.ANNUAL) - .itemId("item_id") - .modelType(NewPlanBulkBpsPrice.ModelType.BULK_BPS) - .name("Annual fee") - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .currency("currency") - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewPlanBulkBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .referenceId("reference_id") - .build() - - val roundtrippedNewPlanBulkBpsPrice = - jsonMapper.readValue( - jsonMapper.writeValueAsString(newPlanBulkBpsPrice), - jacksonTypeRef(), - ) - - assertThat(roundtrippedNewPlanBulkBpsPrice).isEqualTo(newPlanBulkBpsPrice) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBulkPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBulkPriceTest.kt index ec0255a00..0157cd364 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBulkPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBulkPriceTest.kt @@ -84,7 +84,7 @@ internal class NewPlanBulkPriceTest { assertThat(newPlanBulkPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanBulkPrice.conversionRateConfig()) .isEqualTo( - NewPlanBulkPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBulkWithProrationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBulkWithProrationPriceTest.kt index 5c1ebdcde..2fcf10a24 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBulkWithProrationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanBulkWithProrationPriceTest.kt @@ -16,7 +16,18 @@ internal class NewPlanBulkWithProrationPriceTest { NewPlanBulkWithProrationPrice.builder() .bulkWithProrationConfig( NewPlanBulkWithProrationPrice.BulkWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewPlanBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewPlanBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .cadence(NewPlanBulkWithProrationPrice.Cadence.ANNUAL) @@ -63,7 +74,18 @@ internal class NewPlanBulkWithProrationPriceTest { assertThat(newPlanBulkWithProrationPrice.bulkWithProrationConfig()) .isEqualTo( NewPlanBulkWithProrationPrice.BulkWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewPlanBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewPlanBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) assertThat(newPlanBulkWithProrationPrice.cadence()) @@ -84,7 +106,7 @@ internal class NewPlanBulkWithProrationPriceTest { assertThat(newPlanBulkWithProrationPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanBulkWithProrationPrice.conversionRateConfig()) .isEqualTo( - NewPlanBulkWithProrationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -128,7 +150,18 @@ internal class NewPlanBulkWithProrationPriceTest { NewPlanBulkWithProrationPrice.builder() .bulkWithProrationConfig( NewPlanBulkWithProrationPrice.BulkWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewPlanBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewPlanBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .cadence(NewPlanBulkWithProrationPrice.Cadence.ANNUAL) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanCumulativeGroupedBulkPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanCumulativeGroupedBulkPriceTest.kt index 7f43ec232..36c501bb0 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanCumulativeGroupedBulkPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanCumulativeGroupedBulkPriceTest.kt @@ -17,7 +17,16 @@ internal class NewPlanCumulativeGroupedBulkPriceTest { .cadence(NewPlanCumulativeGroupedBulkPrice.Cadence.ANNUAL) .cumulativeGroupedBulkConfig( NewPlanCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addDimensionValue( + NewPlanCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig + .DimensionValue + .builder() + .groupingKey("x") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .group("group") .build() ) .itemId("item_id") @@ -65,7 +74,15 @@ internal class NewPlanCumulativeGroupedBulkPriceTest { assertThat(newPlanCumulativeGroupedBulkPrice.cumulativeGroupedBulkConfig()) .isEqualTo( NewPlanCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addDimensionValue( + NewPlanCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig.DimensionValue + .builder() + .groupingKey("x") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .group("group") .build() ) assertThat(newPlanCumulativeGroupedBulkPrice.itemId()).isEqualTo("item_id") @@ -85,7 +102,7 @@ internal class NewPlanCumulativeGroupedBulkPriceTest { assertThat(newPlanCumulativeGroupedBulkPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanCumulativeGroupedBulkPrice.conversionRateConfig()) .isEqualTo( - NewPlanCumulativeGroupedBulkPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -131,7 +148,16 @@ internal class NewPlanCumulativeGroupedBulkPriceTest { .cadence(NewPlanCumulativeGroupedBulkPrice.Cadence.ANNUAL) .cumulativeGroupedBulkConfig( NewPlanCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addDimensionValue( + NewPlanCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig + .DimensionValue + .builder() + .groupingKey("x") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .group("group") .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedAllocationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedAllocationPriceTest.kt index 00c1fff8d..5e22b6837 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedAllocationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedAllocationPriceTest.kt @@ -17,7 +17,9 @@ internal class NewPlanGroupedAllocationPriceTest { .cadence(NewPlanGroupedAllocationPrice.Cadence.ANNUAL) .groupedAllocationConfig( NewPlanGroupedAllocationPrice.GroupedAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .groupingKey("x") + .overageUnitRate("overage_unit_rate") .build() ) .itemId("item_id") @@ -65,7 +67,9 @@ internal class NewPlanGroupedAllocationPriceTest { assertThat(newPlanGroupedAllocationPrice.groupedAllocationConfig()) .isEqualTo( NewPlanGroupedAllocationPrice.GroupedAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .groupingKey("x") + .overageUnitRate("overage_unit_rate") .build() ) assertThat(newPlanGroupedAllocationPrice.itemId()).isEqualTo("item_id") @@ -84,7 +88,7 @@ internal class NewPlanGroupedAllocationPriceTest { assertThat(newPlanGroupedAllocationPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanGroupedAllocationPrice.conversionRateConfig()) .isEqualTo( - NewPlanGroupedAllocationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -129,7 +133,9 @@ internal class NewPlanGroupedAllocationPriceTest { .cadence(NewPlanGroupedAllocationPrice.Cadence.ANNUAL) .groupedAllocationConfig( NewPlanGroupedAllocationPrice.GroupedAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .groupingKey("x") + .overageUnitRate("overage_unit_rate") .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedTieredPackagePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedTieredPackagePriceTest.kt index d47d0e64e..fe2768ed2 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedTieredPackagePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedTieredPackagePriceTest.kt @@ -17,7 +17,22 @@ internal class NewPlanGroupedTieredPackagePriceTest { .cadence(NewPlanGroupedTieredPackagePrice.Cadence.ANNUAL) .groupedTieredPackageConfig( NewPlanGroupedTieredPackagePrice.GroupedTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewPlanGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewPlanGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .itemId("item_id") @@ -65,7 +80,20 @@ internal class NewPlanGroupedTieredPackagePriceTest { assertThat(newPlanGroupedTieredPackagePrice.groupedTieredPackageConfig()) .isEqualTo( NewPlanGroupedTieredPackagePrice.GroupedTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewPlanGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewPlanGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) assertThat(newPlanGroupedTieredPackagePrice.itemId()).isEqualTo("item_id") @@ -85,7 +113,7 @@ internal class NewPlanGroupedTieredPackagePriceTest { assertThat(newPlanGroupedTieredPackagePrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanGroupedTieredPackagePrice.conversionRateConfig()) .isEqualTo( - NewPlanGroupedTieredPackagePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -131,7 +159,22 @@ internal class NewPlanGroupedTieredPackagePriceTest { .cadence(NewPlanGroupedTieredPackagePrice.Cadence.ANNUAL) .groupedTieredPackageConfig( NewPlanGroupedTieredPackagePrice.GroupedTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewPlanGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewPlanGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedTieredPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedTieredPriceTest.kt index afb68b4b3..b2cfcba91 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedTieredPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedTieredPriceTest.kt @@ -17,7 +17,19 @@ internal class NewPlanGroupedTieredPriceTest { .cadence(NewPlanGroupedTieredPrice.Cadence.ANNUAL) .groupedTieredConfig( NewPlanGroupedTieredPrice.GroupedTieredConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .addTier( + NewPlanGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewPlanGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .itemId("item_id") @@ -65,7 +77,19 @@ internal class NewPlanGroupedTieredPriceTest { assertThat(newPlanGroupedTieredPrice.groupedTieredConfig()) .isEqualTo( NewPlanGroupedTieredPrice.GroupedTieredConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .addTier( + NewPlanGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewPlanGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) assertThat(newPlanGroupedTieredPrice.itemId()).isEqualTo("item_id") @@ -84,7 +108,7 @@ internal class NewPlanGroupedTieredPriceTest { assertThat(newPlanGroupedTieredPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanGroupedTieredPrice.conversionRateConfig()) .isEqualTo( - NewPlanGroupedTieredPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -129,7 +153,19 @@ internal class NewPlanGroupedTieredPriceTest { .cadence(NewPlanGroupedTieredPrice.Cadence.ANNUAL) .groupedTieredConfig( NewPlanGroupedTieredPrice.GroupedTieredConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .addTier( + NewPlanGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewPlanGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedWithMeteredMinimumPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedWithMeteredMinimumPriceTest.kt index 188173c72..8f45e3f76 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedWithMeteredMinimumPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedWithMeteredMinimumPriceTest.kt @@ -17,7 +17,26 @@ internal class NewPlanGroupedWithMeteredMinimumPriceTest { .cadence(NewPlanGroupedWithMeteredMinimumPrice.Cadence.ANNUAL) .groupedWithMeteredMinimumConfig( NewPlanGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimumUnitAmount("minimum_unit_amount") + .pricingKey("pricing_key") + .addScalingFactor( + NewPlanGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig + .ScalingFactor + .builder() + .scalingFactor("scaling_factor") + .scalingValue("scaling_value") + .build() + ) + .scalingKey("scaling_key") + .addUnitAmount( + NewPlanGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig + .UnitAmount + .builder() + .pricingValue("pricing_value") + .unitAmount("unit_amount") + .build() + ) .build() ) .itemId("item_id") @@ -67,7 +86,26 @@ internal class NewPlanGroupedWithMeteredMinimumPriceTest { assertThat(newPlanGroupedWithMeteredMinimumPrice.groupedWithMeteredMinimumConfig()) .isEqualTo( NewPlanGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimumUnitAmount("minimum_unit_amount") + .pricingKey("pricing_key") + .addScalingFactor( + NewPlanGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig + .ScalingFactor + .builder() + .scalingFactor("scaling_factor") + .scalingValue("scaling_value") + .build() + ) + .scalingKey("scaling_key") + .addUnitAmount( + NewPlanGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig + .UnitAmount + .builder() + .pricingValue("pricing_value") + .unitAmount("unit_amount") + .build() + ) .build() ) assertThat(newPlanGroupedWithMeteredMinimumPrice.itemId()).isEqualTo("item_id") @@ -87,7 +125,7 @@ internal class NewPlanGroupedWithMeteredMinimumPriceTest { assertThat(newPlanGroupedWithMeteredMinimumPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanGroupedWithMeteredMinimumPrice.conversionRateConfig()) .isEqualTo( - NewPlanGroupedWithMeteredMinimumPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -133,7 +171,26 @@ internal class NewPlanGroupedWithMeteredMinimumPriceTest { .cadence(NewPlanGroupedWithMeteredMinimumPrice.Cadence.ANNUAL) .groupedWithMeteredMinimumConfig( NewPlanGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimumUnitAmount("minimum_unit_amount") + .pricingKey("pricing_key") + .addScalingFactor( + NewPlanGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig + .ScalingFactor + .builder() + .scalingFactor("scaling_factor") + .scalingValue("scaling_value") + .build() + ) + .scalingKey("scaling_key") + .addUnitAmount( + NewPlanGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig + .UnitAmount + .builder() + .pricingValue("pricing_value") + .unitAmount("unit_amount") + .build() + ) .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedWithProratedMinimumPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedWithProratedMinimumPriceTest.kt index 16cf684c3..9caace8da 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedWithProratedMinimumPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanGroupedWithProratedMinimumPriceTest.kt @@ -18,7 +18,9 @@ internal class NewPlanGroupedWithProratedMinimumPriceTest { .groupedWithProratedMinimumConfig( NewPlanGroupedWithProratedMinimumPrice.GroupedWithProratedMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimum("minimum") + .unitRate("unit_rate") .build() ) .itemId("item_id") @@ -68,7 +70,9 @@ internal class NewPlanGroupedWithProratedMinimumPriceTest { assertThat(newPlanGroupedWithProratedMinimumPrice.groupedWithProratedMinimumConfig()) .isEqualTo( NewPlanGroupedWithProratedMinimumPrice.GroupedWithProratedMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimum("minimum") + .unitRate("unit_rate") .build() ) assertThat(newPlanGroupedWithProratedMinimumPrice.itemId()).isEqualTo("item_id") @@ -90,7 +94,7 @@ internal class NewPlanGroupedWithProratedMinimumPriceTest { assertThat(newPlanGroupedWithProratedMinimumPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanGroupedWithProratedMinimumPrice.conversionRateConfig()) .isEqualTo( - NewPlanGroupedWithProratedMinimumPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -137,7 +141,9 @@ internal class NewPlanGroupedWithProratedMinimumPriceTest { .groupedWithProratedMinimumConfig( NewPlanGroupedWithProratedMinimumPrice.GroupedWithProratedMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimum("minimum") + .unitRate("unit_rate") .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMatrixPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMatrixPriceTest.kt index a297dc9ca..19ac3b71e 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMatrixPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMatrixPriceTest.kt @@ -96,7 +96,7 @@ internal class NewPlanMatrixPriceTest { assertThat(newPlanMatrixPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanMatrixPrice.conversionRateConfig()) .isEqualTo( - NewPlanMatrixPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMatrixWithAllocationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMatrixWithAllocationPriceTest.kt index 039250405..dfbe75165 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMatrixWithAllocationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMatrixWithAllocationPriceTest.kt @@ -18,11 +18,11 @@ internal class NewPlanMatrixWithAllocationPriceTest { .itemId("item_id") .matrixWithAllocationConfig( MatrixWithAllocationConfig.builder() - .allocation(0.0) + .allocation("allocation") .defaultUnitAmount("default_unit_amount") .addDimension("string") .addMatrixValue( - MatrixValue.builder() + MatrixWithAllocationConfig.MatrixValue.builder() .addDimensionValue("string") .unitAmount("unit_amount") .build() @@ -74,11 +74,11 @@ internal class NewPlanMatrixWithAllocationPriceTest { assertThat(newPlanMatrixWithAllocationPrice.matrixWithAllocationConfig()) .isEqualTo( MatrixWithAllocationConfig.builder() - .allocation(0.0) + .allocation("allocation") .defaultUnitAmount("default_unit_amount") .addDimension("string") .addMatrixValue( - MatrixValue.builder() + MatrixWithAllocationConfig.MatrixValue.builder() .addDimensionValue("string") .unitAmount("unit_amount") .build() @@ -101,7 +101,7 @@ internal class NewPlanMatrixWithAllocationPriceTest { assertThat(newPlanMatrixWithAllocationPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanMatrixWithAllocationPrice.conversionRateConfig()) .isEqualTo( - NewPlanMatrixWithAllocationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -148,11 +148,11 @@ internal class NewPlanMatrixWithAllocationPriceTest { .itemId("item_id") .matrixWithAllocationConfig( MatrixWithAllocationConfig.builder() - .allocation(0.0) + .allocation("allocation") .defaultUnitAmount("default_unit_amount") .addDimension("string") .addMatrixValue( - MatrixValue.builder() + MatrixWithAllocationConfig.MatrixValue.builder() .addDimensionValue("string") .unitAmount("unit_amount") .build() diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMatrixWithDisplayNamePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMatrixWithDisplayNamePriceTest.kt index abeb70f32..97c177e28 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMatrixWithDisplayNamePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMatrixWithDisplayNamePriceTest.kt @@ -18,7 +18,15 @@ internal class NewPlanMatrixWithDisplayNamePriceTest { .itemId("item_id") .matrixWithDisplayNameConfig( NewPlanMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .dimension("dimension") + .addUnitAmount( + NewPlanMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig.UnitAmount + .builder() + .dimensionValue("dimension_value") + .displayName("display_name") + .unitAmount("unit_amount") + .build() + ) .build() ) .modelType(NewPlanMatrixWithDisplayNamePrice.ModelType.MATRIX_WITH_DISPLAY_NAME) @@ -66,7 +74,15 @@ internal class NewPlanMatrixWithDisplayNamePriceTest { assertThat(newPlanMatrixWithDisplayNamePrice.matrixWithDisplayNameConfig()) .isEqualTo( NewPlanMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .dimension("dimension") + .addUnitAmount( + NewPlanMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig.UnitAmount + .builder() + .dimensionValue("dimension_value") + .displayName("display_name") + .unitAmount("unit_amount") + .build() + ) .build() ) assertThat(newPlanMatrixWithDisplayNamePrice.modelType()) @@ -85,7 +101,7 @@ internal class NewPlanMatrixWithDisplayNamePriceTest { assertThat(newPlanMatrixWithDisplayNamePrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanMatrixWithDisplayNamePrice.conversionRateConfig()) .isEqualTo( - NewPlanMatrixWithDisplayNamePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -132,7 +148,15 @@ internal class NewPlanMatrixWithDisplayNamePriceTest { .itemId("item_id") .matrixWithDisplayNameConfig( NewPlanMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .dimension("dimension") + .addUnitAmount( + NewPlanMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig.UnitAmount + .builder() + .dimensionValue("dimension_value") + .displayName("display_name") + .unitAmount("unit_amount") + .build() + ) .build() ) .modelType(NewPlanMatrixWithDisplayNamePrice.ModelType.MATRIX_WITH_DISPLAY_NAME) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMaxGroupTieredPackagePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMaxGroupTieredPackagePriceTest.kt index f2c577f5f..908236f45 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMaxGroupTieredPackagePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMaxGroupTieredPackagePriceTest.kt @@ -18,7 +18,22 @@ internal class NewPlanMaxGroupTieredPackagePriceTest { .itemId("item_id") .maxGroupTieredPackageConfig( NewPlanMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewPlanMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewPlanMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .modelType(NewPlanMaxGroupTieredPackagePrice.ModelType.MAX_GROUP_TIERED_PACKAGE) @@ -66,7 +81,20 @@ internal class NewPlanMaxGroupTieredPackagePriceTest { assertThat(newPlanMaxGroupTieredPackagePrice.maxGroupTieredPackageConfig()) .isEqualTo( NewPlanMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewPlanMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewPlanMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) assertThat(newPlanMaxGroupTieredPackagePrice.modelType()) @@ -85,7 +113,7 @@ internal class NewPlanMaxGroupTieredPackagePriceTest { assertThat(newPlanMaxGroupTieredPackagePrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanMaxGroupTieredPackagePrice.conversionRateConfig()) .isEqualTo( - NewPlanMaxGroupTieredPackagePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -132,7 +160,22 @@ internal class NewPlanMaxGroupTieredPackagePriceTest { .itemId("item_id") .maxGroupTieredPackageConfig( NewPlanMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewPlanMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewPlanMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .modelType(NewPlanMaxGroupTieredPackagePrice.ModelType.MAX_GROUP_TIERED_PACKAGE) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTierWithProrationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMinimumCompositePriceTest.kt similarity index 61% rename from orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTierWithProrationPriceTest.kt rename to orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMinimumCompositePriceTest.kt index 7afcceec8..5584c0752 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTierWithProrationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanMinimumCompositePriceTest.kt @@ -8,21 +8,22 @@ import com.withorb.api.core.jsonMapper import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -internal class NewPlanTierWithProrationPriceTest { +internal class NewPlanMinimumCompositePriceTest { @Test fun create() { - val newPlanTierWithProrationPrice = - NewPlanTierWithProrationPrice.builder() - .cadence(NewPlanTierWithProrationPrice.Cadence.ANNUAL) + val newPlanMinimumCompositePrice = + NewPlanMinimumCompositePrice.builder() + .cadence(NewPlanMinimumCompositePrice.Cadence.ANNUAL) .itemId("item_id") - .modelType(NewPlanTierWithProrationPrice.ModelType.TIERED_WITH_PRORATION) - .name("Annual fee") - .tieredWithProrationConfig( - NewPlanTierWithProrationPrice.TieredWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .minimumConfig( + NewPlanMinimumCompositePrice.MinimumConfig.builder() + .minimumAmount("minimum_amount") + .prorated(true) .build() ) + .modelType(NewPlanMinimumCompositePrice.ModelType.MINIMUM) + .name("Annual fee") .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -53,38 +54,39 @@ internal class NewPlanTierWithProrationPriceTest { .build() ) .metadata( - NewPlanTierWithProrationPrice.Metadata.builder() + NewPlanMinimumCompositePrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) .referenceId("reference_id") .build() - assertThat(newPlanTierWithProrationPrice.cadence()) - .isEqualTo(NewPlanTierWithProrationPrice.Cadence.ANNUAL) - assertThat(newPlanTierWithProrationPrice.itemId()).isEqualTo("item_id") - assertThat(newPlanTierWithProrationPrice.modelType()) - .isEqualTo(NewPlanTierWithProrationPrice.ModelType.TIERED_WITH_PRORATION) - assertThat(newPlanTierWithProrationPrice.name()).isEqualTo("Annual fee") - assertThat(newPlanTierWithProrationPrice.tieredWithProrationConfig()) + assertThat(newPlanMinimumCompositePrice.cadence()) + .isEqualTo(NewPlanMinimumCompositePrice.Cadence.ANNUAL) + assertThat(newPlanMinimumCompositePrice.itemId()).isEqualTo("item_id") + assertThat(newPlanMinimumCompositePrice.minimumConfig()) .isEqualTo( - NewPlanTierWithProrationPrice.TieredWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + NewPlanMinimumCompositePrice.MinimumConfig.builder() + .minimumAmount("minimum_amount") + .prorated(true) .build() ) - assertThat(newPlanTierWithProrationPrice.billableMetricId()).isEqualTo("billable_metric_id") - assertThat(newPlanTierWithProrationPrice.billedInAdvance()).isEqualTo(true) - assertThat(newPlanTierWithProrationPrice.billingCycleConfiguration()) + assertThat(newPlanMinimumCompositePrice.modelType()) + .isEqualTo(NewPlanMinimumCompositePrice.ModelType.MINIMUM) + assertThat(newPlanMinimumCompositePrice.name()).isEqualTo("Annual fee") + assertThat(newPlanMinimumCompositePrice.billableMetricId()).isEqualTo("billable_metric_id") + assertThat(newPlanMinimumCompositePrice.billedInAdvance()).isEqualTo(true) + assertThat(newPlanMinimumCompositePrice.billingCycleConfiguration()) .isEqualTo( NewBillingCycleConfiguration.builder() .duration(0L) .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) .build() ) - assertThat(newPlanTierWithProrationPrice.conversionRate()).isEqualTo(0.0) - assertThat(newPlanTierWithProrationPrice.conversionRateConfig()) + assertThat(newPlanMinimumCompositePrice.conversionRate()).isEqualTo(0.0) + assertThat(newPlanMinimumCompositePrice.conversionRateConfig()) .isEqualTo( - NewPlanTierWithProrationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -93,8 +95,8 @@ internal class NewPlanTierWithProrationPriceTest { .build() ) ) - assertThat(newPlanTierWithProrationPrice.currency()).isEqualTo("currency") - assertThat(newPlanTierWithProrationPrice.dimensionalPriceConfiguration()) + assertThat(newPlanMinimumCompositePrice.currency()).isEqualTo("currency") + assertThat(newPlanMinimumCompositePrice.dimensionalPriceConfiguration()) .isEqualTo( NewDimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -102,39 +104,40 @@ internal class NewPlanTierWithProrationPriceTest { .externalDimensionalPriceGroupId("external_dimensional_price_group_id") .build() ) - assertThat(newPlanTierWithProrationPrice.externalPriceId()).isEqualTo("external_price_id") - assertThat(newPlanTierWithProrationPrice.fixedPriceQuantity()).isEqualTo(0.0) - assertThat(newPlanTierWithProrationPrice.invoiceGroupingKey()).isEqualTo("x") - assertThat(newPlanTierWithProrationPrice.invoicingCycleConfiguration()) + assertThat(newPlanMinimumCompositePrice.externalPriceId()).isEqualTo("external_price_id") + assertThat(newPlanMinimumCompositePrice.fixedPriceQuantity()).isEqualTo(0.0) + assertThat(newPlanMinimumCompositePrice.invoiceGroupingKey()).isEqualTo("x") + assertThat(newPlanMinimumCompositePrice.invoicingCycleConfiguration()) .isEqualTo( NewBillingCycleConfiguration.builder() .duration(0L) .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) .build() ) - assertThat(newPlanTierWithProrationPrice.metadata()) + assertThat(newPlanMinimumCompositePrice.metadata()) .isEqualTo( - NewPlanTierWithProrationPrice.Metadata.builder() + NewPlanMinimumCompositePrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) - assertThat(newPlanTierWithProrationPrice.referenceId()).isEqualTo("reference_id") + assertThat(newPlanMinimumCompositePrice.referenceId()).isEqualTo("reference_id") } @Test fun roundtrip() { val jsonMapper = jsonMapper() - val newPlanTierWithProrationPrice = - NewPlanTierWithProrationPrice.builder() - .cadence(NewPlanTierWithProrationPrice.Cadence.ANNUAL) + val newPlanMinimumCompositePrice = + NewPlanMinimumCompositePrice.builder() + .cadence(NewPlanMinimumCompositePrice.Cadence.ANNUAL) .itemId("item_id") - .modelType(NewPlanTierWithProrationPrice.ModelType.TIERED_WITH_PRORATION) - .name("Annual fee") - .tieredWithProrationConfig( - NewPlanTierWithProrationPrice.TieredWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .minimumConfig( + NewPlanMinimumCompositePrice.MinimumConfig.builder() + .minimumAmount("minimum_amount") + .prorated(true) .build() ) + .modelType(NewPlanMinimumCompositePrice.ModelType.MINIMUM) + .name("Annual fee") .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -165,20 +168,19 @@ internal class NewPlanTierWithProrationPriceTest { .build() ) .metadata( - NewPlanTierWithProrationPrice.Metadata.builder() + NewPlanMinimumCompositePrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) .referenceId("reference_id") .build() - val roundtrippedNewPlanTierWithProrationPrice = + val roundtrippedNewPlanMinimumCompositePrice = jsonMapper.readValue( - jsonMapper.writeValueAsString(newPlanTierWithProrationPrice), - jacksonTypeRef(), + jsonMapper.writeValueAsString(newPlanMinimumCompositePrice), + jacksonTypeRef(), ) - assertThat(roundtrippedNewPlanTierWithProrationPrice) - .isEqualTo(newPlanTierWithProrationPrice) + assertThat(roundtrippedNewPlanMinimumCompositePrice).isEqualTo(newPlanMinimumCompositePrice) } } diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanPackagePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanPackagePriceTest.kt index bd18e0007..bf2b79b77 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanPackagePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanPackagePriceTest.kt @@ -19,7 +19,7 @@ internal class NewPlanPackagePriceTest { .modelType(NewPlanPackagePrice.ModelType.PACKAGE) .name("Annual fee") .packageConfig( - PackageConfig.builder().packageAmount("package_amount").packageSize(0L).build() + PackageConfig.builder().packageAmount("package_amount").packageSize(1L).build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -64,7 +64,7 @@ internal class NewPlanPackagePriceTest { assertThat(newPlanPackagePrice.name()).isEqualTo("Annual fee") assertThat(newPlanPackagePrice.packageConfig()) .isEqualTo( - PackageConfig.builder().packageAmount("package_amount").packageSize(0L).build() + PackageConfig.builder().packageAmount("package_amount").packageSize(1L).build() ) assertThat(newPlanPackagePrice.billableMetricId()).isEqualTo("billable_metric_id") assertThat(newPlanPackagePrice.billedInAdvance()).isEqualTo(true) @@ -78,7 +78,7 @@ internal class NewPlanPackagePriceTest { assertThat(newPlanPackagePrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanPackagePrice.conversionRateConfig()) .isEqualTo( - NewPlanPackagePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -125,7 +125,7 @@ internal class NewPlanPackagePriceTest { .modelType(NewPlanPackagePrice.ModelType.PACKAGE) .name("Annual fee") .packageConfig( - PackageConfig.builder().packageAmount("package_amount").packageSize(0L).build() + PackageConfig.builder().packageAmount("package_amount").packageSize(1L).build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanPackageWithAllocationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanPackageWithAllocationPriceTest.kt index d296806fe..98a49d888 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanPackageWithAllocationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanPackageWithAllocationPriceTest.kt @@ -20,7 +20,9 @@ internal class NewPlanPackageWithAllocationPriceTest { .name("Annual fee") .packageWithAllocationConfig( NewPlanPackageWithAllocationPrice.PackageWithAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .packageAmount("package_amount") + .packageSize("package_size") .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +71,9 @@ internal class NewPlanPackageWithAllocationPriceTest { assertThat(newPlanPackageWithAllocationPrice.packageWithAllocationConfig()) .isEqualTo( NewPlanPackageWithAllocationPrice.PackageWithAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .packageAmount("package_amount") + .packageSize("package_size") .build() ) assertThat(newPlanPackageWithAllocationPrice.billableMetricId()) @@ -85,7 +89,7 @@ internal class NewPlanPackageWithAllocationPriceTest { assertThat(newPlanPackageWithAllocationPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanPackageWithAllocationPrice.conversionRateConfig()) .isEqualTo( - NewPlanPackageWithAllocationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -134,7 +138,9 @@ internal class NewPlanPackageWithAllocationPriceTest { .name("Annual fee") .packageWithAllocationConfig( NewPlanPackageWithAllocationPrice.PackageWithAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .packageAmount("package_amount") + .packageSize("package_size") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithTieredPricingPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithTieredPricingPriceTest.kt index a31a1007f..6316d5afd 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithTieredPricingPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithTieredPricingPriceTest.kt @@ -25,7 +25,36 @@ internal class NewPlanScalableMatrixWithTieredPricingPriceTest { NewPlanScalableMatrixWithTieredPricingPrice .ScalableMatrixWithTieredPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewPlanScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .addTier( + NewPlanScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewPlanScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .secondDimension("second_dimension") .build() ) .billableMetricId("billable_metric_id") @@ -80,7 +109,36 @@ internal class NewPlanScalableMatrixWithTieredPricingPriceTest { .isEqualTo( NewPlanScalableMatrixWithTieredPricingPrice.ScalableMatrixWithTieredPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewPlanScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .addTier( + NewPlanScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewPlanScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .secondDimension("second_dimension") .build() ) assertThat(newPlanScalableMatrixWithTieredPricingPrice.billableMetricId()) @@ -96,7 +154,7 @@ internal class NewPlanScalableMatrixWithTieredPricingPriceTest { assertThat(newPlanScalableMatrixWithTieredPricingPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanScalableMatrixWithTieredPricingPrice.conversionRateConfig()) .isEqualTo( - NewPlanScalableMatrixWithTieredPricingPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -151,7 +209,36 @@ internal class NewPlanScalableMatrixWithTieredPricingPriceTest { NewPlanScalableMatrixWithTieredPricingPrice .ScalableMatrixWithTieredPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewPlanScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .addTier( + NewPlanScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewPlanScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .secondDimension("second_dimension") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithUnitPricingPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithUnitPricingPriceTest.kt index e7df79b43..b6c1600b0 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithUnitPricingPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanScalableMatrixWithUnitPricingPriceTest.kt @@ -24,7 +24,20 @@ internal class NewPlanScalableMatrixWithUnitPricingPriceTest { .scalableMatrixWithUnitPricingConfig( NewPlanScalableMatrixWithUnitPricingPrice.ScalableMatrixWithUnitPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewPlanScalableMatrixWithUnitPricingPrice + .ScalableMatrixWithUnitPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .unitPrice("unit_price") + .prorate(true) + .secondDimension("second_dimension") .build() ) .billableMetricId("billable_metric_id") @@ -77,7 +90,20 @@ internal class NewPlanScalableMatrixWithUnitPricingPriceTest { .isEqualTo( NewPlanScalableMatrixWithUnitPricingPrice.ScalableMatrixWithUnitPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewPlanScalableMatrixWithUnitPricingPrice + .ScalableMatrixWithUnitPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .unitPrice("unit_price") + .prorate(true) + .secondDimension("second_dimension") .build() ) assertThat(newPlanScalableMatrixWithUnitPricingPrice.billableMetricId()) @@ -93,7 +119,7 @@ internal class NewPlanScalableMatrixWithUnitPricingPriceTest { assertThat(newPlanScalableMatrixWithUnitPricingPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanScalableMatrixWithUnitPricingPrice.conversionRateConfig()) .isEqualTo( - NewPlanScalableMatrixWithUnitPricingPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -147,7 +173,20 @@ internal class NewPlanScalableMatrixWithUnitPricingPriceTest { .scalableMatrixWithUnitPricingConfig( NewPlanScalableMatrixWithUnitPricingPrice.ScalableMatrixWithUnitPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewPlanScalableMatrixWithUnitPricingPrice + .ScalableMatrixWithUnitPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .unitPrice("unit_price") + .prorate(true) + .secondDimension("second_dimension") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanThresholdTotalAmountPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanThresholdTotalAmountPriceTest.kt index 112d43a25..b0652a089 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanThresholdTotalAmountPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanThresholdTotalAmountPriceTest.kt @@ -20,7 +20,23 @@ internal class NewPlanThresholdTotalAmountPriceTest { .name("Annual fee") .thresholdTotalAmountConfig( NewPlanThresholdTotalAmountPrice.ThresholdTotalAmountConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addConsumptionTable( + NewPlanThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .addConsumptionTable( + NewPlanThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .prorate(true) .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +85,21 @@ internal class NewPlanThresholdTotalAmountPriceTest { assertThat(newPlanThresholdTotalAmountPrice.thresholdTotalAmountConfig()) .isEqualTo( NewPlanThresholdTotalAmountPrice.ThresholdTotalAmountConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addConsumptionTable( + NewPlanThresholdTotalAmountPrice.ThresholdTotalAmountConfig.ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .addConsumptionTable( + NewPlanThresholdTotalAmountPrice.ThresholdTotalAmountConfig.ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .prorate(true) .build() ) assertThat(newPlanThresholdTotalAmountPrice.billableMetricId()) @@ -85,7 +115,7 @@ internal class NewPlanThresholdTotalAmountPriceTest { assertThat(newPlanThresholdTotalAmountPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanThresholdTotalAmountPrice.conversionRateConfig()) .isEqualTo( - NewPlanThresholdTotalAmountPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -134,7 +164,23 @@ internal class NewPlanThresholdTotalAmountPriceTest { .name("Annual fee") .thresholdTotalAmountConfig( NewPlanThresholdTotalAmountPrice.ThresholdTotalAmountConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addConsumptionTable( + NewPlanThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .addConsumptionTable( + NewPlanThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .prorate(true) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredBpsPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredBpsPriceTest.kt deleted file mode 100644 index 8b1b16fa9..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredBpsPriceTest.kt +++ /dev/null @@ -1,203 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.JsonValue -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class NewPlanTieredBpsPriceTest { - - @Test - fun create() { - val newPlanTieredBpsPrice = - NewPlanTieredBpsPrice.builder() - .cadence(NewPlanTieredBpsPrice.Cadence.ANNUAL) - .itemId("item_id") - .modelType(NewPlanTieredBpsPrice.ModelType.TIERED_BPS) - .name("Annual fee") - .tieredBpsConfig( - TieredBpsConfig.builder() - .addTier( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .currency("currency") - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewPlanTieredBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .referenceId("reference_id") - .build() - - assertThat(newPlanTieredBpsPrice.cadence()).isEqualTo(NewPlanTieredBpsPrice.Cadence.ANNUAL) - assertThat(newPlanTieredBpsPrice.itemId()).isEqualTo("item_id") - assertThat(newPlanTieredBpsPrice.modelType()) - .isEqualTo(NewPlanTieredBpsPrice.ModelType.TIERED_BPS) - assertThat(newPlanTieredBpsPrice.name()).isEqualTo("Annual fee") - assertThat(newPlanTieredBpsPrice.tieredBpsConfig()) - .isEqualTo( - TieredBpsConfig.builder() - .addTier( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - assertThat(newPlanTieredBpsPrice.billableMetricId()).isEqualTo("billable_metric_id") - assertThat(newPlanTieredBpsPrice.billedInAdvance()).isEqualTo(true) - assertThat(newPlanTieredBpsPrice.billingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newPlanTieredBpsPrice.conversionRate()).isEqualTo(0.0) - assertThat(newPlanTieredBpsPrice.conversionRateConfig()) - .isEqualTo( - NewPlanTieredBpsPrice.ConversionRateConfig.ofUnit( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .build() - ) - ) - assertThat(newPlanTieredBpsPrice.currency()).isEqualTo("currency") - assertThat(newPlanTieredBpsPrice.dimensionalPriceConfiguration()) - .isEqualTo( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - assertThat(newPlanTieredBpsPrice.externalPriceId()).isEqualTo("external_price_id") - assertThat(newPlanTieredBpsPrice.fixedPriceQuantity()).isEqualTo(0.0) - assertThat(newPlanTieredBpsPrice.invoiceGroupingKey()).isEqualTo("x") - assertThat(newPlanTieredBpsPrice.invoicingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newPlanTieredBpsPrice.metadata()) - .isEqualTo( - NewPlanTieredBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - assertThat(newPlanTieredBpsPrice.referenceId()).isEqualTo("reference_id") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val newPlanTieredBpsPrice = - NewPlanTieredBpsPrice.builder() - .cadence(NewPlanTieredBpsPrice.Cadence.ANNUAL) - .itemId("item_id") - .modelType(NewPlanTieredBpsPrice.ModelType.TIERED_BPS) - .name("Annual fee") - .tieredBpsConfig( - TieredBpsConfig.builder() - .addTier( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .currency("currency") - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewPlanTieredBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .referenceId("reference_id") - .build() - - val roundtrippedNewPlanTieredBpsPrice = - jsonMapper.readValue( - jsonMapper.writeValueAsString(newPlanTieredBpsPrice), - jacksonTypeRef(), - ) - - assertThat(roundtrippedNewPlanTieredBpsPrice).isEqualTo(newPlanTieredBpsPrice) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredPackagePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredPackagePriceTest.kt index 0fe80bd26..30bbe4959 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredPackagePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredPackagePriceTest.kt @@ -20,7 +20,19 @@ internal class NewPlanTieredPackagePriceTest { .name("Annual fee") .tieredPackageConfig( NewPlanTieredPackagePrice.TieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize("package_size") + .addTier( + NewPlanTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewPlanTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +81,19 @@ internal class NewPlanTieredPackagePriceTest { assertThat(newPlanTieredPackagePrice.tieredPackageConfig()) .isEqualTo( NewPlanTieredPackagePrice.TieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize("package_size") + .addTier( + NewPlanTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewPlanTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) assertThat(newPlanTieredPackagePrice.billableMetricId()).isEqualTo("billable_metric_id") @@ -84,7 +108,7 @@ internal class NewPlanTieredPackagePriceTest { assertThat(newPlanTieredPackagePrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanTieredPackagePrice.conversionRateConfig()) .isEqualTo( - NewPlanTieredPackagePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -132,7 +156,19 @@ internal class NewPlanTieredPackagePriceTest { .name("Annual fee") .tieredPackageConfig( NewPlanTieredPackagePrice.TieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize("package_size") + .addTier( + NewPlanTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewPlanTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredPackageWithMinimumPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredPackageWithMinimumPriceTest.kt index 7e2402b67..73e9780e2 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredPackageWithMinimumPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredPackageWithMinimumPriceTest.kt @@ -22,7 +22,23 @@ internal class NewPlanTieredPackageWithMinimumPriceTest { .name("Annual fee") .tieredPackageWithMinimumConfig( NewPlanTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize(0.0) + .addTier( + NewPlanTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewPlanTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .billableMetricId("billable_metric_id") @@ -71,7 +87,23 @@ internal class NewPlanTieredPackageWithMinimumPriceTest { assertThat(newPlanTieredPackageWithMinimumPrice.tieredPackageWithMinimumConfig()) .isEqualTo( NewPlanTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize(0.0) + .addTier( + NewPlanTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewPlanTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) assertThat(newPlanTieredPackageWithMinimumPrice.billableMetricId()) @@ -87,7 +119,7 @@ internal class NewPlanTieredPackageWithMinimumPriceTest { assertThat(newPlanTieredPackageWithMinimumPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanTieredPackageWithMinimumPrice.conversionRateConfig()) .isEqualTo( - NewPlanTieredPackageWithMinimumPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -138,7 +170,23 @@ internal class NewPlanTieredPackageWithMinimumPriceTest { .name("Annual fee") .tieredPackageWithMinimumConfig( NewPlanTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize(0.0) + .addTier( + NewPlanTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewPlanTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredPriceTest.kt index a11adcc5b..df536eea4 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredPriceTest.kt @@ -27,6 +27,7 @@ internal class NewPlanTieredPriceTest { .lastUnit(0.0) .build() ) + .prorated(true) .build() ) .billableMetricId("billable_metric_id") @@ -80,6 +81,7 @@ internal class NewPlanTieredPriceTest { .lastUnit(0.0) .build() ) + .prorated(true) .build() ) assertThat(newPlanTieredPrice.billableMetricId()).isEqualTo("billable_metric_id") @@ -94,7 +96,7 @@ internal class NewPlanTieredPriceTest { assertThat(newPlanTieredPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanTieredPrice.conversionRateConfig()) .isEqualTo( - NewPlanTieredPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -149,6 +151,7 @@ internal class NewPlanTieredPriceTest { .lastUnit(0.0) .build() ) + .prorated(true) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredWithMinimumPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredWithMinimumPriceTest.kt index d02a76ed5..b3e9ee8ea 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredWithMinimumPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanTieredWithMinimumPriceTest.kt @@ -20,7 +20,22 @@ internal class NewPlanTieredWithMinimumPriceTest { .name("Annual fee") .tieredWithMinimumConfig( NewPlanTieredWithMinimumPrice.TieredWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewPlanTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewPlanTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .hideZeroAmountTiers(true) + .prorate(true) .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +84,22 @@ internal class NewPlanTieredWithMinimumPriceTest { assertThat(newPlanTieredWithMinimumPrice.tieredWithMinimumConfig()) .isEqualTo( NewPlanTieredWithMinimumPrice.TieredWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewPlanTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewPlanTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .hideZeroAmountTiers(true) + .prorate(true) .build() ) assertThat(newPlanTieredWithMinimumPrice.billableMetricId()).isEqualTo("billable_metric_id") @@ -84,7 +114,7 @@ internal class NewPlanTieredWithMinimumPriceTest { assertThat(newPlanTieredWithMinimumPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanTieredWithMinimumPrice.conversionRateConfig()) .isEqualTo( - NewPlanTieredWithMinimumPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -132,7 +162,22 @@ internal class NewPlanTieredWithMinimumPriceTest { .name("Annual fee") .tieredWithMinimumConfig( NewPlanTieredWithMinimumPrice.TieredWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewPlanTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewPlanTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .hideZeroAmountTiers(true) + .prorate(true) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanUnitPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanUnitPriceTest.kt index acd68b19c..65af2ecd7 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanUnitPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanUnitPriceTest.kt @@ -18,7 +18,7 @@ internal class NewPlanUnitPriceTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig(UnitConfig.builder().unitAmount("unit_amount").prorated(true).build()) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -61,7 +61,7 @@ internal class NewPlanUnitPriceTest { assertThat(newPlanUnitPrice.modelType()).isEqualTo(NewPlanUnitPrice.ModelType.UNIT) assertThat(newPlanUnitPrice.name()).isEqualTo("Annual fee") assertThat(newPlanUnitPrice.unitConfig()) - .isEqualTo(UnitConfig.builder().unitAmount("unit_amount").build()) + .isEqualTo(UnitConfig.builder().unitAmount("unit_amount").prorated(true).build()) assertThat(newPlanUnitPrice.billableMetricId()).isEqualTo("billable_metric_id") assertThat(newPlanUnitPrice.billedInAdvance()).isEqualTo(true) assertThat(newPlanUnitPrice.billingCycleConfiguration()) @@ -74,7 +74,7 @@ internal class NewPlanUnitPriceTest { assertThat(newPlanUnitPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanUnitPrice.conversionRateConfig()) .isEqualTo( - NewPlanUnitPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -120,7 +120,7 @@ internal class NewPlanUnitPriceTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig(UnitConfig.builder().unitAmount("unit_amount").prorated(true).build()) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanUnitWithPercentPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanUnitWithPercentPriceTest.kt index e63af8296..87ac558d8 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanUnitWithPercentPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanUnitWithPercentPriceTest.kt @@ -20,7 +20,8 @@ internal class NewPlanUnitWithPercentPriceTest { .name("Annual fee") .unitWithPercentConfig( NewPlanUnitWithPercentPrice.UnitWithPercentConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .percent("percent") + .unitAmount("unit_amount") .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +70,8 @@ internal class NewPlanUnitWithPercentPriceTest { assertThat(newPlanUnitWithPercentPrice.unitWithPercentConfig()) .isEqualTo( NewPlanUnitWithPercentPrice.UnitWithPercentConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .percent("percent") + .unitAmount("unit_amount") .build() ) assertThat(newPlanUnitWithPercentPrice.billableMetricId()).isEqualTo("billable_metric_id") @@ -84,7 +86,7 @@ internal class NewPlanUnitWithPercentPriceTest { assertThat(newPlanUnitWithPercentPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanUnitWithPercentPrice.conversionRateConfig()) .isEqualTo( - NewPlanUnitWithPercentPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -132,7 +134,8 @@ internal class NewPlanUnitWithPercentPriceTest { .name("Annual fee") .unitWithPercentConfig( NewPlanUnitWithPercentPrice.UnitWithPercentConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .percent("percent") + .unitAmount("unit_amount") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanUnitWithProrationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanUnitWithProrationPriceTest.kt index da5b14d78..fe6f859e6 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanUnitWithProrationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewPlanUnitWithProrationPriceTest.kt @@ -20,7 +20,7 @@ internal class NewPlanUnitWithProrationPriceTest { .name("Annual fee") .unitWithProrationConfig( NewPlanUnitWithProrationPrice.UnitWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .unitAmount("unit_amount") .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +69,7 @@ internal class NewPlanUnitWithProrationPriceTest { assertThat(newPlanUnitWithProrationPrice.unitWithProrationConfig()) .isEqualTo( NewPlanUnitWithProrationPrice.UnitWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .unitAmount("unit_amount") .build() ) assertThat(newPlanUnitWithProrationPrice.billableMetricId()).isEqualTo("billable_metric_id") @@ -84,7 +84,7 @@ internal class NewPlanUnitWithProrationPriceTest { assertThat(newPlanUnitWithProrationPrice.conversionRate()).isEqualTo(0.0) assertThat(newPlanUnitWithProrationPrice.conversionRateConfig()) .isEqualTo( - NewPlanUnitWithProrationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -132,7 +132,7 @@ internal class NewPlanUnitWithProrationPriceTest { .name("Annual fee") .unitWithProrationConfig( NewPlanUnitWithProrationPrice.UnitWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .unitAmount("unit_amount") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSphereConfigurationTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSphereConfigurationTest.kt index 49be8be28..de461f3e0 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSphereConfigurationTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSphereConfigurationTest.kt @@ -15,11 +15,13 @@ internal class NewSphereConfigurationTest { NewSphereConfiguration.builder() .taxExempt(true) .taxProvider(NewSphereConfiguration.TaxProvider.SPHERE) + .automaticTaxEnabled(true) .build() assertThat(newSphereConfiguration.taxExempt()).isEqualTo(true) assertThat(newSphereConfiguration.taxProvider()) .isEqualTo(NewSphereConfiguration.TaxProvider.SPHERE) + assertThat(newSphereConfiguration.automaticTaxEnabled()).isEqualTo(true) } @Test @@ -29,6 +31,7 @@ internal class NewSphereConfigurationTest { NewSphereConfiguration.builder() .taxExempt(true) .taxProvider(NewSphereConfiguration.TaxProvider.SPHERE) + .automaticTaxEnabled(true) .build() val roundtrippedNewSphereConfiguration = diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBpsPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBpsPriceTest.kt deleted file mode 100644 index 52bd33636..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBpsPriceTest.kt +++ /dev/null @@ -1,171 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.JsonValue -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class NewSubscriptionBpsPriceTest { - - @Test - fun create() { - val newSubscriptionBpsPrice = - NewSubscriptionBpsPrice.builder() - .bpsConfig(BpsConfig.builder().bps(0.0).perUnitMaximum("per_unit_maximum").build()) - .cadence(NewSubscriptionBpsPrice.Cadence.ANNUAL) - .itemId("item_id") - .modelType(NewSubscriptionBpsPrice.ModelType.BPS) - .name("Annual fee") - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .currency("currency") - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewSubscriptionBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .referenceId("reference_id") - .build() - - assertThat(newSubscriptionBpsPrice.bpsConfig()) - .isEqualTo(BpsConfig.builder().bps(0.0).perUnitMaximum("per_unit_maximum").build()) - assertThat(newSubscriptionBpsPrice.cadence()) - .isEqualTo(NewSubscriptionBpsPrice.Cadence.ANNUAL) - assertThat(newSubscriptionBpsPrice.itemId()).isEqualTo("item_id") - assertThat(newSubscriptionBpsPrice.modelType()) - .isEqualTo(NewSubscriptionBpsPrice.ModelType.BPS) - assertThat(newSubscriptionBpsPrice.name()).isEqualTo("Annual fee") - assertThat(newSubscriptionBpsPrice.billableMetricId()).isEqualTo("billable_metric_id") - assertThat(newSubscriptionBpsPrice.billedInAdvance()).isEqualTo(true) - assertThat(newSubscriptionBpsPrice.billingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newSubscriptionBpsPrice.conversionRate()).isEqualTo(0.0) - assertThat(newSubscriptionBpsPrice.conversionRateConfig()) - .isEqualTo( - NewSubscriptionBpsPrice.ConversionRateConfig.ofUnit( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .build() - ) - ) - assertThat(newSubscriptionBpsPrice.currency()).isEqualTo("currency") - assertThat(newSubscriptionBpsPrice.dimensionalPriceConfiguration()) - .isEqualTo( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - assertThat(newSubscriptionBpsPrice.externalPriceId()).isEqualTo("external_price_id") - assertThat(newSubscriptionBpsPrice.fixedPriceQuantity()).isEqualTo(0.0) - assertThat(newSubscriptionBpsPrice.invoiceGroupingKey()).isEqualTo("x") - assertThat(newSubscriptionBpsPrice.invoicingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newSubscriptionBpsPrice.metadata()) - .isEqualTo( - NewSubscriptionBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - assertThat(newSubscriptionBpsPrice.referenceId()).isEqualTo("reference_id") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val newSubscriptionBpsPrice = - NewSubscriptionBpsPrice.builder() - .bpsConfig(BpsConfig.builder().bps(0.0).perUnitMaximum("per_unit_maximum").build()) - .cadence(NewSubscriptionBpsPrice.Cadence.ANNUAL) - .itemId("item_id") - .modelType(NewSubscriptionBpsPrice.ModelType.BPS) - .name("Annual fee") - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .currency("currency") - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewSubscriptionBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .referenceId("reference_id") - .build() - - val roundtrippedNewSubscriptionBpsPrice = - jsonMapper.readValue( - jsonMapper.writeValueAsString(newSubscriptionBpsPrice), - jacksonTypeRef(), - ) - - assertThat(roundtrippedNewSubscriptionBpsPrice).isEqualTo(newSubscriptionBpsPrice) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBulkBpsPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBulkBpsPriceTest.kt deleted file mode 100644 index 40cce68a7..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBulkBpsPriceTest.kt +++ /dev/null @@ -1,201 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.JsonValue -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class NewSubscriptionBulkBpsPriceTest { - - @Test - fun create() { - val newSubscriptionBulkBpsPrice = - NewSubscriptionBulkBpsPrice.builder() - .bulkBpsConfig( - BulkBpsConfig.builder() - .addTier( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - .cadence(NewSubscriptionBulkBpsPrice.Cadence.ANNUAL) - .itemId("item_id") - .modelType(NewSubscriptionBulkBpsPrice.ModelType.BULK_BPS) - .name("Annual fee") - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .currency("currency") - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewSubscriptionBulkBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .referenceId("reference_id") - .build() - - assertThat(newSubscriptionBulkBpsPrice.bulkBpsConfig()) - .isEqualTo( - BulkBpsConfig.builder() - .addTier( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - assertThat(newSubscriptionBulkBpsPrice.cadence()) - .isEqualTo(NewSubscriptionBulkBpsPrice.Cadence.ANNUAL) - assertThat(newSubscriptionBulkBpsPrice.itemId()).isEqualTo("item_id") - assertThat(newSubscriptionBulkBpsPrice.modelType()) - .isEqualTo(NewSubscriptionBulkBpsPrice.ModelType.BULK_BPS) - assertThat(newSubscriptionBulkBpsPrice.name()).isEqualTo("Annual fee") - assertThat(newSubscriptionBulkBpsPrice.billableMetricId()).isEqualTo("billable_metric_id") - assertThat(newSubscriptionBulkBpsPrice.billedInAdvance()).isEqualTo(true) - assertThat(newSubscriptionBulkBpsPrice.billingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newSubscriptionBulkBpsPrice.conversionRate()).isEqualTo(0.0) - assertThat(newSubscriptionBulkBpsPrice.conversionRateConfig()) - .isEqualTo( - NewSubscriptionBulkBpsPrice.ConversionRateConfig.ofUnit( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .build() - ) - ) - assertThat(newSubscriptionBulkBpsPrice.currency()).isEqualTo("currency") - assertThat(newSubscriptionBulkBpsPrice.dimensionalPriceConfiguration()) - .isEqualTo( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - assertThat(newSubscriptionBulkBpsPrice.externalPriceId()).isEqualTo("external_price_id") - assertThat(newSubscriptionBulkBpsPrice.fixedPriceQuantity()).isEqualTo(0.0) - assertThat(newSubscriptionBulkBpsPrice.invoiceGroupingKey()).isEqualTo("x") - assertThat(newSubscriptionBulkBpsPrice.invoicingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newSubscriptionBulkBpsPrice.metadata()) - .isEqualTo( - NewSubscriptionBulkBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - assertThat(newSubscriptionBulkBpsPrice.referenceId()).isEqualTo("reference_id") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val newSubscriptionBulkBpsPrice = - NewSubscriptionBulkBpsPrice.builder() - .bulkBpsConfig( - BulkBpsConfig.builder() - .addTier( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - .cadence(NewSubscriptionBulkBpsPrice.Cadence.ANNUAL) - .itemId("item_id") - .modelType(NewSubscriptionBulkBpsPrice.ModelType.BULK_BPS) - .name("Annual fee") - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .currency("currency") - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewSubscriptionBulkBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .referenceId("reference_id") - .build() - - val roundtrippedNewSubscriptionBulkBpsPrice = - jsonMapper.readValue( - jsonMapper.writeValueAsString(newSubscriptionBulkBpsPrice), - jacksonTypeRef(), - ) - - assertThat(roundtrippedNewSubscriptionBulkBpsPrice).isEqualTo(newSubscriptionBulkBpsPrice) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBulkPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBulkPriceTest.kt index c5f480a5f..80ee67f14 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBulkPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBulkPriceTest.kt @@ -86,7 +86,7 @@ internal class NewSubscriptionBulkPriceTest { assertThat(newSubscriptionBulkPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionBulkPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionBulkPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBulkWithProrationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBulkWithProrationPriceTest.kt index ecca5f90f..db304f963 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBulkWithProrationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionBulkWithProrationPriceTest.kt @@ -16,7 +16,20 @@ internal class NewSubscriptionBulkWithProrationPriceTest { NewSubscriptionBulkWithProrationPrice.builder() .bulkWithProrationConfig( NewSubscriptionBulkWithProrationPrice.BulkWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewSubscriptionBulkWithProrationPrice.BulkWithProrationConfig.Tier + .builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewSubscriptionBulkWithProrationPrice.BulkWithProrationConfig.Tier + .builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .cadence(NewSubscriptionBulkWithProrationPrice.Cadence.ANNUAL) @@ -63,7 +76,18 @@ internal class NewSubscriptionBulkWithProrationPriceTest { assertThat(newSubscriptionBulkWithProrationPrice.bulkWithProrationConfig()) .isEqualTo( NewSubscriptionBulkWithProrationPrice.BulkWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewSubscriptionBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewSubscriptionBulkWithProrationPrice.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) assertThat(newSubscriptionBulkWithProrationPrice.cadence()) @@ -85,7 +109,7 @@ internal class NewSubscriptionBulkWithProrationPriceTest { assertThat(newSubscriptionBulkWithProrationPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionBulkWithProrationPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionBulkWithProrationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -130,7 +154,20 @@ internal class NewSubscriptionBulkWithProrationPriceTest { NewSubscriptionBulkWithProrationPrice.builder() .bulkWithProrationConfig( NewSubscriptionBulkWithProrationPrice.BulkWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewSubscriptionBulkWithProrationPrice.BulkWithProrationConfig.Tier + .builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewSubscriptionBulkWithProrationPrice.BulkWithProrationConfig.Tier + .builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .cadence(NewSubscriptionBulkWithProrationPrice.Cadence.ANNUAL) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionCumulativeGroupedBulkPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionCumulativeGroupedBulkPriceTest.kt index 9c7f12de1..34dec871b 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionCumulativeGroupedBulkPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionCumulativeGroupedBulkPriceTest.kt @@ -17,7 +17,16 @@ internal class NewSubscriptionCumulativeGroupedBulkPriceTest { .cadence(NewSubscriptionCumulativeGroupedBulkPrice.Cadence.ANNUAL) .cumulativeGroupedBulkConfig( NewSubscriptionCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addDimensionValue( + NewSubscriptionCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig + .DimensionValue + .builder() + .groupingKey("x") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .group("group") .build() ) .itemId("item_id") @@ -67,7 +76,16 @@ internal class NewSubscriptionCumulativeGroupedBulkPriceTest { assertThat(newSubscriptionCumulativeGroupedBulkPrice.cumulativeGroupedBulkConfig()) .isEqualTo( NewSubscriptionCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addDimensionValue( + NewSubscriptionCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig + .DimensionValue + .builder() + .groupingKey("x") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .group("group") .build() ) assertThat(newSubscriptionCumulativeGroupedBulkPrice.itemId()).isEqualTo("item_id") @@ -87,7 +105,7 @@ internal class NewSubscriptionCumulativeGroupedBulkPriceTest { assertThat(newSubscriptionCumulativeGroupedBulkPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionCumulativeGroupedBulkPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionCumulativeGroupedBulkPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -134,7 +152,16 @@ internal class NewSubscriptionCumulativeGroupedBulkPriceTest { .cadence(NewSubscriptionCumulativeGroupedBulkPrice.Cadence.ANNUAL) .cumulativeGroupedBulkConfig( NewSubscriptionCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addDimensionValue( + NewSubscriptionCumulativeGroupedBulkPrice.CumulativeGroupedBulkConfig + .DimensionValue + .builder() + .groupingKey("x") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .group("group") .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedAllocationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedAllocationPriceTest.kt index f5df29519..0917f44d5 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedAllocationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedAllocationPriceTest.kt @@ -17,7 +17,9 @@ internal class NewSubscriptionGroupedAllocationPriceTest { .cadence(NewSubscriptionGroupedAllocationPrice.Cadence.ANNUAL) .groupedAllocationConfig( NewSubscriptionGroupedAllocationPrice.GroupedAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .groupingKey("x") + .overageUnitRate("overage_unit_rate") .build() ) .itemId("item_id") @@ -65,7 +67,9 @@ internal class NewSubscriptionGroupedAllocationPriceTest { assertThat(newSubscriptionGroupedAllocationPrice.groupedAllocationConfig()) .isEqualTo( NewSubscriptionGroupedAllocationPrice.GroupedAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .groupingKey("x") + .overageUnitRate("overage_unit_rate") .build() ) assertThat(newSubscriptionGroupedAllocationPrice.itemId()).isEqualTo("item_id") @@ -85,7 +89,7 @@ internal class NewSubscriptionGroupedAllocationPriceTest { assertThat(newSubscriptionGroupedAllocationPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionGroupedAllocationPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionGroupedAllocationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -131,7 +135,9 @@ internal class NewSubscriptionGroupedAllocationPriceTest { .cadence(NewSubscriptionGroupedAllocationPrice.Cadence.ANNUAL) .groupedAllocationConfig( NewSubscriptionGroupedAllocationPrice.GroupedAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .groupingKey("x") + .overageUnitRate("overage_unit_rate") .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPackagePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPackagePriceTest.kt index cd83b46b2..ddf18d03a 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPackagePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPackagePriceTest.kt @@ -17,7 +17,22 @@ internal class NewSubscriptionGroupedTieredPackagePriceTest { .cadence(NewSubscriptionGroupedTieredPackagePrice.Cadence.ANNUAL) .groupedTieredPackageConfig( NewSubscriptionGroupedTieredPackagePrice.GroupedTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewSubscriptionGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewSubscriptionGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .itemId("item_id") @@ -67,7 +82,22 @@ internal class NewSubscriptionGroupedTieredPackagePriceTest { assertThat(newSubscriptionGroupedTieredPackagePrice.groupedTieredPackageConfig()) .isEqualTo( NewSubscriptionGroupedTieredPackagePrice.GroupedTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewSubscriptionGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewSubscriptionGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) assertThat(newSubscriptionGroupedTieredPackagePrice.itemId()).isEqualTo("item_id") @@ -87,7 +117,7 @@ internal class NewSubscriptionGroupedTieredPackagePriceTest { assertThat(newSubscriptionGroupedTieredPackagePrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionGroupedTieredPackagePrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionGroupedTieredPackagePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -133,7 +163,22 @@ internal class NewSubscriptionGroupedTieredPackagePriceTest { .cadence(NewSubscriptionGroupedTieredPackagePrice.Cadence.ANNUAL) .groupedTieredPackageConfig( NewSubscriptionGroupedTieredPackagePrice.GroupedTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewSubscriptionGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewSubscriptionGroupedTieredPackagePrice.GroupedTieredPackageConfig.Tier + .builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPriceTest.kt index a23cffc54..c587b8e07 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedTieredPriceTest.kt @@ -17,7 +17,19 @@ internal class NewSubscriptionGroupedTieredPriceTest { .cadence(NewSubscriptionGroupedTieredPrice.Cadence.ANNUAL) .groupedTieredConfig( NewSubscriptionGroupedTieredPrice.GroupedTieredConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .addTier( + NewSubscriptionGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewSubscriptionGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .itemId("item_id") @@ -65,7 +77,19 @@ internal class NewSubscriptionGroupedTieredPriceTest { assertThat(newSubscriptionGroupedTieredPrice.groupedTieredConfig()) .isEqualTo( NewSubscriptionGroupedTieredPrice.GroupedTieredConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .addTier( + NewSubscriptionGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewSubscriptionGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) assertThat(newSubscriptionGroupedTieredPrice.itemId()).isEqualTo("item_id") @@ -85,7 +109,7 @@ internal class NewSubscriptionGroupedTieredPriceTest { assertThat(newSubscriptionGroupedTieredPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionGroupedTieredPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionGroupedTieredPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -131,7 +155,19 @@ internal class NewSubscriptionGroupedTieredPriceTest { .cadence(NewSubscriptionGroupedTieredPrice.Cadence.ANNUAL) .groupedTieredConfig( NewSubscriptionGroupedTieredPrice.GroupedTieredConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .addTier( + NewSubscriptionGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewSubscriptionGroupedTieredPrice.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithMeteredMinimumPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithMeteredMinimumPriceTest.kt index 3a88cf7ca..ad2499640 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithMeteredMinimumPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithMeteredMinimumPriceTest.kt @@ -18,7 +18,28 @@ internal class NewSubscriptionGroupedWithMeteredMinimumPriceTest { .groupedWithMeteredMinimumConfig( NewSubscriptionGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimumUnitAmount("minimum_unit_amount") + .pricingKey("pricing_key") + .addScalingFactor( + NewSubscriptionGroupedWithMeteredMinimumPrice + .GroupedWithMeteredMinimumConfig + .ScalingFactor + .builder() + .scalingFactor("scaling_factor") + .scalingValue("scaling_value") + .build() + ) + .scalingKey("scaling_key") + .addUnitAmount( + NewSubscriptionGroupedWithMeteredMinimumPrice + .GroupedWithMeteredMinimumConfig + .UnitAmount + .builder() + .pricingValue("pricing_value") + .unitAmount("unit_amount") + .build() + ) .build() ) .itemId("item_id") @@ -70,7 +91,28 @@ internal class NewSubscriptionGroupedWithMeteredMinimumPriceTest { .isEqualTo( NewSubscriptionGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimumUnitAmount("minimum_unit_amount") + .pricingKey("pricing_key") + .addScalingFactor( + NewSubscriptionGroupedWithMeteredMinimumPrice + .GroupedWithMeteredMinimumConfig + .ScalingFactor + .builder() + .scalingFactor("scaling_factor") + .scalingValue("scaling_value") + .build() + ) + .scalingKey("scaling_key") + .addUnitAmount( + NewSubscriptionGroupedWithMeteredMinimumPrice + .GroupedWithMeteredMinimumConfig + .UnitAmount + .builder() + .pricingValue("pricing_value") + .unitAmount("unit_amount") + .build() + ) .build() ) assertThat(newSubscriptionGroupedWithMeteredMinimumPrice.itemId()).isEqualTo("item_id") @@ -92,7 +134,7 @@ internal class NewSubscriptionGroupedWithMeteredMinimumPriceTest { assertThat(newSubscriptionGroupedWithMeteredMinimumPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionGroupedWithMeteredMinimumPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionGroupedWithMeteredMinimumPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -142,7 +184,28 @@ internal class NewSubscriptionGroupedWithMeteredMinimumPriceTest { .groupedWithMeteredMinimumConfig( NewSubscriptionGroupedWithMeteredMinimumPrice.GroupedWithMeteredMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimumUnitAmount("minimum_unit_amount") + .pricingKey("pricing_key") + .addScalingFactor( + NewSubscriptionGroupedWithMeteredMinimumPrice + .GroupedWithMeteredMinimumConfig + .ScalingFactor + .builder() + .scalingFactor("scaling_factor") + .scalingValue("scaling_value") + .build() + ) + .scalingKey("scaling_key") + .addUnitAmount( + NewSubscriptionGroupedWithMeteredMinimumPrice + .GroupedWithMeteredMinimumConfig + .UnitAmount + .builder() + .pricingValue("pricing_value") + .unitAmount("unit_amount") + .build() + ) .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithProratedMinimumPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithProratedMinimumPriceTest.kt index 9ba6f6b16..08a681998 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithProratedMinimumPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionGroupedWithProratedMinimumPriceTest.kt @@ -18,7 +18,9 @@ internal class NewSubscriptionGroupedWithProratedMinimumPriceTest { .groupedWithProratedMinimumConfig( NewSubscriptionGroupedWithProratedMinimumPrice.GroupedWithProratedMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimum("minimum") + .unitRate("unit_rate") .build() ) .itemId("item_id") @@ -72,7 +74,9 @@ internal class NewSubscriptionGroupedWithProratedMinimumPriceTest { .isEqualTo( NewSubscriptionGroupedWithProratedMinimumPrice.GroupedWithProratedMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimum("minimum") + .unitRate("unit_rate") .build() ) assertThat(newSubscriptionGroupedWithProratedMinimumPrice.itemId()).isEqualTo("item_id") @@ -95,7 +99,7 @@ internal class NewSubscriptionGroupedWithProratedMinimumPriceTest { assertThat(newSubscriptionGroupedWithProratedMinimumPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionGroupedWithProratedMinimumPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionGroupedWithProratedMinimumPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -145,7 +149,9 @@ internal class NewSubscriptionGroupedWithProratedMinimumPriceTest { .groupedWithProratedMinimumConfig( NewSubscriptionGroupedWithProratedMinimumPrice.GroupedWithProratedMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .minimum("minimum") + .unitRate("unit_rate") .build() ) .itemId("item_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMatrixPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMatrixPriceTest.kt index e9493b446..25d87020d 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMatrixPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMatrixPriceTest.kt @@ -98,7 +98,7 @@ internal class NewSubscriptionMatrixPriceTest { assertThat(newSubscriptionMatrixPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionMatrixPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionMatrixPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithAllocationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithAllocationPriceTest.kt index 62c2de376..500e0edf8 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithAllocationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithAllocationPriceTest.kt @@ -18,11 +18,11 @@ internal class NewSubscriptionMatrixWithAllocationPriceTest { .itemId("item_id") .matrixWithAllocationConfig( MatrixWithAllocationConfig.builder() - .allocation(0.0) + .allocation("allocation") .defaultUnitAmount("default_unit_amount") .addDimension("string") .addMatrixValue( - MatrixValue.builder() + MatrixWithAllocationConfig.MatrixValue.builder() .addDimensionValue("string") .unitAmount("unit_amount") .build() @@ -76,11 +76,11 @@ internal class NewSubscriptionMatrixWithAllocationPriceTest { assertThat(newSubscriptionMatrixWithAllocationPrice.matrixWithAllocationConfig()) .isEqualTo( MatrixWithAllocationConfig.builder() - .allocation(0.0) + .allocation("allocation") .defaultUnitAmount("default_unit_amount") .addDimension("string") .addMatrixValue( - MatrixValue.builder() + MatrixWithAllocationConfig.MatrixValue.builder() .addDimensionValue("string") .unitAmount("unit_amount") .build() @@ -103,7 +103,7 @@ internal class NewSubscriptionMatrixWithAllocationPriceTest { assertThat(newSubscriptionMatrixWithAllocationPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionMatrixWithAllocationPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionMatrixWithAllocationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -150,11 +150,11 @@ internal class NewSubscriptionMatrixWithAllocationPriceTest { .itemId("item_id") .matrixWithAllocationConfig( MatrixWithAllocationConfig.builder() - .allocation(0.0) + .allocation("allocation") .defaultUnitAmount("default_unit_amount") .addDimension("string") .addMatrixValue( - MatrixValue.builder() + MatrixWithAllocationConfig.MatrixValue.builder() .addDimensionValue("string") .unitAmount("unit_amount") .build() diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithDisplayNamePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithDisplayNamePriceTest.kt index 71d7eb7bf..22e5656f9 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithDisplayNamePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMatrixWithDisplayNamePriceTest.kt @@ -18,7 +18,16 @@ internal class NewSubscriptionMatrixWithDisplayNamePriceTest { .itemId("item_id") .matrixWithDisplayNameConfig( NewSubscriptionMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .dimension("dimension") + .addUnitAmount( + NewSubscriptionMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig + .UnitAmount + .builder() + .dimensionValue("dimension_value") + .displayName("display_name") + .unitAmount("unit_amount") + .build() + ) .build() ) .modelType( @@ -68,7 +77,16 @@ internal class NewSubscriptionMatrixWithDisplayNamePriceTest { assertThat(newSubscriptionMatrixWithDisplayNamePrice.matrixWithDisplayNameConfig()) .isEqualTo( NewSubscriptionMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .dimension("dimension") + .addUnitAmount( + NewSubscriptionMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig + .UnitAmount + .builder() + .dimensionValue("dimension_value") + .displayName("display_name") + .unitAmount("unit_amount") + .build() + ) .build() ) assertThat(newSubscriptionMatrixWithDisplayNamePrice.modelType()) @@ -87,7 +105,7 @@ internal class NewSubscriptionMatrixWithDisplayNamePriceTest { assertThat(newSubscriptionMatrixWithDisplayNamePrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionMatrixWithDisplayNamePrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionMatrixWithDisplayNamePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -135,7 +153,16 @@ internal class NewSubscriptionMatrixWithDisplayNamePriceTest { .itemId("item_id") .matrixWithDisplayNameConfig( NewSubscriptionMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .dimension("dimension") + .addUnitAmount( + NewSubscriptionMatrixWithDisplayNamePrice.MatrixWithDisplayNameConfig + .UnitAmount + .builder() + .dimensionValue("dimension_value") + .displayName("display_name") + .unitAmount("unit_amount") + .build() + ) .build() ) .modelType( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMaxGroupTieredPackagePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMaxGroupTieredPackagePriceTest.kt index 5f18dafca..f5ed48d10 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMaxGroupTieredPackagePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMaxGroupTieredPackagePriceTest.kt @@ -18,7 +18,24 @@ internal class NewSubscriptionMaxGroupTieredPackagePriceTest { .itemId("item_id") .maxGroupTieredPackageConfig( NewSubscriptionMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewSubscriptionMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewSubscriptionMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .modelType( @@ -68,7 +85,22 @@ internal class NewSubscriptionMaxGroupTieredPackagePriceTest { assertThat(newSubscriptionMaxGroupTieredPackagePrice.maxGroupTieredPackageConfig()) .isEqualTo( NewSubscriptionMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewSubscriptionMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewSubscriptionMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) assertThat(newSubscriptionMaxGroupTieredPackagePrice.modelType()) @@ -87,7 +119,7 @@ internal class NewSubscriptionMaxGroupTieredPackagePriceTest { assertThat(newSubscriptionMaxGroupTieredPackagePrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionMaxGroupTieredPackagePrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionMaxGroupTieredPackagePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -135,7 +167,24 @@ internal class NewSubscriptionMaxGroupTieredPackagePriceTest { .itemId("item_id") .maxGroupTieredPackageConfig( NewSubscriptionMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupingKey("x") + .packageSize("package_size") + .addTier( + NewSubscriptionMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewSubscriptionMaxGroupTieredPackagePrice.MaxGroupTieredPackageConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .modelType( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTierWithProrationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMinimumCompositePriceTest.kt similarity index 60% rename from orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTierWithProrationPriceTest.kt rename to orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMinimumCompositePriceTest.kt index 7c9e21217..317aab45c 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTierWithProrationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionMinimumCompositePriceTest.kt @@ -8,21 +8,22 @@ import com.withorb.api.core.jsonMapper import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -internal class NewSubscriptionTierWithProrationPriceTest { +internal class NewSubscriptionMinimumCompositePriceTest { @Test fun create() { - val newSubscriptionTierWithProrationPrice = - NewSubscriptionTierWithProrationPrice.builder() - .cadence(NewSubscriptionTierWithProrationPrice.Cadence.ANNUAL) + val newSubscriptionMinimumCompositePrice = + NewSubscriptionMinimumCompositePrice.builder() + .cadence(NewSubscriptionMinimumCompositePrice.Cadence.ANNUAL) .itemId("item_id") - .modelType(NewSubscriptionTierWithProrationPrice.ModelType.TIERED_WITH_PRORATION) - .name("Annual fee") - .tieredWithProrationConfig( - NewSubscriptionTierWithProrationPrice.TieredWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .minimumConfig( + NewSubscriptionMinimumCompositePrice.MinimumConfig.builder() + .minimumAmount("minimum_amount") + .prorated(true) .build() ) + .modelType(NewSubscriptionMinimumCompositePrice.ModelType.MINIMUM) + .name("Annual fee") .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -53,39 +54,40 @@ internal class NewSubscriptionTierWithProrationPriceTest { .build() ) .metadata( - NewSubscriptionTierWithProrationPrice.Metadata.builder() + NewSubscriptionMinimumCompositePrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) .referenceId("reference_id") .build() - assertThat(newSubscriptionTierWithProrationPrice.cadence()) - .isEqualTo(NewSubscriptionTierWithProrationPrice.Cadence.ANNUAL) - assertThat(newSubscriptionTierWithProrationPrice.itemId()).isEqualTo("item_id") - assertThat(newSubscriptionTierWithProrationPrice.modelType()) - .isEqualTo(NewSubscriptionTierWithProrationPrice.ModelType.TIERED_WITH_PRORATION) - assertThat(newSubscriptionTierWithProrationPrice.name()).isEqualTo("Annual fee") - assertThat(newSubscriptionTierWithProrationPrice.tieredWithProrationConfig()) + assertThat(newSubscriptionMinimumCompositePrice.cadence()) + .isEqualTo(NewSubscriptionMinimumCompositePrice.Cadence.ANNUAL) + assertThat(newSubscriptionMinimumCompositePrice.itemId()).isEqualTo("item_id") + assertThat(newSubscriptionMinimumCompositePrice.minimumConfig()) .isEqualTo( - NewSubscriptionTierWithProrationPrice.TieredWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + NewSubscriptionMinimumCompositePrice.MinimumConfig.builder() + .minimumAmount("minimum_amount") + .prorated(true) .build() ) - assertThat(newSubscriptionTierWithProrationPrice.billableMetricId()) + assertThat(newSubscriptionMinimumCompositePrice.modelType()) + .isEqualTo(NewSubscriptionMinimumCompositePrice.ModelType.MINIMUM) + assertThat(newSubscriptionMinimumCompositePrice.name()).isEqualTo("Annual fee") + assertThat(newSubscriptionMinimumCompositePrice.billableMetricId()) .isEqualTo("billable_metric_id") - assertThat(newSubscriptionTierWithProrationPrice.billedInAdvance()).isEqualTo(true) - assertThat(newSubscriptionTierWithProrationPrice.billingCycleConfiguration()) + assertThat(newSubscriptionMinimumCompositePrice.billedInAdvance()).isEqualTo(true) + assertThat(newSubscriptionMinimumCompositePrice.billingCycleConfiguration()) .isEqualTo( NewBillingCycleConfiguration.builder() .duration(0L) .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) .build() ) - assertThat(newSubscriptionTierWithProrationPrice.conversionRate()).isEqualTo(0.0) - assertThat(newSubscriptionTierWithProrationPrice.conversionRateConfig()) + assertThat(newSubscriptionMinimumCompositePrice.conversionRate()).isEqualTo(0.0) + assertThat(newSubscriptionMinimumCompositePrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionTierWithProrationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -94,8 +96,8 @@ internal class NewSubscriptionTierWithProrationPriceTest { .build() ) ) - assertThat(newSubscriptionTierWithProrationPrice.currency()).isEqualTo("currency") - assertThat(newSubscriptionTierWithProrationPrice.dimensionalPriceConfiguration()) + assertThat(newSubscriptionMinimumCompositePrice.currency()).isEqualTo("currency") + assertThat(newSubscriptionMinimumCompositePrice.dimensionalPriceConfiguration()) .isEqualTo( NewDimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -103,40 +105,41 @@ internal class NewSubscriptionTierWithProrationPriceTest { .externalDimensionalPriceGroupId("external_dimensional_price_group_id") .build() ) - assertThat(newSubscriptionTierWithProrationPrice.externalPriceId()) + assertThat(newSubscriptionMinimumCompositePrice.externalPriceId()) .isEqualTo("external_price_id") - assertThat(newSubscriptionTierWithProrationPrice.fixedPriceQuantity()).isEqualTo(0.0) - assertThat(newSubscriptionTierWithProrationPrice.invoiceGroupingKey()).isEqualTo("x") - assertThat(newSubscriptionTierWithProrationPrice.invoicingCycleConfiguration()) + assertThat(newSubscriptionMinimumCompositePrice.fixedPriceQuantity()).isEqualTo(0.0) + assertThat(newSubscriptionMinimumCompositePrice.invoiceGroupingKey()).isEqualTo("x") + assertThat(newSubscriptionMinimumCompositePrice.invoicingCycleConfiguration()) .isEqualTo( NewBillingCycleConfiguration.builder() .duration(0L) .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) .build() ) - assertThat(newSubscriptionTierWithProrationPrice.metadata()) + assertThat(newSubscriptionMinimumCompositePrice.metadata()) .isEqualTo( - NewSubscriptionTierWithProrationPrice.Metadata.builder() + NewSubscriptionMinimumCompositePrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) - assertThat(newSubscriptionTierWithProrationPrice.referenceId()).isEqualTo("reference_id") + assertThat(newSubscriptionMinimumCompositePrice.referenceId()).isEqualTo("reference_id") } @Test fun roundtrip() { val jsonMapper = jsonMapper() - val newSubscriptionTierWithProrationPrice = - NewSubscriptionTierWithProrationPrice.builder() - .cadence(NewSubscriptionTierWithProrationPrice.Cadence.ANNUAL) + val newSubscriptionMinimumCompositePrice = + NewSubscriptionMinimumCompositePrice.builder() + .cadence(NewSubscriptionMinimumCompositePrice.Cadence.ANNUAL) .itemId("item_id") - .modelType(NewSubscriptionTierWithProrationPrice.ModelType.TIERED_WITH_PRORATION) - .name("Annual fee") - .tieredWithProrationConfig( - NewSubscriptionTierWithProrationPrice.TieredWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .minimumConfig( + NewSubscriptionMinimumCompositePrice.MinimumConfig.builder() + .minimumAmount("minimum_amount") + .prorated(true) .build() ) + .modelType(NewSubscriptionMinimumCompositePrice.ModelType.MINIMUM) + .name("Annual fee") .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -167,20 +170,20 @@ internal class NewSubscriptionTierWithProrationPriceTest { .build() ) .metadata( - NewSubscriptionTierWithProrationPrice.Metadata.builder() + NewSubscriptionMinimumCompositePrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) .referenceId("reference_id") .build() - val roundtrippedNewSubscriptionTierWithProrationPrice = + val roundtrippedNewSubscriptionMinimumCompositePrice = jsonMapper.readValue( - jsonMapper.writeValueAsString(newSubscriptionTierWithProrationPrice), - jacksonTypeRef(), + jsonMapper.writeValueAsString(newSubscriptionMinimumCompositePrice), + jacksonTypeRef(), ) - assertThat(roundtrippedNewSubscriptionTierWithProrationPrice) - .isEqualTo(newSubscriptionTierWithProrationPrice) + assertThat(roundtrippedNewSubscriptionMinimumCompositePrice) + .isEqualTo(newSubscriptionMinimumCompositePrice) } } diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionPackagePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionPackagePriceTest.kt index 7d90a6764..89db836da 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionPackagePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionPackagePriceTest.kt @@ -19,7 +19,7 @@ internal class NewSubscriptionPackagePriceTest { .modelType(NewSubscriptionPackagePrice.ModelType.PACKAGE) .name("Annual fee") .packageConfig( - PackageConfig.builder().packageAmount("package_amount").packageSize(0L).build() + PackageConfig.builder().packageAmount("package_amount").packageSize(1L).build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -66,7 +66,7 @@ internal class NewSubscriptionPackagePriceTest { assertThat(newSubscriptionPackagePrice.name()).isEqualTo("Annual fee") assertThat(newSubscriptionPackagePrice.packageConfig()) .isEqualTo( - PackageConfig.builder().packageAmount("package_amount").packageSize(0L).build() + PackageConfig.builder().packageAmount("package_amount").packageSize(1L).build() ) assertThat(newSubscriptionPackagePrice.billableMetricId()).isEqualTo("billable_metric_id") assertThat(newSubscriptionPackagePrice.billedInAdvance()).isEqualTo(true) @@ -80,7 +80,7 @@ internal class NewSubscriptionPackagePriceTest { assertThat(newSubscriptionPackagePrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionPackagePrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionPackagePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -127,7 +127,7 @@ internal class NewSubscriptionPackagePriceTest { .modelType(NewSubscriptionPackagePrice.ModelType.PACKAGE) .name("Annual fee") .packageConfig( - PackageConfig.builder().packageAmount("package_amount").packageSize(0L).build() + PackageConfig.builder().packageAmount("package_amount").packageSize(1L).build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionPackageWithAllocationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionPackageWithAllocationPriceTest.kt index b3fa7171b..fd0a8c31a 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionPackageWithAllocationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionPackageWithAllocationPriceTest.kt @@ -22,7 +22,9 @@ internal class NewSubscriptionPackageWithAllocationPriceTest { .name("Annual fee") .packageWithAllocationConfig( NewSubscriptionPackageWithAllocationPrice.PackageWithAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .packageAmount("package_amount") + .packageSize("package_size") .build() ) .billableMetricId("billable_metric_id") @@ -71,7 +73,9 @@ internal class NewSubscriptionPackageWithAllocationPriceTest { assertThat(newSubscriptionPackageWithAllocationPrice.packageWithAllocationConfig()) .isEqualTo( NewSubscriptionPackageWithAllocationPrice.PackageWithAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .packageAmount("package_amount") + .packageSize("package_size") .build() ) assertThat(newSubscriptionPackageWithAllocationPrice.billableMetricId()) @@ -87,7 +91,7 @@ internal class NewSubscriptionPackageWithAllocationPriceTest { assertThat(newSubscriptionPackageWithAllocationPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionPackageWithAllocationPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionPackageWithAllocationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -139,7 +143,9 @@ internal class NewSubscriptionPackageWithAllocationPriceTest { .name("Annual fee") .packageWithAllocationConfig( NewSubscriptionPackageWithAllocationPrice.PackageWithAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .allocation("allocation") + .packageAmount("package_amount") + .packageSize("package_size") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithTieredPricingPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithTieredPricingPriceTest.kt index a305938f4..d18079001 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithTieredPricingPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithTieredPricingPriceTest.kt @@ -25,7 +25,36 @@ internal class NewSubscriptionScalableMatrixWithTieredPricingPriceTest { NewSubscriptionScalableMatrixWithTieredPricingPrice .ScalableMatrixWithTieredPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewSubscriptionScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .addTier( + NewSubscriptionScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewSubscriptionScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .secondDimension("second_dimension") .build() ) .billableMetricId("billable_metric_id") @@ -84,7 +113,36 @@ internal class NewSubscriptionScalableMatrixWithTieredPricingPriceTest { NewSubscriptionScalableMatrixWithTieredPricingPrice .ScalableMatrixWithTieredPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewSubscriptionScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .addTier( + NewSubscriptionScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewSubscriptionScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .secondDimension("second_dimension") .build() ) assertThat(newSubscriptionScalableMatrixWithTieredPricingPrice.billableMetricId()) @@ -102,7 +160,7 @@ internal class NewSubscriptionScalableMatrixWithTieredPricingPriceTest { .isEqualTo(0.0) assertThat(newSubscriptionScalableMatrixWithTieredPricingPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionScalableMatrixWithTieredPricingPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -164,7 +222,36 @@ internal class NewSubscriptionScalableMatrixWithTieredPricingPriceTest { NewSubscriptionScalableMatrixWithTieredPricingPrice .ScalableMatrixWithTieredPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewSubscriptionScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .addTier( + NewSubscriptionScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewSubscriptionScalableMatrixWithTieredPricingPrice + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .secondDimension("second_dimension") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithUnitPricingPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithUnitPricingPriceTest.kt index 054343a55..88521ee0c 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithUnitPricingPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionScalableMatrixWithUnitPricingPriceTest.kt @@ -25,7 +25,20 @@ internal class NewSubscriptionScalableMatrixWithUnitPricingPriceTest { NewSubscriptionScalableMatrixWithUnitPricingPrice .ScalableMatrixWithUnitPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewSubscriptionScalableMatrixWithUnitPricingPrice + .ScalableMatrixWithUnitPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .unitPrice("unit_price") + .prorate(true) + .secondDimension("second_dimension") .build() ) .billableMetricId("billable_metric_id") @@ -82,7 +95,20 @@ internal class NewSubscriptionScalableMatrixWithUnitPricingPriceTest { NewSubscriptionScalableMatrixWithUnitPricingPrice .ScalableMatrixWithUnitPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewSubscriptionScalableMatrixWithUnitPricingPrice + .ScalableMatrixWithUnitPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .unitPrice("unit_price") + .prorate(true) + .secondDimension("second_dimension") .build() ) assertThat(newSubscriptionScalableMatrixWithUnitPricingPrice.billableMetricId()) @@ -100,7 +126,7 @@ internal class NewSubscriptionScalableMatrixWithUnitPricingPriceTest { .isEqualTo(0.0) assertThat(newSubscriptionScalableMatrixWithUnitPricingPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionScalableMatrixWithUnitPricingPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -160,7 +186,20 @@ internal class NewSubscriptionScalableMatrixWithUnitPricingPriceTest { NewSubscriptionScalableMatrixWithUnitPricingPrice .ScalableMatrixWithUnitPricingConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .firstDimension("first_dimension") + .addMatrixScalingFactor( + NewSubscriptionScalableMatrixWithUnitPricingPrice + .ScalableMatrixWithUnitPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .unitPrice("unit_price") + .prorate(true) + .secondDimension("second_dimension") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionThresholdTotalAmountPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionThresholdTotalAmountPriceTest.kt index f265a8b1e..420a96ce9 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionThresholdTotalAmountPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionThresholdTotalAmountPriceTest.kt @@ -22,7 +22,23 @@ internal class NewSubscriptionThresholdTotalAmountPriceTest { .name("Annual fee") .thresholdTotalAmountConfig( NewSubscriptionThresholdTotalAmountPrice.ThresholdTotalAmountConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addConsumptionTable( + NewSubscriptionThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .addConsumptionTable( + NewSubscriptionThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .prorate(true) .build() ) .billableMetricId("billable_metric_id") @@ -71,7 +87,23 @@ internal class NewSubscriptionThresholdTotalAmountPriceTest { assertThat(newSubscriptionThresholdTotalAmountPrice.thresholdTotalAmountConfig()) .isEqualTo( NewSubscriptionThresholdTotalAmountPrice.ThresholdTotalAmountConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addConsumptionTable( + NewSubscriptionThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .addConsumptionTable( + NewSubscriptionThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .prorate(true) .build() ) assertThat(newSubscriptionThresholdTotalAmountPrice.billableMetricId()) @@ -87,7 +119,7 @@ internal class NewSubscriptionThresholdTotalAmountPriceTest { assertThat(newSubscriptionThresholdTotalAmountPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionThresholdTotalAmountPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionThresholdTotalAmountPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -138,7 +170,23 @@ internal class NewSubscriptionThresholdTotalAmountPriceTest { .name("Annual fee") .thresholdTotalAmountConfig( NewSubscriptionThresholdTotalAmountPrice.ThresholdTotalAmountConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addConsumptionTable( + NewSubscriptionThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .addConsumptionTable( + NewSubscriptionThresholdTotalAmountPrice.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .prorate(true) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredBpsPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredBpsPriceTest.kt deleted file mode 100644 index 7a98653c4..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredBpsPriceTest.kt +++ /dev/null @@ -1,205 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.JsonValue -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class NewSubscriptionTieredBpsPriceTest { - - @Test - fun create() { - val newSubscriptionTieredBpsPrice = - NewSubscriptionTieredBpsPrice.builder() - .cadence(NewSubscriptionTieredBpsPrice.Cadence.ANNUAL) - .itemId("item_id") - .modelType(NewSubscriptionTieredBpsPrice.ModelType.TIERED_BPS) - .name("Annual fee") - .tieredBpsConfig( - TieredBpsConfig.builder() - .addTier( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .currency("currency") - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewSubscriptionTieredBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .referenceId("reference_id") - .build() - - assertThat(newSubscriptionTieredBpsPrice.cadence()) - .isEqualTo(NewSubscriptionTieredBpsPrice.Cadence.ANNUAL) - assertThat(newSubscriptionTieredBpsPrice.itemId()).isEqualTo("item_id") - assertThat(newSubscriptionTieredBpsPrice.modelType()) - .isEqualTo(NewSubscriptionTieredBpsPrice.ModelType.TIERED_BPS) - assertThat(newSubscriptionTieredBpsPrice.name()).isEqualTo("Annual fee") - assertThat(newSubscriptionTieredBpsPrice.tieredBpsConfig()) - .isEqualTo( - TieredBpsConfig.builder() - .addTier( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - assertThat(newSubscriptionTieredBpsPrice.billableMetricId()).isEqualTo("billable_metric_id") - assertThat(newSubscriptionTieredBpsPrice.billedInAdvance()).isEqualTo(true) - assertThat(newSubscriptionTieredBpsPrice.billingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newSubscriptionTieredBpsPrice.conversionRate()).isEqualTo(0.0) - assertThat(newSubscriptionTieredBpsPrice.conversionRateConfig()) - .isEqualTo( - NewSubscriptionTieredBpsPrice.ConversionRateConfig.ofUnit( - UnitConversionRateConfig.builder() - .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) - .unitConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .build() - ) - ) - assertThat(newSubscriptionTieredBpsPrice.currency()).isEqualTo("currency") - assertThat(newSubscriptionTieredBpsPrice.dimensionalPriceConfiguration()) - .isEqualTo( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - assertThat(newSubscriptionTieredBpsPrice.externalPriceId()).isEqualTo("external_price_id") - assertThat(newSubscriptionTieredBpsPrice.fixedPriceQuantity()).isEqualTo(0.0) - assertThat(newSubscriptionTieredBpsPrice.invoiceGroupingKey()).isEqualTo("x") - assertThat(newSubscriptionTieredBpsPrice.invoicingCycleConfiguration()) - .isEqualTo( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - assertThat(newSubscriptionTieredBpsPrice.metadata()) - .isEqualTo( - NewSubscriptionTieredBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - assertThat(newSubscriptionTieredBpsPrice.referenceId()).isEqualTo("reference_id") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val newSubscriptionTieredBpsPrice = - NewSubscriptionTieredBpsPrice.builder() - .cadence(NewSubscriptionTieredBpsPrice.Cadence.ANNUAL) - .itemId("item_id") - .modelType(NewSubscriptionTieredBpsPrice.ModelType.TIERED_BPS) - .name("Annual fee") - .tieredBpsConfig( - TieredBpsConfig.builder() - .addTier( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) - .billableMetricId("billable_metric_id") - .billedInAdvance(true) - .billingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .currency("currency") - .dimensionalPriceConfiguration( - NewDimensionalPriceConfiguration.builder() - .addDimensionValue("string") - .dimensionalPriceGroupId("dimensional_price_group_id") - .externalDimensionalPriceGroupId("external_dimensional_price_group_id") - .build() - ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .invoiceGroupingKey("x") - .invoicingCycleConfiguration( - NewBillingCycleConfiguration.builder() - .duration(0L) - .durationUnit(NewBillingCycleConfiguration.DurationUnit.DAY) - .build() - ) - .metadata( - NewSubscriptionTieredBpsPrice.Metadata.builder() - .putAdditionalProperty("foo", JsonValue.from("string")) - .build() - ) - .referenceId("reference_id") - .build() - - val roundtrippedNewSubscriptionTieredBpsPrice = - jsonMapper.readValue( - jsonMapper.writeValueAsString(newSubscriptionTieredBpsPrice), - jacksonTypeRef(), - ) - - assertThat(roundtrippedNewSubscriptionTieredBpsPrice) - .isEqualTo(newSubscriptionTieredBpsPrice) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredPackagePriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredPackagePriceTest.kt index d14d25327..ea2ffaee5 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredPackagePriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredPackagePriceTest.kt @@ -20,7 +20,19 @@ internal class NewSubscriptionTieredPackagePriceTest { .name("Annual fee") .tieredPackageConfig( NewSubscriptionTieredPackagePrice.TieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize("package_size") + .addTier( + NewSubscriptionTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewSubscriptionTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +81,19 @@ internal class NewSubscriptionTieredPackagePriceTest { assertThat(newSubscriptionTieredPackagePrice.tieredPackageConfig()) .isEqualTo( NewSubscriptionTieredPackagePrice.TieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize("package_size") + .addTier( + NewSubscriptionTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewSubscriptionTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) assertThat(newSubscriptionTieredPackagePrice.billableMetricId()) @@ -85,7 +109,7 @@ internal class NewSubscriptionTieredPackagePriceTest { assertThat(newSubscriptionTieredPackagePrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionTieredPackagePrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionTieredPackagePrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -134,7 +158,19 @@ internal class NewSubscriptionTieredPackagePriceTest { .name("Annual fee") .tieredPackageConfig( NewSubscriptionTieredPackagePrice.TieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize("package_size") + .addTier( + NewSubscriptionTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewSubscriptionTieredPackagePrice.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredPackageWithMinimumPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredPackageWithMinimumPriceTest.kt index a7f589d0d..5c439c752 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredPackageWithMinimumPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredPackageWithMinimumPriceTest.kt @@ -24,7 +24,27 @@ internal class NewSubscriptionTieredPackageWithMinimumPriceTest { .tieredPackageWithMinimumConfig( NewSubscriptionTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize(0.0) + .addTier( + NewSubscriptionTieredPackageWithMinimumPrice + .TieredPackageWithMinimumConfig + .Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewSubscriptionTieredPackageWithMinimumPrice + .TieredPackageWithMinimumConfig + .Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .billableMetricId("billable_metric_id") @@ -76,7 +96,25 @@ internal class NewSubscriptionTieredPackageWithMinimumPriceTest { .isEqualTo( NewSubscriptionTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize(0.0) + .addTier( + NewSubscriptionTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig + .Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewSubscriptionTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig + .Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) assertThat(newSubscriptionTieredPackageWithMinimumPrice.billableMetricId()) @@ -92,7 +130,7 @@ internal class NewSubscriptionTieredPackageWithMinimumPriceTest { assertThat(newSubscriptionTieredPackageWithMinimumPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionTieredPackageWithMinimumPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionTieredPackageWithMinimumPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -146,7 +184,27 @@ internal class NewSubscriptionTieredPackageWithMinimumPriceTest { .tieredPackageWithMinimumConfig( NewSubscriptionTieredPackageWithMinimumPrice.TieredPackageWithMinimumConfig .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageSize(0.0) + .addTier( + NewSubscriptionTieredPackageWithMinimumPrice + .TieredPackageWithMinimumConfig + .Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + NewSubscriptionTieredPackageWithMinimumPrice + .TieredPackageWithMinimumConfig + .Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredPriceTest.kt index 54e509149..497d65f80 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredPriceTest.kt @@ -27,6 +27,7 @@ internal class NewSubscriptionTieredPriceTest { .lastUnit(0.0) .build() ) + .prorated(true) .build() ) .billableMetricId("billable_metric_id") @@ -82,6 +83,7 @@ internal class NewSubscriptionTieredPriceTest { .lastUnit(0.0) .build() ) + .prorated(true) .build() ) assertThat(newSubscriptionTieredPrice.billableMetricId()).isEqualTo("billable_metric_id") @@ -96,7 +98,7 @@ internal class NewSubscriptionTieredPriceTest { assertThat(newSubscriptionTieredPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionTieredPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionTieredPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -151,6 +153,7 @@ internal class NewSubscriptionTieredPriceTest { .lastUnit(0.0) .build() ) + .prorated(true) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredWithMinimumPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredWithMinimumPriceTest.kt index 258e05776..90bdb5722 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredWithMinimumPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionTieredWithMinimumPriceTest.kt @@ -20,7 +20,24 @@ internal class NewSubscriptionTieredWithMinimumPriceTest { .name("Annual fee") .tieredWithMinimumConfig( NewSubscriptionTieredWithMinimumPrice.TieredWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewSubscriptionTieredWithMinimumPrice.TieredWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewSubscriptionTieredWithMinimumPrice.TieredWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .hideZeroAmountTiers(true) + .prorate(true) .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +86,22 @@ internal class NewSubscriptionTieredWithMinimumPriceTest { assertThat(newSubscriptionTieredWithMinimumPrice.tieredWithMinimumConfig()) .isEqualTo( NewSubscriptionTieredWithMinimumPrice.TieredWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewSubscriptionTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewSubscriptionTieredWithMinimumPrice.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .hideZeroAmountTiers(true) + .prorate(true) .build() ) assertThat(newSubscriptionTieredWithMinimumPrice.billableMetricId()) @@ -85,7 +117,7 @@ internal class NewSubscriptionTieredWithMinimumPriceTest { assertThat(newSubscriptionTieredWithMinimumPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionTieredWithMinimumPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionTieredWithMinimumPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -134,7 +166,24 @@ internal class NewSubscriptionTieredWithMinimumPriceTest { .name("Annual fee") .tieredWithMinimumConfig( NewSubscriptionTieredWithMinimumPrice.TieredWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addTier( + NewSubscriptionTieredWithMinimumPrice.TieredWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + NewSubscriptionTieredWithMinimumPrice.TieredWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .hideZeroAmountTiers(true) + .prorate(true) .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionUnitPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionUnitPriceTest.kt index c45afd67c..7a25fc48f 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionUnitPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionUnitPriceTest.kt @@ -18,7 +18,7 @@ internal class NewSubscriptionUnitPriceTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig(UnitConfig.builder().unitAmount("unit_amount").prorated(true).build()) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -63,7 +63,7 @@ internal class NewSubscriptionUnitPriceTest { .isEqualTo(NewSubscriptionUnitPrice.ModelType.UNIT) assertThat(newSubscriptionUnitPrice.name()).isEqualTo("Annual fee") assertThat(newSubscriptionUnitPrice.unitConfig()) - .isEqualTo(UnitConfig.builder().unitAmount("unit_amount").build()) + .isEqualTo(UnitConfig.builder().unitAmount("unit_amount").prorated(true).build()) assertThat(newSubscriptionUnitPrice.billableMetricId()).isEqualTo("billable_metric_id") assertThat(newSubscriptionUnitPrice.billedInAdvance()).isEqualTo(true) assertThat(newSubscriptionUnitPrice.billingCycleConfiguration()) @@ -76,7 +76,7 @@ internal class NewSubscriptionUnitPriceTest { assertThat(newSubscriptionUnitPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionUnitPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionUnitPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -122,7 +122,7 @@ internal class NewSubscriptionUnitPriceTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig(UnitConfig.builder().unitAmount("unit_amount").prorated(true).build()) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionUnitWithPercentPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionUnitWithPercentPriceTest.kt index 93df74627..7b99e00b2 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionUnitWithPercentPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionUnitWithPercentPriceTest.kt @@ -20,7 +20,8 @@ internal class NewSubscriptionUnitWithPercentPriceTest { .name("Annual fee") .unitWithPercentConfig( NewSubscriptionUnitWithPercentPrice.UnitWithPercentConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .percent("percent") + .unitAmount("unit_amount") .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +70,8 @@ internal class NewSubscriptionUnitWithPercentPriceTest { assertThat(newSubscriptionUnitWithPercentPrice.unitWithPercentConfig()) .isEqualTo( NewSubscriptionUnitWithPercentPrice.UnitWithPercentConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .percent("percent") + .unitAmount("unit_amount") .build() ) assertThat(newSubscriptionUnitWithPercentPrice.billableMetricId()) @@ -85,7 +87,7 @@ internal class NewSubscriptionUnitWithPercentPriceTest { assertThat(newSubscriptionUnitWithPercentPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionUnitWithPercentPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionUnitWithPercentPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -134,7 +136,8 @@ internal class NewSubscriptionUnitWithPercentPriceTest { .name("Annual fee") .unitWithPercentConfig( NewSubscriptionUnitWithPercentPrice.UnitWithPercentConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .percent("percent") + .unitAmount("unit_amount") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionUnitWithProrationPriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionUnitWithProrationPriceTest.kt index b33dafb45..9922c5992 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionUnitWithProrationPriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewSubscriptionUnitWithProrationPriceTest.kt @@ -20,7 +20,7 @@ internal class NewSubscriptionUnitWithProrationPriceTest { .name("Annual fee") .unitWithProrationConfig( NewSubscriptionUnitWithProrationPrice.UnitWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .unitAmount("unit_amount") .build() ) .billableMetricId("billable_metric_id") @@ -69,7 +69,7 @@ internal class NewSubscriptionUnitWithProrationPriceTest { assertThat(newSubscriptionUnitWithProrationPrice.unitWithProrationConfig()) .isEqualTo( NewSubscriptionUnitWithProrationPrice.UnitWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .unitAmount("unit_amount") .build() ) assertThat(newSubscriptionUnitWithProrationPrice.billableMetricId()) @@ -85,7 +85,7 @@ internal class NewSubscriptionUnitWithProrationPriceTest { assertThat(newSubscriptionUnitWithProrationPrice.conversionRate()).isEqualTo(0.0) assertThat(newSubscriptionUnitWithProrationPrice.conversionRateConfig()) .isEqualTo( - NewSubscriptionUnitWithProrationPrice.ConversionRateConfig.ofUnit( + ConversionRateConfig.ofUnit( UnitConversionRateConfig.builder() .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) .unitConfig( @@ -134,7 +134,7 @@ internal class NewSubscriptionUnitWithProrationPriceTest { .name("Annual fee") .unitWithProrationConfig( NewSubscriptionUnitWithProrationPrice.UnitWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .unitAmount("unit_amount") .build() ) .billableMetricId("billable_metric_id") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewTaxJarConfigurationTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewTaxJarConfigurationTest.kt index fb36e0bf7..e3014ff4c 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewTaxJarConfigurationTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewTaxJarConfigurationTest.kt @@ -15,11 +15,13 @@ internal class NewTaxJarConfigurationTest { NewTaxJarConfiguration.builder() .taxExempt(true) .taxProvider(NewTaxJarConfiguration.TaxProvider.TAXJAR) + .automaticTaxEnabled(true) .build() assertThat(newTaxJarConfiguration.taxExempt()).isEqualTo(true) assertThat(newTaxJarConfiguration.taxProvider()) .isEqualTo(NewTaxJarConfiguration.TaxProvider.TAXJAR) + assertThat(newTaxJarConfiguration.automaticTaxEnabled()).isEqualTo(true) } @Test @@ -29,6 +31,7 @@ internal class NewTaxJarConfigurationTest { NewTaxJarConfiguration.builder() .taxExempt(true) .taxProvider(NewTaxJarConfiguration.TaxProvider.TAXJAR) + .automaticTaxEnabled(true) .build() val roundtrippedNewTaxJarConfiguration = diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewUsageDiscountTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewUsageDiscountTest.kt index 9e3756157..1d60c49a2 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewUsageDiscountTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/NewUsageDiscountTest.kt @@ -22,9 +22,9 @@ internal class NewUsageDiscountTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewUsageDiscount.Filter.builder() + .field(NewUsageDiscount.Filter.Field.PRICE_ID) + .operator(NewUsageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -41,9 +41,9 @@ internal class NewUsageDiscountTest { assertThat(newUsageDiscount.currency()).isEqualTo("currency") assertThat(newUsageDiscount.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewUsageDiscount.Filter.builder() + .field(NewUsageDiscount.Filter.Field.PRICE_ID) + .operator(NewUsageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -65,9 +65,9 @@ internal class NewUsageDiscountTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewUsageDiscount.Filter.builder() + .field(NewUsageDiscount.Filter.Field.PRICE_ID) + .operator(NewUsageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PackageConfigTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PackageConfigTest.kt index 9a21cd29a..e615c4bdc 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PackageConfigTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PackageConfigTest.kt @@ -12,17 +12,17 @@ internal class PackageConfigTest { @Test fun create() { val packageConfig = - PackageConfig.builder().packageAmount("package_amount").packageSize(0L).build() + PackageConfig.builder().packageAmount("package_amount").packageSize(1L).build() assertThat(packageConfig.packageAmount()).isEqualTo("package_amount") - assertThat(packageConfig.packageSize()).isEqualTo(0L) + assertThat(packageConfig.packageSize()).isEqualTo(1L) } @Test fun roundtrip() { val jsonMapper = jsonMapper() val packageConfig = - PackageConfig.builder().packageAmount("package_amount").packageSize(0L).build() + PackageConfig.builder().packageAmount("package_amount").packageSize(1L).build() val roundtrippedPackageConfig = jsonMapper.readValue( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PerPriceCostTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PerPriceCostTest.kt index 130363b39..43dbfd2a7 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PerPriceCostTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PerPriceCostTest.kt @@ -16,7 +16,7 @@ internal class PerPriceCostTest { val perPriceCost = PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -25,7 +25,15 @@ internal class PerPriceCostTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -41,6 +49,13 @@ internal class PerPriceCostTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -51,9 +66,9 @@ internal class PerPriceCostTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -73,9 +88,9 @@ internal class PerPriceCostTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -84,7 +99,7 @@ internal class PerPriceCostTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -92,9 +107,9 @@ internal class PerPriceCostTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -104,9 +119,11 @@ internal class PerPriceCostTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -124,7 +141,7 @@ internal class PerPriceCostTest { assertThat(perPriceCost.price()) .isEqualTo( Price.ofUnit( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -133,7 +150,15 @@ internal class PerPriceCostTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -149,6 +174,13 @@ internal class PerPriceCostTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -159,9 +191,9 @@ internal class PerPriceCostTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -181,9 +213,9 @@ internal class PerPriceCostTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -192,7 +224,7 @@ internal class PerPriceCostTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -200,9 +232,9 @@ internal class PerPriceCostTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -212,9 +244,11 @@ internal class PerPriceCostTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -236,7 +270,7 @@ internal class PerPriceCostTest { val perPriceCost = PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -245,7 +279,15 @@ internal class PerPriceCostTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -261,6 +303,13 @@ internal class PerPriceCostTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -271,9 +320,9 @@ internal class PerPriceCostTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -293,9 +342,9 @@ internal class PerPriceCostTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -304,7 +353,7 @@ internal class PerPriceCostTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -312,9 +361,9 @@ internal class PerPriceCostTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -324,9 +373,11 @@ internal class PerPriceCostTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PercentageDiscountIntervalTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PercentageDiscountIntervalTest.kt index 68e6bacc1..35dc5a244 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PercentageDiscountIntervalTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PercentageDiscountIntervalTest.kt @@ -18,9 +18,9 @@ internal class PercentageDiscountIntervalTest { .discountType(PercentageDiscountInterval.DiscountType.PERCENTAGE) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscountInterval.Filter.builder() + .field(PercentageDiscountInterval.Filter.Field.PRICE_ID) + .operator(PercentageDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -35,9 +35,9 @@ internal class PercentageDiscountIntervalTest { .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(percentageDiscountInterval.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscountInterval.Filter.builder() + .field(PercentageDiscountInterval.Filter.Field.PRICE_ID) + .operator(PercentageDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -55,9 +55,9 @@ internal class PercentageDiscountIntervalTest { .discountType(PercentageDiscountInterval.DiscountType.PERCENTAGE) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscountInterval.Filter.builder() + .field(PercentageDiscountInterval.Filter.Field.PRICE_ID) + .operator(PercentageDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PercentageDiscountTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PercentageDiscountTest.kt index bbd801afd..eb2a72463 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PercentageDiscountTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PercentageDiscountTest.kt @@ -18,9 +18,9 @@ internal class PercentageDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -34,9 +34,9 @@ internal class PercentageDiscountTest { .containsExactly("h74gfhdjvn7ujokd", "7hfgtgjnbvc3ujkl") assertThat(percentageDiscount.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -53,9 +53,9 @@ internal class PercentageDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanCreateParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanCreateParamsTest.kt index a10615880..236bd88d4 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanCreateParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanCreateParamsTest.kt @@ -27,6 +27,15 @@ internal class PlanCreateParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -36,7 +45,12 @@ internal class PlanCreateParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -93,9 +107,9 @@ internal class PlanCreateParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -146,6 +160,15 @@ internal class PlanCreateParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -155,7 +178,12 @@ internal class PlanCreateParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -214,9 +242,9 @@ internal class PlanCreateParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -265,6 +293,15 @@ internal class PlanCreateParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -274,7 +311,12 @@ internal class PlanCreateParamsTest { .itemId("item_id") .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -332,9 +374,9 @@ internal class PlanCreateParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanListPageResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanListPageResponseTest.kt index c54feb689..f88092a24 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanListPageResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanListPageResponseTest.kt @@ -26,9 +26,14 @@ internal class PlanListPageResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -58,9 +63,9 @@ internal class PlanListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -73,9 +78,9 @@ internal class PlanListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -92,9 +97,9 @@ internal class PlanListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -115,9 +120,11 @@ internal class PlanListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -130,9 +137,9 @@ internal class PlanListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -144,9 +151,9 @@ internal class PlanListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -159,7 +166,7 @@ internal class PlanListPageResponseTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -168,7 +175,17 @@ internal class PlanListPageResponseTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -186,6 +203,13 @@ internal class PlanListPageResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -196,9 +220,11 @@ internal class PlanListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -218,9 +244,9 @@ internal class PlanListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -229,7 +255,7 @@ internal class PlanListPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -237,9 +263,9 @@ internal class PlanListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -249,9 +275,14 @@ internal class PlanListPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -294,9 +325,11 @@ internal class PlanListPageResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -326,9 +359,9 @@ internal class PlanListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -341,9 +374,9 @@ internal class PlanListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -360,9 +393,9 @@ internal class PlanListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -383,9 +416,9 @@ internal class PlanListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -398,9 +431,9 @@ internal class PlanListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -412,9 +445,9 @@ internal class PlanListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -427,7 +460,7 @@ internal class PlanListPageResponseTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -436,7 +469,17 @@ internal class PlanListPageResponseTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -452,6 +495,13 @@ internal class PlanListPageResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -462,9 +512,9 @@ internal class PlanListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -484,9 +534,9 @@ internal class PlanListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -495,7 +545,7 @@ internal class PlanListPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -503,9 +553,9 @@ internal class PlanListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -515,9 +565,14 @@ internal class PlanListPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -563,9 +618,14 @@ internal class PlanListPageResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -595,9 +655,9 @@ internal class PlanListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -610,9 +670,9 @@ internal class PlanListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -629,9 +689,9 @@ internal class PlanListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -652,9 +712,11 @@ internal class PlanListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -667,9 +729,9 @@ internal class PlanListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -681,9 +743,9 @@ internal class PlanListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -696,7 +758,7 @@ internal class PlanListPageResponseTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -705,7 +767,17 @@ internal class PlanListPageResponseTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -723,6 +795,13 @@ internal class PlanListPageResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -733,9 +812,11 @@ internal class PlanListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -755,9 +836,9 @@ internal class PlanListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -766,7 +847,7 @@ internal class PlanListPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -774,9 +855,9 @@ internal class PlanListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -786,9 +867,14 @@ internal class PlanListPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseAmountDiscountAdjustmentTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseAmountDiscountAdjustmentTest.kt index c517b6dc4..08189a45e 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseAmountDiscountAdjustmentTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseAmountDiscountAdjustmentTest.kt @@ -18,9 +18,9 @@ internal class PlanPhaseAmountDiscountAdjustmentTest { .amountDiscount("amount_discount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseAmountDiscountAdjustment.Filter.builder() + .field(PlanPhaseAmountDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseAmountDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -37,9 +37,9 @@ internal class PlanPhaseAmountDiscountAdjustmentTest { assertThat(planPhaseAmountDiscountAdjustment.appliesToPriceIds()).containsExactly("string") assertThat(planPhaseAmountDiscountAdjustment.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseAmountDiscountAdjustment.Filter.builder() + .field(PlanPhaseAmountDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseAmountDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -60,9 +60,9 @@ internal class PlanPhaseAmountDiscountAdjustmentTest { .amountDiscount("amount_discount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseAmountDiscountAdjustment.Filter.builder() + .field(PlanPhaseAmountDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseAmountDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseMaximumAdjustmentTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseMaximumAdjustmentTest.kt index 207be4844..4208f22f1 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseMaximumAdjustmentTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseMaximumAdjustmentTest.kt @@ -17,9 +17,9 @@ internal class PlanPhaseMaximumAdjustmentTest { .adjustmentType(PlanPhaseMaximumAdjustment.AdjustmentType.MAXIMUM) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseMaximumAdjustment.Filter.builder() + .field(PlanPhaseMaximumAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseMaximumAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -36,9 +36,9 @@ internal class PlanPhaseMaximumAdjustmentTest { assertThat(planPhaseMaximumAdjustment.appliesToPriceIds()).containsExactly("string") assertThat(planPhaseMaximumAdjustment.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseMaximumAdjustment.Filter.builder() + .field(PlanPhaseMaximumAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseMaximumAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -59,9 +59,9 @@ internal class PlanPhaseMaximumAdjustmentTest { .adjustmentType(PlanPhaseMaximumAdjustment.AdjustmentType.MAXIMUM) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseMaximumAdjustment.Filter.builder() + .field(PlanPhaseMaximumAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseMaximumAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseMinimumAdjustmentTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseMinimumAdjustmentTest.kt index 7e8b11db1..b6e6f1e84 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseMinimumAdjustmentTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseMinimumAdjustmentTest.kt @@ -17,9 +17,9 @@ internal class PlanPhaseMinimumAdjustmentTest { .adjustmentType(PlanPhaseMinimumAdjustment.AdjustmentType.MINIMUM) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseMinimumAdjustment.Filter.builder() + .field(PlanPhaseMinimumAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseMinimumAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -37,9 +37,9 @@ internal class PlanPhaseMinimumAdjustmentTest { assertThat(planPhaseMinimumAdjustment.appliesToPriceIds()).containsExactly("string") assertThat(planPhaseMinimumAdjustment.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseMinimumAdjustment.Filter.builder() + .field(PlanPhaseMinimumAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseMinimumAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -61,9 +61,9 @@ internal class PlanPhaseMinimumAdjustmentTest { .adjustmentType(PlanPhaseMinimumAdjustment.AdjustmentType.MINIMUM) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseMinimumAdjustment.Filter.builder() + .field(PlanPhaseMinimumAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseMinimumAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhasePercentageDiscountAdjustmentTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhasePercentageDiscountAdjustmentTest.kt index c8700e346..6d2e00adc 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhasePercentageDiscountAdjustmentTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhasePercentageDiscountAdjustmentTest.kt @@ -19,9 +19,9 @@ internal class PlanPhasePercentageDiscountAdjustmentTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhasePercentageDiscountAdjustment.Filter.builder() + .field(PlanPhasePercentageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhasePercentageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -39,9 +39,9 @@ internal class PlanPhasePercentageDiscountAdjustmentTest { .containsExactly("string") assertThat(planPhasePercentageDiscountAdjustment.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhasePercentageDiscountAdjustment.Filter.builder() + .field(PlanPhasePercentageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhasePercentageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -64,9 +64,9 @@ internal class PlanPhasePercentageDiscountAdjustmentTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhasePercentageDiscountAdjustment.Filter.builder() + .field(PlanPhasePercentageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhasePercentageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseUsageDiscountAdjustmentTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseUsageDiscountAdjustmentTest.kt index 45fa2142c..b317ab87d 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseUsageDiscountAdjustmentTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanPhaseUsageDiscountAdjustmentTest.kt @@ -17,9 +17,9 @@ internal class PlanPhaseUsageDiscountAdjustmentTest { .adjustmentType(PlanPhaseUsageDiscountAdjustment.AdjustmentType.USAGE_DISCOUNT) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -36,9 +36,9 @@ internal class PlanPhaseUsageDiscountAdjustmentTest { assertThat(planPhaseUsageDiscountAdjustment.appliesToPriceIds()).containsExactly("string") assertThat(planPhaseUsageDiscountAdjustment.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -59,9 +59,9 @@ internal class PlanPhaseUsageDiscountAdjustmentTest { .adjustmentType(PlanPhaseUsageDiscountAdjustment.AdjustmentType.USAGE_DISCOUNT) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanTest.kt index 58c70483a..b62525d63 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanTest.kt @@ -24,9 +24,9 @@ internal class PlanTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -56,9 +56,9 @@ internal class PlanTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -71,9 +71,9 @@ internal class PlanTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -90,9 +90,9 @@ internal class PlanTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -113,9 +113,9 @@ internal class PlanTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -128,9 +128,9 @@ internal class PlanTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -142,9 +142,9 @@ internal class PlanTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -157,7 +157,7 @@ internal class PlanTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -166,7 +166,15 @@ internal class PlanTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -182,6 +190,13 @@ internal class PlanTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -192,9 +207,9 @@ internal class PlanTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -214,9 +229,9 @@ internal class PlanTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -225,7 +240,7 @@ internal class PlanTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -233,9 +248,9 @@ internal class PlanTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -245,9 +260,11 @@ internal class PlanTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -284,9 +301,9 @@ internal class PlanTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -320,9 +337,9 @@ internal class PlanTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -337,9 +354,9 @@ internal class PlanTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -358,9 +375,9 @@ internal class PlanTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -382,9 +399,9 @@ internal class PlanTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -397,9 +414,9 @@ internal class PlanTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -411,9 +428,9 @@ internal class PlanTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -428,7 +445,7 @@ internal class PlanTest { assertThat(plan.prices()) .containsExactly( Price.ofUnit( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -437,7 +454,15 @@ internal class PlanTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -453,6 +478,13 @@ internal class PlanTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -463,9 +495,9 @@ internal class PlanTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -485,9 +517,9 @@ internal class PlanTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -496,7 +528,7 @@ internal class PlanTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -504,9 +536,9 @@ internal class PlanTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -516,9 +548,11 @@ internal class PlanTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -561,9 +595,9 @@ internal class PlanTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -593,9 +627,9 @@ internal class PlanTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -608,9 +642,9 @@ internal class PlanTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -627,9 +661,9 @@ internal class PlanTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -650,9 +684,9 @@ internal class PlanTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -665,9 +699,9 @@ internal class PlanTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -679,9 +713,9 @@ internal class PlanTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -694,7 +728,7 @@ internal class PlanTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -703,7 +737,15 @@ internal class PlanTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -719,6 +761,13 @@ internal class PlanTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -729,9 +778,9 @@ internal class PlanTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -751,9 +800,9 @@ internal class PlanTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -762,7 +811,7 @@ internal class PlanTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -770,9 +819,9 @@ internal class PlanTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -782,9 +831,11 @@ internal class PlanTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanVersionTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanVersionTest.kt index 8aefdd658..9598f0122 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanVersionTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PlanVersionTest.kt @@ -23,9 +23,9 @@ internal class PlanVersionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -48,7 +48,7 @@ internal class PlanVersionTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -57,7 +57,15 @@ internal class PlanVersionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -73,6 +81,13 @@ internal class PlanVersionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -83,9 +98,9 @@ internal class PlanVersionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -105,9 +120,9 @@ internal class PlanVersionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -116,7 +131,7 @@ internal class PlanVersionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -124,9 +139,9 @@ internal class PlanVersionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -136,9 +151,11 @@ internal class PlanVersionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -160,9 +177,9 @@ internal class PlanVersionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -190,7 +207,7 @@ internal class PlanVersionTest { assertThat(planVersion.prices()) .containsExactly( Price.ofUnit( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -199,7 +216,15 @@ internal class PlanVersionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -215,6 +240,13 @@ internal class PlanVersionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -225,9 +257,9 @@ internal class PlanVersionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -247,9 +279,9 @@ internal class PlanVersionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -258,7 +290,7 @@ internal class PlanVersionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -266,9 +298,9 @@ internal class PlanVersionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -278,9 +310,11 @@ internal class PlanVersionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -306,9 +340,9 @@ internal class PlanVersionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator(PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -331,7 +365,7 @@ internal class PlanVersionTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -340,7 +374,15 @@ internal class PlanVersionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -356,6 +398,13 @@ internal class PlanVersionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -366,9 +415,9 @@ internal class PlanVersionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -388,9 +437,9 @@ internal class PlanVersionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -399,7 +448,7 @@ internal class PlanVersionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -407,9 +456,9 @@ internal class PlanVersionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -419,9 +468,11 @@ internal class PlanVersionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceCreateParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceCreateParamsTest.kt index 8b457c08d..4f4e9b97c 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceCreateParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceCreateParamsTest.kt @@ -18,7 +18,9 @@ internal class PriceCreateParamsTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -68,7 +70,9 @@ internal class PriceCreateParamsTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -119,7 +123,9 @@ internal class PriceCreateParamsTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceEvaluateMultipleParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceEvaluateMultipleParamsTest.kt index 0b559e17e..34d0427ab 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceEvaluateMultipleParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceEvaluateMultipleParamsTest.kt @@ -28,7 +28,12 @@ internal class PriceEvaluateMultipleParamsTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -92,7 +97,12 @@ internal class PriceEvaluateMultipleParamsTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -157,7 +167,12 @@ internal class PriceEvaluateMultipleParamsTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceEvaluatePreviewEventsParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceEvaluatePreviewEventsParamsTest.kt index 0dff1be2a..dd34c6175 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceEvaluatePreviewEventsParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceEvaluatePreviewEventsParamsTest.kt @@ -41,7 +41,12 @@ internal class PriceEvaluatePreviewEventsParamsTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -118,7 +123,12 @@ internal class PriceEvaluatePreviewEventsParamsTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -197,7 +207,12 @@ internal class PriceEvaluatePreviewEventsParamsTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceIntervalTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceIntervalTest.kt index ca898ff5c..9beca844c 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceIntervalTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceIntervalTest.kt @@ -17,6 +17,7 @@ internal class PriceIntervalTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .currentBillingPeriodStartDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) @@ -29,7 +30,7 @@ internal class PriceIntervalTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -38,7 +39,15 @@ internal class PriceIntervalTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -54,6 +63,13 @@ internal class PriceIntervalTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -64,9 +80,9 @@ internal class PriceIntervalTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -86,9 +102,9 @@ internal class PriceIntervalTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -97,7 +113,7 @@ internal class PriceIntervalTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -105,9 +121,9 @@ internal class PriceIntervalTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -117,9 +133,11 @@ internal class PriceIntervalTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -134,6 +152,7 @@ internal class PriceIntervalTest { assertThat(priceInterval.id()).isEqualTo("id") assertThat(priceInterval.billingCycleDay()).isEqualTo(0L) + assertThat(priceInterval.canDeferBilling()).isEqualTo(true) assertThat(priceInterval.currentBillingPeriodEndDate()) .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(priceInterval.currentBillingPeriodStartDate()) @@ -152,7 +171,7 @@ internal class PriceIntervalTest { assertThat(priceInterval.price()) .isEqualTo( Price.ofUnit( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -161,7 +180,15 @@ internal class PriceIntervalTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -177,6 +204,13 @@ internal class PriceIntervalTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -187,9 +221,9 @@ internal class PriceIntervalTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -209,9 +243,9 @@ internal class PriceIntervalTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -220,7 +254,7 @@ internal class PriceIntervalTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -228,9 +262,9 @@ internal class PriceIntervalTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -240,9 +274,11 @@ internal class PriceIntervalTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -264,6 +300,7 @@ internal class PriceIntervalTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .currentBillingPeriodStartDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) @@ -276,7 +313,7 @@ internal class PriceIntervalTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -285,7 +322,15 @@ internal class PriceIntervalTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -301,6 +346,13 @@ internal class PriceIntervalTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -311,9 +363,9 @@ internal class PriceIntervalTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -333,9 +385,9 @@ internal class PriceIntervalTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -344,7 +396,7 @@ internal class PriceIntervalTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -352,9 +404,9 @@ internal class PriceIntervalTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -364,9 +416,11 @@ internal class PriceIntervalTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceListPageResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceListPageResponseTest.kt index fcecceb07..adcd2fae7 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceListPageResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceListPageResponseTest.kt @@ -16,7 +16,7 @@ internal class PriceListPageResponseTest { val priceListPageResponse = PriceListPageResponse.builder() .addData( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -25,7 +25,15 @@ internal class PriceListPageResponseTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -41,6 +49,13 @@ internal class PriceListPageResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -51,9 +66,9 @@ internal class PriceListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -73,9 +88,9 @@ internal class PriceListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -84,7 +99,7 @@ internal class PriceListPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -92,9 +107,9 @@ internal class PriceListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -104,9 +119,11 @@ internal class PriceListPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -123,7 +140,7 @@ internal class PriceListPageResponseTest { assertThat(priceListPageResponse.data()) .containsExactly( Price.ofUnit( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -132,7 +149,15 @@ internal class PriceListPageResponseTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -148,6 +173,13 @@ internal class PriceListPageResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -158,9 +190,9 @@ internal class PriceListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -180,9 +212,9 @@ internal class PriceListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -191,7 +223,7 @@ internal class PriceListPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -199,9 +231,9 @@ internal class PriceListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -211,9 +243,11 @@ internal class PriceListPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -233,7 +267,7 @@ internal class PriceListPageResponseTest { val priceListPageResponse = PriceListPageResponse.builder() .addData( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -242,7 +276,15 @@ internal class PriceListPageResponseTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -258,6 +300,13 @@ internal class PriceListPageResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -268,9 +317,9 @@ internal class PriceListPageResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -290,9 +339,9 @@ internal class PriceListPageResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -301,7 +350,7 @@ internal class PriceListPageResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -309,9 +358,9 @@ internal class PriceListPageResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -321,9 +370,11 @@ internal class PriceListPageResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceTest.kt index 9ff32f91b..97ef7c46c 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/PriceTest.kt @@ -18,7 +18,7 @@ internal class PriceTest { @Test fun ofUnit() { val unit = - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -27,7 +27,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -43,6 +51,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -53,9 +68,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -75,9 +90,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -86,7 +101,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -94,9 +109,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -106,9 +121,9 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig(UnitConfig.builder().unitAmount("unit_amount").prorated(true).build()) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -120,17 +135,15 @@ internal class PriceTest { val price = Price.ofUnit(unit) assertThat(price.unit()).isEqualTo(unit) - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -138,16 +151,20 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test @@ -155,7 +172,7 @@ internal class PriceTest { val jsonMapper = jsonMapper() val price = Price.ofUnit( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -164,7 +181,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -180,6 +205,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -190,9 +222,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -212,9 +244,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -223,7 +255,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -231,9 +263,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -243,9 +275,11 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -262,9 +296,9 @@ internal class PriceTest { } @Test - fun ofPackage() { - val package_ = - Price.Package.builder() + fun ofTiered() { + val tiered = + Price.Tiered.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -273,7 +307,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Package.Cadence.ONE_TIME) + .billingMode(Price.Tiered.BillingMode.IN_ADVANCE) + .cadence(Price.Tiered.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.Tiered.CompositePriceFilter.builder() + .field(Price.Tiered.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.Tiered.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -289,6 +331,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -299,9 +348,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -321,9 +370,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -332,7 +381,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Package.Metadata.builder() + Price.Tiered.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -340,9 +389,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -351,12 +400,21 @@ internal class PriceTest { ) .minimumAmount("minimum_amount") .name("name") - .packageConfig( - PackageConfig.builder().packageAmount("package_amount").packageSize(0L).build() - ) .planPhaseOrder(0L) - .priceType(Price.Package.PriceType.USAGE_PRICE) + .priceType(Price.Tiered.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") + .tieredConfig( + TieredConfig.builder() + .addTier( + Tier.builder() + .firstUnit(0.0) + .unitAmount("unit_amount") + .lastUnit(0.0) + .build() + ) + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -365,20 +423,18 @@ internal class PriceTest { ) .build() - val price = Price.ofPackage(package_) + val price = Price.ofTiered(tiered) assertThat(price.unit()).isNull() - assertThat(price.package_()).isEqualTo(package_) - assertThat(price.matrix()).isNull() - assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() + assertThat(price.tiered()).isEqualTo(tiered) assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -386,24 +442,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofPackageRoundtrip() { + fun ofTieredRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofPackage( - Price.Package.builder() + Price.ofTiered( + Price.Tiered.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -412,7 +472,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Package.Cadence.ONE_TIME) + .billingMode(Price.Tiered.BillingMode.IN_ADVANCE) + .cadence(Price.Tiered.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.Tiered.CompositePriceFilter.builder() + .field(Price.Tiered.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.Tiered.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -428,6 +496,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -438,9 +513,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -460,9 +535,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -471,7 +546,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Package.Metadata.builder() + Price.Tiered.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -479,9 +554,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -490,15 +565,21 @@ internal class PriceTest { ) .minimumAmount("minimum_amount") .name("name") - .packageConfig( - PackageConfig.builder() - .packageAmount("package_amount") - .packageSize(0L) - .build() - ) .planPhaseOrder(0L) - .priceType(Price.Package.PriceType.USAGE_PRICE) + .priceType(Price.Tiered.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") + .tieredConfig( + TieredConfig.builder() + .addTier( + Tier.builder() + .firstUnit(0.0) + .unitAmount("unit_amount") + .lastUnit(0.0) + .build() + ) + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -515,9 +596,9 @@ internal class PriceTest { } @Test - fun ofMatrix() { - val matrix = - Price.Matrix.builder() + fun ofBulk() { + val bulk = + Price.Bulk.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -526,7 +607,22 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Matrix.Cadence.ONE_TIME) + .billingMode(Price.Bulk.BillingMode.IN_ADVANCE) + .bulkConfig( + BulkConfig.builder() + .addTier( + BulkTier.builder().unitAmount("unit_amount").maximumUnits(0.0).build() + ) + .build() + ) + .cadence(Price.Bulk.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.Bulk.CompositePriceFilter.builder() + .field(Price.Bulk.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.Bulk.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -542,6 +638,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -552,9 +655,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -570,25 +673,13 @@ internal class PriceTest { .build() ) .item(ItemSlim.builder().id("id").name("name").build()) - .matrixConfig( - MatrixConfig.builder() - .defaultUnitAmount("default_unit_amount") - .addDimension("string") - .addMatrixValue( - MatrixValue.builder() - .addDimensionValue("string") - .unitAmount("unit_amount") - .build() - ) - .build() - ) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -597,7 +688,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Matrix.Metadata.builder() + Price.Bulk.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -605,9 +696,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -617,7 +708,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Matrix.PriceType.USAGE_PRICE) + .priceType(Price.Bulk.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -627,20 +718,18 @@ internal class PriceTest { ) .build() - val price = Price.ofMatrix(matrix) + val price = Price.ofBulk(bulk) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isEqualTo(matrix) assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() - assertThat(price.bulk()).isNull() + assertThat(price.bulk()).isEqualTo(bulk) + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -648,24 +737,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofMatrixRoundtrip() { + fun ofBulkRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofMatrix( - Price.Matrix.builder() + Price.ofBulk( + Price.Bulk.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -674,7 +767,25 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Matrix.Cadence.ONE_TIME) + .billingMode(Price.Bulk.BillingMode.IN_ADVANCE) + .bulkConfig( + BulkConfig.builder() + .addTier( + BulkTier.builder() + .unitAmount("unit_amount") + .maximumUnits(0.0) + .build() + ) + .build() + ) + .cadence(Price.Bulk.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.Bulk.CompositePriceFilter.builder() + .field(Price.Bulk.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.Bulk.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -690,6 +801,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -700,9 +818,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -718,25 +836,13 @@ internal class PriceTest { .build() ) .item(ItemSlim.builder().id("id").name("name").build()) - .matrixConfig( - MatrixConfig.builder() - .defaultUnitAmount("default_unit_amount") - .addDimension("string") - .addMatrixValue( - MatrixValue.builder() - .addDimensionValue("string") - .unitAmount("unit_amount") - .build() - ) - .build() - ) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -745,7 +851,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Matrix.Metadata.builder() + Price.Bulk.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -753,9 +859,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -765,7 +871,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Matrix.PriceType.USAGE_PRICE) + .priceType(Price.Bulk.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -783,9 +889,9 @@ internal class PriceTest { } @Test - fun ofTiered() { - val tiered = - Price.Tiered.builder() + fun ofBulkWithFilters() { + val bulkWithFilters = + Price.BulkWithFilters.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -794,7 +900,37 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Tiered.Cadence.ONE_TIME) + .billingMode(Price.BulkWithFilters.BillingMode.IN_ADVANCE) + .bulkWithFiltersConfig( + Price.BulkWithFilters.BulkWithFiltersConfig.builder() + .addFilter( + Price.BulkWithFilters.BulkWithFiltersConfig.Filter.builder() + .propertyKey("x") + .propertyValue("x") + .build() + ) + .addTier( + Price.BulkWithFilters.BulkWithFiltersConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + Price.BulkWithFilters.BulkWithFiltersConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .build() + ) + .cadence(Price.BulkWithFilters.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.BulkWithFilters.CompositePriceFilter.builder() + .field(Price.BulkWithFilters.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.BulkWithFilters.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -810,6 +946,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -820,9 +963,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -842,9 +985,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -853,7 +996,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Tiered.Metadata.builder() + Price.BulkWithFilters.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -861,9 +1004,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -873,19 +1016,8 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Tiered.PriceType.USAGE_PRICE) + .priceType(Price.BulkWithFilters.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .tieredConfig( - TieredConfig.builder() - .addTier( - Tier.builder() - .firstUnit(0.0) - .unitAmount("unit_amount") - .lastUnit(0.0) - .build() - ) - .build() - ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -894,20 +1026,18 @@ internal class PriceTest { ) .build() - val price = Price.ofTiered(tiered) + val price = Price.ofBulkWithFilters(bulkWithFilters) assertThat(price.unit()).isNull() + assertThat(price.tiered()).isNull() + assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isEqualTo(bulkWithFilters) assertThat(price.package_()).isNull() assertThat(price.matrix()).isNull() - assertThat(price.tiered()).isEqualTo(tiered) - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() - assertThat(price.bulk()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -915,24 +1045,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofTieredRoundtrip() { + fun ofBulkWithFiltersRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofTiered( - Price.Tiered.builder() + Price.ofBulkWithFilters( + Price.BulkWithFilters.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -941,22 +1075,59 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Tiered.Cadence.ONE_TIME) - .conversionRate(0.0) - .unitConversionRateConfig( - ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() - ) - .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) - .creditAllocation( - Allocation.builder() - .allowsRollover(true) - .currency("currency") - .customExpiration( - CustomExpiration.builder() - .duration(0L) + .billingMode(Price.BulkWithFilters.BillingMode.IN_ADVANCE) + .bulkWithFiltersConfig( + Price.BulkWithFilters.BulkWithFiltersConfig.builder() + .addFilter( + Price.BulkWithFilters.BulkWithFiltersConfig.Filter.builder() + .propertyKey("x") + .propertyValue("x") + .build() + ) + .addTier( + Price.BulkWithFilters.BulkWithFiltersConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + Price.BulkWithFilters.BulkWithFiltersConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .build() + ) + .cadence(Price.BulkWithFilters.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.BulkWithFilters.CompositePriceFilter.builder() + .field(Price.BulkWithFilters.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.BulkWithFilters.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .conversionRate(0.0) + .unitConversionRateConfig( + ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() + ) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Allocation.builder() + .allowsRollover(true) + .currency("currency") + .customExpiration( + CustomExpiration.builder() + .duration(0L) .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -967,9 +1138,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -989,9 +1160,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1000,7 +1171,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Tiered.Metadata.builder() + Price.BulkWithFilters.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1008,9 +1179,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1020,19 +1191,8 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Tiered.PriceType.USAGE_PRICE) + .priceType(Price.BulkWithFilters.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .tieredConfig( - TieredConfig.builder() - .addTier( - Tier.builder() - .firstUnit(0.0) - .unitAmount("unit_amount") - .lastUnit(0.0) - .build() - ) - .build() - ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -1049,9 +1209,9 @@ internal class PriceTest { } @Test - fun ofTieredBps() { - val tieredBps = - Price.TieredBps.builder() + fun ofPackage() { + val package_ = + Price.Package.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1060,7 +1220,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.TieredBps.Cadence.ONE_TIME) + .billingMode(Price.Package.BillingMode.IN_ADVANCE) + .cadence(Price.Package.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.Package.CompositePriceFilter.builder() + .field(Price.Package.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.Package.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -1076,6 +1244,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1086,9 +1261,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1108,9 +1283,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1119,7 +1294,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.TieredBps.Metadata.builder() + Price.Package.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1127,9 +1302,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1138,21 +1313,12 @@ internal class PriceTest { ) .minimumAmount("minimum_amount") .name("name") + .packageConfig( + PackageConfig.builder().packageAmount("package_amount").packageSize(1L).build() + ) .planPhaseOrder(0L) - .priceType(Price.TieredBps.PriceType.USAGE_PRICE) + .priceType(Price.Package.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .tieredBpsConfig( - TieredBpsConfig.builder() - .addTier( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -1161,20 +1327,18 @@ internal class PriceTest { ) .build() - val price = Price.ofTieredBps(tieredBps) + val price = Price.ofPackage(package_) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isEqualTo(tieredBps) - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isEqualTo(package_) + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -1182,24 +1346,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofTieredBpsRoundtrip() { + fun ofPackageRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofTieredBps( - Price.TieredBps.builder() + Price.ofPackage( + Price.Package.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1208,7 +1376,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.TieredBps.Cadence.ONE_TIME) + .billingMode(Price.Package.BillingMode.IN_ADVANCE) + .cadence(Price.Package.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.Package.CompositePriceFilter.builder() + .field(Price.Package.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.Package.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -1224,6 +1400,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1234,9 +1417,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1256,9 +1439,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1267,7 +1450,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.TieredBps.Metadata.builder() + Price.Package.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1275,9 +1458,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1286,21 +1469,15 @@ internal class PriceTest { ) .minimumAmount("minimum_amount") .name("name") - .planPhaseOrder(0L) - .priceType(Price.TieredBps.PriceType.USAGE_PRICE) - .replacesPriceId("replaces_price_id") - .tieredBpsConfig( - TieredBpsConfig.builder() - .addTier( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) + .packageConfig( + PackageConfig.builder() + .packageAmount("package_amount") + .packageSize(1L) .build() ) + .planPhaseOrder(0L) + .priceType(Price.Package.PriceType.USAGE_PRICE) + .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -1317,9 +1494,9 @@ internal class PriceTest { } @Test - fun ofBps() { - val bps = - Price.Bps.builder() + fun ofMatrix() { + val matrix = + Price.Matrix.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1328,8 +1505,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .bpsConfig(BpsConfig.builder().bps(0.0).perUnitMaximum("per_unit_maximum").build()) - .cadence(Price.Bps.Cadence.ONE_TIME) + .billingMode(Price.Matrix.BillingMode.IN_ADVANCE) + .cadence(Price.Matrix.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.Matrix.CompositePriceFilter.builder() + .field(Price.Matrix.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.Matrix.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -1345,6 +1529,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1355,9 +1546,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1373,13 +1564,25 @@ internal class PriceTest { .build() ) .item(ItemSlim.builder().id("id").name("name").build()) + .matrixConfig( + MatrixConfig.builder() + .defaultUnitAmount("default_unit_amount") + .addDimension("string") + .addMatrixValue( + MatrixValue.builder() + .addDimensionValue("string") + .unitAmount("unit_amount") + .build() + ) + .build() + ) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1388,7 +1591,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Bps.Metadata.builder() + Price.Matrix.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1396,9 +1599,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1408,7 +1611,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Bps.PriceType.USAGE_PRICE) + .priceType(Price.Matrix.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -1418,20 +1621,18 @@ internal class PriceTest { ) .build() - val price = Price.ofBps(bps) + val price = Price.ofMatrix(matrix) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isEqualTo(bps) - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isEqualTo(matrix) assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -1439,24 +1640,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofBpsRoundtrip() { + fun ofMatrixRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofBps( - Price.Bps.builder() + Price.ofMatrix( + Price.Matrix.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1465,10 +1670,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .bpsConfig( - BpsConfig.builder().bps(0.0).perUnitMaximum("per_unit_maximum").build() + .billingMode(Price.Matrix.BillingMode.IN_ADVANCE) + .cadence(Price.Matrix.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.Matrix.CompositePriceFilter.builder() + .field(Price.Matrix.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.Matrix.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() ) - .cadence(Price.Bps.Cadence.ONE_TIME) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -1484,6 +1694,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1494,9 +1711,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1512,13 +1729,25 @@ internal class PriceTest { .build() ) .item(ItemSlim.builder().id("id").name("name").build()) + .matrixConfig( + MatrixConfig.builder() + .defaultUnitAmount("default_unit_amount") + .addDimension("string") + .addMatrixValue( + MatrixValue.builder() + .addDimensionValue("string") + .unitAmount("unit_amount") + .build() + ) + .build() + ) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1527,7 +1756,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Bps.Metadata.builder() + Price.Matrix.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1535,9 +1764,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1547,7 +1776,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Bps.PriceType.USAGE_PRICE) + .priceType(Price.Matrix.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -1565,9 +1794,9 @@ internal class PriceTest { } @Test - fun ofBulkBps() { - val bulkBps = - Price.BulkBps.builder() + fun ofThresholdTotalAmount() { + val thresholdTotalAmount = + Price.ThresholdTotalAmount.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1576,18 +1805,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .bulkBpsConfig( - BulkBpsConfig.builder() - .addTier( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) + .billingMode(Price.ThresholdTotalAmount.BillingMode.IN_ADVANCE) + .cadence(Price.ThresholdTotalAmount.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.ThresholdTotalAmount.CompositePriceFilter.builder() + .field(Price.ThresholdTotalAmount.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.ThresholdTotalAmount.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") .build() ) - .cadence(Price.BulkBps.Cadence.ONE_TIME) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -1603,6 +1829,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1613,9 +1846,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1635,9 +1868,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1646,7 +1879,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.BulkBps.Metadata.builder() + Price.ThresholdTotalAmount.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1654,9 +1887,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1666,8 +1899,27 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.BulkBps.PriceType.USAGE_PRICE) + .priceType(Price.ThresholdTotalAmount.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") + .thresholdTotalAmountConfig( + Price.ThresholdTotalAmount.ThresholdTotalAmountConfig.builder() + .addConsumptionTable( + Price.ThresholdTotalAmount.ThresholdTotalAmountConfig.ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .addConsumptionTable( + Price.ThresholdTotalAmount.ThresholdTotalAmountConfig.ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .prorate(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -1676,20 +1928,18 @@ internal class PriceTest { ) .build() - val price = Price.ofBulkBps(bulkBps) + val price = Price.ofThresholdTotalAmount(thresholdTotalAmount) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isEqualTo(bulkBps) assertThat(price.bulk()).isNull() - assertThat(price.thresholdTotalAmount()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() + assertThat(price.thresholdTotalAmount()).isEqualTo(thresholdTotalAmount) assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -1697,24 +1947,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofBulkBpsRoundtrip() { + fun ofThresholdTotalAmountRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofBulkBps( - Price.BulkBps.builder() + Price.ofThresholdTotalAmount( + Price.ThresholdTotalAmount.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1723,18 +1977,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .bulkBpsConfig( - BulkBpsConfig.builder() - .addTier( - BulkBpsTier.builder() - .bps(0.0) - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() + .billingMode(Price.ThresholdTotalAmount.BillingMode.IN_ADVANCE) + .cadence(Price.ThresholdTotalAmount.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.ThresholdTotalAmount.CompositePriceFilter.builder() + .field(Price.ThresholdTotalAmount.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.ThresholdTotalAmount.CompositePriceFilter.Operator.INCLUDES ) + .addValue("string") .build() ) - .cadence(Price.BulkBps.Cadence.ONE_TIME) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -1750,6 +2003,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1760,9 +2020,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1782,9 +2042,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1793,7 +2053,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.BulkBps.Metadata.builder() + Price.ThresholdTotalAmount.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1801,9 +2061,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1813,8 +2073,29 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.BulkBps.PriceType.USAGE_PRICE) + .priceType(Price.ThresholdTotalAmount.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") + .thresholdTotalAmountConfig( + Price.ThresholdTotalAmount.ThresholdTotalAmountConfig.builder() + .addConsumptionTable( + Price.ThresholdTotalAmount.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .addConsumptionTable( + Price.ThresholdTotalAmount.ThresholdTotalAmountConfig + .ConsumptionTable + .builder() + .threshold("threshold") + .totalAmount("total_amount") + .build() + ) + .prorate(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -1831,9 +2112,9 @@ internal class PriceTest { } @Test - fun ofBulk() { - val bulk = - Price.Bulk.builder() + fun ofTieredPackage() { + val tieredPackage = + Price.TieredPackage.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1842,14 +2123,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .bulkConfig( - BulkConfig.builder() - .addTier( - BulkTier.builder().unitAmount("unit_amount").maximumUnits(0.0).build() - ) + .billingMode(Price.TieredPackage.BillingMode.IN_ADVANCE) + .cadence(Price.TieredPackage.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.TieredPackage.CompositePriceFilter.builder() + .field(Price.TieredPackage.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.TieredPackage.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") .build() ) - .cadence(Price.Bulk.Cadence.ONE_TIME) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -1865,6 +2147,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1875,9 +2164,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1897,9 +2186,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1908,7 +2197,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Bulk.Metadata.builder() + Price.TieredPackage.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1916,9 +2205,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1928,8 +2217,25 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Bulk.PriceType.USAGE_PRICE) + .priceType(Price.TieredPackage.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") + .tieredPackageConfig( + Price.TieredPackage.TieredPackageConfig.builder() + .packageSize("package_size") + .addTier( + Price.TieredPackage.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + Price.TieredPackage.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -1938,20 +2244,18 @@ internal class PriceTest { ) .build() - val price = Price.ofBulk(bulk) + val price = Price.ofTieredPackage(tieredPackage) assertThat(price.unit()).isNull() + assertThat(price.tiered()).isNull() + assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() assertThat(price.package_()).isNull() assertThat(price.matrix()).isNull() - assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() - assertThat(price.bulk()).isEqualTo(bulk) assertThat(price.thresholdTotalAmount()).isNull() - assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() + assertThat(price.tieredPackage()).isEqualTo(tieredPackage) assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -1959,24 +2263,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofBulkRoundtrip() { + fun ofTieredPackageRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofBulk( - Price.Bulk.builder() + Price.ofTieredPackage( + Price.TieredPackage.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1985,17 +2293,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .bulkConfig( - BulkConfig.builder() - .addTier( - BulkTier.builder() - .unitAmount("unit_amount") - .maximumUnits(0.0) - .build() - ) + .billingMode(Price.TieredPackage.BillingMode.IN_ADVANCE) + .cadence(Price.TieredPackage.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.TieredPackage.CompositePriceFilter.builder() + .field(Price.TieredPackage.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.TieredPackage.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") .build() ) - .cadence(Price.Bulk.Cadence.ONE_TIME) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -2011,6 +2317,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2021,9 +2334,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2043,9 +2356,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2054,7 +2367,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Bulk.Metadata.builder() + Price.TieredPackage.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2062,9 +2375,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2074,8 +2387,25 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Bulk.PriceType.USAGE_PRICE) + .priceType(Price.TieredPackage.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") + .tieredPackageConfig( + Price.TieredPackage.TieredPackageConfig.builder() + .packageSize("package_size") + .addTier( + Price.TieredPackage.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + Price.TieredPackage.TieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -2092,9 +2422,9 @@ internal class PriceTest { } @Test - fun ofThresholdTotalAmount() { - val thresholdTotalAmount = - Price.ThresholdTotalAmount.builder() + fun ofTieredWithMinimum() { + val tieredWithMinimum = + Price.TieredWithMinimum.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2103,7 +2433,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.ThresholdTotalAmount.Cadence.ONE_TIME) + .billingMode(Price.TieredWithMinimum.BillingMode.IN_ADVANCE) + .cadence(Price.TieredWithMinimum.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.TieredWithMinimum.CompositePriceFilter.builder() + .field(Price.TieredWithMinimum.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.TieredWithMinimum.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -2119,6 +2457,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2129,9 +2474,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2151,9 +2496,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2162,7 +2507,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.ThresholdTotalAmount.Metadata.builder() + Price.TieredWithMinimum.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2170,9 +2515,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2182,11 +2527,26 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.ThresholdTotalAmount.PriceType.USAGE_PRICE) + .priceType(Price.TieredWithMinimum.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .thresholdTotalAmountConfig( - Price.ThresholdTotalAmount.ThresholdTotalAmountConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .tieredWithMinimumConfig( + Price.TieredWithMinimum.TieredWithMinimumConfig.builder() + .addTier( + Price.TieredWithMinimum.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + Price.TieredWithMinimum.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .hideZeroAmountTiers(true) + .prorate(true) .build() ) .dimensionalPriceConfiguration( @@ -2197,20 +2557,18 @@ internal class PriceTest { ) .build() - val price = Price.ofThresholdTotalAmount(thresholdTotalAmount) + val price = Price.ofTieredWithMinimum(tieredWithMinimum) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() - assertThat(price.thresholdTotalAmount()).isEqualTo(thresholdTotalAmount) + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() + assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() + assertThat(price.tieredWithMinimum()).isEqualTo(tieredWithMinimum) assertThat(price.groupedTiered()).isNull() - assertThat(price.tieredWithMinimum()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -2218,24 +2576,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofThresholdTotalAmountRoundtrip() { + fun ofTieredWithMinimumRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofThresholdTotalAmount( - Price.ThresholdTotalAmount.builder() + Price.ofTieredWithMinimum( + Price.TieredWithMinimum.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2244,7 +2606,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.ThresholdTotalAmount.Cadence.ONE_TIME) + .billingMode(Price.TieredWithMinimum.BillingMode.IN_ADVANCE) + .cadence(Price.TieredWithMinimum.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.TieredWithMinimum.CompositePriceFilter.builder() + .field(Price.TieredWithMinimum.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.TieredWithMinimum.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -2260,6 +2632,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2270,9 +2649,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2292,9 +2671,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2303,7 +2682,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.ThresholdTotalAmount.Metadata.builder() + Price.TieredWithMinimum.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2311,9 +2690,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2323,11 +2702,26 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.ThresholdTotalAmount.PriceType.USAGE_PRICE) + .priceType(Price.TieredWithMinimum.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .thresholdTotalAmountConfig( - Price.ThresholdTotalAmount.ThresholdTotalAmountConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .tieredWithMinimumConfig( + Price.TieredWithMinimum.TieredWithMinimumConfig.builder() + .addTier( + Price.TieredWithMinimum.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + Price.TieredWithMinimum.TieredWithMinimumConfig.Tier.builder() + .minimumAmount("minimum_amount") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .hideZeroAmountTiers(true) + .prorate(true) .build() ) .dimensionalPriceConfiguration( @@ -2346,9 +2740,9 @@ internal class PriceTest { } @Test - fun ofTieredPackage() { - val tieredPackage = - Price.TieredPackage.builder() + fun ofGroupedTiered() { + val groupedTiered = + Price.GroupedTiered.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2357,7 +2751,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.TieredPackage.Cadence.ONE_TIME) + .billingMode(Price.GroupedTiered.BillingMode.IN_ADVANCE) + .cadence(Price.GroupedTiered.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.GroupedTiered.CompositePriceFilter.builder() + .field(Price.GroupedTiered.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.GroupedTiered.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -2373,6 +2775,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2383,9 +2792,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2394,6 +2803,23 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) + .groupedTieredConfig( + Price.GroupedTiered.GroupedTieredConfig.builder() + .groupingKey("x") + .addTier( + Price.GroupedTiered.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + Price.GroupedTiered.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .build() + ) .invoicingCycleConfiguration( BillingCycleConfiguration.builder() .duration(0L) @@ -2405,9 +2831,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2416,7 +2842,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.TieredPackage.Metadata.builder() + Price.GroupedTiered.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2424,9 +2850,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2436,13 +2862,8 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.TieredPackage.PriceType.USAGE_PRICE) + .priceType(Price.GroupedTiered.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .tieredPackageConfig( - Price.TieredPackage.TieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -2451,20 +2872,18 @@ internal class PriceTest { ) .build() - val price = Price.ofTieredPackage(tieredPackage) + val price = Price.ofGroupedTiered(groupedTiered) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() - assertThat(price.tieredPackage()).isEqualTo(tieredPackage) - assertThat(price.groupedTiered()).isNull() + assertThat(price.tieredPackage()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isEqualTo(groupedTiered) assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -2472,24 +2891,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofTieredPackageRoundtrip() { + fun ofGroupedTieredRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofTieredPackage( - Price.TieredPackage.builder() + Price.ofGroupedTiered( + Price.GroupedTiered.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2498,7 +2921,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.TieredPackage.Cadence.ONE_TIME) + .billingMode(Price.GroupedTiered.BillingMode.IN_ADVANCE) + .cadence(Price.GroupedTiered.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.GroupedTiered.CompositePriceFilter.builder() + .field(Price.GroupedTiered.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.GroupedTiered.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -2514,6 +2945,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2524,9 +2962,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2535,6 +2973,23 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) + .groupedTieredConfig( + Price.GroupedTiered.GroupedTieredConfig.builder() + .groupingKey("x") + .addTier( + Price.GroupedTiered.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + Price.GroupedTiered.GroupedTieredConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .build() + ) .invoicingCycleConfiguration( BillingCycleConfiguration.builder() .duration(0L) @@ -2546,9 +3001,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2557,7 +3012,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.TieredPackage.Metadata.builder() + Price.GroupedTiered.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2565,9 +3020,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2577,13 +3032,8 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.TieredPackage.PriceType.USAGE_PRICE) + .priceType(Price.GroupedTiered.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .tieredPackageConfig( - Price.TieredPackage.TieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -2600,9 +3050,9 @@ internal class PriceTest { } @Test - fun ofGroupedTiered() { - val groupedTiered = - Price.GroupedTiered.builder() + fun ofTieredPackageWithMinimum() { + val tieredPackageWithMinimum = + Price.TieredPackageWithMinimum.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2611,7 +3061,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.GroupedTiered.Cadence.ONE_TIME) + .billingMode(Price.TieredPackageWithMinimum.BillingMode.IN_ADVANCE) + .cadence(Price.TieredPackageWithMinimum.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.TieredPackageWithMinimum.CompositePriceFilter.builder() + .field(Price.TieredPackageWithMinimum.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.TieredPackageWithMinimum.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -2627,6 +3087,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2637,9 +3104,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2648,11 +3115,6 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) - .groupedTieredConfig( - Price.GroupedTiered.GroupedTieredConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .invoicingCycleConfiguration( BillingCycleConfiguration.builder() .duration(0L) @@ -2664,9 +3126,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2675,7 +3137,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.GroupedTiered.Metadata.builder() + Price.TieredPackageWithMinimum.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2683,9 +3145,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2695,8 +3157,29 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.GroupedTiered.PriceType.USAGE_PRICE) + .priceType(Price.TieredPackageWithMinimum.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") + .tieredPackageWithMinimumConfig( + Price.TieredPackageWithMinimum.TieredPackageWithMinimumConfig.builder() + .packageSize(0.0) + .addTier( + Price.TieredPackageWithMinimum.TieredPackageWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + Price.TieredPackageWithMinimum.TieredPackageWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -2705,45 +3188,47 @@ internal class PriceTest { ) .build() - val price = Price.ofGroupedTiered(groupedTiered) + val price = Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isEqualTo(groupedTiered) assertThat(price.tieredWithMinimum()).isNull() - assertThat(price.tieredPackageWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() + assertThat(price.tieredPackageWithMinimum()).isEqualTo(tieredPackageWithMinimum) assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() assertThat(price.matrixWithAllocation()).isNull() assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofGroupedTieredRoundtrip() { + fun ofTieredPackageWithMinimumRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofGroupedTiered( - Price.GroupedTiered.builder() + Price.ofTieredPackageWithMinimum( + Price.TieredPackageWithMinimum.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2752,7 +3237,20 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.GroupedTiered.Cadence.ONE_TIME) + .billingMode(Price.TieredPackageWithMinimum.BillingMode.IN_ADVANCE) + .cadence(Price.TieredPackageWithMinimum.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.TieredPackageWithMinimum.CompositePriceFilter.builder() + .field( + Price.TieredPackageWithMinimum.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.TieredPackageWithMinimum.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -2768,7 +3266,14 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) - .build() + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .build() ) .currency("currency") .discount( @@ -2778,9 +3283,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2789,11 +3294,6 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) - .groupedTieredConfig( - Price.GroupedTiered.GroupedTieredConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .invoicingCycleConfiguration( BillingCycleConfiguration.builder() .duration(0L) @@ -2805,9 +3305,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2816,7 +3316,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.GroupedTiered.Metadata.builder() + Price.TieredPackageWithMinimum.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2824,9 +3324,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2836,8 +3336,29 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.GroupedTiered.PriceType.USAGE_PRICE) + .priceType(Price.TieredPackageWithMinimum.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") + .tieredPackageWithMinimumConfig( + Price.TieredPackageWithMinimum.TieredPackageWithMinimumConfig.builder() + .packageSize(0.0) + .addTier( + Price.TieredPackageWithMinimum.TieredPackageWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + Price.TieredPackageWithMinimum.TieredPackageWithMinimumConfig.Tier + .builder() + .minimumAmount("minimum_amount") + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -2854,9 +3375,9 @@ internal class PriceTest { } @Test - fun ofTieredWithMinimum() { - val tieredWithMinimum = - Price.TieredWithMinimum.builder() + fun ofPackageWithAllocation() { + val packageWithAllocation = + Price.PackageWithAllocation.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2865,7 +3386,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.TieredWithMinimum.Cadence.ONE_TIME) + .billingMode(Price.PackageWithAllocation.BillingMode.IN_ADVANCE) + .cadence(Price.PackageWithAllocation.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.PackageWithAllocation.CompositePriceFilter.builder() + .field(Price.PackageWithAllocation.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.PackageWithAllocation.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -2881,6 +3412,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2891,9 +3429,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2913,9 +3451,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2924,7 +3462,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.TieredWithMinimum.Metadata.builder() + Price.PackageWithAllocation.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2932,9 +3470,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2943,14 +3481,16 @@ internal class PriceTest { ) .minimumAmount("minimum_amount") .name("name") - .planPhaseOrder(0L) - .priceType(Price.TieredWithMinimum.PriceType.USAGE_PRICE) - .replacesPriceId("replaces_price_id") - .tieredWithMinimumConfig( - Price.TieredWithMinimum.TieredWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageWithAllocationConfig( + Price.PackageWithAllocation.PackageWithAllocationConfig.builder() + .allocation("allocation") + .packageAmount("package_amount") + .packageSize("package_size") .build() ) + .planPhaseOrder(0L) + .priceType(Price.PackageWithAllocation.PriceType.USAGE_PRICE) + .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -2959,45 +3499,47 @@ internal class PriceTest { ) .build() - val price = Price.ofTieredWithMinimum(tieredWithMinimum) + val price = Price.ofPackageWithAllocation(packageWithAllocation) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() + assertThat(price.tieredWithMinimum()).isNull() assertThat(price.groupedTiered()).isNull() - assertThat(price.tieredWithMinimum()).isEqualTo(tieredWithMinimum) assertThat(price.tieredPackageWithMinimum()).isNull() - assertThat(price.packageWithAllocation()).isNull() + assertThat(price.packageWithAllocation()).isEqualTo(packageWithAllocation) assertThat(price.unitWithPercent()).isNull() assertThat(price.matrixWithAllocation()).isNull() assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofTieredWithMinimumRoundtrip() { + fun ofPackageWithAllocationRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofTieredWithMinimum( - Price.TieredWithMinimum.builder() + Price.ofPackageWithAllocation( + Price.PackageWithAllocation.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -3006,7 +3548,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.TieredWithMinimum.Cadence.ONE_TIME) + .billingMode(Price.PackageWithAllocation.BillingMode.IN_ADVANCE) + .cadence(Price.PackageWithAllocation.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.PackageWithAllocation.CompositePriceFilter.builder() + .field(Price.PackageWithAllocation.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.PackageWithAllocation.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -3022,6 +3574,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3032,9 +3591,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3054,9 +3613,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3065,7 +3624,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.TieredWithMinimum.Metadata.builder() + Price.PackageWithAllocation.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -3073,9 +3632,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3084,14 +3643,16 @@ internal class PriceTest { ) .minimumAmount("minimum_amount") .name("name") - .planPhaseOrder(0L) - .priceType(Price.TieredWithMinimum.PriceType.USAGE_PRICE) - .replacesPriceId("replaces_price_id") - .tieredWithMinimumConfig( - Price.TieredWithMinimum.TieredWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .packageWithAllocationConfig( + Price.PackageWithAllocation.PackageWithAllocationConfig.builder() + .allocation("allocation") + .packageAmount("package_amount") + .packageSize("package_size") .build() ) + .planPhaseOrder(0L) + .priceType(Price.PackageWithAllocation.PriceType.USAGE_PRICE) + .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -3108,9 +3669,9 @@ internal class PriceTest { } @Test - fun ofTieredPackageWithMinimum() { - val tieredPackageWithMinimum = - Price.TieredPackageWithMinimum.builder() + fun ofUnitWithPercent() { + val unitWithPercent = + Price.UnitWithPercent.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -3119,7 +3680,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.TieredPackageWithMinimum.Cadence.ONE_TIME) + .billingMode(Price.UnitWithPercent.BillingMode.IN_ADVANCE) + .cadence(Price.UnitWithPercent.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitWithPercent.CompositePriceFilter.builder() + .field(Price.UnitWithPercent.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitWithPercent.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -3135,6 +3704,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3145,9 +3721,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3167,9 +3743,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3178,7 +3754,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.TieredPackageWithMinimum.Metadata.builder() + Price.UnitWithPercent.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -3186,9 +3762,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3198,11 +3774,12 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.TieredPackageWithMinimum.PriceType.USAGE_PRICE) + .priceType(Price.UnitWithPercent.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .tieredPackageWithMinimumConfig( - Price.TieredPackageWithMinimum.TieredPackageWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .unitWithPercentConfig( + Price.UnitWithPercent.UnitWithPercentConfig.builder() + .percent("percent") + .unitAmount("unit_amount") .build() ) .dimensionalPriceConfiguration( @@ -3213,45 +3790,47 @@ internal class PriceTest { ) .build() - val price = Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum) + val price = Price.ofUnitWithPercent(unitWithPercent) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() - assertThat(price.tieredPackageWithMinimum()).isEqualTo(tieredPackageWithMinimum) + assertThat(price.groupedTiered()).isNull() + assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() - assertThat(price.unitWithPercent()).isNull() + assertThat(price.unitWithPercent()).isEqualTo(unitWithPercent) assertThat(price.matrixWithAllocation()).isNull() assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofTieredPackageWithMinimumRoundtrip() { + fun ofUnitWithPercentRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofTieredPackageWithMinimum( - Price.TieredPackageWithMinimum.builder() + Price.ofUnitWithPercent( + Price.UnitWithPercent.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -3260,7 +3839,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.TieredPackageWithMinimum.Cadence.ONE_TIME) + .billingMode(Price.UnitWithPercent.BillingMode.IN_ADVANCE) + .cadence(Price.UnitWithPercent.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitWithPercent.CompositePriceFilter.builder() + .field(Price.UnitWithPercent.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitWithPercent.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -3276,6 +3863,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3286,9 +3880,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3308,9 +3902,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3319,7 +3913,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.TieredPackageWithMinimum.Metadata.builder() + Price.UnitWithPercent.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -3327,9 +3921,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3339,11 +3933,12 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.TieredPackageWithMinimum.PriceType.USAGE_PRICE) + .priceType(Price.UnitWithPercent.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .tieredPackageWithMinimumConfig( - Price.TieredPackageWithMinimum.TieredPackageWithMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .unitWithPercentConfig( + Price.UnitWithPercent.UnitWithPercentConfig.builder() + .percent("percent") + .unitAmount("unit_amount") .build() ) .dimensionalPriceConfiguration( @@ -3362,9 +3957,9 @@ internal class PriceTest { } @Test - fun ofPackageWithAllocation() { - val packageWithAllocation = - Price.PackageWithAllocation.builder() + fun ofMatrixWithAllocation() { + val matrixWithAllocation = + Price.MatrixWithAllocation.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -3373,7 +3968,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.PackageWithAllocation.Cadence.ONE_TIME) + .billingMode(Price.MatrixWithAllocation.BillingMode.IN_ADVANCE) + .cadence(Price.MatrixWithAllocation.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.MatrixWithAllocation.CompositePriceFilter.builder() + .field(Price.MatrixWithAllocation.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.MatrixWithAllocation.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -3389,6 +3992,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3399,9 +4009,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3417,13 +4027,26 @@ internal class PriceTest { .build() ) .item(ItemSlim.builder().id("id").name("name").build()) + .matrixWithAllocationConfig( + MatrixWithAllocationConfig.builder() + .allocation("allocation") + .defaultUnitAmount("default_unit_amount") + .addDimension("string") + .addMatrixValue( + MatrixWithAllocationConfig.MatrixValue.builder() + .addDimensionValue("string") + .unitAmount("unit_amount") + .build() + ) + .build() + ) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3432,7 +4055,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.PackageWithAllocation.Metadata.builder() + Price.MatrixWithAllocation.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -3440,9 +4063,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3451,13 +4074,8 @@ internal class PriceTest { ) .minimumAmount("minimum_amount") .name("name") - .packageWithAllocationConfig( - Price.PackageWithAllocation.PackageWithAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .planPhaseOrder(0L) - .priceType(Price.PackageWithAllocation.PriceType.USAGE_PRICE) + .priceType(Price.MatrixWithAllocation.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -3467,45 +4085,47 @@ internal class PriceTest { ) .build() - val price = Price.ofPackageWithAllocation(packageWithAllocation) + val price = Price.ofMatrixWithAllocation(matrixWithAllocation) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() - assertThat(price.packageWithAllocation()).isEqualTo(packageWithAllocation) + assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() - assertThat(price.matrixWithAllocation()).isNull() + assertThat(price.matrixWithAllocation()).isEqualTo(matrixWithAllocation) assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofPackageWithAllocationRoundtrip() { + fun ofMatrixWithAllocationRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofPackageWithAllocation( - Price.PackageWithAllocation.builder() + Price.ofMatrixWithAllocation( + Price.MatrixWithAllocation.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -3514,7 +4134,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.PackageWithAllocation.Cadence.ONE_TIME) + .billingMode(Price.MatrixWithAllocation.BillingMode.IN_ADVANCE) + .cadence(Price.MatrixWithAllocation.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.MatrixWithAllocation.CompositePriceFilter.builder() + .field(Price.MatrixWithAllocation.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.MatrixWithAllocation.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -3530,6 +4160,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3540,9 +4177,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3558,13 +4195,26 @@ internal class PriceTest { .build() ) .item(ItemSlim.builder().id("id").name("name").build()) + .matrixWithAllocationConfig( + MatrixWithAllocationConfig.builder() + .allocation("allocation") + .defaultUnitAmount("default_unit_amount") + .addDimension("string") + .addMatrixValue( + MatrixWithAllocationConfig.MatrixValue.builder() + .addDimensionValue("string") + .unitAmount("unit_amount") + .build() + ) + .build() + ) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3573,7 +4223,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.PackageWithAllocation.Metadata.builder() + Price.MatrixWithAllocation.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -3581,9 +4231,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3592,13 +4242,8 @@ internal class PriceTest { ) .minimumAmount("minimum_amount") .name("name") - .packageWithAllocationConfig( - Price.PackageWithAllocation.PackageWithAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .planPhaseOrder(0L) - .priceType(Price.PackageWithAllocation.PriceType.USAGE_PRICE) + .priceType(Price.MatrixWithAllocation.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -3616,9 +4261,9 @@ internal class PriceTest { } @Test - fun ofUnitWithPercent() { - val unitWithPercent = - Price.UnitWithPercent.builder() + fun ofTieredWithProration() { + val tieredWithProration = + Price.TieredWithProration.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -3627,7 +4272,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.UnitWithPercent.Cadence.ONE_TIME) + .billingMode(Price.TieredWithProration.BillingMode.IN_ADVANCE) + .cadence(Price.TieredWithProration.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.TieredWithProration.CompositePriceFilter.builder() + .field(Price.TieredWithProration.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.TieredWithProration.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -3643,6 +4296,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3653,9 +4313,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3675,9 +4335,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3686,7 +4346,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.UnitWithPercent.Metadata.builder() + Price.TieredWithProration.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -3694,9 +4354,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3706,11 +4366,16 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.UnitWithPercent.PriceType.USAGE_PRICE) + .priceType(Price.TieredWithProration.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitWithPercentConfig( - Price.UnitWithPercent.UnitWithPercentConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .tieredWithProrationConfig( + Price.TieredWithProration.TieredWithProrationConfig.builder() + .addTier( + Price.TieredWithProration.TieredWithProrationConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .dimensionalPriceConfiguration( @@ -3721,45 +4386,47 @@ internal class PriceTest { ) .build() - val price = Price.ofUnitWithPercent(unitWithPercent) + val price = Price.ofTieredWithProration(tieredWithProration) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() - assertThat(price.unitWithPercent()).isEqualTo(unitWithPercent) + assertThat(price.unitWithPercent()).isNull() assertThat(price.matrixWithAllocation()).isNull() - assertThat(price.tieredWithProration()).isNull() + assertThat(price.tieredWithProration()).isEqualTo(tieredWithProration) assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofUnitWithPercentRoundtrip() { + fun ofTieredWithProrationRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofUnitWithPercent( - Price.UnitWithPercent.builder() + Price.ofTieredWithProration( + Price.TieredWithProration.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -3768,7 +4435,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.UnitWithPercent.Cadence.ONE_TIME) + .billingMode(Price.TieredWithProration.BillingMode.IN_ADVANCE) + .cadence(Price.TieredWithProration.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.TieredWithProration.CompositePriceFilter.builder() + .field(Price.TieredWithProration.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.TieredWithProration.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -3784,6 +4461,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3794,9 +4478,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3816,9 +4500,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3827,7 +4511,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.UnitWithPercent.Metadata.builder() + Price.TieredWithProration.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -3835,9 +4519,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3847,11 +4531,16 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.UnitWithPercent.PriceType.USAGE_PRICE) + .priceType(Price.TieredWithProration.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitWithPercentConfig( - Price.UnitWithPercent.UnitWithPercentConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .tieredWithProrationConfig( + Price.TieredWithProration.TieredWithProrationConfig.builder() + .addTier( + Price.TieredWithProration.TieredWithProrationConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) .build() ) .dimensionalPriceConfiguration( @@ -3870,9 +4559,9 @@ internal class PriceTest { } @Test - fun ofMatrixWithAllocation() { - val matrixWithAllocation = - Price.MatrixWithAllocation.builder() + fun ofUnitWithProration() { + val unitWithProration = + Price.UnitWithProration.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -3881,7 +4570,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.MatrixWithAllocation.Cadence.ONE_TIME) + .billingMode(Price.UnitWithProration.BillingMode.IN_ADVANCE) + .cadence(Price.UnitWithProration.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitWithProration.CompositePriceFilter.builder() + .field(Price.UnitWithProration.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.UnitWithProration.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -3897,6 +4594,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3907,9 +4611,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3925,26 +4629,13 @@ internal class PriceTest { .build() ) .item(ItemSlim.builder().id("id").name("name").build()) - .matrixWithAllocationConfig( - MatrixWithAllocationConfig.builder() - .allocation(0.0) - .defaultUnitAmount("default_unit_amount") - .addDimension("string") - .addMatrixValue( - MatrixValue.builder() - .addDimensionValue("string") - .unitAmount("unit_amount") - .build() - ) - .build() - ) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3953,7 +4644,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.MatrixWithAllocation.Metadata.builder() + Price.UnitWithProration.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -3961,9 +4652,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3973,8 +4664,13 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.MatrixWithAllocation.PriceType.USAGE_PRICE) + .priceType(Price.UnitWithProration.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") + .unitWithProrationConfig( + Price.UnitWithProration.UnitWithProrationConfig.builder() + .unitAmount("unit_amount") + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -3983,45 +4679,47 @@ internal class PriceTest { ) .build() - val price = Price.ofMatrixWithAllocation(matrixWithAllocation) + val price = Price.ofUnitWithProration(unitWithProration) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() - assertThat(price.matrixWithAllocation()).isEqualTo(matrixWithAllocation) + assertThat(price.matrixWithAllocation()).isNull() assertThat(price.tieredWithProration()).isNull() - assertThat(price.unitWithProration()).isNull() + assertThat(price.unitWithProration()).isEqualTo(unitWithProration) assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofMatrixWithAllocationRoundtrip() { + fun ofUnitWithProrationRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofMatrixWithAllocation( - Price.MatrixWithAllocation.builder() + Price.ofUnitWithProration( + Price.UnitWithProration.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -4030,7 +4728,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.MatrixWithAllocation.Cadence.ONE_TIME) + .billingMode(Price.UnitWithProration.BillingMode.IN_ADVANCE) + .cadence(Price.UnitWithProration.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitWithProration.CompositePriceFilter.builder() + .field(Price.UnitWithProration.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitWithProration.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -4046,6 +4754,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4056,9 +4771,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4074,26 +4789,13 @@ internal class PriceTest { .build() ) .item(ItemSlim.builder().id("id").name("name").build()) - .matrixWithAllocationConfig( - MatrixWithAllocationConfig.builder() - .allocation(0.0) - .defaultUnitAmount("default_unit_amount") - .addDimension("string") - .addMatrixValue( - MatrixValue.builder() - .addDimensionValue("string") - .unitAmount("unit_amount") - .build() - ) - .build() - ) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4102,7 +4804,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.MatrixWithAllocation.Metadata.builder() + Price.UnitWithProration.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -4110,9 +4812,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4122,8 +4824,13 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.MatrixWithAllocation.PriceType.USAGE_PRICE) + .priceType(Price.UnitWithProration.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") + .unitWithProrationConfig( + Price.UnitWithProration.UnitWithProrationConfig.builder() + .unitAmount("unit_amount") + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -4140,9 +4847,9 @@ internal class PriceTest { } @Test - fun ofTieredWithProration() { - val tieredWithProration = - Price.TieredWithProration.builder() + fun ofGroupedAllocation() { + val groupedAllocation = + Price.GroupedAllocation.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -4151,7 +4858,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.TieredWithProration.Cadence.ONE_TIME) + .billingMode(Price.GroupedAllocation.BillingMode.IN_ADVANCE) + .cadence(Price.GroupedAllocation.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.GroupedAllocation.CompositePriceFilter.builder() + .field(Price.GroupedAllocation.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.GroupedAllocation.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -4167,6 +4882,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4177,9 +4899,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4188,6 +4910,13 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) + .groupedAllocationConfig( + Price.GroupedAllocation.GroupedAllocationConfig.builder() + .allocation("allocation") + .groupingKey("x") + .overageUnitRate("overage_unit_rate") + .build() + ) .invoicingCycleConfiguration( BillingCycleConfiguration.builder() .duration(0L) @@ -4199,9 +4928,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4210,7 +4939,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.TieredWithProration.Metadata.builder() + Price.GroupedAllocation.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -4218,9 +4947,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4230,13 +4959,8 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.TieredWithProration.PriceType.USAGE_PRICE) + .priceType(Price.GroupedAllocation.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .tieredWithProrationConfig( - Price.TieredWithProration.TieredWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -4245,45 +4969,47 @@ internal class PriceTest { ) .build() - val price = Price.ofTieredWithProration(tieredWithProration) + val price = Price.ofGroupedAllocation(groupedAllocation) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() assertThat(price.matrixWithAllocation()).isNull() - assertThat(price.tieredWithProration()).isEqualTo(tieredWithProration) + assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() - assertThat(price.groupedAllocation()).isNull() + assertThat(price.groupedAllocation()).isEqualTo(groupedAllocation) + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofTieredWithProrationRoundtrip() { + fun ofGroupedAllocationRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofTieredWithProration( - Price.TieredWithProration.builder() + Price.ofGroupedAllocation( + Price.GroupedAllocation.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -4292,7 +5018,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.TieredWithProration.Cadence.ONE_TIME) + .billingMode(Price.GroupedAllocation.BillingMode.IN_ADVANCE) + .cadence(Price.GroupedAllocation.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.GroupedAllocation.CompositePriceFilter.builder() + .field(Price.GroupedAllocation.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.GroupedAllocation.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -4308,6 +5044,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4318,9 +5061,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4329,6 +5072,13 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) + .groupedAllocationConfig( + Price.GroupedAllocation.GroupedAllocationConfig.builder() + .allocation("allocation") + .groupingKey("x") + .overageUnitRate("overage_unit_rate") + .build() + ) .invoicingCycleConfiguration( BillingCycleConfiguration.builder() .duration(0L) @@ -4340,9 +5090,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4351,7 +5101,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.TieredWithProration.Metadata.builder() + Price.GroupedAllocation.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -4359,9 +5109,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4371,13 +5121,8 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.TieredWithProration.PriceType.USAGE_PRICE) + .priceType(Price.GroupedAllocation.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .tieredWithProrationConfig( - Price.TieredWithProration.TieredWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -4394,9 +5139,9 @@ internal class PriceTest { } @Test - fun ofUnitWithProration() { - val unitWithProration = - Price.UnitWithProration.builder() + fun ofBulkWithProration() { + val bulkWithProration = + Price.BulkWithProration.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -4405,7 +5150,31 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.UnitWithProration.Cadence.ONE_TIME) + .billingMode(Price.BulkWithProration.BillingMode.IN_ADVANCE) + .bulkWithProrationConfig( + Price.BulkWithProration.BulkWithProrationConfig.builder() + .addTier( + Price.BulkWithProration.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + Price.BulkWithProration.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .build() + ) + .cadence(Price.BulkWithProration.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.BulkWithProration.CompositePriceFilter.builder() + .field(Price.BulkWithProration.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.BulkWithProration.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -4421,6 +5190,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4431,9 +5207,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4453,9 +5229,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4464,7 +5240,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.UnitWithProration.Metadata.builder() + Price.BulkWithProration.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -4472,9 +5248,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4484,13 +5260,8 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.UnitWithProration.PriceType.USAGE_PRICE) + .priceType(Price.BulkWithProration.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitWithProrationConfig( - Price.UnitWithProration.UnitWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -4499,45 +5270,47 @@ internal class PriceTest { ) .build() - val price = Price.ofUnitWithProration(unitWithProration) + val price = Price.ofBulkWithProration(bulkWithProration) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() assertThat(price.matrixWithAllocation()).isNull() assertThat(price.tieredWithProration()).isNull() - assertThat(price.unitWithProration()).isEqualTo(unitWithProration) + assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isEqualTo(bulkWithProration) assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofUnitWithProrationRoundtrip() { + fun ofBulkWithProrationRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofUnitWithProration( - Price.UnitWithProration.builder() + Price.ofBulkWithProration( + Price.BulkWithProration.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -4546,7 +5319,33 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.UnitWithProration.Cadence.ONE_TIME) + .billingMode(Price.BulkWithProration.BillingMode.IN_ADVANCE) + .bulkWithProrationConfig( + Price.BulkWithProration.BulkWithProrationConfig.builder() + .addTier( + Price.BulkWithProration.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + Price.BulkWithProration.BulkWithProrationConfig.Tier.builder() + .unitAmount("unit_amount") + .tierLowerBound("tier_lower_bound") + .build() + ) + .build() + ) + .cadence(Price.BulkWithProration.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.BulkWithProration.CompositePriceFilter.builder() + .field(Price.BulkWithProration.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.BulkWithProration.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -4562,6 +5361,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4572,9 +5378,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4594,9 +5400,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4605,7 +5411,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.UnitWithProration.Metadata.builder() + Price.BulkWithProration.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -4613,9 +5419,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4625,13 +5431,8 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.UnitWithProration.PriceType.USAGE_PRICE) + .priceType(Price.BulkWithProration.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitWithProrationConfig( - Price.UnitWithProration.UnitWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -4648,9 +5449,9 @@ internal class PriceTest { } @Test - fun ofGroupedAllocation() { - val groupedAllocation = - Price.GroupedAllocation.builder() + fun ofGroupedWithProratedMinimum() { + val groupedWithProratedMinimum = + Price.GroupedWithProratedMinimum.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -4659,7 +5460,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.GroupedAllocation.Cadence.ONE_TIME) + .billingMode(Price.GroupedWithProratedMinimum.BillingMode.IN_ADVANCE) + .cadence(Price.GroupedWithProratedMinimum.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.GroupedWithProratedMinimum.CompositePriceFilter.builder() + .field(Price.GroupedWithProratedMinimum.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.GroupedWithProratedMinimum.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -4675,6 +5486,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4685,9 +5503,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4696,9 +5514,11 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) - .groupedAllocationConfig( - Price.GroupedAllocation.GroupedAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupedWithProratedMinimumConfig( + Price.GroupedWithProratedMinimum.GroupedWithProratedMinimumConfig.builder() + .groupingKey("x") + .minimum("minimum") + .unitRate("unit_rate") .build() ) .invoicingCycleConfiguration( @@ -4712,9 +5532,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4723,7 +5543,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.GroupedAllocation.Metadata.builder() + Price.GroupedWithProratedMinimum.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -4731,9 +5551,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4743,7 +5563,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.GroupedAllocation.PriceType.USAGE_PRICE) + .priceType(Price.GroupedWithProratedMinimum.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -4753,45 +5573,47 @@ internal class PriceTest { ) .build() - val price = Price.ofGroupedAllocation(groupedAllocation) + val price = Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() assertThat(price.matrixWithAllocation()).isNull() assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() - assertThat(price.groupedAllocation()).isEqualTo(groupedAllocation) - assertThat(price.groupedWithProratedMinimum()).isNull() + assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() + assertThat(price.groupedWithProratedMinimum()).isEqualTo(groupedWithProratedMinimum) assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofGroupedAllocationRoundtrip() { + fun ofGroupedWithProratedMinimumRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofGroupedAllocation( - Price.GroupedAllocation.builder() + Price.ofGroupedWithProratedMinimum( + Price.GroupedWithProratedMinimum.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -4800,7 +5622,20 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.GroupedAllocation.Cadence.ONE_TIME) + .billingMode(Price.GroupedWithProratedMinimum.BillingMode.IN_ADVANCE) + .cadence(Price.GroupedWithProratedMinimum.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.GroupedWithProratedMinimum.CompositePriceFilter.builder() + .field( + Price.GroupedWithProratedMinimum.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.GroupedWithProratedMinimum.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -4816,6 +5651,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4826,9 +5668,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4837,9 +5679,11 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) - .groupedAllocationConfig( - Price.GroupedAllocation.GroupedAllocationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupedWithProratedMinimumConfig( + Price.GroupedWithProratedMinimum.GroupedWithProratedMinimumConfig.builder() + .groupingKey("x") + .minimum("minimum") + .unitRate("unit_rate") .build() ) .invoicingCycleConfiguration( @@ -4853,9 +5697,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4864,7 +5708,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.GroupedAllocation.Metadata.builder() + Price.GroupedWithProratedMinimum.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -4872,9 +5716,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4884,7 +5728,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.GroupedAllocation.PriceType.USAGE_PRICE) + .priceType(Price.GroupedWithProratedMinimum.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -4902,9 +5746,9 @@ internal class PriceTest { } @Test - fun ofGroupedWithProratedMinimum() { - val groupedWithProratedMinimum = - Price.GroupedWithProratedMinimum.builder() + fun ofGroupedWithMeteredMinimum() { + val groupedWithMeteredMinimum = + Price.GroupedWithMeteredMinimum.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -4913,7 +5757,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.GroupedWithProratedMinimum.Cadence.ONE_TIME) + .billingMode(Price.GroupedWithMeteredMinimum.BillingMode.IN_ADVANCE) + .cadence(Price.GroupedWithMeteredMinimum.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.GroupedWithMeteredMinimum.CompositePriceFilter.builder() + .field(Price.GroupedWithMeteredMinimum.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.GroupedWithMeteredMinimum.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -4929,6 +5783,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4939,9 +5800,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4950,9 +5811,28 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) - .groupedWithProratedMinimumConfig( - Price.GroupedWithProratedMinimum.GroupedWithProratedMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupedWithMeteredMinimumConfig( + Price.GroupedWithMeteredMinimum.GroupedWithMeteredMinimumConfig.builder() + .groupingKey("x") + .minimumUnitAmount("minimum_unit_amount") + .pricingKey("pricing_key") + .addScalingFactor( + Price.GroupedWithMeteredMinimum.GroupedWithMeteredMinimumConfig + .ScalingFactor + .builder() + .scalingFactor("scaling_factor") + .scalingValue("scaling_value") + .build() + ) + .scalingKey("scaling_key") + .addUnitAmount( + Price.GroupedWithMeteredMinimum.GroupedWithMeteredMinimumConfig + .UnitAmount + .builder() + .pricingValue("pricing_value") + .unitAmount("unit_amount") + .build() + ) .build() ) .invoicingCycleConfiguration( @@ -4966,9 +5846,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4977,7 +5857,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.GroupedWithProratedMinimum.Metadata.builder() + Price.GroupedWithMeteredMinimum.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -4985,9 +5865,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4997,7 +5877,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.GroupedWithProratedMinimum.PriceType.USAGE_PRICE) + .priceType(Price.GroupedWithMeteredMinimum.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -5007,20 +5887,18 @@ internal class PriceTest { ) .build() - val price = Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum) + val price = Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -5028,24 +5906,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() - assertThat(price.groupedWithProratedMinimum()).isEqualTo(groupedWithProratedMinimum) - assertThat(price.groupedWithMeteredMinimum()).isNull() - assertThat(price.matrixWithDisplayName()).isNull() assertThat(price.bulkWithProration()).isNull() + assertThat(price.groupedWithProratedMinimum()).isNull() + assertThat(price.groupedWithMeteredMinimum()).isEqualTo(groupedWithMeteredMinimum) + assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.matrixWithDisplayName()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofGroupedWithProratedMinimumRoundtrip() { + fun ofGroupedWithMeteredMinimumRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofGroupedWithProratedMinimum( - Price.GroupedWithProratedMinimum.builder() + Price.ofGroupedWithMeteredMinimum( + Price.GroupedWithMeteredMinimum.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -5054,7 +5936,20 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.GroupedWithProratedMinimum.Cadence.ONE_TIME) + .billingMode(Price.GroupedWithMeteredMinimum.BillingMode.IN_ADVANCE) + .cadence(Price.GroupedWithMeteredMinimum.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.GroupedWithMeteredMinimum.CompositePriceFilter.builder() + .field( + Price.GroupedWithMeteredMinimum.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.GroupedWithMeteredMinimum.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -5070,6 +5965,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -5080,9 +5982,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5091,9 +5993,28 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) - .groupedWithProratedMinimumConfig( - Price.GroupedWithProratedMinimum.GroupedWithProratedMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupedWithMeteredMinimumConfig( + Price.GroupedWithMeteredMinimum.GroupedWithMeteredMinimumConfig.builder() + .groupingKey("x") + .minimumUnitAmount("minimum_unit_amount") + .pricingKey("pricing_key") + .addScalingFactor( + Price.GroupedWithMeteredMinimum.GroupedWithMeteredMinimumConfig + .ScalingFactor + .builder() + .scalingFactor("scaling_factor") + .scalingValue("scaling_value") + .build() + ) + .scalingKey("scaling_key") + .addUnitAmount( + Price.GroupedWithMeteredMinimum.GroupedWithMeteredMinimumConfig + .UnitAmount + .builder() + .pricingValue("pricing_value") + .unitAmount("unit_amount") + .build() + ) .build() ) .invoicingCycleConfiguration( @@ -5107,9 +6028,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5118,7 +6039,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.GroupedWithProratedMinimum.Metadata.builder() + Price.GroupedWithMeteredMinimum.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -5126,9 +6047,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5138,7 +6059,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.GroupedWithProratedMinimum.PriceType.USAGE_PRICE) + .priceType(Price.GroupedWithMeteredMinimum.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -5156,9 +6077,9 @@ internal class PriceTest { } @Test - fun ofGroupedWithMeteredMinimum() { - val groupedWithMeteredMinimum = - Price.GroupedWithMeteredMinimum.builder() + fun ofGroupedWithMinMaxThresholds() { + val groupedWithMinMaxThresholds = + Price.GroupedWithMinMaxThresholds.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -5167,7 +6088,19 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.GroupedWithMeteredMinimum.Cadence.ONE_TIME) + .billingMode(Price.GroupedWithMinMaxThresholds.BillingMode.IN_ADVANCE) + .cadence(Price.GroupedWithMinMaxThresholds.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.GroupedWithMinMaxThresholds.CompositePriceFilter.builder() + .field( + Price.GroupedWithMinMaxThresholds.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.GroupedWithMinMaxThresholds.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -5183,6 +6116,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -5193,9 +6133,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5204,9 +6144,12 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) - .groupedWithMeteredMinimumConfig( - Price.GroupedWithMeteredMinimum.GroupedWithMeteredMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupedWithMinMaxThresholdsConfig( + Price.GroupedWithMinMaxThresholds.GroupedWithMinMaxThresholdsConfig.builder() + .groupingKey("x") + .maximumCharge("maximum_charge") + .minimumCharge("minimum_charge") + .perUnitRate("per_unit_rate") .build() ) .invoicingCycleConfiguration( @@ -5220,9 +6163,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5231,7 +6174,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.GroupedWithMeteredMinimum.Metadata.builder() + Price.GroupedWithMinMaxThresholds.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -5239,9 +6182,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5251,7 +6194,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.GroupedWithMeteredMinimum.PriceType.USAGE_PRICE) + .priceType(Price.GroupedWithMinMaxThresholds.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -5261,20 +6204,18 @@ internal class PriceTest { ) .build() - val price = Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum) + val price = Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -5282,24 +6223,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() - assertThat(price.groupedWithMeteredMinimum()).isEqualTo(groupedWithMeteredMinimum) + assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isEqualTo(groupedWithMinMaxThresholds) assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofGroupedWithMeteredMinimumRoundtrip() { + fun ofGroupedWithMinMaxThresholdsRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofGroupedWithMeteredMinimum( - Price.GroupedWithMeteredMinimum.builder() + Price.ofGroupedWithMinMaxThresholds( + Price.GroupedWithMinMaxThresholds.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -5308,7 +6253,21 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.GroupedWithMeteredMinimum.Cadence.ONE_TIME) + .billingMode(Price.GroupedWithMinMaxThresholds.BillingMode.IN_ADVANCE) + .cadence(Price.GroupedWithMinMaxThresholds.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.GroupedWithMinMaxThresholds.CompositePriceFilter.builder() + .field( + Price.GroupedWithMinMaxThresholds.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.GroupedWithMinMaxThresholds.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -5324,6 +6283,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -5334,9 +6300,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5345,9 +6311,13 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) - .groupedWithMeteredMinimumConfig( - Price.GroupedWithMeteredMinimum.GroupedWithMeteredMinimumConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .groupedWithMinMaxThresholdsConfig( + Price.GroupedWithMinMaxThresholds.GroupedWithMinMaxThresholdsConfig + .builder() + .groupingKey("x") + .maximumCharge("maximum_charge") + .minimumCharge("minimum_charge") + .perUnitRate("per_unit_rate") .build() ) .invoicingCycleConfiguration( @@ -5361,9 +6331,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5372,7 +6342,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.GroupedWithMeteredMinimum.Metadata.builder() + Price.GroupedWithMinMaxThresholds.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -5380,9 +6350,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5392,7 +6362,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.GroupedWithMeteredMinimum.PriceType.USAGE_PRICE) + .priceType(Price.GroupedWithMinMaxThresholds.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -5421,7 +6391,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) + .billingMode(Price.MatrixWithDisplayName.BillingMode.IN_ADVANCE) .cadence(Price.MatrixWithDisplayName.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.MatrixWithDisplayName.CompositePriceFilter.builder() + .field(Price.MatrixWithDisplayName.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.MatrixWithDisplayName.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -5437,6 +6417,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -5447,9 +6434,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5467,16 +6454,24 @@ internal class PriceTest { .item(ItemSlim.builder().id("id").name("name").build()) .matrixWithDisplayNameConfig( Price.MatrixWithDisplayName.MatrixWithDisplayNameConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .dimension("dimension") + .addUnitAmount( + Price.MatrixWithDisplayName.MatrixWithDisplayNameConfig.UnitAmount + .builder() + .dimensionValue("dimension_value") + .displayName("display_name") + .unitAmount("unit_amount") + .build() + ) .build() ) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5493,9 +6488,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5518,17 +6513,15 @@ internal class PriceTest { val price = Price.ofMatrixWithDisplayName(matrixWithDisplayName) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -5536,16 +6529,20 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isEqualTo(matrixWithDisplayName) - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test @@ -5562,7 +6559,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) + .billingMode(Price.MatrixWithDisplayName.BillingMode.IN_ADVANCE) .cadence(Price.MatrixWithDisplayName.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.MatrixWithDisplayName.CompositePriceFilter.builder() + .field(Price.MatrixWithDisplayName.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.MatrixWithDisplayName.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -5578,9 +6585,16 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) - .build() - ) - .currency("currency") + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .build() + ) + .currency("currency") .discount( PercentageDiscount.builder() .discountType(PercentageDiscount.DiscountType.PERCENTAGE) @@ -5588,9 +6602,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5608,16 +6622,24 @@ internal class PriceTest { .item(ItemSlim.builder().id("id").name("name").build()) .matrixWithDisplayNameConfig( Price.MatrixWithDisplayName.MatrixWithDisplayNameConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .dimension("dimension") + .addUnitAmount( + Price.MatrixWithDisplayName.MatrixWithDisplayNameConfig.UnitAmount + .builder() + .dimensionValue("dimension_value") + .displayName("display_name") + .unitAmount("unit_amount") + .build() + ) .build() ) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5634,9 +6656,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5664,9 +6686,9 @@ internal class PriceTest { } @Test - fun ofBulkWithProration() { - val bulkWithProration = - Price.BulkWithProration.builder() + fun ofGroupedTieredPackage() { + val groupedTieredPackage = + Price.GroupedTieredPackage.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -5675,12 +6697,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .bulkWithProrationConfig( - Price.BulkWithProration.BulkWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .billingMode(Price.GroupedTieredPackage.BillingMode.IN_ADVANCE) + .cadence(Price.GroupedTieredPackage.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.GroupedTieredPackage.CompositePriceFilter.builder() + .field(Price.GroupedTieredPackage.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.GroupedTieredPackage.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") .build() ) - .cadence(Price.BulkWithProration.Cadence.ONE_TIME) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -5696,6 +6721,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -5706,9 +6738,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5717,6 +6749,24 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) + .groupedTieredPackageConfig( + Price.GroupedTieredPackage.GroupedTieredPackageConfig.builder() + .groupingKey("x") + .packageSize("package_size") + .addTier( + Price.GroupedTieredPackage.GroupedTieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + Price.GroupedTieredPackage.GroupedTieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .build() + ) .invoicingCycleConfiguration( BillingCycleConfiguration.builder() .duration(0L) @@ -5728,9 +6778,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5739,7 +6789,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.BulkWithProration.Metadata.builder() + Price.GroupedTieredPackage.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -5747,9 +6797,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5759,7 +6809,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.BulkWithProration.PriceType.USAGE_PRICE) + .priceType(Price.GroupedTieredPackage.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -5769,20 +6819,18 @@ internal class PriceTest { ) .build() - val price = Price.ofBulkWithProration(bulkWithProration) + val price = Price.ofGroupedTieredPackage(groupedTieredPackage) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -5790,24 +6838,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isEqualTo(bulkWithProration) - assertThat(price.groupedTieredPackage()).isNull() + assertThat(price.groupedTieredPackage()).isEqualTo(groupedTieredPackage) assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofBulkWithProrationRoundtrip() { + fun ofGroupedTieredPackageRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofBulkWithProration( - Price.BulkWithProration.builder() + Price.ofGroupedTieredPackage( + Price.GroupedTieredPackage.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -5816,12 +6868,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .bulkWithProrationConfig( - Price.BulkWithProration.BulkWithProrationConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .billingMode(Price.GroupedTieredPackage.BillingMode.IN_ADVANCE) + .cadence(Price.GroupedTieredPackage.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.GroupedTieredPackage.CompositePriceFilter.builder() + .field(Price.GroupedTieredPackage.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.GroupedTieredPackage.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") .build() ) - .cadence(Price.BulkWithProration.Cadence.ONE_TIME) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -5837,6 +6894,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -5847,9 +6911,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5858,6 +6922,24 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) + .groupedTieredPackageConfig( + Price.GroupedTieredPackage.GroupedTieredPackageConfig.builder() + .groupingKey("x") + .packageSize("package_size") + .addTier( + Price.GroupedTieredPackage.GroupedTieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .addTier( + Price.GroupedTieredPackage.GroupedTieredPackageConfig.Tier.builder() + .perUnit("per_unit") + .tierLowerBound("tier_lower_bound") + .build() + ) + .build() + ) .invoicingCycleConfiguration( BillingCycleConfiguration.builder() .duration(0L) @@ -5869,9 +6951,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5880,7 +6962,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.BulkWithProration.Metadata.builder() + Price.GroupedTieredPackage.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -5888,9 +6970,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5900,7 +6982,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.BulkWithProration.PriceType.USAGE_PRICE) + .priceType(Price.GroupedTieredPackage.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -5918,9 +7000,9 @@ internal class PriceTest { } @Test - fun ofGroupedTieredPackage() { - val groupedTieredPackage = - Price.GroupedTieredPackage.builder() + fun ofMaxGroupTieredPackage() { + val maxGroupTieredPackage = + Price.MaxGroupTieredPackage.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -5929,7 +7011,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.GroupedTieredPackage.Cadence.ONE_TIME) + .billingMode(Price.MaxGroupTieredPackage.BillingMode.IN_ADVANCE) + .cadence(Price.MaxGroupTieredPackage.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.MaxGroupTieredPackage.CompositePriceFilter.builder() + .field(Price.MaxGroupTieredPackage.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.MaxGroupTieredPackage.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -5945,6 +7037,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -5955,9 +7054,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5966,11 +7065,6 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) - .groupedTieredPackageConfig( - Price.GroupedTieredPackage.GroupedTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .invoicingCycleConfiguration( BillingCycleConfiguration.builder() .duration(0L) @@ -5978,13 +7072,31 @@ internal class PriceTest { .build() ) .item(ItemSlim.builder().id("id").name("name").build()) + .maxGroupTieredPackageConfig( + Price.MaxGroupTieredPackage.MaxGroupTieredPackageConfig.builder() + .groupingKey("x") + .packageSize("package_size") + .addTier( + Price.MaxGroupTieredPackage.MaxGroupTieredPackageConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + Price.MaxGroupTieredPackage.MaxGroupTieredPackageConfig.Tier.builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .build() + ) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5993,7 +7105,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.GroupedTieredPackage.Metadata.builder() + Price.MaxGroupTieredPackage.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -6001,9 +7113,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6013,7 +7125,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.GroupedTieredPackage.PriceType.USAGE_PRICE) + .priceType(Price.MaxGroupTieredPackage.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -6023,20 +7135,18 @@ internal class PriceTest { ) .build() - val price = Price.ofGroupedTieredPackage(groupedTieredPackage) + val price = Price.ofMaxGroupTieredPackage(maxGroupTieredPackage) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -6044,24 +7154,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() - assertThat(price.groupedTieredPackage()).isEqualTo(groupedTieredPackage) - assertThat(price.maxGroupTieredPackage()).isNull() + assertThat(price.groupedTieredPackage()).isNull() + assertThat(price.maxGroupTieredPackage()).isEqualTo(maxGroupTieredPackage) assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofGroupedTieredPackageRoundtrip() { + fun ofMaxGroupTieredPackageRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofGroupedTieredPackage( - Price.GroupedTieredPackage.builder() + Price.ofMaxGroupTieredPackage( + Price.MaxGroupTieredPackage.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -6070,7 +7184,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.GroupedTieredPackage.Cadence.ONE_TIME) + .billingMode(Price.MaxGroupTieredPackage.BillingMode.IN_ADVANCE) + .cadence(Price.MaxGroupTieredPackage.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.MaxGroupTieredPackage.CompositePriceFilter.builder() + .field(Price.MaxGroupTieredPackage.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.MaxGroupTieredPackage.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -6086,6 +7210,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -6096,9 +7227,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6107,11 +7238,6 @@ internal class PriceTest { ) .externalPriceId("external_price_id") .fixedPriceQuantity(0.0) - .groupedTieredPackageConfig( - Price.GroupedTieredPackage.GroupedTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .invoicingCycleConfiguration( BillingCycleConfiguration.builder() .duration(0L) @@ -6119,13 +7245,33 @@ internal class PriceTest { .build() ) .item(ItemSlim.builder().id("id").name("name").build()) + .maxGroupTieredPackageConfig( + Price.MaxGroupTieredPackage.MaxGroupTieredPackageConfig.builder() + .groupingKey("x") + .packageSize("package_size") + .addTier( + Price.MaxGroupTieredPackage.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + Price.MaxGroupTieredPackage.MaxGroupTieredPackageConfig.Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .build() + ) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6134,7 +7280,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.GroupedTieredPackage.Metadata.builder() + Price.MaxGroupTieredPackage.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -6142,9 +7288,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6154,7 +7300,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.GroupedTieredPackage.PriceType.USAGE_PRICE) + .priceType(Price.MaxGroupTieredPackage.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -6172,9 +7318,9 @@ internal class PriceTest { } @Test - fun ofMaxGroupTieredPackage() { - val maxGroupTieredPackage = - Price.MaxGroupTieredPackage.builder() + fun ofScalableMatrixWithUnitPricing() { + val scalableMatrixWithUnitPricing = + Price.ScalableMatrixWithUnitPricing.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -6183,7 +7329,20 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.MaxGroupTieredPackage.Cadence.ONE_TIME) + .billingMode(Price.ScalableMatrixWithUnitPricing.BillingMode.IN_ADVANCE) + .cadence(Price.ScalableMatrixWithUnitPricing.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.ScalableMatrixWithUnitPricing.CompositePriceFilter.builder() + .field( + Price.ScalableMatrixWithUnitPricing.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.ScalableMatrixWithUnitPricing.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -6199,6 +7358,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -6209,9 +7375,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6227,18 +7393,706 @@ internal class PriceTest { .build() ) .item(ItemSlim.builder().id("id").name("name").build()) - .maxGroupTieredPackageConfig( - Price.MaxGroupTieredPackage.MaxGroupTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .maximum( + Maximum.builder() + .addAppliesToPriceId("string") + .addFilter( + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Price.ScalableMatrixWithUnitPricing.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Minimum.builder() + .addAppliesToPriceId("string") + .addFilter( + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .name("name") + .planPhaseOrder(0L) + .priceType(Price.ScalableMatrixWithUnitPricing.PriceType.USAGE_PRICE) + .replacesPriceId("replaces_price_id") + .scalableMatrixWithUnitPricingConfig( + Price.ScalableMatrixWithUnitPricing.ScalableMatrixWithUnitPricingConfig + .builder() + .firstDimension("first_dimension") + .addMatrixScalingFactor( + Price.ScalableMatrixWithUnitPricing.ScalableMatrixWithUnitPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .unitPrice("unit_price") + .prorate(true) + .secondDimension("second_dimension") + .build() + ) + .dimensionalPriceConfiguration( + DimensionalPriceConfiguration.builder() + .addDimensionValue("string") + .dimensionalPriceGroupId("dimensional_price_group_id") + .build() + ) + .build() + + val price = Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) + + assertThat(price.unit()).isNull() + assertThat(price.tiered()).isNull() + assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() + assertThat(price.thresholdTotalAmount()).isNull() + assertThat(price.tieredPackage()).isNull() + assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() + assertThat(price.tieredPackageWithMinimum()).isNull() + assertThat(price.packageWithAllocation()).isNull() + assertThat(price.unitWithPercent()).isNull() + assertThat(price.matrixWithAllocation()).isNull() + assertThat(price.tieredWithProration()).isNull() + assertThat(price.unitWithProration()).isNull() + assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() + assertThat(price.groupedWithProratedMinimum()).isNull() + assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.matrixWithDisplayName()).isNull() + assertThat(price.groupedTieredPackage()).isNull() + assertThat(price.maxGroupTieredPackage()).isNull() + assertThat(price.scalableMatrixWithUnitPricing()).isEqualTo(scalableMatrixWithUnitPricing) + assertThat(price.scalableMatrixWithTieredPricing()).isNull() + assertThat(price.cumulativeGroupedBulk()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() + } + + @Test + fun ofScalableMatrixWithUnitPricingRoundtrip() { + val jsonMapper = jsonMapper() + val price = + Price.ofScalableMatrixWithUnitPricing( + Price.ScalableMatrixWithUnitPricing.builder() + .id("id") + .billableMetric(BillableMetricTiny.builder().id("id").build()) + .billingCycleConfiguration( + BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) + .build() + ) + .billingMode(Price.ScalableMatrixWithUnitPricing.BillingMode.IN_ADVANCE) + .cadence(Price.ScalableMatrixWithUnitPricing.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.ScalableMatrixWithUnitPricing.CompositePriceFilter.builder() + .field( + Price.ScalableMatrixWithUnitPricing.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.ScalableMatrixWithUnitPricing.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) + .conversionRate(0.0) + .unitConversionRateConfig( + ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() + ) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Allocation.builder() + .allowsRollover(true) + .currency("currency") + .customExpiration( + CustomExpiration.builder() + .duration(0L) + .durationUnit(CustomExpiration.DurationUnit.DAY) + .build() + ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .build() + ) + .currency("currency") + .discount( + PercentageDiscount.builder() + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .addFilter( + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .reason("reason") + .build() + ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) + .invoicingCycleConfiguration( + BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) + .build() + ) + .item(ItemSlim.builder().id("id").name("name").build()) + .maximum( + Maximum.builder() + .addAppliesToPriceId("string") + .addFilter( + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Price.ScalableMatrixWithUnitPricing.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Minimum.builder() + .addAppliesToPriceId("string") + .addFilter( + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .name("name") + .planPhaseOrder(0L) + .priceType(Price.ScalableMatrixWithUnitPricing.PriceType.USAGE_PRICE) + .replacesPriceId("replaces_price_id") + .scalableMatrixWithUnitPricingConfig( + Price.ScalableMatrixWithUnitPricing.ScalableMatrixWithUnitPricingConfig + .builder() + .firstDimension("first_dimension") + .addMatrixScalingFactor( + Price.ScalableMatrixWithUnitPricing + .ScalableMatrixWithUnitPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .unitPrice("unit_price") + .prorate(true) + .secondDimension("second_dimension") + .build() + ) + .dimensionalPriceConfiguration( + DimensionalPriceConfiguration.builder() + .addDimensionValue("string") + .dimensionalPriceGroupId("dimensional_price_group_id") + .build() + ) + .build() + ) + + val roundtrippedPrice = + jsonMapper.readValue(jsonMapper.writeValueAsString(price), jacksonTypeRef()) + + assertThat(roundtrippedPrice).isEqualTo(price) + } + + @Test + fun ofScalableMatrixWithTieredPricing() { + val scalableMatrixWithTieredPricing = + Price.ScalableMatrixWithTieredPricing.builder() + .id("id") + .billableMetric(BillableMetricTiny.builder().id("id").build()) + .billingCycleConfiguration( + BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) + .build() + ) + .billingMode(Price.ScalableMatrixWithTieredPricing.BillingMode.IN_ADVANCE) + .cadence(Price.ScalableMatrixWithTieredPricing.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.ScalableMatrixWithTieredPricing.CompositePriceFilter.builder() + .field( + Price.ScalableMatrixWithTieredPricing.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.ScalableMatrixWithTieredPricing.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) + .conversionRate(0.0) + .unitConversionRateConfig( + ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() + ) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Allocation.builder() + .allowsRollover(true) + .currency("currency") + .customExpiration( + CustomExpiration.builder() + .duration(0L) + .durationUnit(CustomExpiration.DurationUnit.DAY) + .build() + ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .build() + ) + .currency("currency") + .discount( + PercentageDiscount.builder() + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .addFilter( + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .reason("reason") + .build() + ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) + .invoicingCycleConfiguration( + BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) + .build() + ) + .item(ItemSlim.builder().id("id").name("name").build()) + .maximum( + Maximum.builder() + .addAppliesToPriceId("string") + .addFilter( + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Price.ScalableMatrixWithTieredPricing.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Minimum.builder() + .addAppliesToPriceId("string") + .addFilter( + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .name("name") + .planPhaseOrder(0L) + .priceType(Price.ScalableMatrixWithTieredPricing.PriceType.USAGE_PRICE) + .replacesPriceId("replaces_price_id") + .scalableMatrixWithTieredPricingConfig( + Price.ScalableMatrixWithTieredPricing.ScalableMatrixWithTieredPricingConfig + .builder() + .firstDimension("first_dimension") + .addMatrixScalingFactor( + Price.ScalableMatrixWithTieredPricing + .ScalableMatrixWithTieredPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .addTier( + Price.ScalableMatrixWithTieredPricing + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + Price.ScalableMatrixWithTieredPricing + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .secondDimension("second_dimension") + .build() + ) + .dimensionalPriceConfiguration( + DimensionalPriceConfiguration.builder() + .addDimensionValue("string") + .dimensionalPriceGroupId("dimensional_price_group_id") + .build() + ) + .build() + + val price = Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing) + + assertThat(price.unit()).isNull() + assertThat(price.tiered()).isNull() + assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() + assertThat(price.thresholdTotalAmount()).isNull() + assertThat(price.tieredPackage()).isNull() + assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() + assertThat(price.tieredPackageWithMinimum()).isNull() + assertThat(price.packageWithAllocation()).isNull() + assertThat(price.unitWithPercent()).isNull() + assertThat(price.matrixWithAllocation()).isNull() + assertThat(price.tieredWithProration()).isNull() + assertThat(price.unitWithProration()).isNull() + assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() + assertThat(price.groupedWithProratedMinimum()).isNull() + assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.matrixWithDisplayName()).isNull() + assertThat(price.groupedTieredPackage()).isNull() + assertThat(price.maxGroupTieredPackage()).isNull() + assertThat(price.scalableMatrixWithUnitPricing()).isNull() + assertThat(price.scalableMatrixWithTieredPricing()) + .isEqualTo(scalableMatrixWithTieredPricing) + assertThat(price.cumulativeGroupedBulk()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() + } + + @Test + fun ofScalableMatrixWithTieredPricingRoundtrip() { + val jsonMapper = jsonMapper() + val price = + Price.ofScalableMatrixWithTieredPricing( + Price.ScalableMatrixWithTieredPricing.builder() + .id("id") + .billableMetric(BillableMetricTiny.builder().id("id").build()) + .billingCycleConfiguration( + BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) + .build() + ) + .billingMode(Price.ScalableMatrixWithTieredPricing.BillingMode.IN_ADVANCE) + .cadence(Price.ScalableMatrixWithTieredPricing.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.ScalableMatrixWithTieredPricing.CompositePriceFilter.builder() + .field( + Price.ScalableMatrixWithTieredPricing.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.ScalableMatrixWithTieredPricing.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) + .conversionRate(0.0) + .unitConversionRateConfig( + ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() + ) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Allocation.builder() + .allowsRollover(true) + .currency("currency") + .customExpiration( + CustomExpiration.builder() + .duration(0L) + .durationUnit(CustomExpiration.DurationUnit.DAY) + .build() + ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .build() + ) + .currency("currency") + .discount( + PercentageDiscount.builder() + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .addFilter( + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .reason("reason") + .build() + ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) + .invoicingCycleConfiguration( + BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) + .build() + ) + .item(ItemSlim.builder().id("id").name("name").build()) + .maximum( + Maximum.builder() + .addAppliesToPriceId("string") + .addFilter( + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Price.ScalableMatrixWithTieredPricing.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Minimum.builder() + .addAppliesToPriceId("string") + .addFilter( + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .name("name") + .planPhaseOrder(0L) + .priceType(Price.ScalableMatrixWithTieredPricing.PriceType.USAGE_PRICE) + .replacesPriceId("replaces_price_id") + .scalableMatrixWithTieredPricingConfig( + Price.ScalableMatrixWithTieredPricing.ScalableMatrixWithTieredPricingConfig + .builder() + .firstDimension("first_dimension") + .addMatrixScalingFactor( + Price.ScalableMatrixWithTieredPricing + .ScalableMatrixWithTieredPricingConfig + .MatrixScalingFactor + .builder() + .firstDimensionValue("first_dimension_value") + .scalingFactor("scaling_factor") + .secondDimensionValue("second_dimension_value") + .build() + ) + .addTier( + Price.ScalableMatrixWithTieredPricing + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .addTier( + Price.ScalableMatrixWithTieredPricing + .ScalableMatrixWithTieredPricingConfig + .Tier + .builder() + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .secondDimension("second_dimension") + .build() + ) + .dimensionalPriceConfiguration( + DimensionalPriceConfiguration.builder() + .addDimensionValue("string") + .dimensionalPriceGroupId("dimensional_price_group_id") + .build() + ) + .build() + ) + + val roundtrippedPrice = + jsonMapper.readValue(jsonMapper.writeValueAsString(price), jacksonTypeRef()) + + assertThat(roundtrippedPrice).isEqualTo(price) + } + + @Test + fun ofCumulativeGroupedBulk() { + val cumulativeGroupedBulk = + Price.CumulativeGroupedBulk.builder() + .id("id") + .billableMetric(BillableMetricTiny.builder().id("id").build()) + .billingCycleConfiguration( + BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) + .build() + ) + .billingMode(Price.CumulativeGroupedBulk.BillingMode.IN_ADVANCE) + .cadence(Price.CumulativeGroupedBulk.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.CumulativeGroupedBulk.CompositePriceFilter.builder() + .field(Price.CumulativeGroupedBulk.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.CumulativeGroupedBulk.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) + .conversionRate(0.0) + .unitConversionRateConfig( + ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() + ) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Allocation.builder() + .allowsRollover(true) + .currency("currency") + .customExpiration( + CustomExpiration.builder() + .duration(0L) + .durationUnit(CustomExpiration.DurationUnit.DAY) + .build() + ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .build() + ) + .cumulativeGroupedBulkConfig( + Price.CumulativeGroupedBulk.CumulativeGroupedBulkConfig.builder() + .addDimensionValue( + Price.CumulativeGroupedBulk.CumulativeGroupedBulkConfig.DimensionValue + .builder() + .groupingKey("x") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .group("group") + .build() + ) + .currency("currency") + .discount( + PercentageDiscount.builder() + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .addFilter( + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .reason("reason") + .build() + ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) + .invoicingCycleConfiguration( + BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) + .item(ItemSlim.builder().id("id").name("name").build()) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6247,7 +8101,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.MaxGroupTieredPackage.Metadata.builder() + Price.CumulativeGroupedBulk.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -6255,9 +8109,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6267,7 +8121,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.MaxGroupTieredPackage.PriceType.USAGE_PRICE) + .priceType(Price.CumulativeGroupedBulk.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -6277,20 +8131,18 @@ internal class PriceTest { ) .build() - val price = Price.ofMaxGroupTieredPackage(maxGroupTieredPackage) + val price = Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -6298,24 +8150,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() - assertThat(price.maxGroupTieredPackage()).isEqualTo(maxGroupTieredPackage) + assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() - assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedBulk()).isEqualTo(cumulativeGroupedBulk) + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofMaxGroupTieredPackageRoundtrip() { + fun ofCumulativeGroupedBulkRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofMaxGroupTieredPackage( - Price.MaxGroupTieredPackage.builder() + Price.ofCumulativeGroupedBulk( + Price.CumulativeGroupedBulk.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -6324,7 +8180,17 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.MaxGroupTieredPackage.Cadence.ONE_TIME) + .billingMode(Price.CumulativeGroupedBulk.BillingMode.IN_ADVANCE) + .cadence(Price.CumulativeGroupedBulk.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.CumulativeGroupedBulk.CompositePriceFilter.builder() + .field(Price.CumulativeGroupedBulk.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.CumulativeGroupedBulk.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -6340,6 +8206,27 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .build() + ) + .cumulativeGroupedBulkConfig( + Price.CumulativeGroupedBulk.CumulativeGroupedBulkConfig.builder() + .addDimensionValue( + Price.CumulativeGroupedBulk.CumulativeGroupedBulkConfig + .DimensionValue + .builder() + .groupingKey("x") + .tierLowerBound("tier_lower_bound") + .unitAmount("unit_amount") + .build() + ) + .group("group") .build() ) .currency("currency") @@ -6350,9 +8237,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6368,18 +8255,13 @@ internal class PriceTest { .build() ) .item(ItemSlim.builder().id("id").name("name").build()) - .maxGroupTieredPackageConfig( - Price.MaxGroupTieredPackage.MaxGroupTieredPackageConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .maximum( Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6388,7 +8270,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.MaxGroupTieredPackage.Metadata.builder() + Price.CumulativeGroupedBulk.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -6396,9 +8278,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6408,7 +8290,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.MaxGroupTieredPackage.PriceType.USAGE_PRICE) + .priceType(Price.CumulativeGroupedBulk.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -6426,9 +8308,9 @@ internal class PriceTest { } @Test - fun ofScalableMatrixWithUnitPricing() { - val scalableMatrixWithUnitPricing = - Price.ScalableMatrixWithUnitPricing.builder() + fun ofCumulativeGroupedAllocation() { + val cumulativeGroupedAllocation = + Price.CumulativeGroupedAllocation.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -6437,7 +8319,19 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.ScalableMatrixWithUnitPricing.Cadence.ONE_TIME) + .billingMode(Price.CumulativeGroupedAllocation.BillingMode.IN_ADVANCE) + .cadence(Price.CumulativeGroupedAllocation.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.CumulativeGroupedAllocation.CompositePriceFilter.builder() + .field( + Price.CumulativeGroupedAllocation.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.CumulativeGroupedAllocation.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -6453,6 +8347,21 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .build() + ) + .cumulativeGroupedAllocationConfig( + Price.CumulativeGroupedAllocation.CumulativeGroupedAllocationConfig.builder() + .cumulativeAllocation("cumulative_allocation") + .groupAllocation("group_allocation") + .groupingKey("x") + .unitAmount("unit_amount") .build() ) .currency("currency") @@ -6463,9 +8372,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6485,9 +8394,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6496,7 +8405,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.ScalableMatrixWithUnitPricing.Metadata.builder() + Price.CumulativeGroupedAllocation.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -6504,9 +8413,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6516,14 +8425,8 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.ScalableMatrixWithUnitPricing.PriceType.USAGE_PRICE) + .priceType(Price.CumulativeGroupedAllocation.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .scalableMatrixWithUnitPricingConfig( - Price.ScalableMatrixWithUnitPricing.ScalableMatrixWithUnitPricingConfig - .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -6532,20 +8435,18 @@ internal class PriceTest { ) .build() - val price = Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing) + val price = Price.ofCumulativeGroupedAllocation(cumulativeGroupedAllocation) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -6553,24 +8454,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() - assertThat(price.scalableMatrixWithUnitPricing()).isEqualTo(scalableMatrixWithUnitPricing) + assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isEqualTo(cumulativeGroupedAllocation) + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofScalableMatrixWithUnitPricingRoundtrip() { + fun ofCumulativeGroupedAllocationRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofScalableMatrixWithUnitPricing( - Price.ScalableMatrixWithUnitPricing.builder() + Price.ofCumulativeGroupedAllocation( + Price.CumulativeGroupedAllocation.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -6579,7 +8484,21 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.ScalableMatrixWithUnitPricing.Cadence.ONE_TIME) + .billingMode(Price.CumulativeGroupedAllocation.BillingMode.IN_ADVANCE) + .cadence(Price.CumulativeGroupedAllocation.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.CumulativeGroupedAllocation.CompositePriceFilter.builder() + .field( + Price.CumulativeGroupedAllocation.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.CumulativeGroupedAllocation.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -6595,6 +8514,22 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .build() + ) + .cumulativeGroupedAllocationConfig( + Price.CumulativeGroupedAllocation.CumulativeGroupedAllocationConfig + .builder() + .cumulativeAllocation("cumulative_allocation") + .groupAllocation("group_allocation") + .groupingKey("x") + .unitAmount("unit_amount") .build() ) .currency("currency") @@ -6605,9 +8540,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6627,9 +8562,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6638,7 +8573,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.ScalableMatrixWithUnitPricing.Metadata.builder() + Price.CumulativeGroupedAllocation.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -6646,9 +8581,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6658,14 +8593,8 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.ScalableMatrixWithUnitPricing.PriceType.USAGE_PRICE) + .priceType(Price.CumulativeGroupedAllocation.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .scalableMatrixWithUnitPricingConfig( - Price.ScalableMatrixWithUnitPricing.ScalableMatrixWithUnitPricingConfig - .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -6682,9 +8611,9 @@ internal class PriceTest { } @Test - fun ofScalableMatrixWithTieredPricing() { - val scalableMatrixWithTieredPricing = - Price.ScalableMatrixWithTieredPricing.builder() + fun ofMinimum() { + val minimum = + Price.Minimum.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -6693,7 +8622,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.ScalableMatrixWithTieredPricing.Cadence.ONE_TIME) + .billingMode(Price.Minimum.BillingMode.IN_ADVANCE) + .cadence(Price.Minimum.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.Minimum.CompositePriceFilter.builder() + .field(Price.Minimum.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.Minimum.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -6709,6 +8646,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -6719,9 +8663,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6741,9 +8685,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6752,7 +8696,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.ScalableMatrixWithTieredPricing.Metadata.builder() + Price.Minimum.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -6760,9 +8704,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6770,16 +8714,16 @@ internal class PriceTest { .build() ) .minimumAmount("minimum_amount") + .minimumConfig( + Price.Minimum.MinimumConfig.builder() + .minimumAmount("minimum_amount") + .prorated(true) + .build() + ) .name("name") .planPhaseOrder(0L) - .priceType(Price.ScalableMatrixWithTieredPricing.PriceType.USAGE_PRICE) + .priceType(Price.Minimum.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .scalableMatrixWithTieredPricingConfig( - Price.ScalableMatrixWithTieredPricing.ScalableMatrixWithTieredPricingConfig - .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -6788,20 +8732,18 @@ internal class PriceTest { ) .build() - val price = Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing) + val price = Price.ofMinimum(minimum) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -6809,25 +8751,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() - assertThat(price.scalableMatrixWithTieredPricing()) - .isEqualTo(scalableMatrixWithTieredPricing) + assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isEqualTo(minimum) + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isNull() } @Test - fun ofScalableMatrixWithTieredPricingRoundtrip() { + fun ofMinimumRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofScalableMatrixWithTieredPricing( - Price.ScalableMatrixWithTieredPricing.builder() + Price.ofMinimum( + Price.Minimum.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -6836,7 +8781,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.ScalableMatrixWithTieredPricing.Cadence.ONE_TIME) + .billingMode(Price.Minimum.BillingMode.IN_ADVANCE) + .cadence(Price.Minimum.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.Minimum.CompositePriceFilter.builder() + .field(Price.Minimum.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.Minimum.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -6852,6 +8805,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -6862,9 +8822,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6884,9 +8844,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6895,7 +8855,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.ScalableMatrixWithTieredPricing.Metadata.builder() + Price.Minimum.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -6903,9 +8863,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -6913,16 +8873,16 @@ internal class PriceTest { .build() ) .minimumAmount("minimum_amount") + .minimumConfig( + Price.Minimum.MinimumConfig.builder() + .minimumAmount("minimum_amount") + .prorated(true) + .build() + ) .name("name") .planPhaseOrder(0L) - .priceType(Price.ScalableMatrixWithTieredPricing.PriceType.USAGE_PRICE) + .priceType(Price.Minimum.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .scalableMatrixWithTieredPricingConfig( - Price.ScalableMatrixWithTieredPricing.ScalableMatrixWithTieredPricingConfig - .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) - .build() - ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -6939,9 +8899,9 @@ internal class PriceTest { } @Test - fun ofCumulativeGroupedBulk() { - val cumulativeGroupedBulk = - Price.CumulativeGroupedBulk.builder() + fun ofPercent() { + val percent = + Price.Percent.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -6950,7 +8910,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.CumulativeGroupedBulk.Cadence.ONE_TIME) + .billingMode(Price.Percent.BillingMode.IN_ADVANCE) + .cadence(Price.Percent.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.Percent.CompositePriceFilter.builder() + .field(Price.Percent.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.Percent.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -6966,11 +8934,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) - .build() - ) - .cumulativeGroupedBulkConfig( - Price.CumulativeGroupedBulk.CumulativeGroupedBulkConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -6981,9 +8951,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -7003,9 +8973,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -7014,7 +8984,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.CumulativeGroupedBulk.Metadata.builder() + Price.Percent.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -7022,9 +8992,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -7033,8 +9003,9 @@ internal class PriceTest { ) .minimumAmount("minimum_amount") .name("name") + .percentConfig(Price.Percent.PercentConfig.builder().percent(0.0).build()) .planPhaseOrder(0L) - .priceType(Price.CumulativeGroupedBulk.PriceType.USAGE_PRICE) + .priceType(Price.Percent.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -7044,20 +9015,18 @@ internal class PriceTest { ) .build() - val price = Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk) + val price = Price.ofPercent(percent) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -7065,24 +9034,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() - assertThat(price.cumulativeGroupedBulk()).isEqualTo(cumulativeGroupedBulk) - assertThat(price.groupedWithMinMaxThresholds()).isNull() + assertThat(price.cumulativeGroupedBulk()).isNull() + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isEqualTo(percent) + assertThat(price.eventOutput()).isNull() } @Test - fun ofCumulativeGroupedBulkRoundtrip() { + fun ofPercentRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofCumulativeGroupedBulk( - Price.CumulativeGroupedBulk.builder() + Price.ofPercent( + Price.Percent.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -7091,7 +9064,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.CumulativeGroupedBulk.Cadence.ONE_TIME) + .billingMode(Price.Percent.BillingMode.IN_ADVANCE) + .cadence(Price.Percent.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.Percent.CompositePriceFilter.builder() + .field(Price.Percent.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.Percent.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -7107,11 +9088,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) - .build() - ) - .cumulativeGroupedBulkConfig( - Price.CumulativeGroupedBulk.CumulativeGroupedBulkConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -7122,9 +9105,9 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -7144,9 +9127,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -7155,7 +9138,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.CumulativeGroupedBulk.Metadata.builder() + Price.Percent.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -7163,9 +9146,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -7174,8 +9157,9 @@ internal class PriceTest { ) .minimumAmount("minimum_amount") .name("name") + .percentConfig(Price.Percent.PercentConfig.builder().percent(0.0).build()) .planPhaseOrder(0L) - .priceType(Price.CumulativeGroupedBulk.PriceType.USAGE_PRICE) + .priceType(Price.Percent.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -7193,9 +9177,9 @@ internal class PriceTest { } @Test - fun ofGroupedWithMinMaxThresholds() { - val groupedWithMinMaxThresholds = - Price.GroupedWithMinMaxThresholds.builder() + fun ofEventOutput() { + val eventOutput = + Price.EventOutput.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -7204,7 +9188,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.GroupedWithMinMaxThresholds.Cadence.ONE_TIME) + .billingMode(Price.EventOutput.BillingMode.IN_ADVANCE) + .cadence(Price.EventOutput.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.EventOutput.CompositePriceFilter.builder() + .field(Price.EventOutput.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.EventOutput.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -7220,6 +9212,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -7230,22 +9229,24 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) .reason("reason") .build() ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .groupedWithMinMaxThresholdsConfig( - Price.GroupedWithMinMaxThresholds.GroupedWithMinMaxThresholdsConfig.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .eventOutputConfig( + Price.EventOutput.EventOutputConfig.builder() + .unitRatingKey("x") + .defaultUnitRate("default_unit_rate") + .groupingKey("grouping_key") .build() ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) .invoicingCycleConfiguration( BillingCycleConfiguration.builder() .duration(0L) @@ -7257,9 +9258,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -7268,7 +9269,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.GroupedWithMinMaxThresholds.Metadata.builder() + Price.EventOutput.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -7276,9 +9277,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -7288,7 +9289,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.GroupedWithMinMaxThresholds.PriceType.USAGE_PRICE) + .priceType(Price.EventOutput.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -7298,20 +9299,18 @@ internal class PriceTest { ) .build() - val price = Price.ofGroupedWithMinMaxThresholds(groupedWithMinMaxThresholds) + val price = Price.ofEventOutput(eventOutput) assertThat(price.unit()).isNull() - assertThat(price.package_()).isNull() - assertThat(price.matrix()).isNull() assertThat(price.tiered()).isNull() - assertThat(price.tieredBps()).isNull() - assertThat(price.bps()).isNull() - assertThat(price.bulkBps()).isNull() assertThat(price.bulk()).isNull() + assertThat(price.bulkWithFilters()).isNull() + assertThat(price.package_()).isNull() + assertThat(price.matrix()).isNull() assertThat(price.thresholdTotalAmount()).isNull() assertThat(price.tieredPackage()).isNull() - assertThat(price.groupedTiered()).isNull() assertThat(price.tieredWithMinimum()).isNull() + assertThat(price.groupedTiered()).isNull() assertThat(price.tieredPackageWithMinimum()).isNull() assertThat(price.packageWithAllocation()).isNull() assertThat(price.unitWithPercent()).isNull() @@ -7319,24 +9318,28 @@ internal class PriceTest { assertThat(price.tieredWithProration()).isNull() assertThat(price.unitWithProration()).isNull() assertThat(price.groupedAllocation()).isNull() + assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedWithProratedMinimum()).isNull() assertThat(price.groupedWithMeteredMinimum()).isNull() + assertThat(price.groupedWithMinMaxThresholds()).isNull() assertThat(price.matrixWithDisplayName()).isNull() - assertThat(price.bulkWithProration()).isNull() assertThat(price.groupedTieredPackage()).isNull() assertThat(price.maxGroupTieredPackage()).isNull() assertThat(price.scalableMatrixWithUnitPricing()).isNull() assertThat(price.scalableMatrixWithTieredPricing()).isNull() assertThat(price.cumulativeGroupedBulk()).isNull() - assertThat(price.groupedWithMinMaxThresholds()).isEqualTo(groupedWithMinMaxThresholds) + assertThat(price.cumulativeGroupedAllocation()).isNull() + assertThat(price.minimum()).isNull() + assertThat(price.percent()).isNull() + assertThat(price.eventOutput()).isEqualTo(eventOutput) } @Test - fun ofGroupedWithMinMaxThresholdsRoundtrip() { + fun ofEventOutputRoundtrip() { val jsonMapper = jsonMapper() val price = - Price.ofGroupedWithMinMaxThresholds( - Price.GroupedWithMinMaxThresholds.builder() + Price.ofEventOutput( + Price.EventOutput.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -7345,7 +9348,15 @@ internal class PriceTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.GroupedWithMinMaxThresholds.Cadence.ONE_TIME) + .billingMode(Price.EventOutput.BillingMode.IN_ADVANCE) + .cadence(Price.EventOutput.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.EventOutput.CompositePriceFilter.builder() + .field(Price.EventOutput.CompositePriceFilter.Field.PRICE_ID) + .operator(Price.EventOutput.CompositePriceFilter.Operator.INCLUDES) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -7361,6 +9372,13 @@ internal class PriceTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -7371,23 +9389,24 @@ internal class PriceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) .reason("reason") .build() ) - .externalPriceId("external_price_id") - .fixedPriceQuantity(0.0) - .groupedWithMinMaxThresholdsConfig( - Price.GroupedWithMinMaxThresholds.GroupedWithMinMaxThresholdsConfig - .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .eventOutputConfig( + Price.EventOutput.EventOutputConfig.builder() + .unitRatingKey("x") + .defaultUnitRate("default_unit_rate") + .groupingKey("grouping_key") .build() ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) .invoicingCycleConfiguration( BillingCycleConfiguration.builder() .duration(0L) @@ -7399,9 +9418,9 @@ internal class PriceTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -7410,7 +9429,7 @@ internal class PriceTest { ) .maximumAmount("maximum_amount") .metadata( - Price.GroupedWithMinMaxThresholds.Metadata.builder() + Price.EventOutput.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -7418,9 +9437,9 @@ internal class PriceTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -7430,7 +9449,7 @@ internal class PriceTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.GroupedWithMinMaxThresholds.PriceType.USAGE_PRICE) + .priceType(Price.EventOutput.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeApplyParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeApplyParamsTest.kt index 112683b79..aa16826a5 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeApplyParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeApplyParamsTest.kt @@ -2,6 +2,7 @@ package com.withorb.api.models +import java.time.LocalDate import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -12,6 +13,10 @@ internal class SubscriptionChangeApplyParamsTest { SubscriptionChangeApplyParams.builder() .subscriptionChangeId("subscription_change_id") .description("description") + .markAsPaid(true) + .paymentExternalId("payment_external_id") + .paymentNotes("payment_notes") + .paymentReceivedDate(LocalDate.parse("2019-12-27")) .previouslyCollectedAmount("previously_collected_amount") .build() } @@ -34,12 +39,20 @@ internal class SubscriptionChangeApplyParamsTest { SubscriptionChangeApplyParams.builder() .subscriptionChangeId("subscription_change_id") .description("description") + .markAsPaid(true) + .paymentExternalId("payment_external_id") + .paymentNotes("payment_notes") + .paymentReceivedDate(LocalDate.parse("2019-12-27")) .previouslyCollectedAmount("previously_collected_amount") .build() val body = params._body() assertThat(body.description()).isEqualTo("description") + assertThat(body.markAsPaid()).isEqualTo(true) + assertThat(body.paymentExternalId()).isEqualTo("payment_external_id") + assertThat(body.paymentNotes()).isEqualTo("payment_notes") + assertThat(body.paymentReceivedDate()).isEqualTo(LocalDate.parse("2019-12-27")) assertThat(body.previouslyCollectedAmount()).isEqualTo("previously_collected_amount") } diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeApplyResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeApplyResponseTest.kt index 34dde21f7..e7bc57a31 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeApplyResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeApplyResponseTest.kt @@ -16,6 +16,7 @@ internal class SubscriptionChangeApplyResponseTest { val subscriptionChangeApplyResponse = SubscriptionChangeApplyResponse.builder() .id("id") + .changeType("change_type") .expirationTime(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .status(SubscriptionChangeApplyResponse.Status.PENDING) .subscription( @@ -34,9 +35,15 @@ internal class SubscriptionChangeApplyResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -73,6 +80,7 @@ internal class SubscriptionChangeApplyResponseTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -150,6 +158,21 @@ internal class SubscriptionChangeApplyResponseTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -163,9 +186,9 @@ internal class SubscriptionChangeApplyResponseTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -187,9 +210,9 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -207,9 +230,9 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -234,9 +257,15 @@ internal class SubscriptionChangeApplyResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -266,9 +295,11 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -281,9 +312,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -300,9 +331,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -325,10 +356,13 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -342,11 +376,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -358,11 +390,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -375,7 +405,7 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -388,7 +418,21 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -408,6 +452,15 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -420,10 +473,13 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -446,11 +502,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -459,7 +513,7 @@ internal class SubscriptionChangeApplyResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -470,11 +524,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -484,10 +536,13 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -520,6 +575,7 @@ internal class SubscriptionChangeApplyResponseTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -538,7 +594,7 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -551,7 +607,21 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -571,6 +641,15 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -583,10 +662,13 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -609,11 +691,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -622,7 +702,7 @@ internal class SubscriptionChangeApplyResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -633,11 +713,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -647,10 +725,13 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -778,11 +859,13 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice + .AutoCollection + .builder() .enabled(true) .nextAttemptAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") @@ -807,7 +890,8 @@ internal class SubscriptionChangeApplyResponseTest { OffsetDateTime.parse("2022-05-01T07:01:31+00:00") ) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote + .builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -829,10 +913,14 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action .APPLIED_TO_INVOICE ) .amount("11.00") @@ -853,7 +941,9 @@ internal class SubscriptionChangeApplyResponseTest { ) .startingBalance("33.00") .type( - Invoice.CustomerBalanceTransaction.Type + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type .INCREMENT ) .build() @@ -875,10 +965,13 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -898,13 +991,19 @@ internal class SubscriptionChangeApplyResponseTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice + .InvoiceSource + .SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem + .builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -918,13 +1017,18 @@ internal class SubscriptionChangeApplyResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field + MonetaryUsageDiscountAdjustment + .Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -940,31 +1044,6 @@ internal class SubscriptionChangeApplyResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType - .PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse( "2022-02-01T08:00:00+00:00" @@ -972,50 +1051,10 @@ internal class SubscriptionChangeApplyResponseTest { ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -1032,7 +1071,28 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice + .CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice + .CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1058,6 +1118,20 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1075,14 +1149,17 @@ internal class SubscriptionChangeApplyResponseTest { "7hfgtgjnbvc3ujkl" ) .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter + .builder() .field( - TransformPriceFilter + PercentageDiscount + .Filter .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount + .Filter .Operator .INCLUDES ) @@ -1114,15 +1191,13 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter - .Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -1133,7 +1208,7 @@ internal class SubscriptionChangeApplyResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1144,15 +1219,13 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter - .Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -1164,11 +1237,14 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -1204,6 +1280,7 @@ internal class SubscriptionChangeApplyResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1221,11 +1298,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1235,7 +1310,8 @@ internal class SubscriptionChangeApplyResponseTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata + .builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1246,11 +1322,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1260,16 +1334,24 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .builder() .id("id") .amount("amount") .createdAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .paymentProvider( - Invoice.PaymentAttempt.PaymentProvider.STRIPE + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .PaymentProvider + .STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -1292,7 +1374,10 @@ internal class SubscriptionChangeApplyResponseTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status( + ChangedSubscriptionResources.CreatedInvoice.Status + .ISSUED + ) .subscription( SubscriptionMinified.builder() .id("VDGsT23osdLb84KD") @@ -1500,10 +1585,13 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -1543,13 +1631,18 @@ internal class SubscriptionChangeApplyResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field + MonetaryUsageDiscountAdjustment + .Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -1565,31 +1658,6 @@ internal class SubscriptionChangeApplyResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType - .PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse( "2022-02-01T08:00:00+00:00" @@ -1597,50 +1665,10 @@ internal class SubscriptionChangeApplyResponseTest { ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -1657,7 +1685,28 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice + .CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice + .CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1683,6 +1732,20 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1700,14 +1763,17 @@ internal class SubscriptionChangeApplyResponseTest { "7hfgtgjnbvc3ujkl" ) .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter + .builder() .field( - TransformPriceFilter + PercentageDiscount + .Filter .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount + .Filter .Operator .INCLUDES ) @@ -1739,15 +1805,13 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter - .Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -1758,7 +1822,7 @@ internal class SubscriptionChangeApplyResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1769,15 +1833,13 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter - .Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -1789,11 +1851,14 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -1829,6 +1894,7 @@ internal class SubscriptionChangeApplyResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1846,11 +1912,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1871,11 +1935,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1895,6 +1957,9 @@ internal class SubscriptionChangeApplyResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -1937,10 +2002,15 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .appliedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .billingCycleAlignment("billing_cycle_alignment") .cancelledAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .changeOption("change_option") + .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .planId("plan_id") .build() assertThat(subscriptionChangeApplyResponse.id()).isEqualTo("id") + assertThat(subscriptionChangeApplyResponse.changeType()).isEqualTo("change_type") assertThat(subscriptionChangeApplyResponse.expirationTime()) .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(subscriptionChangeApplyResponse.status()) @@ -1962,9 +2032,15 @@ internal class SubscriptionChangeApplyResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -1993,6 +2069,7 @@ internal class SubscriptionChangeApplyResponseTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -2070,6 +2147,21 @@ internal class SubscriptionChangeApplyResponseTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -2083,9 +2175,9 @@ internal class SubscriptionChangeApplyResponseTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2107,9 +2199,9 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2127,9 +2219,9 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2154,9 +2246,15 @@ internal class SubscriptionChangeApplyResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -2186,9 +2284,9 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2201,9 +2299,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2220,9 +2318,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2245,10 +2343,10 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2262,11 +2360,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2278,11 +2374,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2295,7 +2389,7 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2306,7 +2400,20 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -2324,6 +2431,13 @@ internal class SubscriptionChangeApplyResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2336,10 +2450,10 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2362,11 +2476,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2375,7 +2487,7 @@ internal class SubscriptionChangeApplyResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2383,11 +2495,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2397,10 +2507,13 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -2431,6 +2544,7 @@ internal class SubscriptionChangeApplyResponseTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -2447,7 +2561,7 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2458,7 +2572,20 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -2476,6 +2603,13 @@ internal class SubscriptionChangeApplyResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2488,10 +2622,10 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2514,11 +2648,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2527,7 +2659,7 @@ internal class SubscriptionChangeApplyResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2535,11 +2667,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2549,10 +2679,13 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -2676,11 +2809,12 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice.AutoCollection + .builder() .enabled(true) .nextAttemptAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") @@ -2703,7 +2837,8 @@ internal class SubscriptionChangeApplyResponseTest { ) .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote + .builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -2723,10 +2858,14 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action .APPLIED_TO_INVOICE ) .amount("11.00") @@ -2740,7 +2879,12 @@ internal class SubscriptionChangeApplyResponseTest { InvoiceTiny.builder().id("gXcsPTVyC4YZa3Sc").build() ) .startingBalance("33.00") - .type(Invoice.CustomerBalanceTransaction.Type.INCREMENT) + .type( + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type + .INCREMENT + ) .build() ) .customerTaxId( @@ -2760,10 +2904,10 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2781,11 +2925,16 @@ internal class SubscriptionChangeApplyResponseTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice.InvoiceSource + .SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem + .builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -2799,12 +2948,18 @@ internal class SubscriptionChangeApplyResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field.PRICE_ID + MonetaryUsageDiscountAdjustment + .Filter + .Field + .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -2818,76 +2973,15 @@ internal class SubscriptionChangeApplyResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse("2022-02-01T08:00:00+00:00") ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -2904,7 +2998,26 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -2930,6 +3043,19 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2943,13 +3069,14 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount.Filter .Operator .INCLUDES ) @@ -2981,14 +3108,13 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -2999,7 +3125,7 @@ internal class SubscriptionChangeApplyResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -3010,14 +3136,13 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -3029,11 +3154,14 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -3067,6 +3195,7 @@ internal class SubscriptionChangeApplyResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -3084,11 +3213,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3098,7 +3225,8 @@ internal class SubscriptionChangeApplyResponseTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata + .builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -3106,11 +3234,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3120,16 +3246,23 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice.PaymentAttempt + .builder() .id("id") .amount("amount") .createdAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .paymentProvider( - Invoice.PaymentAttempt.PaymentProvider.STRIPE + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .PaymentProvider + .STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -3152,7 +3285,9 @@ internal class SubscriptionChangeApplyResponseTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status( + ChangedSubscriptionResources.CreatedInvoice.Status.ISSUED + ) .subscription( SubscriptionMinified.builder() .id("VDGsT23osdLb84KD") @@ -3343,10 +3478,10 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -3382,12 +3517,18 @@ internal class SubscriptionChangeApplyResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field.PRICE_ID + MonetaryUsageDiscountAdjustment + .Filter + .Field + .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -3401,76 +3542,15 @@ internal class SubscriptionChangeApplyResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse("2022-02-01T08:00:00+00:00") ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -3487,7 +3567,26 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -3513,6 +3612,19 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3526,13 +3638,14 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount.Filter .Operator .INCLUDES ) @@ -3564,14 +3677,13 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -3582,7 +3694,7 @@ internal class SubscriptionChangeApplyResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -3593,14 +3705,13 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -3612,11 +3723,14 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -3650,6 +3764,7 @@ internal class SubscriptionChangeApplyResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -3667,11 +3782,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3689,11 +3802,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3713,6 +3824,9 @@ internal class SubscriptionChangeApplyResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -3754,8 +3868,14 @@ internal class SubscriptionChangeApplyResponseTest { ) assertThat(subscriptionChangeApplyResponse.appliedAt()) .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(subscriptionChangeApplyResponse.billingCycleAlignment()) + .isEqualTo("billing_cycle_alignment") assertThat(subscriptionChangeApplyResponse.cancelledAt()) .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(subscriptionChangeApplyResponse.changeOption()).isEqualTo("change_option") + assertThat(subscriptionChangeApplyResponse.effectiveDate()) + .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(subscriptionChangeApplyResponse.planId()).isEqualTo("plan_id") } @Test @@ -3764,6 +3884,7 @@ internal class SubscriptionChangeApplyResponseTest { val subscriptionChangeApplyResponse = SubscriptionChangeApplyResponse.builder() .id("id") + .changeType("change_type") .expirationTime(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .status(SubscriptionChangeApplyResponse.Status.PENDING) .subscription( @@ -3782,9 +3903,15 @@ internal class SubscriptionChangeApplyResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -3821,6 +3948,7 @@ internal class SubscriptionChangeApplyResponseTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -3898,6 +4026,21 @@ internal class SubscriptionChangeApplyResponseTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -3911,9 +4054,9 @@ internal class SubscriptionChangeApplyResponseTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3935,9 +4078,9 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3955,9 +4098,9 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3982,9 +4125,15 @@ internal class SubscriptionChangeApplyResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -4014,9 +4163,11 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -4029,9 +4180,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4048,9 +4199,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4073,10 +4224,13 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -4090,11 +4244,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4106,11 +4258,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4123,7 +4273,7 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -4136,7 +4286,21 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -4156,6 +4320,15 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4168,10 +4341,13 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -4194,11 +4370,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4207,7 +4381,7 @@ internal class SubscriptionChangeApplyResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4218,11 +4392,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4232,10 +4404,13 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -4268,6 +4443,7 @@ internal class SubscriptionChangeApplyResponseTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -4286,7 +4462,7 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -4299,7 +4475,21 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -4319,6 +4509,15 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4331,10 +4530,13 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -4357,11 +4559,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4370,7 +4570,7 @@ internal class SubscriptionChangeApplyResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4381,11 +4581,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4395,10 +4593,13 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -4526,11 +4727,13 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice + .AutoCollection + .builder() .enabled(true) .nextAttemptAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") @@ -4555,7 +4758,8 @@ internal class SubscriptionChangeApplyResponseTest { OffsetDateTime.parse("2022-05-01T07:01:31+00:00") ) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote + .builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -4577,10 +4781,14 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action .APPLIED_TO_INVOICE ) .amount("11.00") @@ -4601,7 +4809,9 @@ internal class SubscriptionChangeApplyResponseTest { ) .startingBalance("33.00") .type( - Invoice.CustomerBalanceTransaction.Type + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type .INCREMENT ) .build() @@ -4623,10 +4833,13 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -4646,13 +4859,19 @@ internal class SubscriptionChangeApplyResponseTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice + .InvoiceSource + .SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem + .builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -4666,13 +4885,18 @@ internal class SubscriptionChangeApplyResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field + MonetaryUsageDiscountAdjustment + .Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -4688,31 +4912,6 @@ internal class SubscriptionChangeApplyResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType - .PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse( "2022-02-01T08:00:00+00:00" @@ -4720,50 +4919,10 @@ internal class SubscriptionChangeApplyResponseTest { ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -4780,7 +4939,28 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice + .CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice + .CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -4806,6 +4986,20 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4823,14 +5017,17 @@ internal class SubscriptionChangeApplyResponseTest { "7hfgtgjnbvc3ujkl" ) .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter + .builder() .field( - TransformPriceFilter + PercentageDiscount + .Filter .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount + .Filter .Operator .INCLUDES ) @@ -4862,15 +5059,13 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter - .Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -4881,7 +5076,7 @@ internal class SubscriptionChangeApplyResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4892,15 +5087,13 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter - .Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -4912,11 +5105,14 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -4952,6 +5148,7 @@ internal class SubscriptionChangeApplyResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -4969,11 +5166,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4983,7 +5178,8 @@ internal class SubscriptionChangeApplyResponseTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata + .builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4994,11 +5190,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5008,16 +5202,24 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .builder() .id("id") .amount("amount") .createdAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .paymentProvider( - Invoice.PaymentAttempt.PaymentProvider.STRIPE + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .PaymentProvider + .STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -5040,7 +5242,10 @@ internal class SubscriptionChangeApplyResponseTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status( + ChangedSubscriptionResources.CreatedInvoice.Status + .ISSUED + ) .subscription( SubscriptionMinified.builder() .id("VDGsT23osdLb84KD") @@ -5248,10 +5453,13 @@ internal class SubscriptionChangeApplyResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -5291,13 +5499,18 @@ internal class SubscriptionChangeApplyResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field + MonetaryUsageDiscountAdjustment + .Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -5313,31 +5526,6 @@ internal class SubscriptionChangeApplyResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType - .PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse( "2022-02-01T08:00:00+00:00" @@ -5345,50 +5533,10 @@ internal class SubscriptionChangeApplyResponseTest { ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -5405,7 +5553,28 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice + .CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice + .CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -5431,6 +5600,20 @@ internal class SubscriptionChangeApplyResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -5448,14 +5631,17 @@ internal class SubscriptionChangeApplyResponseTest { "7hfgtgjnbvc3ujkl" ) .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter + .builder() .field( - TransformPriceFilter + PercentageDiscount + .Filter .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount + .Filter .Operator .INCLUDES ) @@ -5487,15 +5673,13 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter - .Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -5506,7 +5690,7 @@ internal class SubscriptionChangeApplyResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -5517,15 +5701,13 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter - .Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -5537,11 +5719,14 @@ internal class SubscriptionChangeApplyResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -5577,6 +5762,7 @@ internal class SubscriptionChangeApplyResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -5594,11 +5780,9 @@ internal class SubscriptionChangeApplyResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5619,11 +5803,9 @@ internal class SubscriptionChangeApplyResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5643,6 +5825,9 @@ internal class SubscriptionChangeApplyResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -5685,7 +5870,11 @@ internal class SubscriptionChangeApplyResponseTest { .build() ) .appliedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .billingCycleAlignment("billing_cycle_alignment") .cancelledAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .changeOption("change_option") + .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .planId("plan_id") .build() val roundtrippedSubscriptionChangeApplyResponse = diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeCancelResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeCancelResponseTest.kt index 683076fa5..b80e094fe 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeCancelResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeCancelResponseTest.kt @@ -16,6 +16,7 @@ internal class SubscriptionChangeCancelResponseTest { val subscriptionChangeCancelResponse = SubscriptionChangeCancelResponse.builder() .id("id") + .changeType("change_type") .expirationTime(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .status(SubscriptionChangeCancelResponse.Status.PENDING) .subscription( @@ -34,9 +35,15 @@ internal class SubscriptionChangeCancelResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -73,6 +80,7 @@ internal class SubscriptionChangeCancelResponseTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -150,6 +158,21 @@ internal class SubscriptionChangeCancelResponseTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -163,9 +186,9 @@ internal class SubscriptionChangeCancelResponseTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -187,9 +210,9 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -207,9 +230,9 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -234,9 +257,15 @@ internal class SubscriptionChangeCancelResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -266,9 +295,11 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -281,9 +312,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -300,9 +331,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -325,10 +356,13 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -342,11 +376,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -358,11 +390,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -375,7 +405,7 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -388,7 +418,21 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -408,6 +452,15 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -420,10 +473,13 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -446,11 +502,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -459,7 +513,7 @@ internal class SubscriptionChangeCancelResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -470,11 +524,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -484,10 +536,13 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -520,6 +575,7 @@ internal class SubscriptionChangeCancelResponseTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -538,7 +594,7 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -551,7 +607,21 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -571,6 +641,15 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -583,10 +662,13 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -609,11 +691,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -622,7 +702,7 @@ internal class SubscriptionChangeCancelResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -633,11 +713,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -647,10 +725,13 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -778,11 +859,13 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice + .AutoCollection + .builder() .enabled(true) .nextAttemptAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") @@ -807,7 +890,8 @@ internal class SubscriptionChangeCancelResponseTest { OffsetDateTime.parse("2022-05-01T07:01:31+00:00") ) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote + .builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -829,10 +913,14 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action .APPLIED_TO_INVOICE ) .amount("11.00") @@ -853,7 +941,9 @@ internal class SubscriptionChangeCancelResponseTest { ) .startingBalance("33.00") .type( - Invoice.CustomerBalanceTransaction.Type + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type .INCREMENT ) .build() @@ -875,10 +965,13 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -898,13 +991,19 @@ internal class SubscriptionChangeCancelResponseTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice + .InvoiceSource + .SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem + .builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -918,13 +1017,18 @@ internal class SubscriptionChangeCancelResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field + MonetaryUsageDiscountAdjustment + .Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -940,31 +1044,6 @@ internal class SubscriptionChangeCancelResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType - .PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse( "2022-02-01T08:00:00+00:00" @@ -972,50 +1051,10 @@ internal class SubscriptionChangeCancelResponseTest { ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -1032,7 +1071,28 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice + .CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice + .CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1058,6 +1118,20 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1075,14 +1149,17 @@ internal class SubscriptionChangeCancelResponseTest { "7hfgtgjnbvc3ujkl" ) .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter + .builder() .field( - TransformPriceFilter + PercentageDiscount + .Filter .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount + .Filter .Operator .INCLUDES ) @@ -1114,15 +1191,13 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter - .Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -1133,7 +1208,7 @@ internal class SubscriptionChangeCancelResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1144,15 +1219,13 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter - .Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -1164,11 +1237,14 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -1204,6 +1280,7 @@ internal class SubscriptionChangeCancelResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1221,11 +1298,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1235,7 +1310,8 @@ internal class SubscriptionChangeCancelResponseTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata + .builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1246,11 +1322,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1260,16 +1334,24 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .builder() .id("id") .amount("amount") .createdAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .paymentProvider( - Invoice.PaymentAttempt.PaymentProvider.STRIPE + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .PaymentProvider + .STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -1292,7 +1374,10 @@ internal class SubscriptionChangeCancelResponseTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status( + ChangedSubscriptionResources.CreatedInvoice.Status + .ISSUED + ) .subscription( SubscriptionMinified.builder() .id("VDGsT23osdLb84KD") @@ -1500,10 +1585,13 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -1543,13 +1631,18 @@ internal class SubscriptionChangeCancelResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field + MonetaryUsageDiscountAdjustment + .Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -1565,31 +1658,6 @@ internal class SubscriptionChangeCancelResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType - .PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse( "2022-02-01T08:00:00+00:00" @@ -1597,50 +1665,10 @@ internal class SubscriptionChangeCancelResponseTest { ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -1657,7 +1685,28 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice + .CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice + .CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1683,6 +1732,20 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1700,14 +1763,17 @@ internal class SubscriptionChangeCancelResponseTest { "7hfgtgjnbvc3ujkl" ) .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter + .builder() .field( - TransformPriceFilter + PercentageDiscount + .Filter .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount + .Filter .Operator .INCLUDES ) @@ -1739,15 +1805,13 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter - .Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -1758,7 +1822,7 @@ internal class SubscriptionChangeCancelResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1769,15 +1833,13 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter - .Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -1789,11 +1851,14 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -1829,6 +1894,7 @@ internal class SubscriptionChangeCancelResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1846,11 +1912,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1871,11 +1935,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1895,6 +1957,9 @@ internal class SubscriptionChangeCancelResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -1937,10 +2002,15 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .appliedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .billingCycleAlignment("billing_cycle_alignment") .cancelledAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .changeOption("change_option") + .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .planId("plan_id") .build() assertThat(subscriptionChangeCancelResponse.id()).isEqualTo("id") + assertThat(subscriptionChangeCancelResponse.changeType()).isEqualTo("change_type") assertThat(subscriptionChangeCancelResponse.expirationTime()) .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(subscriptionChangeCancelResponse.status()) @@ -1962,9 +2032,15 @@ internal class SubscriptionChangeCancelResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -1993,6 +2069,7 @@ internal class SubscriptionChangeCancelResponseTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -2070,6 +2147,21 @@ internal class SubscriptionChangeCancelResponseTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -2083,9 +2175,9 @@ internal class SubscriptionChangeCancelResponseTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2107,9 +2199,9 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2127,9 +2219,9 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2154,9 +2246,15 @@ internal class SubscriptionChangeCancelResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -2186,9 +2284,9 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2201,9 +2299,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2220,9 +2318,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2245,10 +2343,10 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2262,11 +2360,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2278,11 +2374,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2295,7 +2389,7 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2306,7 +2400,20 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -2324,6 +2431,13 @@ internal class SubscriptionChangeCancelResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2336,10 +2450,10 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2362,11 +2476,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2375,7 +2487,7 @@ internal class SubscriptionChangeCancelResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2383,11 +2495,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2397,10 +2507,13 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -2431,6 +2544,7 @@ internal class SubscriptionChangeCancelResponseTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -2447,7 +2561,7 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2458,7 +2572,20 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -2476,6 +2603,13 @@ internal class SubscriptionChangeCancelResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2488,10 +2622,10 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2514,11 +2648,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2527,7 +2659,7 @@ internal class SubscriptionChangeCancelResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2535,11 +2667,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2549,10 +2679,13 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -2676,11 +2809,12 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice.AutoCollection + .builder() .enabled(true) .nextAttemptAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") @@ -2703,7 +2837,8 @@ internal class SubscriptionChangeCancelResponseTest { ) .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote + .builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -2723,10 +2858,14 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action .APPLIED_TO_INVOICE ) .amount("11.00") @@ -2740,7 +2879,12 @@ internal class SubscriptionChangeCancelResponseTest { InvoiceTiny.builder().id("gXcsPTVyC4YZa3Sc").build() ) .startingBalance("33.00") - .type(Invoice.CustomerBalanceTransaction.Type.INCREMENT) + .type( + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type + .INCREMENT + ) .build() ) .customerTaxId( @@ -2760,10 +2904,10 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2781,11 +2925,16 @@ internal class SubscriptionChangeCancelResponseTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice.InvoiceSource + .SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem + .builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -2799,12 +2948,18 @@ internal class SubscriptionChangeCancelResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field.PRICE_ID + MonetaryUsageDiscountAdjustment + .Filter + .Field + .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -2818,76 +2973,15 @@ internal class SubscriptionChangeCancelResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse("2022-02-01T08:00:00+00:00") ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -2904,7 +2998,26 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -2930,6 +3043,19 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2943,13 +3069,14 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount.Filter .Operator .INCLUDES ) @@ -2981,14 +3108,13 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -2999,7 +3125,7 @@ internal class SubscriptionChangeCancelResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -3010,14 +3136,13 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -3029,11 +3154,14 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -3067,6 +3195,7 @@ internal class SubscriptionChangeCancelResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -3084,11 +3213,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3098,7 +3225,8 @@ internal class SubscriptionChangeCancelResponseTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata + .builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -3106,11 +3234,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3120,16 +3246,23 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice.PaymentAttempt + .builder() .id("id") .amount("amount") .createdAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .paymentProvider( - Invoice.PaymentAttempt.PaymentProvider.STRIPE + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .PaymentProvider + .STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -3152,7 +3285,9 @@ internal class SubscriptionChangeCancelResponseTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status( + ChangedSubscriptionResources.CreatedInvoice.Status.ISSUED + ) .subscription( SubscriptionMinified.builder() .id("VDGsT23osdLb84KD") @@ -3343,10 +3478,10 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -3382,12 +3517,18 @@ internal class SubscriptionChangeCancelResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field.PRICE_ID + MonetaryUsageDiscountAdjustment + .Filter + .Field + .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -3401,76 +3542,15 @@ internal class SubscriptionChangeCancelResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse("2022-02-01T08:00:00+00:00") ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -3487,7 +3567,26 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -3513,6 +3612,19 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3526,13 +3638,14 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount.Filter .Operator .INCLUDES ) @@ -3564,14 +3677,13 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -3582,7 +3694,7 @@ internal class SubscriptionChangeCancelResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -3593,14 +3705,13 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -3612,11 +3723,14 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -3650,6 +3764,7 @@ internal class SubscriptionChangeCancelResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -3667,11 +3782,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3689,11 +3802,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3713,6 +3824,9 @@ internal class SubscriptionChangeCancelResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -3754,8 +3868,14 @@ internal class SubscriptionChangeCancelResponseTest { ) assertThat(subscriptionChangeCancelResponse.appliedAt()) .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(subscriptionChangeCancelResponse.billingCycleAlignment()) + .isEqualTo("billing_cycle_alignment") assertThat(subscriptionChangeCancelResponse.cancelledAt()) .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(subscriptionChangeCancelResponse.changeOption()).isEqualTo("change_option") + assertThat(subscriptionChangeCancelResponse.effectiveDate()) + .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(subscriptionChangeCancelResponse.planId()).isEqualTo("plan_id") } @Test @@ -3764,6 +3884,7 @@ internal class SubscriptionChangeCancelResponseTest { val subscriptionChangeCancelResponse = SubscriptionChangeCancelResponse.builder() .id("id") + .changeType("change_type") .expirationTime(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .status(SubscriptionChangeCancelResponse.Status.PENDING) .subscription( @@ -3782,9 +3903,15 @@ internal class SubscriptionChangeCancelResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -3821,6 +3948,7 @@ internal class SubscriptionChangeCancelResponseTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -3898,6 +4026,21 @@ internal class SubscriptionChangeCancelResponseTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -3911,9 +4054,9 @@ internal class SubscriptionChangeCancelResponseTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3935,9 +4078,9 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3955,9 +4098,9 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3982,9 +4125,15 @@ internal class SubscriptionChangeCancelResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -4014,9 +4163,11 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -4029,9 +4180,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4048,9 +4199,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4073,10 +4224,13 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -4090,11 +4244,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4106,11 +4258,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4123,7 +4273,7 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -4136,7 +4286,21 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -4156,6 +4320,15 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4168,10 +4341,13 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -4194,11 +4370,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4207,7 +4381,7 @@ internal class SubscriptionChangeCancelResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4218,11 +4392,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4232,10 +4404,13 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -4268,6 +4443,7 @@ internal class SubscriptionChangeCancelResponseTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -4286,7 +4462,7 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -4299,7 +4475,21 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -4319,6 +4509,15 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4331,10 +4530,13 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -4357,11 +4559,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4370,7 +4570,7 @@ internal class SubscriptionChangeCancelResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4381,11 +4581,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4395,10 +4593,13 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -4526,11 +4727,13 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice + .AutoCollection + .builder() .enabled(true) .nextAttemptAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") @@ -4555,7 +4758,8 @@ internal class SubscriptionChangeCancelResponseTest { OffsetDateTime.parse("2022-05-01T07:01:31+00:00") ) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote + .builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -4577,10 +4781,14 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action .APPLIED_TO_INVOICE ) .amount("11.00") @@ -4601,7 +4809,9 @@ internal class SubscriptionChangeCancelResponseTest { ) .startingBalance("33.00") .type( - Invoice.CustomerBalanceTransaction.Type + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type .INCREMENT ) .build() @@ -4623,10 +4833,13 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -4646,13 +4859,19 @@ internal class SubscriptionChangeCancelResponseTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice + .InvoiceSource + .SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem + .builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -4666,13 +4885,18 @@ internal class SubscriptionChangeCancelResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field + MonetaryUsageDiscountAdjustment + .Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -4688,31 +4912,6 @@ internal class SubscriptionChangeCancelResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType - .PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse( "2022-02-01T08:00:00+00:00" @@ -4720,50 +4919,10 @@ internal class SubscriptionChangeCancelResponseTest { ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -4780,7 +4939,28 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice + .CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice + .CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -4806,6 +4986,20 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4823,14 +5017,17 @@ internal class SubscriptionChangeCancelResponseTest { "7hfgtgjnbvc3ujkl" ) .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter + .builder() .field( - TransformPriceFilter + PercentageDiscount + .Filter .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount + .Filter .Operator .INCLUDES ) @@ -4862,15 +5059,13 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter - .Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -4881,7 +5076,7 @@ internal class SubscriptionChangeCancelResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4892,15 +5087,13 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter - .Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -4912,11 +5105,14 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -4952,6 +5148,7 @@ internal class SubscriptionChangeCancelResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -4969,11 +5166,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4983,7 +5178,8 @@ internal class SubscriptionChangeCancelResponseTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata + .builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4994,11 +5190,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5008,16 +5202,24 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .builder() .id("id") .amount("amount") .createdAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .paymentProvider( - Invoice.PaymentAttempt.PaymentProvider.STRIPE + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .PaymentProvider + .STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -5040,7 +5242,10 @@ internal class SubscriptionChangeCancelResponseTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status( + ChangedSubscriptionResources.CreatedInvoice.Status + .ISSUED + ) .subscription( SubscriptionMinified.builder() .id("VDGsT23osdLb84KD") @@ -5248,10 +5453,13 @@ internal class SubscriptionChangeCancelResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -5291,13 +5499,18 @@ internal class SubscriptionChangeCancelResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field + MonetaryUsageDiscountAdjustment + .Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -5313,31 +5526,6 @@ internal class SubscriptionChangeCancelResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType - .PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse( "2022-02-01T08:00:00+00:00" @@ -5345,50 +5533,10 @@ internal class SubscriptionChangeCancelResponseTest { ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -5405,7 +5553,28 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice + .CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice + .CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -5431,6 +5600,20 @@ internal class SubscriptionChangeCancelResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -5448,14 +5631,17 @@ internal class SubscriptionChangeCancelResponseTest { "7hfgtgjnbvc3ujkl" ) .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter + .builder() .field( - TransformPriceFilter + PercentageDiscount + .Filter .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount + .Filter .Operator .INCLUDES ) @@ -5487,15 +5673,13 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter - .Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -5506,7 +5690,7 @@ internal class SubscriptionChangeCancelResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -5517,15 +5701,13 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter - .Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -5537,11 +5719,14 @@ internal class SubscriptionChangeCancelResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -5577,6 +5762,7 @@ internal class SubscriptionChangeCancelResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -5594,11 +5780,9 @@ internal class SubscriptionChangeCancelResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5619,11 +5803,9 @@ internal class SubscriptionChangeCancelResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5643,6 +5825,9 @@ internal class SubscriptionChangeCancelResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -5685,7 +5870,11 @@ internal class SubscriptionChangeCancelResponseTest { .build() ) .appliedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .billingCycleAlignment("billing_cycle_alignment") .cancelledAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .changeOption("change_option") + .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .planId("plan_id") .build() val roundtrippedSubscriptionChangeCancelResponse = diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeRetrieveResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeRetrieveResponseTest.kt index 1a4cb4614..75089ebbb 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeRetrieveResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionChangeRetrieveResponseTest.kt @@ -16,6 +16,7 @@ internal class SubscriptionChangeRetrieveResponseTest { val subscriptionChangeRetrieveResponse = SubscriptionChangeRetrieveResponse.builder() .id("id") + .changeType("change_type") .expirationTime(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .status(SubscriptionChangeRetrieveResponse.Status.PENDING) .subscription( @@ -34,9 +35,15 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -73,6 +80,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -150,6 +158,21 @@ internal class SubscriptionChangeRetrieveResponseTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -163,9 +186,9 @@ internal class SubscriptionChangeRetrieveResponseTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -187,9 +210,9 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -207,9 +230,9 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -234,9 +257,15 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -266,9 +295,11 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -281,9 +312,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -300,9 +331,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -325,10 +356,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -342,11 +376,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -358,11 +390,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -375,7 +405,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -388,7 +418,21 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -408,6 +452,15 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -420,10 +473,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -446,11 +502,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -459,7 +513,7 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -470,11 +524,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -484,10 +536,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -520,6 +575,7 @@ internal class SubscriptionChangeRetrieveResponseTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -538,7 +594,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -551,7 +607,21 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -571,6 +641,15 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -583,10 +662,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -609,11 +691,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -622,7 +702,7 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -633,11 +713,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -647,10 +725,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -778,11 +859,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice + .AutoCollection + .builder() .enabled(true) .nextAttemptAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") @@ -807,7 +890,8 @@ internal class SubscriptionChangeRetrieveResponseTest { OffsetDateTime.parse("2022-05-01T07:01:31+00:00") ) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote + .builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -829,10 +913,14 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action .APPLIED_TO_INVOICE ) .amount("11.00") @@ -853,7 +941,9 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .startingBalance("33.00") .type( - Invoice.CustomerBalanceTransaction.Type + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type .INCREMENT ) .build() @@ -875,10 +965,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -898,13 +991,19 @@ internal class SubscriptionChangeRetrieveResponseTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice + .InvoiceSource + .SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem + .builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -918,13 +1017,18 @@ internal class SubscriptionChangeRetrieveResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field + MonetaryUsageDiscountAdjustment + .Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -940,31 +1044,6 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType - .PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse( "2022-02-01T08:00:00+00:00" @@ -972,50 +1051,10 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -1032,7 +1071,28 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice + .CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice + .CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1058,6 +1118,20 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1075,14 +1149,17 @@ internal class SubscriptionChangeRetrieveResponseTest { "7hfgtgjnbvc3ujkl" ) .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter + .builder() .field( - TransformPriceFilter + PercentageDiscount + .Filter .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount + .Filter .Operator .INCLUDES ) @@ -1114,15 +1191,13 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter - .Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -1133,7 +1208,7 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1144,15 +1219,13 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter - .Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -1164,11 +1237,14 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -1204,6 +1280,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1221,11 +1298,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1235,7 +1310,8 @@ internal class SubscriptionChangeRetrieveResponseTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata + .builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1246,11 +1322,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1260,16 +1334,24 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .builder() .id("id") .amount("amount") .createdAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .paymentProvider( - Invoice.PaymentAttempt.PaymentProvider.STRIPE + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .PaymentProvider + .STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -1292,7 +1374,10 @@ internal class SubscriptionChangeRetrieveResponseTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status( + ChangedSubscriptionResources.CreatedInvoice.Status + .ISSUED + ) .subscription( SubscriptionMinified.builder() .id("VDGsT23osdLb84KD") @@ -1500,10 +1585,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -1543,13 +1631,18 @@ internal class SubscriptionChangeRetrieveResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field + MonetaryUsageDiscountAdjustment + .Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -1565,31 +1658,6 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType - .PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse( "2022-02-01T08:00:00+00:00" @@ -1597,50 +1665,10 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -1657,7 +1685,28 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice + .CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice + .CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1683,6 +1732,20 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1700,14 +1763,17 @@ internal class SubscriptionChangeRetrieveResponseTest { "7hfgtgjnbvc3ujkl" ) .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter + .builder() .field( - TransformPriceFilter + PercentageDiscount + .Filter .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount + .Filter .Operator .INCLUDES ) @@ -1739,15 +1805,13 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter - .Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -1758,7 +1822,7 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1769,15 +1833,13 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter - .Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -1789,11 +1851,14 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -1829,6 +1894,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -1846,11 +1912,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1871,11 +1935,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1895,6 +1957,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -1937,10 +2002,15 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .appliedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .billingCycleAlignment("billing_cycle_alignment") .cancelledAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .changeOption("change_option") + .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .planId("plan_id") .build() assertThat(subscriptionChangeRetrieveResponse.id()).isEqualTo("id") + assertThat(subscriptionChangeRetrieveResponse.changeType()).isEqualTo("change_type") assertThat(subscriptionChangeRetrieveResponse.expirationTime()) .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(subscriptionChangeRetrieveResponse.status()) @@ -1962,9 +2032,15 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -1993,6 +2069,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -2070,6 +2147,21 @@ internal class SubscriptionChangeRetrieveResponseTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -2083,9 +2175,9 @@ internal class SubscriptionChangeRetrieveResponseTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2107,9 +2199,9 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2127,9 +2219,9 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2154,9 +2246,15 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -2186,9 +2284,9 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2201,9 +2299,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2220,9 +2318,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2245,10 +2343,10 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2262,11 +2360,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2278,11 +2374,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2295,7 +2389,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2306,7 +2400,20 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -2324,6 +2431,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2336,10 +2450,10 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2362,11 +2476,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2375,7 +2487,7 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2383,11 +2495,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2397,10 +2507,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -2431,6 +2544,7 @@ internal class SubscriptionChangeRetrieveResponseTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -2447,7 +2561,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -2458,7 +2572,20 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -2476,6 +2603,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2488,10 +2622,10 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2514,11 +2648,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2527,7 +2659,7 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -2535,11 +2667,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -2549,10 +2679,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -2676,11 +2809,12 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice.AutoCollection + .builder() .enabled(true) .nextAttemptAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") @@ -2703,7 +2837,8 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote + .builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -2723,10 +2858,14 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action .APPLIED_TO_INVOICE ) .amount("11.00") @@ -2740,7 +2879,12 @@ internal class SubscriptionChangeRetrieveResponseTest { InvoiceTiny.builder().id("gXcsPTVyC4YZa3Sc").build() ) .startingBalance("33.00") - .type(Invoice.CustomerBalanceTransaction.Type.INCREMENT) + .type( + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type + .INCREMENT + ) .build() ) .customerTaxId( @@ -2760,10 +2904,10 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -2781,11 +2925,16 @@ internal class SubscriptionChangeRetrieveResponseTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice.InvoiceSource + .SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem + .builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -2799,12 +2948,18 @@ internal class SubscriptionChangeRetrieveResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field.PRICE_ID + MonetaryUsageDiscountAdjustment + .Filter + .Field + .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -2818,76 +2973,15 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse("2022-02-01T08:00:00+00:00") ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -2904,7 +2998,26 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -2930,6 +3043,19 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -2943,13 +3069,14 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount.Filter .Operator .INCLUDES ) @@ -2981,14 +3108,13 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -2999,7 +3125,7 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -3010,14 +3136,13 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -3029,11 +3154,14 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -3067,6 +3195,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -3084,11 +3213,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3098,7 +3225,8 @@ internal class SubscriptionChangeRetrieveResponseTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata + .builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -3106,11 +3234,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3120,16 +3246,23 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice.PaymentAttempt + .builder() .id("id") .amount("amount") .createdAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .paymentProvider( - Invoice.PaymentAttempt.PaymentProvider.STRIPE + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .PaymentProvider + .STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -3152,7 +3285,9 @@ internal class SubscriptionChangeRetrieveResponseTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status( + ChangedSubscriptionResources.CreatedInvoice.Status.ISSUED + ) .subscription( SubscriptionMinified.builder() .id("VDGsT23osdLb84KD") @@ -3343,10 +3478,10 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -3382,12 +3517,18 @@ internal class SubscriptionChangeRetrieveResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field.PRICE_ID + MonetaryUsageDiscountAdjustment + .Filter + .Field + .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -3401,76 +3542,15 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType.PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse("2022-02-01T08:00:00+00:00") ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field.PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -3487,7 +3567,26 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice.CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -3513,6 +3612,19 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -3526,13 +3638,14 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter.builder() .field( - TransformPriceFilter.Field + PercentageDiscount.Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount.Filter .Operator .INCLUDES ) @@ -3564,14 +3677,13 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter.Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -3582,7 +3694,7 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -3593,14 +3705,13 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter.Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -3612,11 +3723,14 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -3650,6 +3764,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -3667,11 +3782,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3689,11 +3802,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3713,6 +3824,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -3754,8 +3868,14 @@ internal class SubscriptionChangeRetrieveResponseTest { ) assertThat(subscriptionChangeRetrieveResponse.appliedAt()) .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(subscriptionChangeRetrieveResponse.billingCycleAlignment()) + .isEqualTo("billing_cycle_alignment") assertThat(subscriptionChangeRetrieveResponse.cancelledAt()) .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(subscriptionChangeRetrieveResponse.changeOption()).isEqualTo("change_option") + assertThat(subscriptionChangeRetrieveResponse.effectiveDate()) + .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(subscriptionChangeRetrieveResponse.planId()).isEqualTo("plan_id") } @Test @@ -3764,6 +3884,7 @@ internal class SubscriptionChangeRetrieveResponseTest { val subscriptionChangeRetrieveResponse = SubscriptionChangeRetrieveResponse.builder() .id("id") + .changeType("change_type") .expirationTime(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .status(SubscriptionChangeRetrieveResponse.Status.PENDING) .subscription( @@ -3782,9 +3903,15 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -3821,6 +3948,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -3898,6 +4026,21 @@ internal class SubscriptionChangeRetrieveResponseTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -3911,9 +4054,9 @@ internal class SubscriptionChangeRetrieveResponseTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3935,9 +4078,9 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3955,9 +4098,9 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -3982,9 +4125,15 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -4014,9 +4163,11 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -4029,9 +4180,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4048,9 +4199,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4073,10 +4224,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -4090,11 +4244,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4106,11 +4258,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4123,7 +4273,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -4136,7 +4286,21 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -4156,6 +4320,15 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4168,10 +4341,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -4194,11 +4370,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4207,7 +4381,7 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4218,11 +4392,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4232,10 +4404,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -4268,6 +4443,7 @@ internal class SubscriptionChangeRetrieveResponseTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -4286,7 +4462,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -4299,7 +4475,21 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -4319,6 +4509,15 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4331,10 +4530,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -4357,11 +4559,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4370,7 +4570,7 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4381,11 +4581,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4395,10 +4593,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -4526,11 +4727,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .addCreatedInvoice( - Invoice.builder() + ChangedSubscriptionResources.CreatedInvoice.builder() .id("id") .amountDue("8.00") .autoCollection( - Invoice.AutoCollection.builder() + ChangedSubscriptionResources.CreatedInvoice + .AutoCollection + .builder() .enabled(true) .nextAttemptAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") @@ -4555,7 +4758,8 @@ internal class SubscriptionChangeRetrieveResponseTest { OffsetDateTime.parse("2022-05-01T07:01:31+00:00") ) .addCreditNote( - Invoice.CreditNote.builder() + ChangedSubscriptionResources.CreatedInvoice.CreditNote + .builder() .id("id") .creditNoteNumber("credit_note_number") .memo("memo") @@ -4577,10 +4781,14 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .addCustomerBalanceTransaction( - Invoice.CustomerBalanceTransaction.builder() + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .builder() .id("cgZa3SXcsPTVyC4Y") .action( - Invoice.CustomerBalanceTransaction.Action + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Action .APPLIED_TO_INVOICE ) .amount("11.00") @@ -4601,7 +4809,9 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .startingBalance("33.00") .type( - Invoice.CustomerBalanceTransaction.Type + ChangedSubscriptionResources.CreatedInvoice + .CustomerBalanceTransaction + .Type .INCREMENT ) .build() @@ -4623,10 +4833,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -4646,13 +4859,19 @@ internal class SubscriptionChangeRetrieveResponseTest { .invoicePdf( "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" ) - .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .invoiceSource( + ChangedSubscriptionResources.CreatedInvoice + .InvoiceSource + .SUBSCRIPTION + ) + .isPayableNow(true) .issueFailedAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addLineItem( - Invoice.LineItem.builder() + ChangedSubscriptionResources.CreatedInvoice.LineItem + .builder() .id("id") .adjustedSubtotal("5.00") .addAdjustment( @@ -4666,13 +4885,18 @@ internal class SubscriptionChangeRetrieveResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field + MonetaryUsageDiscountAdjustment + .Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -4688,31 +4912,6 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType - .PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse( "2022-02-01T08:00:00+00:00" @@ -4720,50 +4919,10 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -4780,7 +4939,28 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice + .CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice + .CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -4806,6 +4986,20 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -4823,14 +5017,17 @@ internal class SubscriptionChangeRetrieveResponseTest { "7hfgtgjnbvc3ujkl" ) .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter + .builder() .field( - TransformPriceFilter + PercentageDiscount + .Filter .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount + .Filter .Operator .INCLUDES ) @@ -4862,15 +5059,13 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter - .Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -4881,7 +5076,7 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4892,15 +5087,13 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter - .Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -4912,11 +5105,14 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -4952,6 +5148,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -4969,11 +5166,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -4983,7 +5178,8 @@ internal class SubscriptionChangeRetrieveResponseTest { .maximumAmount("maximum_amount") .memo("memo") .metadata( - Invoice.Metadata.builder() + ChangedSubscriptionResources.CreatedInvoice.Metadata + .builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -4994,11 +5190,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5008,16 +5202,24 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addPaymentAttempt( - Invoice.PaymentAttempt.builder() + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .builder() .id("id") .amount("amount") .createdAt( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) .paymentProvider( - Invoice.PaymentAttempt.PaymentProvider.STRIPE + ChangedSubscriptionResources.CreatedInvoice + .PaymentAttempt + .PaymentProvider + .STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -5040,7 +5242,10 @@ internal class SubscriptionChangeRetrieveResponseTest { .state("state") .build() ) - .status(Invoice.Status.ISSUED) + .status( + ChangedSubscriptionResources.CreatedInvoice.Status + .ISSUED + ) .subscription( SubscriptionMinified.builder() .id("VDGsT23osdLb84KD") @@ -5248,10 +5453,13 @@ internal class SubscriptionChangeRetrieveResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -5291,13 +5499,18 @@ internal class SubscriptionChangeRetrieveResponseTest { .amount("amount") .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + MonetaryUsageDiscountAdjustment.Filter + .builder() .field( - TransformPriceFilter.Field + MonetaryUsageDiscountAdjustment + .Filter + .Field .PRICE_ID ) .operator( - TransformPriceFilter.Operator + MonetaryUsageDiscountAdjustment + .Filter + .Operator .INCLUDES ) .addValue("string") @@ -5313,31 +5526,6 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .amount("7.00") .creditsApplied("6.00") - .discount( - PercentageDiscount.builder() - .discountType( - PercentageDiscount.DiscountType - .PERCENTAGE - ) - .percentageDiscount(0.15) - .addAppliesToPriceId("h74gfhdjvn7ujokd") - .addAppliesToPriceId("7hfgtgjnbvc3ujkl") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .reason("reason") - .build() - ) .endDate( OffsetDateTime.parse( "2022-02-01T08:00:00+00:00" @@ -5345,50 +5533,10 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .filter("filter") .grouping("grouping") - .maximum( - Maximum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .maximumAmount("maximum_amount") - .build() - ) - .maximumAmount("maximum_amount") - .minimum( - Minimum.builder() - .addAppliesToPriceId("string") - .addFilter( - TransformPriceFilter.builder() - .field( - TransformPriceFilter.Field - .PRICE_ID - ) - .operator( - TransformPriceFilter.Operator - .INCLUDES - ) - .addValue("string") - .build() - ) - .minimumAmount("minimum_amount") - .build() - ) - .minimumAmount("minimum_amount") .name("Fixed Fee") .partiallyInvoicedAmount("4.00") .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder() @@ -5405,7 +5553,28 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode( + Price.UnitPrice.BillingMode.IN_ADVANCE + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter + .builder() + .field( + Price.UnitPrice + .CompositePriceFilter + .Field + .PRICE_ID + ) + .operator( + Price.UnitPrice + .CompositePriceFilter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -5431,6 +5600,20 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field( + Allocation.Filter.Field + .PRICE_ID + ) + .operator( + Allocation.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -5448,14 +5631,17 @@ internal class SubscriptionChangeRetrieveResponseTest { "7hfgtgjnbvc3ujkl" ) .addFilter( - TransformPriceFilter.builder() + PercentageDiscount.Filter + .builder() .field( - TransformPriceFilter + PercentageDiscount + .Filter .Field .PRICE_ID ) .operator( - TransformPriceFilter + PercentageDiscount + .Filter .Operator .INCLUDES ) @@ -5487,15 +5673,13 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Maximum.Filter.builder() .field( - TransformPriceFilter - .Field + Maximum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Maximum.Filter.Operator .INCLUDES ) .addValue("string") @@ -5506,7 +5690,7 @@ internal class SubscriptionChangeRetrieveResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -5517,15 +5701,13 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() + Minimum.Filter.builder() .field( - TransformPriceFilter - .Field + Minimum.Filter.Field .PRICE_ID ) .operator( - TransformPriceFilter - .Operator + Minimum.Filter.Operator .INCLUDES ) .addValue("string") @@ -5537,11 +5719,14 @@ internal class SubscriptionChangeRetrieveResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType( + Price.UnitPrice.PriceType.USAGE_PRICE + ) .replacesPriceId("replaces_price_id") .unitConfig( UnitConfig.builder() .unitAmount("unit_amount") + .prorated(true) .build() ) .dimensionalPriceConfiguration( @@ -5577,6 +5762,7 @@ internal class SubscriptionChangeRetrieveResponseTest { .name("Tier One") .quantity(5.0) .type(MatrixSubLineItem.Type.MATRIX) + .scaledQuantity(0.0) .build() ) .subtotal("9.00") @@ -5594,11 +5780,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5619,11 +5803,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -5643,6 +5825,9 @@ internal class SubscriptionChangeRetrieveResponseTest { Invoice.PaymentAttempt.PaymentProvider.STRIPE ) .paymentProviderId("payment_provider_id") + .receiptPdf( + "https://assets.withorb.com/receipt/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) .succeeded(true) .build() ) @@ -5685,7 +5870,11 @@ internal class SubscriptionChangeRetrieveResponseTest { .build() ) .appliedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .billingCycleAlignment("billing_cycle_alignment") .cancelledAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .changeOption("change_option") + .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .planId("plan_id") .build() val roundtrippedSubscriptionChangeRetrieveResponse = diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionCreateParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionCreateParamsTest.kt index d3bc4d6d3..79ba16c55 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionCreateParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionCreateParamsTest.kt @@ -27,9 +27,9 @@ internal class SubscriptionCreateParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -56,6 +56,15 @@ internal class SubscriptionCreateParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -77,7 +86,12 @@ internal class SubscriptionCreateParamsTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -177,9 +191,9 @@ internal class SubscriptionCreateParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -205,6 +219,15 @@ internal class SubscriptionCreateParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -225,7 +248,12 @@ internal class SubscriptionCreateParamsTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -293,9 +321,9 @@ internal class SubscriptionCreateParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -322,6 +350,15 @@ internal class SubscriptionCreateParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -343,7 +380,12 @@ internal class SubscriptionCreateParamsTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -445,9 +487,9 @@ internal class SubscriptionCreateParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -473,6 +515,15 @@ internal class SubscriptionCreateParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -493,7 +544,12 @@ internal class SubscriptionCreateParamsTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -561,9 +617,9 @@ internal class SubscriptionCreateParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -591,6 +647,15 @@ internal class SubscriptionCreateParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -612,7 +677,12 @@ internal class SubscriptionCreateParamsTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -717,9 +787,9 @@ internal class SubscriptionCreateParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -746,6 +816,15 @@ internal class SubscriptionCreateParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -766,7 +845,12 @@ internal class SubscriptionCreateParamsTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionFetchCostsResponseTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionFetchCostsResponseTest.kt index 09f8ae0d5..0ae21fa3e 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionFetchCostsResponseTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionFetchCostsResponseTest.kt @@ -20,7 +20,7 @@ internal class SubscriptionFetchCostsResponseTest { .addPerPriceCost( PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -33,7 +33,21 @@ internal class SubscriptionFetchCostsResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -53,6 +67,15 @@ internal class SubscriptionFetchCostsResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -65,10 +88,13 @@ internal class SubscriptionFetchCostsResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -91,11 +117,9 @@ internal class SubscriptionFetchCostsResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -104,7 +128,7 @@ internal class SubscriptionFetchCostsResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -115,11 +139,9 @@ internal class SubscriptionFetchCostsResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -129,10 +151,13 @@ internal class SubscriptionFetchCostsResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -164,7 +189,7 @@ internal class SubscriptionFetchCostsResponseTest { .addPerPriceCost( PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -175,7 +200,20 @@ internal class SubscriptionFetchCostsResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -193,6 +231,13 @@ internal class SubscriptionFetchCostsResponseTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -205,10 +250,10 @@ internal class SubscriptionFetchCostsResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -231,11 +276,9 @@ internal class SubscriptionFetchCostsResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -244,7 +287,7 @@ internal class SubscriptionFetchCostsResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -252,11 +295,9 @@ internal class SubscriptionFetchCostsResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -266,10 +307,13 @@ internal class SubscriptionFetchCostsResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -303,7 +347,7 @@ internal class SubscriptionFetchCostsResponseTest { .addPerPriceCost( PerPriceCost.builder() .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -316,7 +360,21 @@ internal class SubscriptionFetchCostsResponseTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -336,6 +394,15 @@ internal class SubscriptionFetchCostsResponseTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -348,10 +415,13 @@ internal class SubscriptionFetchCostsResponseTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -374,11 +444,9 @@ internal class SubscriptionFetchCostsResponseTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -387,7 +455,7 @@ internal class SubscriptionFetchCostsResponseTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -398,11 +466,9 @@ internal class SubscriptionFetchCostsResponseTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -412,10 +478,13 @@ internal class SubscriptionFetchCostsResponseTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionListParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionListParamsTest.kt index 1c1c73dd5..2fdd22e5b 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionListParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionListParamsTest.kt @@ -19,7 +19,9 @@ internal class SubscriptionListParamsTest { .cursor("cursor") .addCustomerId("string") .addExternalCustomerId("string") + .externalPlanId("external_plan_id") .limit(1L) + .planId("plan_id") .status(SubscriptionListParams.Status.ACTIVE) .build() } @@ -35,7 +37,9 @@ internal class SubscriptionListParamsTest { .cursor("cursor") .addCustomerId("string") .addExternalCustomerId("string") + .externalPlanId("external_plan_id") .limit(1L) + .planId("plan_id") .status(SubscriptionListParams.Status.ACTIVE) .build() @@ -51,7 +55,9 @@ internal class SubscriptionListParamsTest { .put("cursor", "cursor") .put("customer_id[]", "string") .put("external_customer_id[]", "string") + .put("external_plan_id", "external_plan_id") .put("limit", "1") + .put("plan_id", "plan_id") .put("status", "active") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionPriceIntervalsParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionPriceIntervalsParamsTest.kt index f58e70e2b..9ddb51e3d 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionPriceIntervalsParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionPriceIntervalsParamsTest.kt @@ -28,8 +28,18 @@ internal class SubscriptionPriceIntervalsParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) + .canDeferBilling(true) .addAmountDiscount(0.0) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .externalPriceId("external_price_id") @@ -49,7 +59,12 @@ internal class SubscriptionPriceIntervalsParamsTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -93,6 +108,7 @@ internal class SubscriptionPriceIntervalsParamsTest { ) .addAddAdjustment( SubscriptionPriceIntervalsParams.AddAdjustment.builder() + .startDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .adjustment( NewPercentageDiscount.builder() .adjustmentType( @@ -106,9 +122,9 @@ internal class SubscriptionPriceIntervalsParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -116,15 +132,17 @@ internal class SubscriptionPriceIntervalsParamsTest { .priceType(NewPercentageDiscount.PriceType.USAGE) .build() ) - .startDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .adjustmentId("h74gfhdjvn7ujokd") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .allowInvoiceCreditOrVoid(true) + .canDeferBilling(true) .addEdit( SubscriptionPriceIntervalsParams.Edit.builder() .priceIntervalId("sdfs6wdjvn7ujokd") .billingCycleDay(0L) + .canDeferBilling(true) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .filter("my_property > 100 AND my_other_property = 'bar'") .addFixedFeeQuantityTransition( @@ -177,8 +195,18 @@ internal class SubscriptionPriceIntervalsParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) + .canDeferBilling(true) .addAmountDiscount(0.0) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .externalPriceId("external_price_id") @@ -199,7 +227,12 @@ internal class SubscriptionPriceIntervalsParamsTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -245,6 +278,7 @@ internal class SubscriptionPriceIntervalsParamsTest { ) .addAddAdjustment( SubscriptionPriceIntervalsParams.AddAdjustment.builder() + .startDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .adjustment( NewPercentageDiscount.builder() .adjustmentType( @@ -258,9 +292,9 @@ internal class SubscriptionPriceIntervalsParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -268,15 +302,17 @@ internal class SubscriptionPriceIntervalsParamsTest { .priceType(NewPercentageDiscount.PriceType.USAGE) .build() ) - .startDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .adjustmentId("h74gfhdjvn7ujokd") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .allowInvoiceCreditOrVoid(true) + .canDeferBilling(true) .addEdit( SubscriptionPriceIntervalsParams.Edit.builder() .priceIntervalId("sdfs6wdjvn7ujokd") .billingCycleDay(0L) + .canDeferBilling(true) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .filter("my_property > 100 AND my_other_property = 'bar'") .addFixedFeeQuantityTransition( @@ -317,8 +353,18 @@ internal class SubscriptionPriceIntervalsParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) + .canDeferBilling(true) .addAmountDiscount(0.0) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .externalPriceId("external_price_id") @@ -338,7 +384,12 @@ internal class SubscriptionPriceIntervalsParamsTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -383,6 +434,7 @@ internal class SubscriptionPriceIntervalsParamsTest { assertThat(body.addAdjustments()) .containsExactly( SubscriptionPriceIntervalsParams.AddAdjustment.builder() + .startDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .adjustment( NewPercentageDiscount.builder() .adjustmentType( @@ -396,9 +448,9 @@ internal class SubscriptionPriceIntervalsParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -406,16 +458,18 @@ internal class SubscriptionPriceIntervalsParamsTest { .priceType(NewPercentageDiscount.PriceType.USAGE) .build() ) - .startDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .adjustmentId("h74gfhdjvn7ujokd") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) assertThat(body.allowInvoiceCreditOrVoid()).isEqualTo(true) + assertThat(body.canDeferBilling()).isEqualTo(true) assertThat(body.edit()) .containsExactly( SubscriptionPriceIntervalsParams.Edit.builder() .priceIntervalId("sdfs6wdjvn7ujokd") .billingCycleDay(0L) + .canDeferBilling(true) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .filter("my_property > 100 AND my_other_property = 'bar'") .addFixedFeeQuantityTransition( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionSchedulePlanChangeParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionSchedulePlanChangeParamsTest.kt index 31bd5b8f7..83dd5bb9b 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionSchedulePlanChangeParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionSchedulePlanChangeParamsTest.kt @@ -29,9 +29,9 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -58,6 +58,15 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -79,7 +88,12 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -170,9 +184,9 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -198,6 +212,15 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -218,7 +241,12 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -300,9 +328,9 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -329,6 +357,15 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -350,7 +387,12 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -443,9 +485,9 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -471,6 +513,15 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -491,7 +542,12 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -560,9 +616,9 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -590,6 +646,15 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -611,7 +676,12 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -703,9 +773,9 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator(NewPercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -732,6 +802,15 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -752,7 +831,12 @@ internal class SubscriptionSchedulePlanChangeParamsTest { .itemId("item_id") .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionTest.kt index 5159a50e7..29688caf6 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionTest.kt @@ -28,9 +28,14 @@ internal class SubscriptionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -59,6 +64,7 @@ internal class SubscriptionTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -135,6 +141,21 @@ internal class SubscriptionTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -148,9 +169,9 @@ internal class SubscriptionTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -172,9 +193,9 @@ internal class SubscriptionTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -192,9 +213,9 @@ internal class SubscriptionTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -216,9 +237,14 @@ internal class SubscriptionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -248,9 +274,9 @@ internal class SubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -263,9 +289,9 @@ internal class SubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -282,9 +308,9 @@ internal class SubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -305,9 +331,11 @@ internal class SubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -320,9 +348,9 @@ internal class SubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -334,9 +362,9 @@ internal class SubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -349,7 +377,7 @@ internal class SubscriptionTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -358,7 +386,17 @@ internal class SubscriptionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -376,6 +414,13 @@ internal class SubscriptionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -386,9 +431,11 @@ internal class SubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -408,9 +455,9 @@ internal class SubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -419,7 +466,7 @@ internal class SubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -427,9 +474,9 @@ internal class SubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -439,9 +486,14 @@ internal class SubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -471,6 +523,7 @@ internal class SubscriptionTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -487,7 +540,7 @@ internal class SubscriptionTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -496,7 +549,17 @@ internal class SubscriptionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -514,6 +577,13 @@ internal class SubscriptionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -524,9 +594,11 @@ internal class SubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -546,9 +618,9 @@ internal class SubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -557,7 +629,7 @@ internal class SubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -565,9 +637,9 @@ internal class SubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -577,9 +649,14 @@ internal class SubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -622,9 +699,11 @@ internal class SubscriptionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -656,6 +735,7 @@ internal class SubscriptionTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -731,6 +811,20 @@ internal class SubscriptionTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider.ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -746,9 +840,9 @@ internal class SubscriptionTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -774,9 +868,9 @@ internal class SubscriptionTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -796,9 +890,9 @@ internal class SubscriptionTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -822,9 +916,11 @@ internal class SubscriptionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field(PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -854,9 +950,9 @@ internal class SubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -869,9 +965,9 @@ internal class SubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -888,9 +984,9 @@ internal class SubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -911,9 +1007,9 @@ internal class SubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -926,9 +1022,9 @@ internal class SubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -940,9 +1036,9 @@ internal class SubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -955,7 +1051,7 @@ internal class SubscriptionTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -964,7 +1060,17 @@ internal class SubscriptionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -980,6 +1086,13 @@ internal class SubscriptionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -990,9 +1103,9 @@ internal class SubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1012,9 +1125,9 @@ internal class SubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1023,7 +1136,7 @@ internal class SubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1031,9 +1144,9 @@ internal class SubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1043,9 +1156,14 @@ internal class SubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -1076,6 +1194,7 @@ internal class SubscriptionTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .currentBillingPeriodStartDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) @@ -1088,7 +1207,7 @@ internal class SubscriptionTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1097,7 +1216,17 @@ internal class SubscriptionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() @@ -1113,6 +1242,13 @@ internal class SubscriptionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1123,9 +1259,9 @@ internal class SubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1145,9 +1281,9 @@ internal class SubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1156,7 +1292,7 @@ internal class SubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1164,9 +1300,9 @@ internal class SubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1176,9 +1312,14 @@ internal class SubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -1228,9 +1369,14 @@ internal class SubscriptionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -1259,6 +1405,7 @@ internal class SubscriptionTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -1335,6 +1482,21 @@ internal class SubscriptionTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -1348,9 +1510,9 @@ internal class SubscriptionTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1372,9 +1534,9 @@ internal class SubscriptionTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1392,9 +1554,9 @@ internal class SubscriptionTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1416,9 +1578,14 @@ internal class SubscriptionTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field.PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -1448,9 +1615,9 @@ internal class SubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1463,9 +1630,9 @@ internal class SubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1482,9 +1649,9 @@ internal class SubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1505,9 +1672,11 @@ internal class SubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -1520,9 +1689,9 @@ internal class SubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1534,9 +1703,9 @@ internal class SubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1549,7 +1718,7 @@ internal class SubscriptionTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1558,7 +1727,17 @@ internal class SubscriptionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1576,6 +1755,13 @@ internal class SubscriptionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1586,9 +1772,11 @@ internal class SubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -1608,9 +1796,9 @@ internal class SubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1619,7 +1807,7 @@ internal class SubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1627,9 +1815,9 @@ internal class SubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1639,9 +1827,14 @@ internal class SubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") @@ -1671,6 +1864,7 @@ internal class SubscriptionTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -1687,7 +1881,7 @@ internal class SubscriptionTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1696,7 +1890,17 @@ internal class SubscriptionTest { .durationUnit(BillingCycleConfiguration.DurationUnit.DAY) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field(Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1714,6 +1918,13 @@ internal class SubscriptionTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1724,9 +1935,11 @@ internal class SubscriptionTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -1746,9 +1959,9 @@ internal class SubscriptionTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1757,7 +1970,7 @@ internal class SubscriptionTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1765,9 +1978,9 @@ internal class SubscriptionTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1777,9 +1990,14 @@ internal class SubscriptionTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() .addDimensionValue("string") diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionsTest.kt index 6e12850fd..93ca1b208 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/SubscriptionsTest.kt @@ -31,9 +31,15 @@ internal class SubscriptionsTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -70,6 +76,7 @@ internal class SubscriptionsTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -147,6 +154,21 @@ internal class SubscriptionsTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -160,9 +182,9 @@ internal class SubscriptionsTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -184,9 +206,9 @@ internal class SubscriptionsTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -204,9 +226,9 @@ internal class SubscriptionsTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -231,9 +253,15 @@ internal class SubscriptionsTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -263,9 +291,11 @@ internal class SubscriptionsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -278,9 +308,9 @@ internal class SubscriptionsTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -297,9 +327,9 @@ internal class SubscriptionsTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -322,10 +352,13 @@ internal class SubscriptionsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -339,11 +372,9 @@ internal class SubscriptionsTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -355,11 +386,9 @@ internal class SubscriptionsTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -372,7 +401,7 @@ internal class SubscriptionsTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -385,7 +414,21 @@ internal class SubscriptionsTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -405,6 +448,15 @@ internal class SubscriptionsTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -417,10 +469,13 @@ internal class SubscriptionsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -443,11 +498,9 @@ internal class SubscriptionsTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -456,7 +509,7 @@ internal class SubscriptionsTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -467,11 +520,9 @@ internal class SubscriptionsTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -481,10 +532,13 @@ internal class SubscriptionsTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -517,6 +571,7 @@ internal class SubscriptionsTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -535,7 +590,7 @@ internal class SubscriptionsTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -548,7 +603,21 @@ internal class SubscriptionsTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -568,6 +637,15 @@ internal class SubscriptionsTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -580,10 +658,13 @@ internal class SubscriptionsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -606,11 +687,9 @@ internal class SubscriptionsTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -619,7 +698,7 @@ internal class SubscriptionsTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -630,11 +709,9 @@ internal class SubscriptionsTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -644,10 +721,13 @@ internal class SubscriptionsTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -701,9 +781,15 @@ internal class SubscriptionsTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -732,6 +818,7 @@ internal class SubscriptionsTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -809,6 +896,21 @@ internal class SubscriptionsTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -822,9 +924,9 @@ internal class SubscriptionsTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -846,9 +948,9 @@ internal class SubscriptionsTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -866,9 +968,9 @@ internal class SubscriptionsTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -893,9 +995,15 @@ internal class SubscriptionsTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -925,9 +1033,9 @@ internal class SubscriptionsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -940,9 +1048,9 @@ internal class SubscriptionsTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -959,9 +1067,9 @@ internal class SubscriptionsTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -984,10 +1092,10 @@ internal class SubscriptionsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -1001,11 +1109,9 @@ internal class SubscriptionsTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1017,11 +1123,9 @@ internal class SubscriptionsTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1034,7 +1138,7 @@ internal class SubscriptionsTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1045,7 +1149,20 @@ internal class SubscriptionsTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1063,6 +1180,13 @@ internal class SubscriptionsTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1075,10 +1199,10 @@ internal class SubscriptionsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -1101,11 +1225,9 @@ internal class SubscriptionsTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1114,7 +1236,7 @@ internal class SubscriptionsTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1122,11 +1244,9 @@ internal class SubscriptionsTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1136,10 +1256,13 @@ internal class SubscriptionsTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -1170,6 +1293,7 @@ internal class SubscriptionsTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -1186,7 +1310,7 @@ internal class SubscriptionsTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric(BillableMetricTiny.builder().id("id").build()) .billingCycleConfiguration( @@ -1197,7 +1321,20 @@ internal class SubscriptionsTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field.PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1215,6 +1352,13 @@ internal class SubscriptionsTest { .durationUnit(CustomExpiration.DurationUnit.DAY) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator(Allocation.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1227,10 +1371,10 @@ internal class SubscriptionsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator.INCLUDES ) .addValue("string") .build() @@ -1253,11 +1397,9 @@ internal class SubscriptionsTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1266,7 +1408,7 @@ internal class SubscriptionsTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) @@ -1274,11 +1416,9 @@ internal class SubscriptionsTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1288,10 +1428,13 @@ internal class SubscriptionsTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -1346,9 +1489,15 @@ internal class SubscriptionsTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -1385,6 +1534,7 @@ internal class SubscriptionsTest { .id("id") .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .balance("balance") .billingAddress( Address.builder() @@ -1462,6 +1612,21 @@ internal class SubscriptionsTest { .excluded(true) .build() ) + .automaticTaxEnabled(true) + .paymentConfiguration( + Customer.PaymentConfiguration.builder() + .addPaymentProvider( + Customer.PaymentConfiguration.PaymentProvider.builder() + .providerType( + Customer.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .reportingConfiguration( Customer.ReportingConfiguration.builder().exempt(true).build() ) @@ -1475,9 +1640,9 @@ internal class SubscriptionsTest { .discountType(AmountDiscountInterval.DiscountType.AMOUNT) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + AmountDiscountInterval.Filter.builder() + .field(AmountDiscountInterval.Filter.Field.PRICE_ID) + .operator(AmountDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1499,9 +1664,9 @@ internal class SubscriptionsTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MaximumInterval.Filter.builder() + .field(MaximumInterval.Filter.Field.PRICE_ID) + .operator(MaximumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1519,9 +1684,9 @@ internal class SubscriptionsTest { .addAppliesToPriceIntervalId("string") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + MinimumInterval.Filter.builder() + .field(MinimumInterval.Filter.Field.PRICE_ID) + .operator(MinimumInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1546,9 +1711,15 @@ internal class SubscriptionsTest { ) .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PlanPhaseUsageDiscountAdjustment.Filter.builder() + .field( + PlanPhaseUsageDiscountAdjustment.Filter.Field + .PRICE_ID + ) + .operator( + PlanPhaseUsageDiscountAdjustment.Filter.Operator + .INCLUDES + ) .addValue("string") .build() ) @@ -1578,9 +1749,11 @@ internal class SubscriptionsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator( + PercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -1593,9 +1766,9 @@ internal class SubscriptionsTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1612,9 +1785,9 @@ internal class SubscriptionsTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1637,10 +1810,13 @@ internal class SubscriptionsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -1654,11 +1830,9 @@ internal class SubscriptionsTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1670,11 +1844,9 @@ internal class SubscriptionsTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1687,7 +1859,7 @@ internal class SubscriptionsTest { .build() ) .addPrice( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -1700,7 +1872,21 @@ internal class SubscriptionsTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1720,6 +1906,15 @@ internal class SubscriptionsTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1732,10 +1927,13 @@ internal class SubscriptionsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -1758,11 +1956,9 @@ internal class SubscriptionsTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1771,7 +1967,7 @@ internal class SubscriptionsTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1782,11 +1978,9 @@ internal class SubscriptionsTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1796,10 +1990,13 @@ internal class SubscriptionsTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() @@ -1832,6 +2029,7 @@ internal class SubscriptionsTest { PriceInterval.builder() .id("id") .billingCycleDay(0L) + .canDeferBilling(true) .currentBillingPeriodEndDate( OffsetDateTime.parse("2019-12-27T18:11:19.117Z") ) @@ -1850,7 +2048,7 @@ internal class SubscriptionsTest { .build() ) .price( - Price.Unit.builder() + Price.UnitPrice.builder() .id("id") .billableMetric( BillableMetricTiny.builder().id("id").build() @@ -1863,7 +2061,21 @@ internal class SubscriptionsTest { ) .build() ) - .cadence(Price.Unit.Cadence.ONE_TIME) + .billingMode(Price.UnitPrice.BillingMode.IN_ADVANCE) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .addCompositePriceFilter( + Price.UnitPrice.CompositePriceFilter.builder() + .field( + Price.UnitPrice.CompositePriceFilter.Field + .PRICE_ID + ) + .operator( + Price.UnitPrice.CompositePriceFilter.Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .conversionRate(0.0) .unitConversionRateConfig( ConversionRateUnitConfig.builder() @@ -1883,6 +2095,15 @@ internal class SubscriptionsTest { ) .build() ) + .addFilter( + Allocation.Filter.builder() + .field(Allocation.Filter.Field.PRICE_ID) + .operator( + Allocation.Filter.Operator.INCLUDES + ) + .addValue("string") + .build() + ) .build() ) .currency("currency") @@ -1895,10 +2116,13 @@ internal class SubscriptionsTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) + PercentageDiscount.Filter.builder() + .field( + PercentageDiscount.Filter.Field.PRICE_ID + ) .operator( - TransformPriceFilter.Operator.INCLUDES + PercentageDiscount.Filter.Operator + .INCLUDES ) .addValue("string") .build() @@ -1921,11 +2145,9 @@ internal class SubscriptionsTest { Maximum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Maximum.Filter.builder() + .field(Maximum.Filter.Field.PRICE_ID) + .operator(Maximum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1934,7 +2156,7 @@ internal class SubscriptionsTest { ) .maximumAmount("maximum_amount") .metadata( - Price.Unit.Metadata.builder() + Price.UnitPrice.Metadata.builder() .putAdditionalProperty( "foo", JsonValue.from("string"), @@ -1945,11 +2167,9 @@ internal class SubscriptionsTest { Minimum.builder() .addAppliesToPriceId("string") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator( - TransformPriceFilter.Operator.INCLUDES - ) + Minimum.Filter.builder() + .field(Minimum.Filter.Field.PRICE_ID) + .operator(Minimum.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -1959,10 +2179,13 @@ internal class SubscriptionsTest { .minimumAmount("minimum_amount") .name("name") .planPhaseOrder(0L) - .priceType(Price.Unit.PriceType.USAGE_PRICE) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) .replacesPriceId("replaces_price_id") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .dimensionalPriceConfiguration( DimensionalPriceConfiguration.builder() diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TierConfigTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TierConfigTest.kt deleted file mode 100644 index 2651c40fc..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TierConfigTest.kt +++ /dev/null @@ -1,36 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class TierConfigTest { - - @Test - fun create() { - val tierConfig = - TierConfig.builder().firstUnit(1.0).lastUnit(1000.0).unitAmount("3.00").build() - - assertThat(tierConfig.firstUnit()).isEqualTo(1.0) - assertThat(tierConfig.lastUnit()).isEqualTo(1000.0) - assertThat(tierConfig.unitAmount()).isEqualTo("3.00") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val tierConfig = - TierConfig.builder().firstUnit(1.0).lastUnit(1000.0).unitAmount("3.00").build() - - val roundtrippedTierConfig = - jsonMapper.readValue( - jsonMapper.writeValueAsString(tierConfig), - jacksonTypeRef(), - ) - - assertThat(roundtrippedTierConfig).isEqualTo(tierConfig) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TierSubLineItemTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TierSubLineItemTest.kt index db434dc1a..40aafa23b 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TierSubLineItemTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TierSubLineItemTest.kt @@ -18,7 +18,11 @@ internal class TierSubLineItemTest { .name("Tier One") .quantity(5.0) .tierConfig( - TierConfig.builder().firstUnit(1.0).lastUnit(1000.0).unitAmount("3.00").build() + TierSubLineItem.TierConfig.builder() + .firstUnit(1.0) + .lastUnit(1000.0) + .unitAmount("3.00") + .build() ) .type(TierSubLineItem.Type.TIER) .build() @@ -30,7 +34,11 @@ internal class TierSubLineItemTest { assertThat(tierSubLineItem.quantity()).isEqualTo(5.0) assertThat(tierSubLineItem.tierConfig()) .isEqualTo( - TierConfig.builder().firstUnit(1.0).lastUnit(1000.0).unitAmount("3.00").build() + TierSubLineItem.TierConfig.builder() + .firstUnit(1.0) + .lastUnit(1000.0) + .unitAmount("3.00") + .build() ) assertThat(tierSubLineItem.type()).isEqualTo(TierSubLineItem.Type.TIER) } @@ -45,7 +53,11 @@ internal class TierSubLineItemTest { .name("Tier One") .quantity(5.0) .tierConfig( - TierConfig.builder().firstUnit(1.0).lastUnit(1000.0).unitAmount("3.00").build() + TierSubLineItem.TierConfig.builder() + .firstUnit(1.0) + .lastUnit(1000.0) + .unitAmount("3.00") + .build() ) .type(TierSubLineItem.Type.TIER) .build() diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TieredBpsConfigTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TieredBpsConfigTest.kt deleted file mode 100644 index 8b7c363ba..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TieredBpsConfigTest.kt +++ /dev/null @@ -1,60 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class TieredBpsConfigTest { - - @Test - fun create() { - val tieredBpsConfig = - TieredBpsConfig.builder() - .addTier( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - - assertThat(tieredBpsConfig.tiers()) - .containsExactly( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val tieredBpsConfig = - TieredBpsConfig.builder() - .addTier( - BpsTier.builder() - .bps(0.0) - .minimumAmount("minimum_amount") - .maximumAmount("maximum_amount") - .perUnitMaximum("per_unit_maximum") - .build() - ) - .build() - - val roundtrippedTieredBpsConfig = - jsonMapper.readValue( - jsonMapper.writeValueAsString(tieredBpsConfig), - jacksonTypeRef(), - ) - - assertThat(roundtrippedTieredBpsConfig).isEqualTo(tieredBpsConfig) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TieredConfigTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TieredConfigTest.kt index af1c382c5..05a8b5cdc 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TieredConfigTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TieredConfigTest.kt @@ -16,12 +16,14 @@ internal class TieredConfigTest { .addTier( Tier.builder().firstUnit(0.0).unitAmount("unit_amount").lastUnit(0.0).build() ) + .prorated(true) .build() assertThat(tieredConfig.tiers()) .containsExactly( Tier.builder().firstUnit(0.0).unitAmount("unit_amount").lastUnit(0.0).build() ) + assertThat(tieredConfig.prorated()).isEqualTo(true) } @Test @@ -32,6 +34,7 @@ internal class TieredConfigTest { .addTier( Tier.builder().firstUnit(0.0).unitAmount("unit_amount").lastUnit(0.0).build() ) + .prorated(true) .build() val roundtrippedTieredConfig = diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TransformPriceFilterTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TransformPriceFilterTest.kt deleted file mode 100644 index 7fa1c6b87..000000000 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TransformPriceFilterTest.kt +++ /dev/null @@ -1,45 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.withorb.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.withorb.api.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class TransformPriceFilterTest { - - @Test - fun create() { - val transformPriceFilter = - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - - assertThat(transformPriceFilter.field()).isEqualTo(TransformPriceFilter.Field.PRICE_ID) - assertThat(transformPriceFilter.operator()) - .isEqualTo(TransformPriceFilter.Operator.INCLUDES) - assertThat(transformPriceFilter.values()).containsExactly("string") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val transformPriceFilter = - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) - .addValue("string") - .build() - - val roundtrippedTransformPriceFilter = - jsonMapper.readValue( - jsonMapper.writeValueAsString(transformPriceFilter), - jacksonTypeRef(), - ) - - assertThat(roundtrippedTransformPriceFilter).isEqualTo(transformPriceFilter) - } -} diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TrialDiscountTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TrialDiscountTest.kt index 0cb107735..45b8bf898 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TrialDiscountTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/TrialDiscountTest.kt @@ -17,9 +17,9 @@ internal class TrialDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + TrialDiscount.Filter.builder() + .field(TrialDiscount.Filter.Field.PRICE_ID) + .operator(TrialDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -33,9 +33,9 @@ internal class TrialDiscountTest { .containsExactly("h74gfhdjvn7ujokd", "7hfgtgjnbvc3ujkl") assertThat(trialDiscount.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + TrialDiscount.Filter.builder() + .field(TrialDiscount.Filter.Field.PRICE_ID) + .operator(TrialDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -53,9 +53,9 @@ internal class TrialDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + TrialDiscount.Filter.builder() + .field(TrialDiscount.Filter.Field.PRICE_ID) + .operator(TrialDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/UnitConfigTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/UnitConfigTest.kt index 98fcacade..c8d05de67 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/UnitConfigTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/UnitConfigTest.kt @@ -11,15 +11,16 @@ internal class UnitConfigTest { @Test fun create() { - val unitConfig = UnitConfig.builder().unitAmount("unit_amount").build() + val unitConfig = UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() assertThat(unitConfig.unitAmount()).isEqualTo("unit_amount") + assertThat(unitConfig.prorated()).isEqualTo(true) } @Test fun roundtrip() { val jsonMapper = jsonMapper() - val unitConfig = UnitConfig.builder().unitAmount("unit_amount").build() + val unitConfig = UnitConfig.builder().unitAmount("unit_amount").prorated(true).build() val roundtrippedUnitConfig = jsonMapper.readValue( diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/UsageDiscountIntervalTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/UsageDiscountIntervalTest.kt index 04f875ed2..034352cb0 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/UsageDiscountIntervalTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/UsageDiscountIntervalTest.kt @@ -18,9 +18,9 @@ internal class UsageDiscountIntervalTest { .discountType(UsageDiscountInterval.DiscountType.USAGE) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + UsageDiscountInterval.Filter.builder() + .field(UsageDiscountInterval.Filter.Field.PRICE_ID) + .operator(UsageDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -35,9 +35,9 @@ internal class UsageDiscountIntervalTest { .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(usageDiscountInterval.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + UsageDiscountInterval.Filter.builder() + .field(UsageDiscountInterval.Filter.Field.PRICE_ID) + .operator(UsageDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -55,9 +55,9 @@ internal class UsageDiscountIntervalTest { .discountType(UsageDiscountInterval.DiscountType.USAGE) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + UsageDiscountInterval.Filter.builder() + .field(UsageDiscountInterval.Filter.Field.PRICE_ID) + .operator(UsageDiscountInterval.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/UsageDiscountTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/UsageDiscountTest.kt index 4b464a977..deda61052 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/UsageDiscountTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/UsageDiscountTest.kt @@ -18,9 +18,9 @@ internal class UsageDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + UsageDiscount.Filter.builder() + .field(UsageDiscount.Filter.Field.PRICE_ID) + .operator(UsageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -33,9 +33,9 @@ internal class UsageDiscountTest { .containsExactly("h74gfhdjvn7ujokd", "7hfgtgjnbvc3ujkl") assertThat(usageDiscount.filters()) .containsExactly( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + UsageDiscount.Filter.builder() + .field(UsageDiscount.Filter.Field.PRICE_ID) + .operator(UsageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) @@ -52,9 +52,9 @@ internal class UsageDiscountTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + UsageDiscount.Filter.builder() + .field(UsageDiscount.Filter.Field.PRICE_ID) + .operator(UsageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/VoidInitiatedLedgerEntryTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/VoidInitiatedLedgerEntryTest.kt index 9077e8275..c3fb9e8e9 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/VoidInitiatedLedgerEntryTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/VoidInitiatedLedgerEntryTest.kt @@ -22,6 +22,13 @@ internal class VoidInitiatedLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -57,6 +64,13 @@ internal class VoidInitiatedLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -100,6 +114,13 @@ internal class VoidInitiatedLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/VoidLedgerEntryTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/VoidLedgerEntryTest.kt index 4077cfb55..a6e83d0a1 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/VoidLedgerEntryTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/models/VoidLedgerEntryTest.kt @@ -22,6 +22,13 @@ internal class VoidLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -56,6 +63,13 @@ internal class VoidLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) @@ -95,6 +109,13 @@ internal class VoidLedgerEntryTest { AffectedBlock.builder() .id("id") .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + AffectedBlock.Filter.builder() + .field(AffectedBlock.Filter.Field.PRICE_ID) + .operator(AffectedBlock.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) .perUnitCostBasis("per_unit_cost_basis") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/ErrorHandlingTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/ErrorHandlingTest.kt index 591b40a6a..0de61a15a 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/ErrorHandlingTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/ErrorHandlingTest.kt @@ -94,6 +94,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -118,6 +119,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -137,6 +154,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -186,6 +204,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -210,6 +229,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -229,6 +264,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -278,6 +314,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -302,6 +339,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -321,6 +374,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -370,6 +424,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -394,6 +449,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -413,6 +484,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -462,6 +534,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -486,6 +559,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -505,6 +594,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -554,6 +644,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -578,6 +669,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -597,6 +704,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -646,6 +754,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -670,6 +779,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -689,6 +814,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -738,6 +864,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -762,6 +889,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -781,6 +924,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -830,6 +974,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -854,6 +999,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -873,6 +1034,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -922,6 +1084,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -946,6 +1109,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -965,6 +1144,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -1014,6 +1194,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -1038,6 +1219,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -1057,6 +1254,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -1106,6 +1304,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -1130,6 +1329,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -1149,6 +1364,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -1198,6 +1414,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -1222,6 +1439,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -1241,6 +1474,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -1290,6 +1524,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -1314,6 +1549,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -1333,6 +1584,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -1382,6 +1634,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -1406,6 +1659,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -1425,6 +1694,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -1474,6 +1744,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -1498,6 +1769,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -1517,6 +1804,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -1564,6 +1852,7 @@ internal class ErrorHandlingTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -1588,6 +1877,22 @@ internal class ErrorHandlingTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .builder() + .providerType( + CustomerCreateParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -1607,6 +1912,7 @@ internal class ErrorHandlingTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/ServiceParamsTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/ServiceParamsTest.kt index 834d04a53..447c39875 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/ServiceParamsTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/ServiceParamsTest.kt @@ -64,6 +64,7 @@ internal class ServiceParamsTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -88,6 +89,20 @@ internal class ServiceParamsTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider.builder() + .providerType( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration(NewReportingConfiguration.builder().exempt(true).build()) @@ -105,6 +120,7 @@ internal class ServiceParamsTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/BetaServiceAsyncTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/BetaServiceAsyncTest.kt index d0753d065..32d02018b 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/BetaServiceAsyncTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/BetaServiceAsyncTest.kt @@ -15,7 +15,6 @@ import com.withorb.api.models.NewBillingCycleConfiguration import com.withorb.api.models.NewDimensionalPriceConfiguration import com.withorb.api.models.NewPercentageDiscount import com.withorb.api.models.NewPlanUnitPrice -import com.withorb.api.models.TransformPriceFilter import com.withorb.api.models.UnitConfig import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -52,9 +51,11 @@ internal class BetaServiceAsyncTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -79,6 +80,15 @@ internal class BetaServiceAsyncTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -89,7 +99,10 @@ internal class BetaServiceAsyncTest { .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -165,9 +178,11 @@ internal class BetaServiceAsyncTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -194,6 +209,15 @@ internal class BetaServiceAsyncTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -204,7 +228,10 @@ internal class BetaServiceAsyncTest { .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/CustomerServiceAsyncTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/CustomerServiceAsyncTest.kt index 169d39172..f7d254448 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/CustomerServiceAsyncTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/CustomerServiceAsyncTest.kt @@ -48,6 +48,7 @@ internal class CustomerServiceAsyncTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -72,6 +73,20 @@ internal class CustomerServiceAsyncTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider.builder() + .providerType( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -91,6 +106,7 @@ internal class CustomerServiceAsyncTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -134,6 +150,7 @@ internal class CustomerServiceAsyncTest { ) .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -160,6 +177,20 @@ internal class CustomerServiceAsyncTest { .build() ) .name("name") + .paymentConfiguration( + CustomerUpdateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerUpdateParams.PaymentConfiguration.PaymentProvider.builder() + .providerType( + CustomerUpdateParams.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerUpdateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -179,6 +210,7 @@ internal class CustomerServiceAsyncTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -301,6 +333,7 @@ internal class CustomerServiceAsyncTest { ) .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -327,6 +360,23 @@ internal class CustomerServiceAsyncTest { .build() ) .name("name") + .paymentConfiguration( + CustomerUpdateByExternalIdParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerUpdateByExternalIdParams.PaymentConfiguration + .PaymentProvider + .builder() + .providerType( + CustomerUpdateByExternalIdParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerUpdateByExternalIdParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -346,6 +396,7 @@ internal class CustomerServiceAsyncTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/InvoiceLineItemServiceAsyncTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/InvoiceLineItemServiceAsyncTest.kt index 49d963e14..da5ad4379 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/InvoiceLineItemServiceAsyncTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/InvoiceLineItemServiceAsyncTest.kt @@ -27,9 +27,10 @@ internal class InvoiceLineItemServiceAsyncTest { .amount("12.00") .endDate(LocalDate.parse("2023-09-22")) .invoiceId("4khy3nwzktxv7") - .name("Item Name") .quantity(1.0) .startDate(LocalDate.parse("2023-09-22")) + .itemId("4khy3nwzktxv7") + .name("Item Name") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/InvoiceServiceAsyncTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/InvoiceServiceAsyncTest.kt index 8d2d127ca..d6737cdcf 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/InvoiceServiceAsyncTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/InvoiceServiceAsyncTest.kt @@ -11,7 +11,6 @@ import com.withorb.api.models.InvoiceIssueParams import com.withorb.api.models.InvoiceMarkPaidParams import com.withorb.api.models.InvoiceUpdateParams import com.withorb.api.models.PercentageDiscount -import com.withorb.api.models.TransformPriceFilter import com.withorb.api.models.UnitConfig import java.time.LocalDate import java.time.OffsetDateTime @@ -43,7 +42,12 @@ internal class InvoiceServiceAsyncTest { .name("Line Item Name") .quantity(1.0) .startDate(LocalDate.parse("2023-09-22")) - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .build() ) .customerId("4khy3nwzktxv7") @@ -54,15 +58,16 @@ internal class InvoiceServiceAsyncTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) .reason("reason") .build() ) + .dueDate(LocalDate.parse("2023-09-22")) .externalCustomerId("external-customer-id") .memo("An optional memo for my invoice.") .metadata( @@ -91,11 +96,14 @@ internal class InvoiceServiceAsyncTest { invoiceServiceAsync.update( InvoiceUpdateParams.builder() .invoiceId("invoice_id") + .dueDate(LocalDate.parse("2023-09-22")) + .invoiceDate(LocalDate.parse("2023-09-22")) .metadata( InvoiceUpdateParams.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .netTerms(0L) .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/PlanServiceAsyncTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/PlanServiceAsyncTest.kt index f3e9737d4..e64d85947 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/PlanServiceAsyncTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/PlanServiceAsyncTest.kt @@ -14,7 +14,6 @@ import com.withorb.api.models.NewPercentageDiscount import com.withorb.api.models.NewPlanUnitPrice import com.withorb.api.models.PlanCreateParams import com.withorb.api.models.PlanUpdateParams -import com.withorb.api.models.TransformPriceFilter import com.withorb.api.models.UnitConfig import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -50,6 +49,15 @@ internal class PlanServiceAsyncTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -60,7 +68,10 @@ internal class PlanServiceAsyncTest { .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -124,9 +135,11 @@ internal class PlanServiceAsyncTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/PriceServiceAsyncTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/PriceServiceAsyncTest.kt index 5fa67c856..a0a6e8614 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/PriceServiceAsyncTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/PriceServiceAsyncTest.kt @@ -41,7 +41,12 @@ internal class PriceServiceAsyncTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -179,7 +184,10 @@ internal class PriceServiceAsyncTest { .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -277,7 +285,10 @@ internal class PriceServiceAsyncTest { .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/SubscriptionChangeServiceAsyncTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/SubscriptionChangeServiceAsyncTest.kt index 8cd31699a..d7e9db8bd 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/SubscriptionChangeServiceAsyncTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/SubscriptionChangeServiceAsyncTest.kt @@ -5,6 +5,7 @@ package com.withorb.api.services.async import com.withorb.api.TestServerExtension import com.withorb.api.client.okhttp.OrbOkHttpClientAsync import com.withorb.api.models.SubscriptionChangeApplyParams +import java.time.LocalDate import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -39,6 +40,10 @@ internal class SubscriptionChangeServiceAsyncTest { SubscriptionChangeApplyParams.builder() .subscriptionChangeId("subscription_change_id") .description("description") + .markAsPaid(true) + .paymentExternalId("payment_external_id") + .paymentNotes("payment_notes") + .paymentReceivedDate(LocalDate.parse("2019-12-27")) .previouslyCollectedAmount("previously_collected_amount") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/SubscriptionServiceAsyncTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/SubscriptionServiceAsyncTest.kt index 3cff00d60..933aced72 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/SubscriptionServiceAsyncTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/SubscriptionServiceAsyncTest.kt @@ -27,7 +27,6 @@ import com.withorb.api.models.SubscriptionUnscheduleFixedFeeQuantityUpdatesParam import com.withorb.api.models.SubscriptionUpdateFixedFeeQuantityParams import com.withorb.api.models.SubscriptionUpdateParams import com.withorb.api.models.SubscriptionUpdateTrialParams -import com.withorb.api.models.TransformPriceFilter import com.withorb.api.models.UnitConfig import java.time.LocalDate import java.time.OffsetDateTime @@ -65,9 +64,11 @@ internal class SubscriptionServiceAsyncTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -94,6 +95,15 @@ internal class SubscriptionServiceAsyncTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -116,7 +126,10 @@ internal class SubscriptionServiceAsyncTest { .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -223,9 +236,11 @@ internal class SubscriptionServiceAsyncTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -251,6 +266,15 @@ internal class SubscriptionServiceAsyncTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -272,7 +296,10 @@ internal class SubscriptionServiceAsyncTest { .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -505,8 +532,18 @@ internal class SubscriptionServiceAsyncTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) + .canDeferBilling(true) .addAmountDiscount(0.0) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .externalPriceId("external_price_id") @@ -528,7 +565,10 @@ internal class SubscriptionServiceAsyncTest { .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -579,6 +619,7 @@ internal class SubscriptionServiceAsyncTest { ) .addAddAdjustment( SubscriptionPriceIntervalsParams.AddAdjustment.builder() + .startDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .adjustment( NewPercentageDiscount.builder() .adjustmentType( @@ -592,9 +633,11 @@ internal class SubscriptionServiceAsyncTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -602,15 +645,17 @@ internal class SubscriptionServiceAsyncTest { .priceType(NewPercentageDiscount.PriceType.USAGE) .build() ) - .startDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .adjustmentId("h74gfhdjvn7ujokd") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .allowInvoiceCreditOrVoid(true) + .canDeferBilling(true) .addEdit( SubscriptionPriceIntervalsParams.Edit.builder() .priceIntervalId("sdfs6wdjvn7ujokd") .billingCycleDay(0L) + .canDeferBilling(true) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .filter("my_property > 100 AND my_other_property = 'bar'") .addFixedFeeQuantityTransition( @@ -690,9 +735,11 @@ internal class SubscriptionServiceAsyncTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -719,6 +766,15 @@ internal class SubscriptionServiceAsyncTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -741,7 +797,10 @@ internal class SubscriptionServiceAsyncTest { .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -839,9 +898,11 @@ internal class SubscriptionServiceAsyncTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -867,6 +928,15 @@ internal class SubscriptionServiceAsyncTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -888,7 +958,10 @@ internal class SubscriptionServiceAsyncTest { .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/beta/ExternalPlanIdServiceAsyncTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/beta/ExternalPlanIdServiceAsyncTest.kt index 2b99ad625..9f444c1fb 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/beta/ExternalPlanIdServiceAsyncTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/beta/ExternalPlanIdServiceAsyncTest.kt @@ -15,7 +15,6 @@ import com.withorb.api.models.NewBillingCycleConfiguration import com.withorb.api.models.NewDimensionalPriceConfiguration import com.withorb.api.models.NewPercentageDiscount import com.withorb.api.models.NewPlanUnitPrice -import com.withorb.api.models.TransformPriceFilter import com.withorb.api.models.UnitConfig import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -52,9 +51,11 @@ internal class ExternalPlanIdServiceAsyncTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -79,6 +80,15 @@ internal class ExternalPlanIdServiceAsyncTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -89,7 +99,10 @@ internal class ExternalPlanIdServiceAsyncTest { .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -165,9 +178,11 @@ internal class ExternalPlanIdServiceAsyncTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -194,6 +209,15 @@ internal class ExternalPlanIdServiceAsyncTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -204,7 +228,10 @@ internal class ExternalPlanIdServiceAsyncTest { .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncTest.kt index 54a1a58fe..3b240a991 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncTest.kt @@ -49,13 +49,31 @@ internal class LedgerServiceAsyncTest { .description("description") .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter + .builder() + .field( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter + .Field + .ITEM_ID + ) + .operator( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .invoiceSettings( CustomerCreditLedgerCreateEntryParams.Body.Increment.InvoiceSettings .builder() .autoCollection(true) - .netTerms(0L) + .customDueDate(LocalDate.parse("2019-12-27")) .invoiceDate(LocalDate.parse("2019-12-27")) + .itemId("item_id") .memo("memo") + .netTerms(0L) .requireSuccessfulPayment(true) .build() ) @@ -94,14 +112,37 @@ internal class LedgerServiceAsyncTest { .description("description") .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment + .Filter + .builder() + .field( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body + .Increment + .Filter + .Field + .ITEM_ID + ) + .operator( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body + .Increment + .Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .invoiceSettings( CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment .InvoiceSettings .builder() .autoCollection(true) - .netTerms(0L) + .customDueDate(LocalDate.parse("2019-12-27")) .invoiceDate(LocalDate.parse("2019-12-27")) + .itemId("item_id") .memo("memo") + .netTerms(0L) .requireSuccessfulPayment(true) .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/BetaServiceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/BetaServiceTest.kt index 24e977345..7f538b370 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/BetaServiceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/BetaServiceTest.kt @@ -15,7 +15,6 @@ import com.withorb.api.models.NewBillingCycleConfiguration import com.withorb.api.models.NewDimensionalPriceConfiguration import com.withorb.api.models.NewPercentageDiscount import com.withorb.api.models.NewPlanUnitPrice -import com.withorb.api.models.TransformPriceFilter import com.withorb.api.models.UnitConfig import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -52,9 +51,11 @@ internal class BetaServiceTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -79,6 +80,15 @@ internal class BetaServiceTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -89,7 +99,10 @@ internal class BetaServiceTest { .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -165,9 +178,11 @@ internal class BetaServiceTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -194,6 +209,15 @@ internal class BetaServiceTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -204,7 +228,10 @@ internal class BetaServiceTest { .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/CustomerServiceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/CustomerServiceTest.kt index 3218fe7e9..30037704e 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/CustomerServiceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/CustomerServiceTest.kt @@ -48,6 +48,7 @@ internal class CustomerServiceTest { ) .addAdditionalEmail("dev@stainless.com") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -72,6 +73,20 @@ internal class CustomerServiceTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .paymentConfiguration( + CustomerCreateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerCreateParams.PaymentConfiguration.PaymentProvider.builder() + .providerType( + CustomerCreateParams.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -91,6 +106,7 @@ internal class CustomerServiceTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -134,6 +150,7 @@ internal class CustomerServiceTest { ) .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -160,6 +177,20 @@ internal class CustomerServiceTest { .build() ) .name("name") + .paymentConfiguration( + CustomerUpdateParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerUpdateParams.PaymentConfiguration.PaymentProvider.builder() + .providerType( + CustomerUpdateParams.PaymentConfiguration.PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerUpdateParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -179,6 +210,7 @@ internal class CustomerServiceTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) @@ -299,6 +331,7 @@ internal class CustomerServiceTest { ) .addAdditionalEmail("string") .autoCollection(true) + .autoIssuance(true) .billingAddress( AddressInput.builder() .city("city") @@ -325,6 +358,23 @@ internal class CustomerServiceTest { .build() ) .name("name") + .paymentConfiguration( + CustomerUpdateByExternalIdParams.PaymentConfiguration.builder() + .addPaymentProvider( + CustomerUpdateByExternalIdParams.PaymentConfiguration + .PaymentProvider + .builder() + .providerType( + CustomerUpdateByExternalIdParams.PaymentConfiguration + .PaymentProvider + .ProviderType + .STRIPE + ) + .addExcludedPaymentMethodType("string") + .build() + ) + .build() + ) .paymentProvider(CustomerUpdateByExternalIdParams.PaymentProvider.QUICKBOOKS) .paymentProviderId("payment_provider_id") .reportingConfiguration( @@ -344,6 +394,7 @@ internal class CustomerServiceTest { NewAvalaraTaxConfiguration.builder() .taxExempt(true) .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .automaticTaxEnabled(true) .taxExemptionCode("tax_exemption_code") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/InvoiceLineItemServiceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/InvoiceLineItemServiceTest.kt index 2f8dc2ce6..237b42ccc 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/InvoiceLineItemServiceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/InvoiceLineItemServiceTest.kt @@ -27,9 +27,10 @@ internal class InvoiceLineItemServiceTest { .amount("12.00") .endDate(LocalDate.parse("2023-09-22")) .invoiceId("4khy3nwzktxv7") - .name("Item Name") .quantity(1.0) .startDate(LocalDate.parse("2023-09-22")) + .itemId("4khy3nwzktxv7") + .name("Item Name") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/InvoiceServiceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/InvoiceServiceTest.kt index d6a5b2996..e7277f0a1 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/InvoiceServiceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/InvoiceServiceTest.kt @@ -11,7 +11,6 @@ import com.withorb.api.models.InvoiceIssueParams import com.withorb.api.models.InvoiceMarkPaidParams import com.withorb.api.models.InvoiceUpdateParams import com.withorb.api.models.PercentageDiscount -import com.withorb.api.models.TransformPriceFilter import com.withorb.api.models.UnitConfig import java.time.LocalDate import java.time.OffsetDateTime @@ -43,7 +42,12 @@ internal class InvoiceServiceTest { .name("Line Item Name") .quantity(1.0) .startDate(LocalDate.parse("2023-09-22")) - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .build() ) .customerId("4khy3nwzktxv7") @@ -54,15 +58,16 @@ internal class InvoiceServiceTest { .addAppliesToPriceId("h74gfhdjvn7ujokd") .addAppliesToPriceId("7hfgtgjnbvc3ujkl") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + PercentageDiscount.Filter.builder() + .field(PercentageDiscount.Filter.Field.PRICE_ID) + .operator(PercentageDiscount.Filter.Operator.INCLUDES) .addValue("string") .build() ) .reason("reason") .build() ) + .dueDate(LocalDate.parse("2023-09-22")) .externalCustomerId("external-customer-id") .memo("An optional memo for my invoice.") .metadata( @@ -91,11 +96,14 @@ internal class InvoiceServiceTest { invoiceService.update( InvoiceUpdateParams.builder() .invoiceId("invoice_id") + .dueDate(LocalDate.parse("2023-09-22")) + .invoiceDate(LocalDate.parse("2023-09-22")) .metadata( InvoiceUpdateParams.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .netTerms(0L) .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/PlanServiceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/PlanServiceTest.kt index b3af60641..62e6a8a4e 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/PlanServiceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/PlanServiceTest.kt @@ -14,7 +14,6 @@ import com.withorb.api.models.NewPercentageDiscount import com.withorb.api.models.NewPlanUnitPrice import com.withorb.api.models.PlanCreateParams import com.withorb.api.models.PlanUpdateParams -import com.withorb.api.models.TransformPriceFilter import com.withorb.api.models.UnitConfig import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -50,6 +49,15 @@ internal class PlanServiceTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -60,7 +68,10 @@ internal class PlanServiceTest { .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -124,9 +135,11 @@ internal class PlanServiceTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/PriceServiceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/PriceServiceTest.kt index e11ed1229..de3c5a9ae 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/PriceServiceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/PriceServiceTest.kt @@ -41,7 +41,12 @@ internal class PriceServiceTest { .itemId("item_id") .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") - .unitConfig(UnitConfig.builder().unitAmount("unit_amount").build()) + .unitConfig( + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() + ) .billableMetricId("billable_metric_id") .billedInAdvance(true) .billingCycleConfiguration( @@ -179,7 +184,10 @@ internal class PriceServiceTest { .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -277,7 +285,10 @@ internal class PriceServiceTest { .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/SubscriptionChangeServiceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/SubscriptionChangeServiceTest.kt index 4fe649e82..eabf12d7f 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/SubscriptionChangeServiceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/SubscriptionChangeServiceTest.kt @@ -5,6 +5,7 @@ package com.withorb.api.services.blocking import com.withorb.api.TestServerExtension import com.withorb.api.client.okhttp.OrbOkHttpClient import com.withorb.api.models.SubscriptionChangeApplyParams +import java.time.LocalDate import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -39,6 +40,10 @@ internal class SubscriptionChangeServiceTest { SubscriptionChangeApplyParams.builder() .subscriptionChangeId("subscription_change_id") .description("description") + .markAsPaid(true) + .paymentExternalId("payment_external_id") + .paymentNotes("payment_notes") + .paymentReceivedDate(LocalDate.parse("2019-12-27")) .previouslyCollectedAmount("previously_collected_amount") .build() ) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/SubscriptionServiceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/SubscriptionServiceTest.kt index 3c88f501b..457bb6fcd 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/SubscriptionServiceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/SubscriptionServiceTest.kt @@ -27,7 +27,6 @@ import com.withorb.api.models.SubscriptionUnscheduleFixedFeeQuantityUpdatesParam import com.withorb.api.models.SubscriptionUpdateFixedFeeQuantityParams import com.withorb.api.models.SubscriptionUpdateParams import com.withorb.api.models.SubscriptionUpdateTrialParams -import com.withorb.api.models.TransformPriceFilter import com.withorb.api.models.UnitConfig import java.time.LocalDate import java.time.OffsetDateTime @@ -65,9 +64,11 @@ internal class SubscriptionServiceTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -94,6 +95,15 @@ internal class SubscriptionServiceTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -116,7 +126,10 @@ internal class SubscriptionServiceTest { .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -223,9 +236,11 @@ internal class SubscriptionServiceTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -251,6 +266,15 @@ internal class SubscriptionServiceTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -272,7 +296,10 @@ internal class SubscriptionServiceTest { .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -505,8 +532,18 @@ internal class SubscriptionServiceTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) + .canDeferBilling(true) .addAmountDiscount(0.0) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .externalPriceId("external_price_id") @@ -528,7 +565,10 @@ internal class SubscriptionServiceTest { .modelType(NewFloatingUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -579,6 +619,7 @@ internal class SubscriptionServiceTest { ) .addAddAdjustment( SubscriptionPriceIntervalsParams.AddAdjustment.builder() + .startDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .adjustment( NewPercentageDiscount.builder() .adjustmentType( @@ -592,9 +633,11 @@ internal class SubscriptionServiceTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -602,15 +645,17 @@ internal class SubscriptionServiceTest { .priceType(NewPercentageDiscount.PriceType.USAGE) .build() ) - .startDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .adjustmentId("h74gfhdjvn7ujokd") .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) .allowInvoiceCreditOrVoid(true) + .canDeferBilling(true) .addEdit( SubscriptionPriceIntervalsParams.Edit.builder() .priceIntervalId("sdfs6wdjvn7ujokd") .billingCycleDay(0L) + .canDeferBilling(true) .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .filter("my_property > 100 AND my_other_property = 'bar'") .addFixedFeeQuantityTransition( @@ -690,9 +735,11 @@ internal class SubscriptionServiceTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -719,6 +766,15 @@ internal class SubscriptionServiceTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -741,7 +797,10 @@ internal class SubscriptionServiceTest { .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -839,9 +898,11 @@ internal class SubscriptionServiceTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -867,6 +928,15 @@ internal class SubscriptionServiceTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .addDiscount( @@ -888,7 +958,10 @@ internal class SubscriptionServiceTest { .modelType(NewSubscriptionUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/beta/ExternalPlanIdServiceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/beta/ExternalPlanIdServiceTest.kt index f8208215c..961704179 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/beta/ExternalPlanIdServiceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/beta/ExternalPlanIdServiceTest.kt @@ -15,7 +15,6 @@ import com.withorb.api.models.NewBillingCycleConfiguration import com.withorb.api.models.NewDimensionalPriceConfiguration import com.withorb.api.models.NewPercentageDiscount import com.withorb.api.models.NewPlanUnitPrice -import com.withorb.api.models.TransformPriceFilter import com.withorb.api.models.UnitConfig import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -52,9 +51,11 @@ internal class ExternalPlanIdServiceTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -79,6 +80,15 @@ internal class ExternalPlanIdServiceTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -89,7 +99,10 @@ internal class ExternalPlanIdServiceTest { .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) @@ -165,9 +178,11 @@ internal class ExternalPlanIdServiceTest { .addAppliesToPriceId("price_2") .currency("currency") .addFilter( - TransformPriceFilter.builder() - .field(TransformPriceFilter.Field.PRICE_ID) - .operator(TransformPriceFilter.Operator.INCLUDES) + NewPercentageDiscount.Filter.builder() + .field(NewPercentageDiscount.Filter.Field.PRICE_ID) + .operator( + NewPercentageDiscount.Filter.Operator.INCLUDES + ) .addValue("string") .build() ) @@ -194,6 +209,15 @@ internal class ExternalPlanIdServiceTest { .build() ) .expiresAtEndOfCadence(true) + .addFilter( + NewAllocationPrice.Filter.builder() + .field(NewAllocationPrice.Filter.Field.ITEM_ID) + .operator(NewAllocationPrice.Filter.Operator.INCLUDES) + .addValue("string") + .build() + ) + .itemId("item_id") + .perUnitCostBasis("per_unit_cost_basis") .build() ) .planPhaseOrder(0L) @@ -204,7 +228,10 @@ internal class ExternalPlanIdServiceTest { .modelType(NewPlanUnitPrice.ModelType.UNIT) .name("Annual fee") .unitConfig( - UnitConfig.builder().unitAmount("unit_amount").build() + UnitConfig.builder() + .unitAmount("unit_amount") + .prorated(true) + .build() ) .billableMetricId("billable_metric_id") .billedInAdvance(true) diff --git a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceTest.kt b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceTest.kt index c484ee91e..3db03f154 100644 --- a/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceTest.kt +++ b/orb-kotlin-core/src/test/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceTest.kt @@ -49,13 +49,31 @@ internal class LedgerServiceTest { .description("description") .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter + .builder() + .field( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter + .Field + .ITEM_ID + ) + .operator( + CustomerCreditLedgerCreateEntryParams.Body.Increment.Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .invoiceSettings( CustomerCreditLedgerCreateEntryParams.Body.Increment.InvoiceSettings .builder() .autoCollection(true) - .netTerms(0L) + .customDueDate(LocalDate.parse("2019-12-27")) .invoiceDate(LocalDate.parse("2019-12-27")) + .itemId("item_id") .memo("memo") + .netTerms(0L) .requireSuccessfulPayment(true) .build() ) @@ -94,14 +112,37 @@ internal class LedgerServiceTest { .description("description") .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addFilter( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment + .Filter + .builder() + .field( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body + .Increment + .Filter + .Field + .ITEM_ID + ) + .operator( + CustomerCreditLedgerCreateEntryByExternalIdParams.Body + .Increment + .Filter + .Operator + .INCLUDES + ) + .addValue("string") + .build() + ) .invoiceSettings( CustomerCreditLedgerCreateEntryByExternalIdParams.Body.Increment .InvoiceSettings .builder() .autoCollection(true) - .netTerms(0L) + .customDueDate(LocalDate.parse("2019-12-27")) .invoiceDate(LocalDate.parse("2019-12-27")) + .itemId("item_id") .memo("memo") + .netTerms(0L) .requireSuccessfulPayment(true) .build() ) diff --git a/orb-kotlin-example/build.gradle.kts b/orb-kotlin-example/build.gradle.kts index 1bbc9e978..693f55aa4 100644 --- a/orb-kotlin-example/build.gradle.kts +++ b/orb-kotlin-example/build.gradle.kts @@ -9,7 +9,7 @@ dependencies { application { // Use `./gradlew :orb-kotlin-example:run` to run `Main` - // Use `./gradlew :orb-kotlin-example:run -Dexample=Something` to run `SomethingExample` + // Use `./gradlew :orb-kotlin-example:run -Pexample=Something` to run `SomethingExample` mainClass = "com.withorb.api.example.${ if (project.hasProperty("example")) "${project.property("example")}ExampleKt" diff --git a/orb-kotlin-proguard-test/build.gradle.kts b/orb-kotlin-proguard-test/build.gradle.kts new file mode 100644 index 000000000..fdb3abe1a --- /dev/null +++ b/orb-kotlin-proguard-test/build.gradle.kts @@ -0,0 +1,101 @@ +plugins { + id("orb.kotlin") + id("com.gradleup.shadow") version "8.3.8" +} + +buildscript { + repositories { + google() + } + + dependencies { + classpath("com.guardsquare:proguard-gradle:7.4.2") + classpath("com.android.tools:r8:8.3.37") + } +} + +dependencies { + testImplementation(project(":orb-kotlin")) + testImplementation(kotlin("test")) + testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3") + testImplementation("org.assertj:assertj-core:3.25.3") + testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.4") +} + +tasks.shadowJar { + from(sourceSets.test.get().output) + configurations = listOf(project.configurations.testRuntimeClasspath.get()) +} + +val proguardJarPath = "${layout.buildDirectory.get()}/libs/${project.name}-${project.version}-proguard.jar" +val proguardJar by tasks.registering(proguard.gradle.ProGuardTask::class) { + group = "verification" + dependsOn(tasks.shadowJar) + notCompatibleWithConfigurationCache("ProGuard") + + injars(tasks.shadowJar) + outjars(proguardJarPath) + printmapping("${layout.buildDirectory.get()}/proguard-mapping.txt") + + val javaHome = System.getProperty("java.home") + if (System.getProperty("java.version").startsWith("1.")) { + // Before Java 9, the runtime classes were packaged in a single jar file. + libraryjars("$javaHome/lib/rt.jar") + } else { + // As of Java 9, the runtime classes are packaged in modular jmod files. + libraryjars( + // Filters must be specified first, as a map. + mapOf("jarfilter" to "!**.jar", "filter" to "!module-info.class"), + "$javaHome/jmods/java.base.jmod" + ) + } + + configuration("./test.pro") + configuration("../orb-kotlin-core/src/main/resources/META-INF/proguard/orb-kotlin-core.pro") +} + +val testProGuard by tasks.registering(JavaExec::class) { + group = "verification" + dependsOn(proguardJar) + notCompatibleWithConfigurationCache("ProGuard") + + mainClass.set("com.withorb.api.proguard.ProGuardCompatibilityTest") + classpath = files(proguardJarPath) +} + +val r8JarPath = "${layout.buildDirectory.get()}/libs/${project.name}-${project.version}-r8.jar" +val r8Jar by tasks.registering(JavaExec::class) { + group = "verification" + dependsOn(tasks.shadowJar) + notCompatibleWithConfigurationCache("R8") + + mainClass.set("com.android.tools.r8.R8") + classpath = buildscript.configurations["classpath"] + + args = listOf( + "--release", + "--classfile", + "--output", r8JarPath, + "--lib", System.getProperty("java.home"), + "--pg-conf", "./test.pro", + "--pg-conf", "../orb-kotlin-core/src/main/resources/META-INF/proguard/orb-kotlin-core.pro", + "--pg-map-output", "${layout.buildDirectory.get()}/r8-mapping.txt", + tasks.shadowJar.get().archiveFile.get().asFile.absolutePath, + ) +} + +val testR8 by tasks.registering(JavaExec::class) { + group = "verification" + dependsOn(r8Jar) + notCompatibleWithConfigurationCache("R8") + + mainClass.set("com.withorb.api.proguard.ProGuardCompatibilityTest") + classpath = files(r8JarPath) +} + +tasks.test { + dependsOn(testProGuard) + dependsOn(testR8) + // We defer to the tests run via the ProGuard JAR. + enabled = false +} diff --git a/orb-kotlin-proguard-test/src/test/kotlin/com/withorb/api/proguard/ProGuardCompatibilityTest.kt b/orb-kotlin-proguard-test/src/test/kotlin/com/withorb/api/proguard/ProGuardCompatibilityTest.kt new file mode 100644 index 000000000..74be89c60 --- /dev/null +++ b/orb-kotlin-proguard-test/src/test/kotlin/com/withorb/api/proguard/ProGuardCompatibilityTest.kt @@ -0,0 +1,125 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.proguard + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.client.okhttp.OrbOkHttpClient +import com.withorb.api.core.jsonMapper +import com.withorb.api.models.AccountingProviderConfig +import com.withorb.api.models.BillingCycleRelativeDate +import com.withorb.api.models.ConversionRateConfig +import com.withorb.api.models.ConversionRateUnitConfig +import com.withorb.api.models.UnitConversionRateConfig +import kotlin.reflect.full.memberFunctions +import kotlin.reflect.jvm.javaMethod +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ProGuardCompatibilityTest { + + companion object { + + @JvmStatic + fun main(args: Array) { + // To debug that we're using the right JAR. + val jarPath = this::class.java.getProtectionDomain().codeSource.location + println("JAR being used: $jarPath") + + // We have to manually run the test methods instead of using the JUnit runner because it + // seems impossible to get working with R8. + val test = ProGuardCompatibilityTest() + test::class + .memberFunctions + .asSequence() + .filter { function -> + function.javaMethod?.isAnnotationPresent(Test::class.java) == true + } + .forEach { it.call(test) } + } + } + + @Test + fun proguardRules() { + val rulesFile = + javaClass.classLoader.getResourceAsStream("META-INF/proguard/orb-kotlin-core.pro") + + assertThat(rulesFile).isNotNull() + } + + @Test + fun client() { + val client = OrbOkHttpClient.builder().apiKey("My API Key").build() + + assertThat(client).isNotNull() + assertThat(client.topLevel()).isNotNull() + assertThat(client.beta()).isNotNull() + assertThat(client.coupons()).isNotNull() + assertThat(client.creditNotes()).isNotNull() + assertThat(client.customers()).isNotNull() + assertThat(client.events()).isNotNull() + assertThat(client.invoiceLineItems()).isNotNull() + assertThat(client.invoices()).isNotNull() + assertThat(client.items()).isNotNull() + assertThat(client.metrics()).isNotNull() + assertThat(client.plans()).isNotNull() + assertThat(client.prices()).isNotNull() + assertThat(client.subscriptions()).isNotNull() + assertThat(client.alerts()).isNotNull() + assertThat(client.dimensionalPriceGroups()).isNotNull() + assertThat(client.subscriptionChanges()).isNotNull() + } + + @Test + fun accountingProviderConfigRoundtrip() { + val jsonMapper = jsonMapper() + val accountingProviderConfig = + AccountingProviderConfig.builder() + .externalProviderId("external_provider_id") + .providerType("provider_type") + .build() + + val roundtrippedAccountingProviderConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(accountingProviderConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAccountingProviderConfig).isEqualTo(accountingProviderConfig) + } + + @Test + fun conversionRateConfigRoundtrip() { + val jsonMapper = jsonMapper() + val conversionRateConfig = + ConversionRateConfig.ofUnit( + UnitConversionRateConfig.builder() + .conversionRateType(UnitConversionRateConfig.ConversionRateType.UNIT) + .unitConfig( + ConversionRateUnitConfig.builder().unitAmount("unit_amount").build() + ) + .build() + ) + + val roundtrippedConversionRateConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(conversionRateConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedConversionRateConfig).isEqualTo(conversionRateConfig) + } + + @Test + fun billingCycleRelativeDateRoundtrip() { + val jsonMapper = jsonMapper() + val billingCycleRelativeDate = BillingCycleRelativeDate.START_OF_TERM + + val roundtrippedBillingCycleRelativeDate = + jsonMapper.readValue( + jsonMapper.writeValueAsString(billingCycleRelativeDate), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBillingCycleRelativeDate).isEqualTo(billingCycleRelativeDate) + } +} diff --git a/orb-kotlin-proguard-test/test.pro b/orb-kotlin-proguard-test/test.pro new file mode 100644 index 000000000..bda3f4002 --- /dev/null +++ b/orb-kotlin-proguard-test/test.pro @@ -0,0 +1,9 @@ +# Specify the entrypoint where ProGuard starts to determine what's reachable. +-keep class com.withorb.api.proguard.** { *; } + +# For the testing framework. +-keep class org.junit.** { *; } + +# Many warnings don't apply for our testing purposes. +-dontnote +-dontwarn \ No newline at end of file diff --git a/scripts/build b/scripts/build new file mode 100755 index 000000000..f40634826 --- /dev/null +++ b/scripts/build @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +echo "==> Building classes" +./gradlew build testClasses -x test diff --git a/scripts/format b/scripts/format index 456a69db9..9e294b973 100755 --- a/scripts/format +++ b/scripts/format @@ -4,5 +4,10 @@ set -e cd "$(dirname "$0")/.." -echo "==> Running spotlessApply" -./gradlew spotlessApply +if command -v ktfmt &> /dev/null; then + echo "==> Running ktfmt" + find . -name "*.kt" -not -path "./buildSrc/build/*" -print0 | xargs -0 -r ktfmt --kotlinlang-style "$@" +else + echo "==> Running gradlew format" + ./gradlew format +fi diff --git a/scripts/lint b/scripts/lint index e3a5f5e24..5837798cf 100755 --- a/scripts/lint +++ b/scripts/lint @@ -4,5 +4,10 @@ set -e cd "$(dirname "$0")/.." -echo "==> Build classes" -./gradlew build testClasses -x test +if command -v ktfmt &> /dev/null; then + echo "==> Checking ktfmt" + ./scripts/format --dry-run --set-exit-if-changed +else + echo "==> Running gradlew lint" + ./gradlew lint +fi diff --git a/scripts/mock b/scripts/mock index d2814ae6a..0b28f6ea2 100755 --- a/scripts/mock +++ b/scripts/mock @@ -21,7 +21,7 @@ echo "==> Starting mock server with URL ${URL}" # Run prism mock on the given spec if [ "$1" == "--daemon" ]; then - npm exec --package=@stainless-api/prism-cli@5.8.5 -- prism mock "$URL" &> .prism.log & + npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL" &> .prism.log & # Wait for server to come online echo -n "Waiting for server" @@ -37,5 +37,5 @@ if [ "$1" == "--daemon" ]; then echo else - npm exec --package=@stainless-api/prism-cli@5.8.5 -- prism mock "$URL" + npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL" fi diff --git a/scripts/test b/scripts/test index 6b750a74e..047bc1dbb 100755 --- a/scripts/test +++ b/scripts/test @@ -43,7 +43,7 @@ elif ! prism_is_running ; then echo -e "To run the server, pass in the path or url of your OpenAPI" echo -e "spec to the prism command:" echo - echo -e " \$ ${YELLOW}npm exec --package=@stoplight/prism-cli@~5.3.2 -- prism mock path/to/your.openapi.yml${NC}" + echo -e " \$ ${YELLOW}npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock path/to/your.openapi.yml${NC}" echo exit 1 @@ -53,4 +53,4 @@ else fi echo "==> Running tests" -./gradlew test +./gradlew test "$@" diff --git a/settings.gradle.kts b/settings.gradle.kts index 5bb85382d..bf84b730f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,14 @@ rootProject.name = "orb-kotlin-root" -include("orb-kotlin") -include("orb-kotlin-client-okhttp") -include("orb-kotlin-core") -include("orb-kotlin-example") +val projectNames = rootDir.listFiles() + ?.asSequence() + .orEmpty() + .filter { file -> + file.isDirectory && + file.name.startsWith("orb-kotlin") && + file.listFiles()?.asSequence().orEmpty().any { it.name == "build.gradle.kts" } + } + .map { it.name } + .toList() +println("projects: $projectNames") +projectNames.forEach { include(it) }